Skip to content

Commit 5af7da1

Browse files
committed
very wip: finite for all intro
1 parent 6845db6 commit 5af7da1

File tree

7 files changed

+198
-34
lines changed

7 files changed

+198
-34
lines changed

src/decidable/FormulaCode.ard

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@
1414
| code-encode => formulaCode-encode
1515
| code-decode => formulaCode-decode
1616
| decideCode => formulaCode-decide
17-
\where {
18-
\func FormulaCode {_ : Language} {c : Context} (a b : Formula c) : \Prop \elim a, b
19-
| equal a b, equal a1 b1 => \Sigma (a = a1) (b = b1)
20-
| atomic r terms, atomic r1 terms1 => \Sigma (r = r1) (terms = {Array (Term c)} terms1)
21-
| notH a, notH b => FormulaCode a b
22-
| impH a a1, impH b b1 => \Sigma (FormulaCode a b) (FormulaCode a1 b1)
23-
| cAnd a a1, cAnd b b1 => \Sigma (FormulaCode a b) (FormulaCode a1 b1)
24-
| forAllH a, forAllH b => FormulaCode a b
25-
| cExists a, cExists b => FormulaCode a b
26-
| _, _ => Empty
17+
\where {
18+
\func FormulaCode {_ : Language} {c : Context} (a b : Formula c) : \Prop \elim a, b
19+
| equal a b, equal a1 b1 => \Sigma (a = a1) (b = b1)
20+
| atomic r terms, atomic r1 terms1 => \Sigma (r = r1) (terms = {Array (Term c)} terms1)
21+
| notH a, notH b => FormulaCode a b
22+
| impH a a1, impH b b1 => \Sigma (FormulaCode a b) (FormulaCode a1 b1)
23+
| cAnd a a1, cAnd b b1 => \Sigma (FormulaCode a b) (FormulaCode a1 b1)
24+
| forAllH a, forAllH b => FormulaCode a b
25+
| cExists a, cExists b => FormulaCode a b
26+
| _, _ => Empty
2727

28-
\func formulaCode-encode {_ : Language} {c : Context} {a b : Formula c} (p : a = b) : FormulaCode a b
28+
\func formulaCode-encode {_ : Language} {c : Context} {a b : Formula c} (p : a = b) : FormulaCode a b
2929
\elim a, b, p
3030
| equal a b, _, idp => (idp, idp)
3131
| atomic r terms, _, idp => (idp, idp)
@@ -35,7 +35,7 @@
3535
| forAllH a1, _, idp => formulaCode-encode idp
3636
| cExists a, _, idp => formulaCode-encode idp
3737

38-
\func formulaCode-decode {_ : Language} {c : Context} {a b : Formula c} (code : FormulaCode a b) : a = b
38+
\func formulaCode-decode {_ : Language} {c : Context} {a b : Formula c} (code : FormulaCode a b) : a = b
3939
\elim a, b, code
4040
| equal a b1, equal a1 b, (p,p1) => pmap2 equal p p1
4141
| atomic r terms, atomic _ terms1, (idp,p1) => pmap (atomic r) (convertArrayEquality p1)
@@ -45,7 +45,7 @@
4545
| forAllH a, forAllH b, code => pmap forAllH $ formulaCode-decode code
4646
| cExists a, cExists b, code => pmap cExists $ formulaCode-decode code
4747

48-
\func formulaCode-decide {L : DecLanguage} {c : Context} (a b : Formula c) : Dec (FormulaCode a b)
48+
\func formulaCode-decide {L : DecLanguage} {c : Context} (a b : Formula c) : Dec (FormulaCode a b)
4949
\elim a, b
5050
| equal a b, equal a1 b1 => \case TermCodeDec.decideEq a a1, TermCodeDec.decideEq b b1 \with {
5151
| yes e, yes e1 => yes (e, e1)

src/proof/PrfFinite.ard

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
\import Function.Meta
22
\import Logic
33
\import Paths
4+
\import Paths.Meta
45
\import Set
56
\import Set.Fin
67
\import Set.Subset
@@ -9,12 +10,19 @@
910
\import proof.PrfWeaken
1011
\import proof.Proof
1112
\import syntax.Context
13+
\import syntax.Free
14+
\import syntax.Lift
1215
\import syntax.Substitution
1316
\import syntax.Syntax
1417
\import util.SetUtil
1518

1619
\func prfFinite {_ : DecLanguage} {c : Context} {axioms : Theory c} {toShow : Formula c}
17-
(prf : Prf axioms toShow) : \Sigma (axioms' : Theory c) (axioms' ⊆ axioms) (FinSet (Elements axioms')) (Prf axioms' toShow)
20+
(prf : Prf axioms toShow) :
21+
\Sigma
22+
(axioms' : Theory c)
23+
(axioms' ⊆ axioms)
24+
(FinSet (Elements axioms'))
25+
(Prf axioms' toShow)
1826
\elim prf
1927
| AXM e => (single toShow, SubsetHelper.subsetSingle e, FinSets.FinSingle, AXM idp)
2028
| contra f prf1 prf2 =>
@@ -163,3 +171,27 @@
163171
\let
164172
| h => prfFinite prf
165173
\in (h.1, h.2, h.3, cAndElim2 h.4 p)
174+
| forAllIntro f prf p =>
175+
\let
176+
| h => prfFinite prf
177+
| h3 : FinSet (Elements h.1) => h.3
178+
-- | ourSet : Set (Formula c) => mapSet' h.1 (liftFormula 1)
179+
| zeroNotFreeInH1 : 0 ∉ {Fin (suc c)} freeVars h.1 => \case \elim __ \with {
180+
| inP (f, e, free) => \case h.2 e \with {
181+
| inP (f', e', p') => notFreeInLift $ rewriteI p' $ free
182+
}
183+
}
184+
| ourSet : Set (Formula c) => mapSet h.1 (\lam x xe => liftFormula.unliftFormula1 x (\lam free => zeroNotFreeInH1 (inP (x, xe, free))))
185+
\in (
186+
ourSet,
187+
-- \lam e => \case h.2 e \with {
188+
-- | inP (x', e', p') => \let z => liftFormula.unliftPath 1 p' \in rewrite z e'
189+
-- },
190+
\lam {x} => \case \elim x, \elim __ \with {
191+
| _, inP (f, e, idp) => \case h.2 {f} e \with {
192+
| inP (f', e', p') => \let p'' => p' \in {?}
193+
}
194+
},
195+
{?},
196+
forAllIntro f {?} p
197+
)

src/semantics/Interpretation.ard

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@
145145
\func lifted {_ : Language} {c : Context} {I : Interpretation c} {f : Formula c}
146146
{u : I.structure.Universe}
147147
(m : I ⊧ f) (dummy : Term c)
148-
: extend I u ⊧ liftFormula {_} {1} f => fromSub.substitutionLemma->
148+
: extend I u ⊧ liftFormula 1 f => fromSub.substitutionLemma->
149149
{_}
150-
{suc c} {c} {liftFormula {_} {1} f}
150+
{suc c} {c} {liftFormula 1 f}
151151
I {extend I u} {reverseLift.reverse1S dummy}
152152
(\lam v free => \case \elim v, \elim free \with {
153153
| 0, free => absurd $ notFreeInLift free

src/syntax/Free.ard

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
\import Data.Fin
2-
\import Function.Meta
32
\import Logic
43
\import Logic.Meta
54
\import Meta
5+
\import Set.Subset
66
\import syntax.Context
77
\import syntax.Lift
88
\import syntax.Substitution
99
\import syntax.Syntax
10-
\import util.NatUtil
10+
\import util.SetUtil
1111

1212
\func FreeinTerm {_ : Language} {c : Context} (t : Term c) (v : Context.variable c) : \Prop
1313
\elim t
@@ -57,8 +57,18 @@
5757
}) h
5858

5959
\func notFreeInLift {_ : Language} {c : Context} {f : Formula c}
60-
(h : FreeInFormula (liftFormula {_} {1} f) 0)
60+
(h : FreeInFormula (liftFormula 1 f) 0)
6161
: Empty
6262
=> notFreeInRename
6363
(\lam v' (p : 0 = {Fin (suc c)} suc v') => usingOnly p contradiction)
64-
h
64+
h
65+
66+
\func freeVarsFormula {_ : Language} {c : Context} (f : Formula c) : Set (Context.variable c)
67+
=> \lam v => FreeInFormula f v
68+
69+
\func freeVars {_ : Language} {c : Context} (T : Theory c) : Set (Context.variable c)
70+
=> \lam v => ∃ (f : Formula c) (f ∈ T) (FreeInFormula f v)
71+
72+
73+
\func RenameFreeTerm {_ : Language} (c c' : Context) (t : Term c) => \Pi (v : Context.variable c) (FreeinTerm t v) -> Context.variable c'
74+
\func RenameFree {_ : Language} (c c' : Context) (f : Formula c) => \Pi (v : Context.variable c) (FreeInFormula f v) -> Context.variable c'

src/syntax/Lift.ard

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
\import Data.Fin
22
\import Function.Meta
3+
\import Logic
34
\import Meta
45
\import Paths
56
\import Paths.Meta
67
\import syntax.Context
8+
\import syntax.Free
79
\import syntax.Substitution
810
\import syntax.SubstitutionReverse
911
\import syntax.Syntax
@@ -25,6 +27,11 @@
2527
\elim delta
2628
| 0 => idp
2729
| suc delta => pmap suc isActuallyJustAddition
30+
31+
\func unliftFinPath {delta n : Nat} {i j : Fin n} (p : liftFin i = {Fin (delta + n)} liftFin j) : i = j
32+
\elim delta
33+
| 0 => p
34+
| suc delta => \let p' => unfsuc p \in unliftFinPath p'
2835
}
2936

3037
\func liftTerm {_ : Language} {delta c : Context} (t : Term c) : Term (delta + c) =>
@@ -40,17 +47,29 @@
4047
unfold liftTerm Rename.renameTerm.compose
4148
}
4249

43-
\func liftFormula {_ : Language} {delta c : Context} (f : Formula c) : Formula (delta + c) =>
50+
\func liftFormula {_ : Language} (delta : Context) {c : Context} (f : Formula c) : Formula (delta + c) =>
4451
Rename.rename f (\lam v => liftFin v)
4552
\where {
4653
\private \func example {_ : Language} :
47-
liftFormula {_} {2} (forAllH $ forAllH (equal #0 #1)) = {Formula 5}
54+
liftFormula 2 (forAllH $ forAllH (equal #0 #1)) = {Formula 5}
4855
(forAllH $ forAllH $ equal #0 #1) => idp
56+
57+
\func unliftFormula1 {_ : Language} {c : Context}
58+
(f : Formula (suc c))
59+
(h : Not (FreeInFormula f 0))
60+
: Formula c
61+
=> Rename.renameFree f (\lam (v : Fin (suc c)) free => \case \elim v, \elim free \with {
62+
| 0, free => absurd $ h free
63+
| suc v, _ => v
64+
})
65+
66+
\func unliftPath {_ : Language} (delta : Context) {c : Context} {f f' : Formula c} (p : liftFormula delta f = liftFormula delta f')
67+
: f = f' => Rename.unrename liftFin.unliftFinPath p
4968
}
5069

5170
\func reverseLift {_ : Language} {c : Context} {f : Formula c} (dummy : Term c)
52-
: Substitution.substitute (liftFormula {_} {1} f) (reverse1S dummy) = f =>
53-
reverseRename (\lam v => liftFin {1} v) (reverse1S dummy) (\lam t => reverseTerm)
71+
: Substitution.substitute (liftFormula 1 f) (reverse1S dummy) = f =>
72+
reverseRename (\lam v => liftFin {1} v) (reverse1S dummy) (\lam _ => reverseTerm)
5473
\where {
5574
\func reverse1S {_ : Language} {c : Context} (dummy : Term c) : Substitution (suc c) c =>
5675
\lam v => \case \elim v \with {
@@ -65,7 +84,7 @@
6584
| apply f args => pmap (apply f) (ext $ ext (\lam j => reverseTerm {_} {c} {args j}))
6685
}
6786

68-
\func liftTheory {_ : Language} {delta c : Context} (T : Theory c) : Theory (delta + c) => mapSet T liftFormula
87+
\func liftTheory {_ : Language} {delta c : Context} (T : Theory c) : Theory (delta + c) => mapSet T (\lam f _ => liftFormula delta f)
6988

7089
\func subsituteLiftTerm1S {_ : Language} {c c' : Context} {t : Term c} {s : Substitution (suc c) c'}
7190
: Substitution.substituteTerm (liftTerm {_} {1} t) s = Substitution.substituteTerm t (\lam v => s (fsuc v))

src/syntax/Substitution.ard

Lines changed: 88 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
\import Data.Fin
22
\import Function
33
\import Function.Meta
4+
\import Logic
5+
\import Logic.Meta
46
\import Meta
57
\import Paths
68
\import Paths.Meta
9+
\import decidable.FormulaCode
10+
\import decidable.TermCode
711
\import syntax.Context
12+
\import syntax.Free
813
\import syntax.Lift
914
\import syntax.Syntax
15+
\import util.ArrayUtil
1016
\open Context
1117
\open Nat (+)
1218

@@ -52,6 +58,11 @@
5258
| apply f args => pmap (apply f) $ ext $ ext (\lam j => compose {_} {c} {c'} {c''} {args j})
5359
}
5460

61+
\func renameTermFree {_ : Language} {c c' : Context} (t : Term c) (remap : RenameFreeTerm c c' t) : Term c'
62+
\elim t
63+
| var v => var $ remap v idp
64+
| apply f args => apply f (\lam i => renameTermFree (args i) (\lam v free => remap v (inP (i, free))))
65+
5566
\func rename {_ : Language} {c c' : Context} (f : Formula c) (r : Rename c c') : Formula c'
5667
\elim f
5768
| equal a b => equal (renameTerm a r) (renameTerm b r)
@@ -61,6 +72,79 @@
6172
| cAnd a b => cAnd (rename a r) (rename b r)
6273
| forAllH f => forAllH $ rename f (Extend.extend r)
6374
| cExists f => cExists $ rename f (Extend.extend r)
75+
76+
-- same as above but we additionally guarantee r is only applied on the free vars
77+
\func renameFree {_ : Language} {c c' : Context} (f : Formula c) (r : RenameFree c c' f) : Formula c'
78+
\elim f
79+
| equal a b => equal (renameTermFree a (\lam v free => r v (byLeft free))) (renameTermFree b (\lam v free => r v (byRight free)))
80+
| atomic rel terms => atomic rel $ \lam i => renameTermFree (terms i) {?}
81+
| notH f => notH $ renameFree f r
82+
| impH antecedent consequent => impH (renameFree antecedent r) (renameFree consequent r)
83+
| cAnd a b => cAnd (renameFree a r) (renameFree b r)
84+
| forAllH f => forAllH $ renameFree f (Extend.extend r)
85+
| cExists f => cExists $ renameFree f (Extend.extend r)
86+
87+
\func unrenameTerm {_ : Language} {c c' : Context} {t t' : Term c} {r : Rename c c'}
88+
(rInj : \Pi {v v' : variable c} (r v = r v') -> v = v')
89+
(p : renameTerm t r = renameTerm t' r) : t = t'
90+
\elim t, t', p
91+
| var v, var v1, p => \let p' => TermCodeDec.termCode-encode p \in pmap var $ rInj p'
92+
| apply f args, apply f1 args1, p =>
93+
\let
94+
| (p1, p2) => TermCodeDec.termCode-encode p
95+
\in \case \elim f1, \elim args1, p1, p2 \with {
96+
| _, args1, idp, p2 => pmap
97+
(apply f)
98+
(ext $ ext (\lam j => \let p2' => convertArrayEquality p2 | p2Result => pmap (\lam (z : Array _ _) => z j) p2' \in unrenameTerm rInj p2Result))
99+
}
100+
101+
\func unrename {_ : Language} {c c' : Context} {f f' : Formula c} {r : Rename c c'}
102+
(rInj : \Pi {v v' : variable c} (r v = r v') -> v = v')
103+
(p : rename f r = rename f' r) : f = f'
104+
\elim f, f', p
105+
| equal a b, equal a1 b1, p => \let (p1, p2) => FormulaCodeDec.formulaCode-encode p \in
106+
pmap2 equal (unrenameTerm rInj p1) (unrenameTerm rInj p2)
107+
| atomic r1 terms, atomic r2 terms1, p =>
108+
\let
109+
| (p1, p2) => FormulaCodeDec.formulaCode-encode p
110+
\in \case \elim r2, \elim terms1, p1, p2 \with {
111+
| _, _, idp, p2 => pmap
112+
(atomic r1)
113+
(ext $ ext (\lam j => \let p2' => convertArrayEquality p2 | p2Result => pmap (\lam (z : Array _ _) => z j) p2' \in unrenameTerm rInj p2Result))
114+
}
115+
| notH f, notH f', p =>
116+
\let p' => FormulaCodeDec.formulaCode-decode $ FormulaCodeDec.formulaCode-encode p
117+
\in pmap notH $ unrename rInj p'
118+
| impH a f, impH a1 f', p =>
119+
\let
120+
| (p1, p2) => FormulaCodeDec.formulaCode-encode p
121+
| p1' => FormulaCodeDec.formulaCode-decode p1
122+
| p2' => FormulaCodeDec.formulaCode-decode p2
123+
\in pmap2 impH (unrename rInj p1') (unrename rInj p2')
124+
| cAnd a f, cAnd a1 f', p =>
125+
\let
126+
| (p1, p2) => FormulaCodeDec.formulaCode-encode p
127+
| p1' => FormulaCodeDec.formulaCode-decode p1
128+
| p2' => FormulaCodeDec.formulaCode-decode p2
129+
\in pmap2 cAnd (unrename rInj p1') (unrename rInj p2')
130+
| forAllH f, forAllH f', p =>
131+
\let
132+
| p' => FormulaCodeDec.formulaCode-decode $ FormulaCodeDec.formulaCode-encode p
133+
\in pmap forAllH (unrename (\lam {v : variable (suc c)} {v' : variable (suc c)} p => \case \elim v, \elim v', \elim p \with {
134+
| 0, 0, p => idp
135+
| 0, suc f1, p => \let p : 0 = suc _ => p \in usingOnly p contradiction
136+
| suc f1, 0, p => \let p : suc _ = 0 => p \in usingOnly p contradiction
137+
| suc f1, suc f2, p => \let p' => unfsuc p \in pmap fsuc (rInj p')
138+
}) p')
139+
| cExists f, cExists f', p =>
140+
\let
141+
| p' => FormulaCodeDec.formulaCode-decode $ FormulaCodeDec.formulaCode-encode p
142+
\in pmap cExists (unrename (\lam {v : variable (suc c)} {v' : variable (suc c)} p => \case \elim v, \elim v', \elim p \with {
143+
| 0, 0, p => idp
144+
| 0, suc f1, p => \let p : 0 = suc _ => p \in usingOnly p contradiction
145+
| suc f1, 0, p => \let p : suc _ = 0 => p \in usingOnly p contradiction
146+
| suc f1, suc f2, p => \let p' => unfsuc p \in pmap fsuc (rInj p')
147+
}) p')
64148
}
65149

66150
\func Substitution {_ : Language} (c c' : Context) => variable c -> Term c'
@@ -84,6 +168,7 @@
84168
}
85169

86170
-- TODO: this proof seems very complicated. What is the general principle?
171+
87172
\func distributeExtends {_ : Language} {c c' c'' : Context} {s : Substitution c c'} {s' : Substitution c' c''} :
88173
(\lam v => substituteTerm (Extend.extends s v) (Extend.extends s')) = {Substitution (suc c) (suc c'')}
89174
Extend.extends (\lam v => substituteTerm (s v) s') => ext (helper s s')
@@ -101,9 +186,9 @@
101186

102187
\private \func helper2 {_ : Language} {c' c'' : Context} (t : Term c') (s' : Substitution c' c'') :
103188
substituteTerm (Rename.renameTerm t fsuc) (Extend.extends s') = Rename.renameTerm (substituteTerm t s') fsuc
104-
\elim t
105-
| var v => idp
106-
| apply f args => pmap (apply f) (ext $ ext (\lam j => helper2 (args j) s'))
189+
\elim t
190+
| var v => idp
191+
| apply f args => pmap (apply f) (ext $ ext (\lam j => helper2 (args j) s'))
107192
}
108193

109194
\func substitute {_ : Language} {c c' : Context} (f : Formula c) (s : Substitution c c') : Formula c'

0 commit comments

Comments
 (0)