]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/cic_disambiguation/arit_notation.ml
Partial porting to V8 URIs.
[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 "inv"
46     [
47       [ SYMBOL "-"; t = term ->
48         return_term loc (CicAst.Appl [CicAst.Symbol ("uminus", 0); t])
49       ]
50     ];
51   term: LEVEL "relop"
52     [
53       [ t1 = term; SYMBOL <:unicode<leq>> (* ≤ *); t2 = term ->
54           return_term loc (CicAst.Appl [CicAst.Symbol ("leq", 0); t1; t2])
55       | t1 = term; SYMBOL <:unicode<geq>> (* ≥ *); t2 = term ->
56           return_term loc (CicAst.Appl [CicAst.Symbol ("geq", 0); t1; t2])
57       | t1 = term; SYMBOL "<"; t2 = term ->
58           return_term loc (CicAst.Appl [CicAst.Symbol ("lt", 0); t1; t2])
59       | t1 = term; SYMBOL ">"; t2 = term ->
60           return_term loc (CicAst.Appl [CicAst.Symbol ("gt", 0); t1; t2])
61       | t1 = term; SYMBOL <:unicode<ne>> (* ≠ *); t2 = term ->
62           return_term loc (CicAst.Appl [CicAst.Symbol ("neq", 0); t1; t2])
63       ]
64     ];
65 END
66
67 let _ =
68   let const s = Cic.Const (s, []) in
69   let mutind s = Cic.MutInd (s, 0, []) in
70
71   DisambiguateChoices.add_num_choice
72     ("natural number",
73       (fun _ num _ -> HelmLibraryObjects.build_nat (int_of_string num)));
74   DisambiguateChoices.add_num_choice
75     ("real number",
76       (fun _ num _ -> HelmLibraryObjects.build_real (int_of_string num)));
77
78   DisambiguateChoices.add_binary_op "plus" "natural plus"
79     HelmLibraryObjects.Peano.plus;
80   DisambiguateChoices.add_binary_op "plus" "real plus"
81     HelmLibraryObjects.Reals.rplus;
82   DisambiguateChoices.add_binary_op "minus" "natural minus"
83     (const HelmLibraryObjects.Peano.minus_URI);
84   DisambiguateChoices.add_binary_op "minus" "real minus"
85     (const HelmLibraryObjects.Reals.rminus_URI);
86   DisambiguateChoices.add_binary_op "times" "natural times"
87     (const HelmLibraryObjects.Peano.mult_URI);
88   DisambiguateChoices.add_binary_op "times" "real times"
89     (const HelmLibraryObjects.Reals.rmult_URI);
90   DisambiguateChoices.add_binary_op "divide" "real divide"
91     (const HelmLibraryObjects.Reals.rdiv_URI);
92   DisambiguateChoices.add_unary_op "uminus" "real unary minus"
93     (const HelmLibraryObjects.Reals.ropp_URI);
94
95   DisambiguateChoices.add_binary_op "leq" "natural 'less or equal to'"
96     (mutind HelmLibraryObjects.Peano.le_URI);
97   DisambiguateChoices.add_binary_op "leq" "real 'less or equal to'"
98     (const HelmLibraryObjects.Reals.rle_URI);
99   DisambiguateChoices.add_binary_op "geq" "natural 'greater or equal to'"
100     (const HelmLibraryObjects.Peano.ge_URI);
101   DisambiguateChoices.add_binary_op "geq" "real 'greater or equal to'"
102     (const HelmLibraryObjects.Reals.rge_URI);
103   DisambiguateChoices.add_binary_op "lt" "natural 'less than'"
104     (const HelmLibraryObjects.Peano.lt_URI);
105   DisambiguateChoices.add_binary_op "lt" "real 'less than'"
106     (const HelmLibraryObjects.Reals.rlt_URI);
107   DisambiguateChoices.add_binary_op "gt" "natural 'greater than'"
108     (const HelmLibraryObjects.Peano.gt_URI);
109   DisambiguateChoices.add_binary_op "gt" "real 'greater than'"
110     (const HelmLibraryObjects.Reals.rgt_URI);
111   DisambiguateChoices.add_symbol_choice "neq"
112     ("not equal to (leibnitz)",
113       (fun env _ args ->
114         let t1, t2 =
115           match args with 
116           | [t1; t2] -> t1, t2
117           | _ -> raise DisambiguateChoices.Invalid_choice
118         in
119         Cic.Appl [ const HelmLibraryObjects.Logic.not_URI;
120           Cic.Appl [
121             Cic.MutInd (HelmLibraryObjects.Logic.eq_URI, 0, []);
122               Cic.Implicit (Some `Type); t1; t2 ] ]));
123   DisambiguateChoices.add_symbol_choice "neq"
124     ("not equal to (sort Type)",
125       (fun env _ args ->
126         let t1, t2 =
127           match args with
128           | [t1; t2] -> t1, t2
129           | _ -> raise DisambiguateChoices.Invalid_choice
130         in
131         Cic.Appl [ const HelmLibraryObjects.Logic.not_URI;
132           Cic.Appl [
133             Cic.MutInd (HelmLibraryObjects.Logic_Type.eqt_URI, 0, []);
134               Cic.Implicit (Some `Type); t1; t2 ] ]));
135