-
Notifications
You must be signed in to change notification settings - Fork 11
/
def_beta_conv.ml
84 lines (74 loc) · 2.16 KB
/
def_beta_conv.ml
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
let new_defs = ref [];;
let rec crude_printer_ty = function
Tyvar(name) ->
Printf.printf "%s" name
| Tyapp(op,tylist) ->
Printf.printf "%s (" op;
List.iter
(fun x -> crude_printer_ty x; Printf.printf " ; ")
tylist;
Printf.printf ")";;
let rec crude_printer = function
Var(name,ty) ->
Printf.printf "%s" name
| Const(name,_) -> Printf.printf "%s" name
| Comb(Comb(Const(name,_),t1),t2) when (name = "=" || name = "==>") ->
begin
Printf.printf "((";
crude_printer t1;
Printf.printf ") %s (" name;
crude_printer t2;
end;
Printf.printf "))"
| Comb(f,t) ->
begin
crude_printer f;
Printf.printf " ";
end;
crude_printer t
| Abs(Var(name,ty),t) ->
begin
Printf.printf "\%s:" name;
crude_printer_ty ty;
Printf.printf ". "
end;
crude_printer t
| _ -> ();;
let crude_printer_thm thm =
let hyps = hyp thm in
let concl = concl thm in
List.iter crude_printer hyps;
Printf.printf " |- ";
crude_printer concl;
Printf.printf "\n\n";;
let DEF_CONV tm =
let rec apply_def tm =
let (namecst,tycst) = dest_const tm in
function
| [] -> failwith "No definition matches this term"
| (name,def)::other_new_defs when name=namecst ->
INST_TYPE (type_match (type_of (rand (concl def))) tycst []) def
| (name,def)::other_new_defs -> apply_def tm other_new_defs
in
apply_def tm (!new_defs);;
let DEF_BETA_CONV tm =
try BETA_CONV tm with Failure _ ->
try DEF_CONV tm with Failure _ ->
failwith "Not a beta-redex or a definition";;
let DEF_BETA_DEPTH = REDEPTH_CONV DEF_BETA_CONV;;
let CONV_CONV tm1 tm2 =
let thm1 = DEF_BETA_DEPTH tm1 in
let thm2 = DEF_BETA_DEPTH tm2 in
TRANS thm1 (SYM thm2);;
let CONV_CONV_rule tm2 thm =
let tm1 = concl thm in
try
EQ_MP (CONV_CONV tm1 tm2) thm
with Failure _ ->
Printf.printf "Conversion issue between terms \n\n";
crude_printer tm1;
Printf.printf "\n\nand\n\n";
crude_printer tm2;
Printf.printf "\n\nand theorem\n\n";
crude_printer_thm thm;
failwith "CONV_CONV_rule";;