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.
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_______________________________________________________________ *)
15 let string_iter sep f n =
16 let rec aux = function
19 | n -> f n ^ sep ^ aux (pred n)
24 let rec aux = function
27 | n -> f n; aux (pred n)
31 let mk_exists ooch noch c v =
32 let description = "multiple existental quantifier" in
33 let in_prec = "non associative with precedence 20\n" in
34 (* let out_prec = "right associative with precedence 20\n" in *)
35 let name s = P.sprintf "%s%u_%u" s c v in
36 let o_name = name "ex" in
39 let set n = P.sprintf "A%u" (v - n) in
40 let set_list = string_iter "," set v in
41 let set_type = string_iter "→" set v in
43 let ele n = P.sprintf "x%u" (v - n) in
44 let ele_list = string_iter "," ele v in
45 let ele_seq = string_iter " " ele v in
47 let pre n = P.sprintf "P%u" (c - n) in
48 let pre_list = string_iter "," pre c in
49 let pre_seq = string_iter " " pre c in
50 let pre_appl n = P.sprintf "%s %s" (pre n) ele_seq in
51 let pre_type = string_iter " → " pre_appl c in
54 let qm_set = string_iter " " qm v in
55 let qm_pre = string_iter " " qm c in
57 let id n = P.sprintf "ident x%u" (v - n) in
58 let id_list = string_iter " , " id v in
60 let term n = P.sprintf "term 19 P%u" (c - n) in
61 let term_conj = string_iter " break & " term c in
63 let abst b n = let xty = if b then P.sprintf ":$T%u" (v - n) else "" in
64 P.sprintf "λ${ident x%u}%s" (v - n) xty in
66 let abst_clo b = string_iter "." (abst b) v in
68 let full b n = P.sprintf "(%s.$P%u)" (abst_clo b) (c - n) in
69 let full_seq b = string_iter " " (full b) c in
71 P.fprintf ooch "(* %s (%u, %u) *)\n\n" description c v;
73 P.fprintf ooch "inductive %s (%s:Type[0]) (%s:%s→Prop) : Prop ≝\n"
74 o_name set_list pre_list set_type;
75 P.fprintf ooch " | %s_intro: ∀%s. %s → %s %s %s\n.\n\n"
76 o_name ele_list pre_type o_name qm_set qm_pre;
78 P.fprintf ooch "interpretation \"%s (%u, %u)\" %s %s = (%s %s %s).\n\n"
79 description c v i_name pre_seq o_name qm_set pre_seq;
81 P.fprintf noch "(* %s (%u, %u) *)\n\n" description c v;
83 P.fprintf noch "notation > \"hvbox(∃∃ %s break . %s)\"\n %s for @{ %s %s }.\n\n"
84 id_list term_conj in_prec i_name (full_seq false);
86 P.fprintf noch "notation < \"hvbox(∃∃ %s break . %s)\"\n %s for @{ %s %s }.\n\n"
87 id_list term_conj in_prec i_name (full_seq true)
89 let mk_or ooch noch c =
90 let description = "multiple disjunction connective" in
91 let in_prec = "non associative with precedence 30\n" in
92 let name s = P.sprintf "%s%u" s c in
93 let o_name = name "or" in
96 let pre n = P.sprintf "P%u" (c - n) in
97 let pre_list = string_iter "," pre c in
98 let pre_seq = string_iter " " pre c in
101 let qm_pre = string_iter " " qm c in
103 let term n = P.sprintf "term 29 P%u" (c - n) in
104 let term_disj = string_iter " break | " term c in
106 let par n = P.sprintf "$P%u" (c - n) in
107 let par_seq = string_iter " " par c in
109 let mk_con n = P.fprintf ooch " | %s_intro%u: %s → %s %s\n"
110 o_name (c - n) (pre n) o_name qm_pre
113 P.fprintf ooch "(* %s (%u) *)\n\n" description c;
115 P.fprintf ooch "inductive %s (%s:Prop) : Prop ≝\n"
118 P.fprintf ooch ".\n\n";
120 P.fprintf ooch "interpretation \"%s (%u)\" %s %s = (%s %s).\n\n"
121 description c i_name pre_seq o_name pre_seq;
123 P.fprintf noch "(* %s (%u) *)\n\n" description c;
125 P.fprintf noch "notation \"hvbox(∨∨ %s)\"\n %s for @{ %s %s }.\n\n"
126 term_disj in_prec i_name par_seq
128 let generate ooch noch = function
130 if c > 0 && v > 0 then mk_exists ooch noch c v
132 if c > 1 then mk_or ooch noch c