-
Notifications
You must be signed in to change notification settings - Fork 0
/
SecondOrderForm.agda
217 lines (188 loc) · 9.38 KB
/
SecondOrderForm.agda
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
module SecondOrderForm where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; cong; sym)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _∎; step-≡)
open import Relation.Nullary using (¬_)
open import Form
open import PrimaryAlgebra
open import PrimaryArithmetic
data SecondOrderForm (Form : Set) : Set₁ where
n⋆ : SecondOrderForm Form
_+:_ : Form → SecondOrderForm Form → SecondOrderForm Form
_+̂_ : SecondOrderForm Form → SecondOrderForm Form → SecondOrderForm Form
_+:[_]+:_ : SecondOrderForm Form → SecondOrderForm Form → SecondOrderForm Form → SecondOrderForm Form
infixr 15 _+:_
infixr 10 _+:[_]+:_
empty : SecondOrderForm Form
empty = n⋆
singular : SecondOrderForm Form
singular = n +: empty
numberList : SecondOrderForm Form
numberList = m +: singular
orderList : SecondOrderForm Form
orderList = n⋆ +:[ numberList ]+: (m +: n⋆)
evaluateList : SecondOrderForm Form → Form
evaluateList n⋆ = n
evaluateList (x +: xs) = x + (evaluateList xs)
-- evaluateList (x +: (x₁ +: eq)) = x + x₁ + (evaluateList eq)
evaluateList (eq +:[ eq₁ ]+: eq₂) = ((evaluateList eq) + ((evaluateList eq₁) * m)) + (evaluateList eq₂)
-- evaluateList (x +: (eq +:[ eq₁ ]+: eq₂)) = x + (evaluateList ((eq +:[ eq₁ ]+: eq₂)))
-- evaluateList (x +: (x₁ +̂ x₂)) = x + ((evaluateList x₁) + (evaluateList x₂))
evaluateList (x +̂ x₁) = (evaluateList x) + (evaluateList x₁)
-- * -- Theorem 10
theorem10case1 : ∀( r a : Form ) → (((a * m) * m) + r) ≡ (((a + r) * m ) * m )
theorem10case1 r a =
begin
((((a * m) * m) + r))
≡⟨ cong (_+ r) (reflexion a) ⟩
(a + r)
≡⟨ sym (reflexion (a + r)) ⟩
((((a + r) * m ) * m ))
∎
theorem10case2 : ∀( r a b : Form ) → ((((b * m ) + (a * m)) * m) + r) ≡ ((((b + r) * m ) + ((a + r) * m)) * m)
theorem10case2 r a b =
begin
((((b * m) + (a * m)) * m) + r)
≡⟨ sym (transposition b a r) ⟩
(((((b + r) * m) + ((a + r) * m)) * m))
∎
distributeR : SecondOrderForm Form → SecondOrderForm Form → SecondOrderForm Form
distributeR n⋆ _ = n⋆
distributeR (x +: list) r = n⋆
distributeR (list +̂ list₁) r = n⋆
distributeR (list +:[ list₁ ]+: list₂) r = list +:[ (list₁ +̂ r) ]+: distributeR list₂ r
rewriteListTh10 : SecondOrderForm Form → SecondOrderForm Form
rewriteListTh10 n⋆ = n⋆ +:[ n⋆ +:[ n⋆ ]+: n⋆ ]+: n⋆
rewriteListTh10 (x +: list) = n⋆ +:[ n⋆ +:[ (x +: (rewriteListTh10 list)) ]+: n⋆ ]+: n⋆
rewriteListTh10 (list +̂ list₁) = n⋆ +:[ n⋆ +:[ (list +̂ (rewriteListTh10 list₁)) ]+: n⋆ ]+: n⋆
rewriteListTh10 (list +:[ list₁ ]+: list₂) = n⋆ +:[ n⋆ +:[ (list₁ +̂ (rewriteListTh10 list₂)) ]+: n⋆ ]+: n⋆
example : SecondOrderForm Form
example = n⋆ +:[ m +: n⋆ ]+: (n⋆ +:[ m +: n⋆ ]+: (n⋆ +:[ m +: n⋆ ]+: n⋆))
exampleR : SecondOrderForm Form
exampleR = m +: (n +: n⋆)
evalEq : ∀ (x : Form) (xs : SecondOrderForm Form) → evaluateList (x +: xs) ≡ x + evaluateList (xs)
evalEq = λ x xs → begin
evaluateList (x +: xs)
≡⟨⟩
x + (evaluateList xs)
∎
LRidentity : ∀ (list : SecondOrderForm Form) → ((evaluateList (list)) * m) * m ≡ evaluateList ( n⋆ +:[ list ]+: n⋆ ) * m
LRidentity n⋆ = refl
LRidentity (x +: xs) =
begin
((evaluateList (x +: xs)) * m) * m
≡⟨⟩
(((x + evaluateList (xs)) * m) * m)
≡⟨⟩
{! !}
LRidentity (list +̂ list₁) = {! !}
LRidentity (list +:[ list₁ ]+: list₂) = {! !}
-- theorem10case3+ : ∀( r a b c : Form ) → (( ((( c ) + ( b * m )) + ( a * m )) * m ) * r ) ≡ (((( (((( c * m ) * m) + ( b * m )) * m) * m) + (a * m)) * m) * r)
-- theorem10case3+ r a b c =
-- begin
-- (((((c + (b * m)) + (a * m)) * m) * r))
-- ≡⟨ cong (_* r) (cong (_* m) (cong (_+ (a * m)) ( sym (reflexion ((c + (b * m))))))) ⟩
-- (((((((c + (b * m)) * m) * m) + (a * m)) * m) * r))
-- ≡⟨ cong (_* r) (cong (_* m) (cong (_+ (a * m)) (cong (_* m) (cong (_* m) (cong (_+ (b * m)) (sym (reflexion c))))))) ⟩
-- ((((( (((( c * m ) * m) + ( b * m )) * m) * m) + (a * m)) * m) * r))
-- ∎
-- -- theorem10case3+ : ∀( r a b c : Form ) → (( ((( c ) + ( b * m )) + ( a * m )) * m ) * r ) ≡ (((( (((( c * m ) * m) + ( b * m )) * m) * m) + (a * m)) * m) * r) a +: r +: n⋆ b +: r +: n⋆ c +: r +: n⋆ +:[ n⋆ ]+: +:[ n⋆ ]+:
-- theorem10case3+ : ∀ ( r a b : Form) (list : SecondOrderForm Form) → evaluateList ( n⋆ +:[ (( n⋆ +:[ a +: n⋆ ]+: n⋆ +:[ b +: n⋆ ]+: n⋆ ) +̂ ( list +̂ n⋆ ))]+: (r +: n⋆) ) ≡ evaluateList (n⋆ +:[ (n⋆ +:[ a +: r +: n⋆ ]+: n⋆ +:[ b +: r +: n⋆ ]+: n⋆ +:[ r +: list ]+: n⋆) ]+: n⋆)
-- theorem10case3+ r a b n⋆ = {! !}
-- theorem10case3+ r a b (x +: list) = {! !}
-- theorem10case3+ r a b (list +̂ list₁) = {! !}
-- theorem10case3+ r a b (list +:[ list₁ ]+: list₂) = {! !}
lemma2 : ∀ (list : SecondOrderForm Form) → evaluateList (n⋆ +:[ list ]+: n⋆) ≡ (evaluateList list) * m
lemma2 list =
begin
evaluateList (n⋆ +:[ list ]+: n⋆)
≡⟨⟩
n + ((evaluateList list) * m) + n
≡⟨ sym (identity-l (((evaluateList list) * m) + n)) ⟩
((evaluateList list * m) + n)
≡⟨ sym (identity-r ((evaluateList list * m))) ⟩
((evaluateList list) * m) ∎
lemma3 : ∀ (x : Form) (list : SecondOrderForm Form) → x + evaluateList (list) ≡ evaluateList (x +: list)
lemma3 x list =
begin
x + evaluateList (list)
≡⟨⟩
evaluateList (x +: list)
≡⟨⟩
(evaluateList (x +: list))
∎
lemma4 : ∀ (list : SecondOrderForm Form) → evaluateList (n⋆ +:[ n⋆ +:[ list ]+: n⋆ ]+: n⋆) ≡ ((evaluateList list) * m) * m
lemma4 list =
begin
evaluateList (n⋆ +:[ n⋆ +:[ list ]+: n⋆ ]+: n⋆)
≡⟨ lemma2 (n⋆ +:[ list ]+: n⋆) ⟩
(evaluateList (n⋆ +:[ list ]+: n⋆) * m)
≡⟨ cong (_* m) (lemma2 list) ⟩
(((evaluateList list) * m) * m)
∎
lemma5 : ∀ (x y : Form) (xs : SecondOrderForm Form) → rewriteListTh10 (x +: y +: xs) ≡ (n⋆ +:[ n⋆ +:[ x +: (n⋆ +:[ n⋆ +:[ y +: (rewriteListTh10 xs) ]+: n⋆ ]+: n⋆) ]+: n⋆ ]+: n⋆)
lemma5 x y xs =
begin
rewriteListTh10 (x +: y +: xs)
≡⟨⟩
(n⋆ +:[ n⋆ +:[ (x +: (rewriteListTh10 (y +: xs))) ]+: n⋆ ]+: n⋆)
≡⟨⟩
(n⋆ +:[ n⋆ +:[ (x +: (n⋆ +:[ n⋆ +:[ (y +: (rewriteListTh10 (xs))) ]+: n⋆ ]+: n⋆)) ]+: n⋆ ]+: n⋆)
≡⟨⟩
((n⋆ +:[ n⋆ +:[ (x +: (n⋆ +:[ n⋆ +:[ (y +: (rewriteListTh10 (xs))) ]+: n⋆ ]+: n⋆)) ]+: n⋆ ]+: n⋆))
∎
lemma1 : ∀ (list : SecondOrderForm Form) → evaluateList ( list ) ≡ evaluateList (rewriteListTh10 list)
lemma1 n⋆ = refl
lemma1 (x +: n⋆) =
begin
x + n
≡⟨ cong (x +_) (sym (reflexion n)) ⟩
x + ((n * m) * m)
≡⟨ sym (reflexion (x + ((n * m) * m))) ⟩
(((x + ((n * m) * m)) * m) * m)
≡⟨ cong (_* m) (identity-l (((x + ((n * m) * m)) * m))) ⟩
((( n + (x + ((n * m) * m)) * m) * m))
≡⟨ identity-l (((( n + (x + ((n * m) * m)) * m) * m))) ⟩
(n + ((( n + (x + ((n * m) * m)) * m) * m)))
∎
lemma1 (x +: x₁ +: list) =
begin
evaluateList (x +: x₁ +: list)
≡⟨⟩
(x + x₁ + (evaluateList list))
≡⟨ sym (reflexion (x + x₁ + (evaluateList list))) ⟩
(((x + x₁ + evaluateList list) * m) * m)
≡⟨ cong (_* m) (cong (_* m) (cong (x +_) (sym (reflexion (x₁ + evaluateList list))))) ⟩
(((x + (((x₁ + evaluateList list) * m) * m)) * m) * m)
≡⟨ cong (_* m) (cong (_* m) (cong (x +_) (cong (_* m) (cong (_* m) (cong (x₁ +_) (lemma1 list)))))) ⟩
((((x + (((x₁ + evaluateList (rewriteListTh10 list)) * m) * m)) * m) * m))
≡⟨ cong (_* m) (cong (_* m) (cong (x +_) (cong (_* m) (cong (_* m) ( lemma3 x₁ (rewriteListTh10 list) ))))) ⟩
((x + ((evaluateList (x₁ +: rewriteListTh10 list) * m) * m)) * m) * m
≡⟨ cong (_* m) (cong (_* m) (cong (x +_) (sym (lemma4 (x₁ +: rewriteListTh10 list))))) ⟩
((x + evaluateList (n⋆ +:[ n⋆ +:[ x₁ +: rewriteListTh10 list ]+: n⋆ ]+: n⋆)) * m) * m
≡⟨ cong (_* m) (cong (_* m) (lemma3 x (n⋆ +:[ n⋆ +:[ x₁ +: rewriteListTh10 list ]+: n⋆ ]+: n⋆))) ⟩
(((evaluateList (x +: (n⋆ +:[ n⋆ +:[ x₁ +: rewriteListTh10 list ]+: n⋆ ]+: n⋆))) * m) * m)
≡⟨ sym (lemma4 (x +: (n⋆ +:[ n⋆ +:[ x₁ +: rewriteListTh10 list ]+: n⋆ ]+: n⋆)) ) ⟩
evaluateList (n⋆ +:[ n⋆ +:[ x +: (n⋆ +:[ n⋆ +:[ x₁ +: (rewriteListTh10 list) ]+: n⋆ ]+: n⋆) ]+: n⋆ ]+: n⋆)
≡⟨ cong evaluateList (sym (lemma5 x x₁ list)) ⟩
evaluateList (rewriteListTh10 (x +: x₁ +: list))
∎
lemma1 (x +: (list +̂ list₁)) = {! !}
lemma1 (x +: (list +:[ list₁ ]+: list₂)) = {! !}
lemma1 (list +̂ list₁) = {! !}
lemma1 (list +:[ list₁ ]+: list₂) = {! !}
theorem10 : ∀ (list r : SecondOrderForm Form) → evaluateList ( n⋆ +:[ list ]+: r ) ≡ evaluateList (n⋆ +:[ (distributeR list r) ]+: n⋆ )
theorem10 n⋆ n⋆ = refl
theorem10 n⋆ (x +: r) = {! !}
theorem10 n⋆ (r +̂ r₁) = {! !}
theorem10 n⋆ (r +:[ r₁ ]+: r₂) = {! !}
theorem10 (x +: list) r = {! !}
theorem10 (list +̂ list₁) r = {! !}
theorem10 (list +:[ list₁ ]+: n⋆) r =
begin
(evaluateList (( n⋆ +:[ list +:[ list₁ ]+: n⋆ ]+: r ))
≡⟨⟩
{! !}
≡⟨⟩
{! !})
theorem10 (list +:[ list₁ ]+: list₂) r = {! !}