forked from Barry-Jay/lambdaSF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLamSF_Terms.v
113 lines (88 loc) · 3.91 KB
/
LamSF_Terms.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
(**********************************************************************)
(* This program is free software; you can redistribute it and/or *)
(* modify it under the terms of the GNU Lesser General Public License *)
(* as published by the Free Software Foundation; either version 2.1 *)
(* of the License, or (at your option) any later version. *)
(* *)
(* This program is distributed in the hope that it will be useful, *)
(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)
(* GNU General Public License for more details. *)
(* *)
(* You should have received a copy of the GNU Lesser General Public *)
(* License along with this program; if not, write to the Free *)
(* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *)
(* 02110-1301 USA *)
(**********************************************************************)
(**********************************************************************)
(* Intensional Lambda Calculus *)
(* *)
(* is implemented in Coq by adapting the implementation of *)
(* Lambda Calculus from Project Coq *)
(* 2015 *)
(**********************************************************************)
(**********************************************************************)
(* Terms.v *)
(* *)
(* adapted from Terms.v for Lambda Calculus *)
(* *)
(* Barry Jay *)
(* *)
(**********************************************************************)
Require Import Arith.
Require Import General.
Require Import Test.
(* lambda terms with operators and using de Bruijn's indices *)
Inductive operator :=
| Sop
| Fop
.
Inductive lamSF: Set :=
| Ref : nat -> lamSF
| Op : operator -> lamSF
| Abs : lamSF -> lamSF
| App : lamSF -> lamSF -> lamSF
.
Lemma decidable_term_equality : forall (M N: lamSF), M = N \/ M<> N.
Proof.
induction M; induction N; intros; try (left; congruence); try(right; congruence).
elim(decidable_nats n0 n); auto.
intro; right; intro; congruence.
case o; case o0; split_all; try (left; split_all; fail); right; split_all.
elim(IHM N); split_all.
left; congruence.
right; congruence.
elim(IHM1 N1); elim(IHM2 N2); auto;
(right; congruence; fail) || left; congruence.
Qed.
(* Lifting *)
Definition relocate (i k n : nat) :=
match test k i with
(* k<=i *) | left _ => n+i
(* k>i *) | _ => i
end.
Fixpoint lift_rec (L : lamSF) : nat -> nat -> lamSF :=
fun k n =>
match L with
| Ref i => Ref (relocate i k n)
| Op o => Op o
| App M N => App (lift_rec M k n) (lift_rec N k n)
| Abs M => Abs (lift_rec M (S k) n)
end.
Definition lift (n : nat) (N : lamSF) := lift_rec N 0 n.
(* Substitution *)
Definition insert_Ref (N : lamSF) (i k : nat) :=
match compare k i with
(* k<i *) | inleft (left _) => Ref (pred i)
(* k=i *) | inleft _ => lift k N
(* k>i *) | _ => Ref i
end.
Fixpoint subst_rec (L : lamSF) : lamSF -> nat -> lamSF :=
fun (N : lamSF) (k : nat) =>
match L with
| Ref i => insert_Ref N i k
| Op o => Op o
| App M M' => App (subst_rec M N k) (subst_rec M' N k)
| Abs M => Abs (subst_rec M N (S k))
end.
Definition subst (N M : lamSF) := subst_rec M N 0.