[Skip Navigation] [CSUSB] / [CNS] / [Comp Sci Dept] / [R J Botting] / [Samples] / math.syntax
[Index] [Contents] [Source Text] [About] [Notation] [Copyright] [Comment/Contact] [Search ]
Tue Sep 18 15:26:14 PDT 2007

# MATHS - Discrete mathematics in ASCII

## Introduction

This document is a syntax summary of the MATHS notation. The MATHS notation is designed so that mathemtical formulae and definitions can be expressed in a palatable form by software developers in ASCII.

It contains more than the norml Bachus-Normal-Form grammar because a lot of special names need to be given meaning as well as syntax.

This document is a collection of formal (mathematical BNF-style) definitions and assertions. There are less formal introductions that may be easier to understand: [ intro_characters.html ] and [ intro_ebnf.html ] elsewhere.

## Lexemes

[ math.lexicon.html ]

## Syntax of Documentation

1. documentation::=#(formal | break | directive | gloss | (label| ) comment ).
2. formal::=formula | formal_definition | declaration | assertion.
3. double_colon::=colon colon.
4. colon::=":".
5. definition::=formal_definition | gloss.
6. formal_definition::=(for_clause (condition | ) | )term double_colon (context | )"="expression ender,
7. gloss::= term double_colon (context | )"=" (balanced ~ expression) ender.
8. balanced::= See http://www.csci.csusb.edu/dick/maths/notn_12_Expressions.html#balanced.
9. ender::= "." | ",".
10. declaration::= O(for_clause O(condition ))term double_colon context ender.
11. assertion::= axiom | theorem.
12. axiom::= "|" "-" O(name)well_formed_formula.
13. formula::=indentation O(name) expression.
14. theorem::= O(indentation) why "|" "-" O(name)well_formed_formula.
15. why::="(" L(reason) ")".
16. name::="(" label ")" ":" .
17. reason::= label | term | ... .
18. for_clause::= "For" bindings ",".
19. condition::= ("If"|"if") wff "," .

20. break::=two or more end of lines.
21. indentation::= a tab at the start of a line followed by other white space.
22. paragraph_indentation::= A space at the start of a line.
` 		Start of line (continuation of paragraph)`
` 		(label): display and name a formula`
` 			tab displays  a formula, if at start of line`
` 		 Space starts a paragraph, item,...`
23. directive::=a line starting with a dot indicating structure and/or meaning.

24. well_formed_formula::=wff.
25. wff::= See http://csci.csusb.edu/dick/maths/notn_13_Docn_Syntax.html#wff.

## Glossaries

A glossary describes a set of words in terms of other words. The syntax similar to that of a dictionary or grammar, but with less restricted definitions.
26. glossary::= #(gloss).

## Grammars

27. grammar::= #( simple_definition | comment ),
28. simple_definition::=(defined_term"::="set_expression),
29. set_expression::= item #("&" item ),
30. each item expresses a different constraint on the set of ok strings
31. item::= element | defined_term | "("selection ")" | syntax_macro,
32. selection::= alternative #( "|" alternative ),
33. any alternative is a possible form for the set of ok strings.
34. alternative::= complementary_form | sequence,
35. sequence::= #phase ,
36. each phase is part of the whole sequence, in the same order.
37. phase::= item | option | any_number_of | syntax_macro,
38. option::= "O" item ,
39. any_number_of::="#" item, -- including zero.
40. complementary_form::= item "~" item,
41. it must satisfy the first item but not the second.
42. comment::= (#character )~formal,

43. syntax_macro::= option | any_number_of | ..., [ Syntax Macros ] below.

44. element::lexeme=quote #(char~(quote| backslash)|backslash char) quote,
45. element::syntax=element.lexeme | defined_term_in_lexical_dictionary,
46. element::=Things which are not defined elsewhere.
47. defined_term::= (natural_identifier | mathematical_identifier).
48. natural_identifier::=( (letter | digit) #identifier_character) & ( #identifier_character (letter|digit)) & correctly_spelled & defined.
49. identifier_character::=(letter | digit | underscore).

50. correctly_spelled::=#(word | number | underscore).

51. word::=(letter letter #letter) & dictionary.

## Syntax Macros

The following are syntactic macroes - they map one or two sets of strings into a more complex set. The argument is shown as an underscore (_). When there are two arguments they are (1st) and (2nd).
52. non::= character~{(_)},
53. O::= ((_)|),
54. O::=an optional (_).
55. #::=O((_) #(_)),
56. #::= any number of (_).
57. N::= (_) #(_),
58. N::=one or more of (_).
59. P::= "(" (_) #(comma (_)) ")". -- parameter package
60. R::="(" identifier "=>" (_) #( comma identifier "=>" (_) ) ")".
61. R::=record of (_).
62. L::= (1st)#((2nd) (1st)).
63. L::= List of (1st) separated by (2nd).
64. List::=(_) #( comma (_)),
65. List::=List of (_) separated by commas.

66. For x,n x^0="", x^1=1, x^n=x^(n-1).

## Shorthand and Algebra

67. mathematical_identifier::=letter (superscript|)(subscript|).
68. superscript::=prime::="'".
69. subscript::=(digit # digit| "[" expression "]").

Notice that shorthand is inherently personal, and not prepared for others to read. It is used as a personal Aide memoir.

## Expressions

MATHS has a number of predefined forms that are used to construct and define new kinds of expressions: infix, prefix, unary, infix, functional, ... . In the following (1st) stands for an expression and (2nd) for a set of operators or functions. Each definition defines a set of syntax forms like this PREFIX("-",numbers)="-" P(numbers).

Previous defined:

70. |- P(e)::= "(" (e) #(comma (e)) ")".

71. POSTFIX::=P((1st)) (2nd),
72. PREFIX::=(2nd) P((1st)),
73. CAMBRIDGE::="(" (2nd) #(1st) ")",
74. UNARY::= POSTFIX((1st), (2nd)) | PREFIX((1st), (2nd)),
75. INFIX::= "(" (1st) #((2nd) (1st)) ")" . In the following the 1st and 2nd arguments are expressions and the 3rd will be an operator:
76. RPN::=reverse_polish_notation::=(1st) (2nd) (3rd),
77. LISP2::=Cambridge_polish_notation::="(" (3rd) (1st) (2nd) ")",
78. BINARY::= "(" (1st) (3rd) (2nd) ")". In the next definition the argument is an expression
79. EXTENSION::="{" List((_)) "}",
80. EXTENSION::=Set described by listing elements.

The 1st argument is set_of_declarations, and the 2nd a set of expression,

81. LAMBDA::= "map" "[" (1st) "]" "(" (2nd) ")" .
82. INTENSION::= "{" (1st) "||" (2nd) "}",
83. INTENSION::=Set described by giving a rule rather than a list of elements.

84. For e:expressions, p:@(char><char), BRA-KET(e,p)::={ b e k || (b,k) :p }.

## Semantics of logical symbols

85. @::={true, false}.

86. not::@->@.

and, or, not,iff::infix(@,@,@).

if(1st)then(2nd) ::@><@->@.

87. not::=if (_) is true then false else true.
88. and::=True iff both (1st) and (2nd) are true.
89. or::=True if either (1st) or (2nd) is true.
90. iff::=True when (1st) = (2nd).
91. if__then__::=False only when the (1st) is true and (2nd) is false.

92. priority::= /(not, and, or, iff).

93. |- (E1): {and,or} are serial.

94. |- (E2): iff is_in parallel. Note - serial and parallel operators associate differently: Serial: P1 and P2 and P3 = (P1 and P2) and P3 = and(P1, P2, P3). Parallel: P1 iff P2 iff P3 = (P1 iff P2) and (P2 iff P3) = iff(P1, P2, P3).

95. (above)|-(@,or,false,and,true,not) in Boolean_algebra

96. For P=(P1 or P2 or P3 or,...) and Q =(Q1 and Q2, ...) then P :- Q ::= if Q then P.

(for all x:X(W(x))) ::=For all x of type X , W(x) is true,

(for x:X(W(x))) ::= for all x:X(W(x)),

(for no x:X(W(x))) ::=for all x:X(not W(x)),

(for some x:X(W(x))) ::=not for no x:X(W(x)).

(for 0..1 x:X(W(x))) ::=for all y,z:X(if W(y) and W(z) then y=z),

(for 1 x:X(W(x))) ::= for some x:X(W(x)) and for 0..1 x:X(W(x)),

(for 2 x:X(W(x))) ::= for some x:X(W(x)) and for 1 y:X(x<>y and W(y)).

(for 3 x:X(W(x))) ::= for some x:X(W(x)) and for 2 y:X(x<>y and W(y)).

etc.

## Sets

97. Natural::={1,2,3,...}.
98. Nat::=Natural.

99. Nat0::={0,1,2,3,...}.
100. Unsigned::=Nat0.

101. Integer::={...,-3,-2,-1,0,1,2,3,...}.
102. int::=Integer.
103. Int::=Integer.

104. Rational::=A Fraction with a numerator and a denominator that are integers.

105. Real::=The set of all possible numbers with decimals etc.

106. For i,j, i..j::={ k || i<=k<=j }.

107. For Type T, @T::= The sets of elements of type T.
108. For Type T, SetOf(T)::= @T.

109. For Type T, A,B:@T, A & B::={c || c in A and c in B},
110. For Type T, A,B:@T, A | B::={c || c in A or c in B},
111. For Type T, A,B:@T, A ~ B::={c || c in A and not( c in B) },

112. For Type T, A,B:@T, A==>B::= for all a:A(a in B),
113. |-For Type T, A,B:@T, A = B iff A==>B and B==>A,

114. For Type T, A,B:@T, A=>>B::= A==>B and not A=B.
115. For Type T, A,B:@T, A>==B::=( |B=A and for all X,Y:B(X=Y or X&Y={}) ),
116. For Type T, A,B:@T, A>==B iff for all a:A, one X in B(a in X).

117. For A:Sets, a:Elements, A|a::=A|{a},
118. For A:Sets, a:Elements, a|A::={a}|A, etc

119. For S:@T, @S::= { A:@T. A==>S}, the subsets of S.
120. For S, SetOf(S)::= @S.

121. For A,B:Sets, A><B::= \$ Net{1st:A, 2nd:B}, -- -- --(set of pairs)
122. For A,B:Sets, a:A, b:B, (a, b) ::=(1st=>a, 2nd=>b).
123. (above)|-For a,b, (a,b).1st=a and (a,b).2nd=b.
124. For A,B,C:Sets, A><B><C::= \$ Net{1st:A, 2nd:B, 3rd:C }.

125. For A,B,C:Sets,a:A,b:B,c:C, (a,b, c) ::A><B><C=(1st=>a, 2nd=>b, 3rd=>c).

## Lists

126. CAR::=1st,
127. CDR::=2nd,
128. CONS::=map[a,b](a,b).

## Functions

129. For A,B:Sets, functions(A,B)::= A->B ::=Set of functions taking objects of type A and returning objects of type B,
130. For A,B:Sets, A->B::=Functions returning a B when given an argument A.
131. For A,B:Sets, A><B->C::=Functions returning a C given an A and a B.
132. For A,B:Sets, A><B><C->D::=Functions returning a D given an A, B, and C.

## Families of Sets

133. For α:@Sets, |(α)::={a||for some A:α(a in A)}.
134. For α:@Sets, &(α)::={a||for all A:α( a in A )}.

135. For A,B:Sets, A are B::= A ==>B.
136. For A,B:Sets, A ==> B::= for all x:A (x in B).

137. For A,B:Sets, @B::= { A | A ==> B }.

138. For A,B:Sets, A=>>B::= A==>B and not A=B.

139. For T:Types, A:@T, Q :quantifiers, Q A::=for Q x:T (x in A). -- examples: no A, all A, some A indicate that A is empty, universal and has at least one item respectively.

## Relations

140. For Types T1,T2, R::@(T1><T2)={ (x,y) || x R y}.

141. For Types T1,T2, x:T1, R:@(T1,T2), x.R::= { y || x R y } .
142. For Types T1,T2, y:T2, R:@(T1,T2), y./R::= { x || x R y } .

143. For Types T1,T2, A:@T1, A.R::= { y || some a:A ( aRy) } .
144. For Types T1,T2, B:@T2, B./R::= { x || some b:B ( x R b) } .

145. For R, post(R)::=rng(R).
146. For R, rng(R)::=img(R).
147. For R, img(R)::=dom(R).R .
148. (above)|-post(R) = rng(R) = img(R) = |(R).
149. For R, pre(R)::=cor(R).
150. For R, cor(R)::=cod(R)./R.
151. (above)|-pre(R)=cor(R)=cod(R)./R = |(/R)

152. For R, S, (R; S) ::=rel[x:T1,y:T3] for some z(x R z and z S y) (where R :@(T1,T2), S:@(T2,T3) )
153. For R, S, R | S::=rel[x:T1,y:T3] (x R y or x S y)
154. For R, S, R & S::=rel[x:T1,y:T3] (x R y and x S y)

155. For R, inv(R)::={ Q:@dom(R) || Q.R ==> Q }.
156. For R, inv(R)::= the invariant sets of R:@(T1,T1).

157. For R, do(R)::=reflexive transitive closure of R.
158. For R, do(R)::=rel[x,y:dom(R)] for all Q:inv(R) (if x in Q then y in Q),

159. For R, no(R)::=rel[x,y:dom(R)](x=y and 0 x.R),

160. For T:Type, Id(T)::=rel[x,y:dom(R)](x=y ),

161. For T1,T2, abort::@(T1,T2)=T1><T2,
162. For T1,T2, fail::@(T1,T1)=rel[x,y:T1](false).

163. For T1,T2, R is nondeterministic::= for some x:dom(R), 2.. y:cod(R) ( x R y ).

ForU,V, U(Q1)-(Q2)V::= {R || for all x:U, Q2 y (x R y) & all y:V, Q1 x (x R y) }.

164. total::=(any)-(some).

## Functions and maps

165. many_1::= (any)-(0..1).

166. For A,B:Sets, A -> B::= A (any)-(1)B.

167. For x:binding, e:expression(T), map [x]e::=The map taking x into e,

168. Id::=map[x](x).identity mapping or function. (_) ::=Id.

169. For A,B, x,y, x+>y::={(x,y)} maplet.
170. For A,B, x,y, A+>y::={(x,y)||for some x:A}.

For f:A->B, f(x)=x.f=the f of x= the image of x under f.

171. f is one-one iff f in dom(f)(1)-(1)cod(f)

## Concatenation

172. A^n::= if n=0 then 1 else A A^(n-1).
173. #A::= {()}| A | A A | A A A | ... #A =|[i:0..]A^i = min{ B || (A B | ())==>B}

## Documentation and Nets

174. Net{ D } -- network of declarations, comments, assertions, definitions etc.
175. \$ Net{x:X, y:Y, ...}:= { (x=>a, y=>b,...) || a in X and b in Y and ...}

176. variables(U)::= {x,y,z,...}, the names of parts of U, variables act as maps.

For string D where Net{D} in documentation, \$ Net{D, W(v)}::= set v: \$ Net{D} satisfying W(v), \$ Net{D, W(v',v)}::= relation v,v': \$ Net{D} satisfying W(v',v).

For Name_of_documentation N,

177. \$(N)::=tpl of variables in documentation,
178. \$ N::=set of \$(N) that fit the documentation,
179. the N(P)::=the( \$ N and P) ::=the unique \$ N that also fits P,
180. @N::=collection of sets of objects that fit N,
181. %N::=lists of objects that fit the documentation,
182. #N::=strings of objects that fit the documentation,
183. Uses N::=Inserts a copy of N into current document.
184. definition(N)::=inserts a copy of the definition of N.
185. By N::=Derivation of theorem from axioms in N.
186. For Q N::=Assert contents of named documentation.
187. for Q N(wff)::=for Q x: \$ N (wff where x=\$(N)), @{N || for Q1 v1, ...}::= Set of sets of @N satisfying the Qs,
188. N(x=>a, y=>b,...)::=substitute in N,
189. N(for some x,...)::=hide x.. in N,
190. N.(x,y,z,...)::=hide all but x,y,z,....
191. For N1, N2:Name_of_documentation|set_of_documentation,
192. not N1::= complementary documentation to N1,
193. N1 o N2::=combine pieces of documentation,-- o is or,and,...
194. N1 and w::={D. w } where N is the name of Net{D}, N1 with { D2 } ::={D. D2 } where N is the name of Net{D}, S with { D2 } ::={D. D2 } where S is \$ N and N is the name of Net{D},
195. N1->N2::=Sets in @(N1 and N2) with N1 as an indentifier,
196. N1^N2::=maps from type \$ N2 to type \$ N1, N1(Q1)-(Q2)N1::= Relations between N1 and N2.

## Metaproperties of Documentation

197. symbol::@( Strings, Types, Values).

For s: documentation | name_of_documentation,

198. terms(s)::Sets=terms defined in s,
199. expressions(s)::Sets=expressions used to define terms in s,
200. definitions(s)::@(terms(s), types(s), expressions(s))= definitions in s,
201. declarations(s)::@(variables(s), types(s))= declared and defined types of variables in s,
202. types(s)::=types in declarations and definitions in s,
203. variables(s)::=symbols bound in declarations in s,
204. axioms(s)::=wffs assumed to be true | defined equalities,
205. assertions(s)::=(axioms(s) | theorems(s)).

## Operators

206. For X:Set, unary(X)::=X^X.

207. For X:Set, For f:unary(X), fix(f)::={ x:X || f(x)=x }.

208. infix(X)::= X^( X><X ).

For *:infix(X).

209. associative(X)::={* || for all x,y,z:X(x*(y*z)=(x*y)*z)},
210. commutative(X)::={* || for all x,y:X (x*y = y*x)},
211. idempotent(X)::={* || for all x:X (x*x = x)}.

212. For *:infix(X), units(X,*)::={u:X || x * u = u * x = x},
213. zeroes(X,*)::={z:X || for all x:X( z*x = x*z= z},
214. idempotents(X,*)::={i:X || i * i = i}.

For *:infix(X), x, y:X, (x*y) = (*)(x,y) = (x,y).(*).

215. For *:infix(X), x:X, (x*_) ::= map y:X(x*y), (_*x) ::= map y:X(y*x),

216. |-For *:infix(X), x:X, y:X, (x*_)(y)=y.(x*_)=(_*y)(x)=x.(_*y)=x*y in X,

## Types of Relations

Over the years various books and papers have defined a lot of different types of relations. The following are most of the ones I've collected in the last 35 year.

In the following, X is any set and Y is the set of all relations linking objects in X to objects in X. I is the identity relation, and 0 the empty relation.

217. For X:Sets, Y:=@(X,X), I:=Id(X), O:=fail.

218. For X, Y, Transitive(X)::={R:Y || R;R ==> R },
219. For X, Y, Reflexive(X)::={R:Y || I ==> R },
220. For X, Y, Irreflexive(X)::={R:Y || O = I & /R },
221. For X, Y, Antireflexive(X)::={R:Y || O = R & /R },
222. For X, Y, Dichotomettic(X)::={R:Y || Y >== {R, /R }},
223. For X, Y, Trichotomettic(X)::={R:Y || Y >== {R, /R, I}},
224. For X, Y, Symmetric(X)::= {R:Y || R = /R },
225. For X, Y, Antisymmetric(X)::={R:Y || R & /R = I},
226. For X, Y, Asymmetric(X)::={R:Y || R ==> Y~/R },
227. For X, Y, Total(X)::={R:Y || Y~R = /R },
228. For X, Y, Connected(X)::={R || Y~R= /R and R | /R = Y},
229. For X, Y, Regular(X)::= {R:Y || R; /R; R ==> R }.

230. For X:Sets, Right_limited(X)::= {R:Y || for no S:Nat-->X (R(S) ) }.
231. For X:Sets, Left_limited(X)::= {R:Y || for no S:Nat-->X ( /R(S) ) }.

232. For X:Sets, Serial(X)::= (Transitive(X)&Connected(X))~Reflexive( X).

233. For X:Sets, Strict_partial_order(X)::= Irreflexive(X) & Transitive(X).

234. For X:Sets, Partial_order(X)::= Reflexive(X) & Transitive(X) & Antisymmetric(X).

235. For X:Sets, Equivalences(X)::= Reflexive(X) & Symmetric(X) & Transitive(X).

236. For X,Y: Sets, R,S: @(X,Y), R is_more_defined_than S::= pre(S)==>pre(R) and for all x:pre(S) (x.R==>x.S). [Milietal89]

## Strings

237. For x,y:strings, x!y::string=concatenation of x and y.

238. For x:string, c:char, c?x::string=prefix c to x,

239. For x:string, c:char, x?c::string=put c at end of x.

240. For A,B: sets of strings, A B::={c | c=a!b and a in A and b in B},
241. For A: sets of strings, #A::=least{ X | X=({""} | A X) }.

242. For string s, s::@#char={s} .

Given a string s with n symbols in it then |s| ::=n,

243. head::=(_)(1) ::=the first symbol in (_),
244. tail::=all symbols except the first in (_),
245. |- (s1): if |s|>=1 then s=head(s)!tail(s) ,
246. last::=(_)(|(_)|).

247. For Set S, %(%S)::=two dimensional arrays of S's,
248. #(%S)::=%(S),
249. (note): %(%S) <> %(S),
250. lists(S)::=S| %S | %%S | %%%S | ... .