]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/cic_disambiguation/arit_notation.ml
first moogle template checkin
[helm.git] / helm / ocaml / cic_disambiguation / arit_notation.ml
1 (* Copyright (C) 2004, HELM Team.
2  * 
3  * This file is part of HELM, an Hypertextual, Electronic
4  * Library of Mathematics, developed at the Computer Science
5  * Department, University of Bologna, Italy.
6  * 
7  * HELM is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  * 
12  * HELM is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with HELM; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://helm.cs.unibo.it/
24  *)
25
26 open CicTextualParser2
27
28 EXTEND
29   term: LEVEL "add"
30     [
31       [ t1 = term; SYMBOL "+"; t2 = term ->
32           return_term loc (CicAst.Appl [CicAst.Symbol ("plus", 0); t1; t2])
33       | t1 = term; SYMBOL "-"; t2 = term ->
34           return_term loc (CicAst.Appl [CicAst.Symbol ("minus", 0); t1; t2])
35       ]
36     ];
37   term: LEVEL "mult"
38     [
39       [ t1 = term; SYMBOL "*"; t2 = term ->
40           return_term loc (CicAst.Appl [CicAst.Symbol ("times", 0); t1; t2])
41       | t1 = term; SYMBOL "/"; t2 = term ->
42           return_term loc (CicAst.Appl [CicAst.Symbol ("divide", 0); t1; t2])
43       ]
44     ];
45   term: LEVEL "power"
46     [
47       [ t1 = term; SYMBOL "^"; t2 = term ->
48           return_term loc (CicAst.Appl [CicAst.Symbol ("power", 0); t1; t2])
49       ]
50     ];
51   term: LEVEL "inv"
52     [
53       [ SYMBOL "-"; t = term ->
54         return_term loc (CicAst.Appl [CicAst.Symbol ("uminus", 0); t])
55       ]
56     ];
57   term: LEVEL "relop"
58     [
59       [ t1 = term; SYMBOL <:unicode<leq>> (* ≤ *); t2 = term ->
60           return_term loc (CicAst.Appl [CicAst.Symbol ("leq", 0); t1; t2])
61       | t1 = term; SYMBOL <:unicode<geq>> (* ≥ *); t2 = term ->
62           return_term loc (CicAst.Appl [CicAst.Symbol ("geq", 0); t1; t2])
63       | t1 = term; SYMBOL "<"; t2 = term ->
64           return_term loc (CicAst.Appl [CicAst.Symbol ("lt", 0); t1; t2])
65       | t1 = term; SYMBOL ">"; t2 = term ->
66           return_term loc (CicAst.Appl [CicAst.Symbol ("gt", 0); t1; t2])
67       | t1 = term; SYMBOL <:unicode<ne>> (* ≠ *); t2 = term ->
68           return_term loc (CicAst.Appl [CicAst.Symbol ("neq", 0); t1; t2])
69       ]
70     ];
71 END
72
73 let _ =
74   let const s = Cic.Const (s, []) in
75   let mutind s = Cic.MutInd (s, 0, []) in
76
77   DisambiguateChoices.add_num_choice
78     ("natural number",
79       (fun _ num _ -> HelmLibraryObjects.build_nat (int_of_string num)));
80   DisambiguateChoices.add_num_choice
81     ("real number",
82       (fun _ num _ -> HelmLibraryObjects.build_real (int_of_string num)));
83   DisambiguateChoices.add_num_choice
84     ("binary positive number",
85       (fun _ num _ ->
86         let num = int_of_string num in
87         if num = 0 then
88           raise DisambiguateChoices.Invalid_choice
89         else
90           HelmLibraryObjects.build_bin_pos num));
91   DisambiguateChoices.add_num_choice
92     ("binary integer number",
93       (fun _ num _ ->
94         let num = int_of_string num in
95         if num = 0 then
96           HelmLibraryObjects.BinInt.z0
97         else if num > 0 then
98           Cic.Appl [
99             HelmLibraryObjects.BinInt.zpos;
100             HelmLibraryObjects.build_bin_pos num ]
101         else
102           assert false));
103
104   DisambiguateChoices.add_binary_op "plus" "natural plus"
105     HelmLibraryObjects.Peano.plus;
106   DisambiguateChoices.add_binary_op "plus" "real plus"
107     HelmLibraryObjects.Reals.rplus;
108   DisambiguateChoices.add_binary_op "plus" "binary integer plus"
109     HelmLibraryObjects.BinInt.zplus;
110   DisambiguateChoices.add_binary_op "plus" "binary positive plus"
111     HelmLibraryObjects.BinPos.pplus;
112   DisambiguateChoices.add_binary_op "minus" "natural minus"
113     (const HelmLibraryObjects.Peano.minus_URI);
114   DisambiguateChoices.add_binary_op "minus" "real minus"
115     (const HelmLibraryObjects.Reals.rminus_URI);
116   DisambiguateChoices.add_binary_op "minus" "binary integer minus"
117     HelmLibraryObjects.BinInt.zminus;
118   DisambiguateChoices.add_binary_op "minus" "binary positive minus"
119     HelmLibraryObjects.BinPos.pminus;
120   DisambiguateChoices.add_binary_op "times" "natural times"
121     (const HelmLibraryObjects.Peano.mult_URI);
122   DisambiguateChoices.add_binary_op "times" "real times"
123     (const HelmLibraryObjects.Reals.rmult_URI);
124   DisambiguateChoices.add_binary_op "times" "binary positive times"
125     HelmLibraryObjects.BinPos.pmult;
126   DisambiguateChoices.add_binary_op "times" "binary integer times"
127     HelmLibraryObjects.BinInt.zmult;
128   DisambiguateChoices.add_binary_op "power" "real power"
129     (const HelmLibraryObjects.Reals.pow_URI);
130   DisambiguateChoices.add_binary_op "power" "integer power"
131     (const HelmLibraryObjects.BinInt.zpower_URI);
132   DisambiguateChoices.add_binary_op "divide" "real divide"
133     (const HelmLibraryObjects.Reals.rdiv_URI);
134   DisambiguateChoices.add_unary_op "uminus" "real unary minus"
135     (const HelmLibraryObjects.Reals.ropp_URI);
136   DisambiguateChoices.add_unary_op "uminus" "binary integer negative sign"
137     (HelmLibraryObjects.BinInt.zneg);
138   DisambiguateChoices.add_unary_op "uminus" "binary integer unary minus"
139     (HelmLibraryObjects.BinInt.zopp);
140
141   DisambiguateChoices.add_binary_op "leq" "natural 'less or equal to'"
142     (mutind HelmLibraryObjects.Peano.le_URI);
143   DisambiguateChoices.add_binary_op "leq" "real 'less or equal to'"
144     (const HelmLibraryObjects.Reals.rle_URI);
145   DisambiguateChoices.add_binary_op "geq" "natural 'greater or equal to'"
146     (const HelmLibraryObjects.Peano.ge_URI);
147   DisambiguateChoices.add_binary_op "geq" "real 'greater or equal to'"
148     (const HelmLibraryObjects.Reals.rge_URI);
149   DisambiguateChoices.add_binary_op "lt" "natural 'less than'"
150     (const HelmLibraryObjects.Peano.lt_URI);
151   DisambiguateChoices.add_binary_op "lt" "real 'less than'"
152     (const HelmLibraryObjects.Reals.rlt_URI);
153   DisambiguateChoices.add_binary_op "gt" "natural 'greater than'"
154     (const HelmLibraryObjects.Peano.gt_URI);
155   DisambiguateChoices.add_binary_op "gt" "real 'greater than'"
156     (const HelmLibraryObjects.Reals.rgt_URI);
157   DisambiguateChoices.add_symbol_choice "neq"
158     ("not equal to (leibnitz)",
159       (fun env _ args ->
160         let t1, t2 =
161           match args with 
162           | [t1; t2] -> t1, t2
163           | _ -> raise DisambiguateChoices.Invalid_choice
164         in
165         Cic.Appl [ const HelmLibraryObjects.Logic.not_URI;
166           Cic.Appl [
167             Cic.MutInd (HelmLibraryObjects.Logic.eq_URI, 0, []);
168               Cic.Implicit (Some `Type); t1; t2 ] ]));
169
170 (* vim:set encoding=utf8: *)