]> matita.cs.unibo.it Git - helm.git/blob - matita/components/binaries/xoa/engine.ml
xoa: change in naming convenctions for existential quantifies
[helm.git] / matita / components / binaries / xoa / engine.ml
1 (*
2     ||M||  This file is part of HELM, an Hypertextual, Electronic        
3     ||A||  Library of Mathematics, developed at the Computer Science     
4     ||T||  Department, University of Bologna, Italy.                     
5     ||I||                                                                
6     ||T||  HELM is free software; you can redistribute it and/or         
7     ||A||  modify it under the terms of the GNU General Public License   
8     \   /  version 2 or (at your option) any later version.      
9      \ /   This software is distributed as is, NO WARRANTY.     
10       V_______________________________________________________________ *)
11
12 module P = Printf
13 module A = Ast
14
15 let string_iter sep f n =
16    let rec aux = function
17       | n when n < 1 -> ""
18       | 1            -> f 1
19       | n            -> f n ^ sep ^ aux (pred n)
20    in
21    aux n
22
23 let void_iter f n =
24    let rec aux = function
25       | n when n < 1 -> ()
26       | 1            -> f 1
27       | n            -> f n; aux (pred n)
28    in
29    aux n
30
31 let mk_exists ooch noch c v =
32    let description = "multiple existental quantifier" in
33    let prec = "non associative with precedence 20\n" in
34    let name s = 
35       if v = 1 then P.sprintf "%s%u" s c else P.sprintf "%s%u_%u" s c v
36    in
37    let o_name = name "ex" in
38    let i_name = "'Ex" in
39
40    let set n      = P.sprintf "A%u" (v - n) in
41    let set_list   = string_iter "," set v in   
42    let set_type   = string_iter "→" set v in
43       
44    let ele n      = P.sprintf "x%u" (v - n) in
45    let ele_list   = string_iter "," ele v in
46    let ele_seq    = string_iter " " ele v in
47    
48    let pre n      = P.sprintf "P%u" (c - n) in   
49    let pre_list   = string_iter "," pre c in
50    let pre_seq    = string_iter " " pre c in 
51    let pre_appl n = P.sprintf "%s %s" (pre n) ele_seq in 
52    let pre_type   = string_iter " → " pre_appl c in
53
54    let qm n       = "?" in
55    let qm_set     = string_iter " " qm v in 
56    let qm_pre     = string_iter " " qm c in 
57
58    let id n       = P.sprintf "ident x%u" (v - n) in
59    let id_list    = string_iter " , " id v in 
60
61    let term n     = P.sprintf "term 19 P%u" (c - n) in
62    let term_conj  = string_iter " break & " term c in 
63
64    let abst b n   = let xty = if b then P.sprintf ":$T%u" (v - n) else "" in
65                     P.sprintf "λ${ident x%u}%s" (v - n) xty in
66
67    let abst_clo b = string_iter "." (abst b) v in 
68
69    let full b n   = P.sprintf "(%s.$P%u)" (abst_clo b) (c - n) in 
70    let full_seq b = string_iter " " (full b) c in
71
72    P.fprintf ooch "(* %s (%u, %u) *)\n\n" description c v;
73
74    P.fprintf ooch "inductive %s (%s:Type[0]) (%s:%s→Prop) : Prop ≝\n" 
75       o_name set_list pre_list set_type;
76    P.fprintf ooch "   | %s_intro: ∀%s. %s → %s %s %s\n.\n\n"
77       o_name ele_list pre_type o_name qm_set qm_pre;
78
79    P.fprintf ooch "interpretation \"%s (%u, %u)\" %s %s = (%s %s %s).\n\n"
80       description c v i_name pre_seq o_name qm_set pre_seq;
81
82    P.fprintf noch "(* %s (%u, %u) *)\n\n" description c v;
83
84    P.fprintf noch "notation > \"hvbox(∃∃ %s break . %s)\"\n %s for @{ %s %s }.\n\n"
85       id_list term_conj prec i_name (full_seq false);
86
87    P.fprintf noch "notation < \"hvbox(∃∃ %s break . %s)\"\n %s for @{ %s %s }.\n\n"
88       id_list term_conj prec i_name (full_seq true)
89
90 let mk_or ooch noch c =
91    let description = "multiple disjunction connective" in
92    let prec = "non associative with precedence 30\n" in
93    let name s = P.sprintf "%s%u" s c in
94    let o_name = name "or" in
95    let i_name = "'Or" in
96
97    let pre n      = P.sprintf "P%u" (c - n) in   
98    let pre_list   = string_iter "," pre c in
99    let pre_seq    = string_iter " " pre c in 
100
101    let qm n       = "?" in
102    let qm_pre     = string_iter " " qm c in 
103
104    let term n     = P.sprintf "term 29 P%u" (c - n) in
105    let term_disj  = string_iter " break | " term c in 
106
107    let par n     = P.sprintf "$P%u" (c - n) in 
108    let par_seq   = string_iter " " par c in
109
110    let mk_con n   = P.fprintf ooch "   | %s_intro%u: %s → %s %s\n"
111                        o_name (c - n) (pre n) o_name qm_pre
112    in
113
114    P.fprintf ooch "(* %s (%u) *)\n\n" description c;
115
116    P.fprintf ooch "inductive %s (%s:Prop) : Prop ≝\n" 
117       o_name pre_list;
118    void_iter mk_con c;
119    P.fprintf ooch ".\n\n";
120
121    P.fprintf ooch "interpretation \"%s (%u)\" %s %s = (%s %s).\n\n"
122       description c i_name pre_seq o_name pre_seq;
123
124    P.fprintf noch "(* %s (%u) *)\n\n" description c;
125
126    P.fprintf noch "notation \"hvbox(∨∨ %s)\"\n %s for @{ %s %s }.\n\n"
127       term_disj prec i_name par_seq
128
129 let mk_and ooch noch c =
130    let description = "multiple conjunction connective" in
131    let prec = "non associative with precedence 35\n" in
132    let name s = P.sprintf "%s%u" s c in
133    let o_name = name "and" in
134    let i_name = "'And" in
135
136    let pre n      = P.sprintf "P%u" (c - n) in   
137    let pre_list   = string_iter "," pre c in
138    let pre_type   = string_iter " → " pre c in   
139    let pre_seq    = string_iter " " pre c in 
140
141    let qm n       = "?" in
142    let qm_pre     = string_iter " " qm c in 
143
144    let term n     = P.sprintf "term 34 P%u" (c - n) in
145    let term_conj  = string_iter " break & " term c in 
146
147    let par n     = P.sprintf "$P%u" (c - n) in 
148    let par_seq   = string_iter " " par c in
149
150    P.fprintf ooch "(* %s (%u) *)\n\n" description c;
151
152    P.fprintf ooch "inductive %s (%s:Prop) : Prop ≝\n" 
153       o_name pre_list;
154    P.fprintf ooch "   | %s_intro: %s → %s %s\n.\n\n"
155       o_name pre_type o_name qm_pre;
156
157    P.fprintf ooch "interpretation \"%s (%u)\" %s %s = (%s %s).\n\n"
158       description c i_name pre_seq o_name pre_seq;
159
160    P.fprintf noch "(* %s (%u) *)\n\n" description c;
161
162    P.fprintf noch "notation \"hvbox(∧∧ %s)\"\n %s for @{ %s %s }.\n\n"
163       term_conj prec i_name par_seq
164
165 let generate ooch noch = function
166    | A.Exists (c, v) ->
167       if c > 0 && v > 0 then mk_exists ooch noch c v
168    | A.Or c          ->
169       if c > 1 then mk_or ooch noch c
170    | A.And c         ->
171       if c > 1 then mk_and ooch noch c