-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathexample.js
92 lines (76 loc) · 2.09 KB
/
example.js
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
var cedille = require(".");
var example = `
def the [-Unit : Type] [the : Unit] the
-- Natural numbers
def Nat
{-Nat : Type}
{succ : {x : Nat} Nat}
{zero : Nat}
Nat
def succ
[n : Nat]
[-Nat : Type]
[succ : {x : Nat} Nat]
[zero : Nat]
(succ (n -Nat succ zero))
def zero
[-Nat : Type]
[succ : {x : Nat} Nat]
[zero : Nat]
zero
def n0 (the -Nat zero)
def n1 (the -Nat (succ n0))
def n2 (the -Nat (succ n1))
def n3 (the -Nat (succ n2))
def n4 (the -Nat (succ n3))
-- Inductive hypothesis on natural numbers
def Ind <self : Nat>
{-Ind : {n : Nat} Type}
{step : {-n : Nat} {i : (Ind n)} (Ind (succ n))}
{base : (Ind zero)}
(Ind self)
def step [n : Ind] : Ind = (succ .n) &
[-Ind : {n : Nat} Type]
[step : {-n : Nat} {i : (Ind n)} (Ind (succ n))]
[base : (Ind zero)]
(step -.n (+n -Ind step base))
def base : Ind = zero &
[-Ind : {n : Nat} Type]
[step : {-n : Nat} {i : (Ind n)} (Ind (succ n))]
[base : (Ind zero)]
base
def to_ind [n : Nat]
(n -Ind step base)
def i0 (to_ind n0)
def i1 (to_ind n1)
def i2 (to_ind n2)
def i3 (to_ind n3)
def i4 (to_ind n3)
def ind_reflection [i : Ind]
let motive [n : Nat]
|.(to_ind n) = n|
let case_s [-n : Nat] [i : |.(to_ind n) = n|]
def cong [-A : Type] [-B : Type] [-x : A] [-y : A] [-e : |x = y|] [-f : {x : A} B]
(%k |(f x) = (f k)| e ($(f x) [x] x))
(cong -Nat -Nat -.(to_ind n) -n -i -succ)
let case_z
($zero [x] x)
(+i -motive case_s case_z)
def ind_induction
[i : Ind]
[-P : {i : Ind} Type]
[S : {-i : Ind} {ih : (P i)} (P (step i))]
[Z : (P base)]
let motive [n : Nat]
(P (to_ind n))
let case_s [-n : Nat] [ih : (P (to_ind n))]
(S -(to_ind n) ih)
let case_z
Z
(%i (P i) (ind_reflection i) (+i -motive case_s case_z))
ind_induction
`;
var term = cedille.parse(example);
console.log("Input:\n" + term.to_string() + "\n");
console.log("Type:\n" + term.check().to_string() + "\n");
console.log("Normal:\n" + term.eval().to_string() + "\n");