-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScratchpad.v
165 lines (139 loc) · 4.55 KB
/
Scratchpad.v
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
(* Set Implicit Arguments.
Set Asymmetric Patterns. *)
Require Import Unicode.Utf8.
CoInductive MaybeNat :=
| mn_0 : MaybeNat
| mn_S : MaybeNat -> MaybeNat.
Inductive LegitNat : MaybeNat -> Prop :=
| legit_0 : LegitNat mn_0
| legit_S n : LegitNat n -> LegitNat (mn_S n).
Print LegitNat_ind.
Lemma legit_pred n : LegitNat (mn_S n) -> LegitNat n.
intro lSn.
apply (@LegitNat_ind (λ m, ∀ p, (m = mn_S p) -> LegitNat p)) with (mn_S n); intros.
discriminate.
injection H1 as <-; assumption.
assumption.
reflexivity.
Show Proof.
Defined.
Definition lp_reduced := Eval cbv -[LegitNat_ind] in legit_pred.
Print lp_reduced.
Definition lp_reduced_manual n : LegitNat (mn_S n) -> LegitNat n.
refine (
λ lSn,
(LegitNat_ind
(λ m, ∀ p , m = mn_S p → LegitNat p)
(λ p (H : mn_0 = mn_S p),
match H in (_ = a)
return match a with
| mn_0 => True
| mn_S _ => (LegitNat p)
end
with eq_refl => I end
)
(λ m (lm : LegitNat m)
(IH : ∀ p, m = mn_S p → LegitNat p)
p (H : mn_S m = mn_S p),
match
match H in (_ = a)
return (match a with mn_0 => False | mn_S m2 => m = m2 end)
with eq_refl => eq_refl
end
in (_ = a) return (LegitNat a) with
| eq_refl => lm
end)
(mn_S n)
lSn
)
n eq_refl).
Defined.
Parameter OpaqueFormula : Prop.
Parameter q_0 : OpaqueFormula.
Parameter q_S : OpaqueFormula -> OpaqueFormula.
(* Definition ZeroOrSucc q := ∀ C, (q = q_0 -> C) -> (∀ p, q = (q_S p) -> C) -> C. *)
(* Definition InductiveNat n : Prop :=
∀ (P : OpaqueFormula → Prop)
(zero_case : P q_0)
(succ_case : ∀ m, P m → P (q_S m)),
P n. *)
(* Definition CoinductiveNat n :=
∀ C, (∀ State, State -> ()) -> C. *)
Parameter OpaqueEq : OpaqueFormula -> OpaqueFormula -> Prop.
Parameter oeq_refl : ∀ q, OpaqueEq q q.
Definition HigherDestructAllCases q
(ZeroCase : OpaqueFormula -> Prop)
(SuccCase : OpaqueFormula -> OpaqueFormula -> Prop) :=
((OpaqueEq q q_0) -> ZeroCase q) ∧
(∀ p, (OpaqueEq q (q_S p) -> (SuccCase p q))).
Definition HigherDestruct0 := ∀
(ZeroCase : OpaqueFormula -> Prop)
(SuccCase : OpaqueFormula -> OpaqueFormula -> Prop),
ZeroCase q_0 -> HigherDestructAllCases q_0 ZeroCase SuccCase.
Definition HigherDestructS p := ∀
(ZeroCase : OpaqueFormula -> Prop)
(SuccCase : OpaqueFormula -> OpaqueFormula -> Prop),
(SuccCase p (q_S p)) -> HigherDestructAllCases (q_S p) ZeroCase SuccCase.
(* Definition IsSucc Sn n :=
∀ P, P (q_S n) -> P Sn.
Definition PredsAre (P : OpaqueFormula -> Prop) m :=
∀ p, IsSucc m p -> P p. *)
(* Lemma ind_pred n : (∀ n, InductiveNat n -> HigherDestruct n) -> InductiveNat (q_S n) -> InductiveNat n.
intros hd iSn.
unfold InductiveNat; intros.
apply (iSn (λ m, InductiveNat m ∧ ∀ p (is_succ : OpaqueEq m (q_S p)), InductiveNat p)).
{
split.
unfold InductiveNat; trivial.
intros.
assert (HigherDestruct q_0).
apply hd; unfold InductiveNat; trivial.
apply (H True _).
assumption.
}
{
split.
{ unfold InductiveNat; intros. apply succ_case0.
destruct H. apply H. assumption. assumption. }
destruct H.
intros.
assert (HigherDestruct (q_S m)).
{ apply hd. unfold InductiveNat; intros. apply succ_case0.
apply H. assumption. assumption. }
apply (H1 False _). assumption.
}
apply oeq_refl.
assumption.
assumption.
Qed. *)
Definition StrictInductiveNat n : Prop :=
∀ (P : OpaqueFormula → Prop)
(zero_case : HigherDestruct0 -> P q_0)
(succ_case : ∀ m, HigherDestructS m -> P m → P (q_S m)),
P n.
Lemma sind_0 : HigherDestruct0 -> StrictInductiveNat q_0.
unfold StrictInductiveNat; intros; apply zero_case; assumption.
Qed.
Lemma sind_S n : HigherDestructS n -> StrictInductiveNat n -> StrictInductiveNat (q_S n).
unfold StrictInductiveNat; intros; apply succ_case. assumption. apply H0; assumption.
Qed.
Lemma sind_pred n : StrictInductiveNat (q_S n) -> StrictInductiveNat n.
intros iSn.
unfold StrictInductiveNat; intros.
apply (iSn (λ m, StrictInductiveNat m ∧ ∀ p (is_succ : OpaqueEq m (q_S p)), StrictInductiveNat p)); trivial.
{
split.
{ apply sind_0; assumption. }
intros.
apply (H (λ _, True) (λ p _, StrictInductiveNat p)).
exact I.
assumption.
}
{
split; destruct H0.
{ apply sind_S; assumption. }
intros.
apply (H (λ _, False) (λ p _, StrictInductiveNat p)); assumption.
}
{ apply oeq_refl. }
Qed.