-
Notifications
You must be signed in to change notification settings - Fork 1
/
grammar.ebnf
187 lines (109 loc) · 4.29 KB
/
grammar.ebnf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
(* types *)
type_op = '⨯' | '→'
typ = id | (typ) | typ type_op typ
of_type = ':' | '∈'
id_type = id of_type typ
id_opt_type = id [of_type typ]
ids_type = id {',' id}+ of_type typ
(* reasons *)
theorem_num = number {'.' number} ['(' letter ')']
reference =
('axiom' | 'lemma' | 'theorem') theorem_num |
'part (' number ')' ['of this theorem']
reason = (('by' | 'using') reference) | 'by hypothesis'
(* terms *)
term =
sym | id '(' expr {, expr} ')' | var | '(' expr ')'
| '{' var of_type typ '|' proposition '}'
terms = term+
(* expressions *)
binary_op = '·' | '+' | '-' | '∈'
base_expr = terms |
base_expr binary_op base_expr |
'-' base_expr |
base_expr ':' typ
eq_op = '=' | '≠' | '<' | '≤' | '>' | '≥' | '≮'
expr = base_expr { eq_op base_expr [reason] }
atomic = expr ['is true' | 'always holds']
(* small propositions *)
prop_op = 'and' | 'or' | 'implies' | 'if and only if' | ', and' | ', or'
small_prop = atomic | small_prop prop_op small_prop | small_prop 'for all' id_type
(* propositions *)
if_then_prop = 'if' small_prop 'then' small_prop
either_or_prop = 'either' small_prop
for_all_ids = 'For all' ids_type ','
for_all_prop = for_all_ids proposition
there_exists = 'There' ('is' | 'are' | 'exists' | 'exist')
exists_prop =
there_exists ['some' | 'no'] ids_type ['with' small_prop]
'such that' proposition
precisely_prop = ('Exactly' | 'Precisely') 'one of' small_prop 'holds'
cannot_prop = 'It cannot be that' proposition
proposition =
for_all_prop | exists_prop | if_then_prop |
either_or_prop | precisely_prop | cannot_prop |
small_prop
(* top propositions *)
let_prop = 'Let' id_type '.' top_prop
suppose = 'Suppose that' proposition {[','] 'and that' proposition}
suppose_then = suppose '.' 'Then' proposition
top_prop = let_prop | suppose_then | proposition
(* proposition lists *)
label = (letter | number) '.'
top_sentence = top_prop '.'
proposition_item = label top_sentence ['(' word ')']
prop_items = proposition_item+
top_prop_or_items = prop_items | top_sentence
propositions = [for_all_ids] top_prop_or_items
(* axioms *)
operation = ('a' | 'an') ['binary' | 'unary'] ('operation' | 'relation')
axiom_decl = 'a type' id |
(('an element' | 'a function' | operation) id_or_sym of_type typ)
axiom_group = 'Axiom' int '.'
there_exists axiom_decl {('and' | 'with') axiom_decl}
('such that' propositions | '.')
(* definitions *)
eq_definition = 'Let' sym ':' typ '=' term '.'
relation_definition = ['we write'] id sym id 'iff' proposition '.'
definition = 'Definition.'
({eq_definition}+ | for_all_ids {relation_definition})
(* proofs *)
so = 'hence' | 'so' | 'then' | 'therefore' |
'which implies' ['that'] | 'which means that'
have = 'clearly' |
'it' ['then'] 'follows' ['from' reference | reason] 'that' |
'the only alternative is' |
'we conclude that' | 'we deduce that' | 'we have' | 'we know that' |
'we must have' | 'we see that'
so_or_have = so | [reason] have
contra = ',' ['which is'] ['again' | 'also' | 'similarly'] 'a contradiction' ['to' theorem_ref]
proof_prop = (reason [','] [have] proposition |
[have] proposition [reason]) [contra]
proof_if_prop = 'if' small_prop [','] 'then' proof_prop {',' so proof_prop}
and_or_so = 'and' [so] | so
will_show =
'We will' ('show' | 'deduce') 'that' | 'We start by showing that'
assert_step =
proof_if_prop |
'Since' proof_prop ',' proof_prop |
will_show proposition |
'The result follows' reason |
[and_or_so] proof_prop
assert_steps = assert_step {',' and_or_so proof_prop}
now = 'Conversely' | 'First' | 'Finally' | 'Next' | 'Now' |
'In either case' | 'Putting the cases together'
let_step = 'let' ids_type ['with' small_prop]
let_val_step = 'let' id_opt_type '=' term
assume_step = suppose
let_or_assume = let_val_step | let_step | assume_step
let_or_assumes = let_or_assume {", and" let_or_assume}
proof_clause = [now [,]] (let_or_assumes | assert_steps)
proof_sentence = proof_clause {';' proof_clause} '.'
proof_steps = proof_sentence+
proof_item = label proof_steps
proofs = 'Proof.' (proof_item+ | proof_steps)
(* theorems *)
theorem_group = ('Lemma' | 'Theorem') int '.' ['Let' ids_type '.']
top_prop_or_items [proofs]
(* program *)
program = {axiom_group | definition | theorem_group}