-
Notifications
You must be signed in to change notification settings - Fork 1
/
squiggle5.v
139 lines (107 loc) · 4 KB
/
squiggle5.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
(*
Warning! When viewing the file interactively in a Coq editor, the -top arument
must be passed. use the script ./coqid.sh, which should be invoked as follows:
./coqid.sh squiggle5
Note that there is no .v at the end. The script will then pass the argument "-top squiggle5"
to coqtop. No special handling is needed for coqc: it already assumes that the top level module
is squiggle5 (instead of "Top")
*)
Require Import ReflParam.common.
Require Import ReflParam.templateCoqMisc.
Require Import String.
Require Import List.
Require Import Template.Ast.
Require Import SquiggleEq.terms.
Require Import ReflParam.paramDirect ReflParam.indType.
Require Import ReflParam.indProp.
Require Import SquiggleEq.substitution.
Require Import ReflParam.PiTypeR.
Import ListNotations.
Open Scope string_scope.
Require Import ReflParam.Trecord.
Set Imlicit Arguments.
(** Just like [eq] from the standard library. But in [Set], so that IsoRel works *)
Inductive eqs {A : Set} (x : A) : forall (a:A), Prop :=
eq_refls : eqs x x.
Inductive option (A : Set) : Set := Some : A -> option A | None : option A.
Arguments Some {A} _.
Arguments None {A}.
Infix "=" := eqs : type_scope.
Notation True := (true=true).
Notation False := (false=true).
Definition isNone {A:Set} (oa: option A) :=
match oa with
| Some _ => false
| None => true
end.
Infix "+" := sum:type_scope.
Open Scope nat_scope.
Section Squiggle5.
Variables (Tm BTm : Set).
Variable applyBtm: BTm -> Tm -> Tm.
Inductive TmKind :=
| elam (bt: BTm)
| eapp (f a: Tm)
| enum (n: nat)
| evar.
Variable tmKind: Tm -> TmKind.
Fixpoint evaln (n:nat) (t:Tm): option Tm :=
match n with
| 0 => None | S n =>
match (tmKind t)
with
| evar => None
| elam _ | enum _ => Some t
| eapp f a =>
match evaln n f, evaln n a with
| Some f, Some a =>
match (tmKind f) with
| elam bt => evaln n (applyBtm bt a)
| _ => None
end
| _,_ => None
end
end
end.
Definition divergesIff (tl tr:Tm) : Prop :=
(forall (nsteps:nat), (isNone (evaln nsteps tl)) = true) <->
(forall (nsteps:nat), (isNone (evaln nsteps tr)) = true).
Fixpoint obsEq (k:nat) (tl tr:Tm) {struct k}: Prop :=
divergesIff tl tr /\ forall (nsteps:nat),
match k with | 0 => True | S k =>
match evaln nsteps tl, evaln nsteps tr with
| Some vl, Some vr =>
match tmKind vl, tmKind vr with
| enum nl , enum nr => nl = nr
| elam btl , elam btr => forall (ta: Tm), obsEq k (applyBtm btl ta) (applyBtm btr ta)
| _,_ => False
end
| _, _ => True
end
end.
Definition obseq (tl tr:Tm) := forall (k:nat), obsEq k tl tr.
End Squiggle5.
Arguments elam {Tm} {BTm} bt.
Arguments eapp {Tm} {BTm} f a.
Arguments enum {Tm} {BTm} n.
Arguments evar {Tm} {BTm}.
(** Before we translate definition, we must translate all its dependencies : other definitions
mentioned in its body. Someday, this dependency calculation would be automated, like in paramcoq [Lasson and Keller]
For now, we translate items one by one, in the order of dependencies.*)
Run TemplateProgram (genParamIndAll [] "Coq.Init.Datatypes.bool").
Run TemplateProgram (genParamIndAll [] "Coq.Init.Datatypes.nat").
Run TemplateProgram (genParamIndPropAll [] "Top.squiggle5.eqs").
Run TemplateProgram (genParamIndAll [] "Top.squiggle5.option").
Run TemplateProgram (genParamIndPropAll [] "Coq.Init.Logic.and").
Run TemplateProgram (genParamIndAll [] "Top.squiggle5.TmKind").
Run TemplateProgram (mkIndEnv "indTransEnv" [
"Coq.Init.Datatypes.bool" ; "Coq.Init.Datatypes.nat";
"Top.squiggle5.option";
"Top.squiggle5.TmKind"]).
Run TemplateProgram (genWrappers indTransEnv).
Run TemplateProgram (genParam indTransEnv true true "Top.squiggle5.evaln").
Run TemplateProgram (genParam indTransEnv true true "Top.squiggle5.isNone").
Run TemplateProgram (genParam indTransEnv true true "Coq.Init.Logic.iff").
Run TemplateProgram (genParam indTransEnv true true "Top.squiggle5.divergesIff").
Run TemplateProgram (genParam indTransEnv true true "Top.squiggle5.obsEq").
Run TemplateProgram (genParam indTransEnv true true "Top.squiggle5.obseq").