[ t1 = term; SYMBOL "*"; t2 = term ->
return_term loc (CicAst.Appl [CicAst.Symbol ("times", 0); t1; t2])
| t1 = term; SYMBOL "/"; t2 = term ->
- return_term loc (CicAst.Appl [CicAst.Symbol ("div", 0); t1; t2])
+ return_term loc (CicAst.Appl [CicAst.Symbol ("divide", 0); t1; t2])
]
];
term: LEVEL "inv"
return_term loc (CicAst.Appl [CicAst.Symbol ("uminus", 0); t])
]
];
+ term: LEVEL "relop"
+ [
+ [ t1 = term; SYMBOL <:unicode<leq>> (* ≤ *); t2 = term ->
+ return_term loc (CicAst.Appl [CicAst.Symbol ("leq", 0); t1; t2])
+ | t1 = term; SYMBOL <:unicode<geq>> (* ≥ *); t2 = term ->
+ return_term loc (CicAst.Appl [CicAst.Symbol ("geq", 0); t1; t2])
+ | t1 = term; SYMBOL "<"; t2 = term ->
+ return_term loc (CicAst.Appl [CicAst.Symbol ("lt", 0); t1; t2])
+ | t1 = term; SYMBOL ">"; t2 = term ->
+ return_term loc (CicAst.Appl [CicAst.Symbol ("gt", 0); t1; t2])
+ | t1 = term; SYMBOL <:unicode<ne>> (* ≠ *); t2 = term ->
+ return_term loc (CicAst.Appl [CicAst.Symbol ("neq", 0); t1; t2])
+ ]
+ ];
END
let _ =
+ let uri s = UriManager.uri_of_string s in
+ let const s = Cic.Const (uri s, []) in
+ let mutind s = Cic.MutInd (uri s, 0, []) in
+
DisambiguateChoices.add_num_choice
("natural number",
(fun _ num _ -> HelmLibraryObjects.build_nat (int_of_string num)));
DisambiguateChoices.add_num_choice
("real number",
(fun _ num _ -> HelmLibraryObjects.build_real (int_of_string num)));
- DisambiguateChoices.add_symbol_choice "plus"
- ("natural plus",
- (fun env _ args ->
- let t1, t2 =
- match args with
- | [t1; t2] -> t1, t2
- | _ -> raise DisambiguateChoices.Invalid_choice
- in
- Cic.Appl [ HelmLibraryObjects.Peano.plus; t1; t2 ]));
- DisambiguateChoices.add_symbol_choice "plus"
- ("real plus",
- (fun env _ args ->
- let t1, t2 =
- match args with
- | [t1; t2] -> t1, t2
- | _ -> raise DisambiguateChoices.Invalid_choice
- in
- Cic.Appl [ HelmLibraryObjects.Reals.rplus; t1; t2 ]));
+
+ DisambiguateChoices.add_binary_op "plus" "natural plus"
+ HelmLibraryObjects.Peano.plus;
+ DisambiguateChoices.add_binary_op "plus" "real plus"
+ HelmLibraryObjects.Reals.rplus;
+ DisambiguateChoices.add_binary_op "minus" "natural minus"
+ (const "cic:/Coq/Arith/Minus/minus.con");
+ DisambiguateChoices.add_binary_op "minus" "real minus"
+ (const "cic:/Coq/Reals/Rdefinitions/Rminus.con");
+ DisambiguateChoices.add_binary_op "times" "natural times"
+ (const "cic:/Coq/Init/Peano/mult.con");
+ DisambiguateChoices.add_binary_op "times" "real times"
+ (const "cic:/Coq/Reals/Rdefinitions/Rmult.con");
+ DisambiguateChoices.add_binary_op "divide" "real divide"
+ (const "cic:/Coq/Reals/Rdefinitions/Rdiv.con");
+ DisambiguateChoices.add_unary_op "uminus" "real unary minus"
+ (const "cic:/Coq/Reals/Rdefinitions/Ropp.con");
+
+ DisambiguateChoices.add_binary_op "leq" "natural 'less or equal to'"
+ (mutind "cic:/Coq/Init/Peano/le.ind");
+ DisambiguateChoices.add_binary_op "leq" "real 'less or equal to'"
+ (const "cic:/Coq/Reals/Rdefinitions/Rle.con");
+ DisambiguateChoices.add_binary_op "geq" "natural 'greater or equal to'"
+ (const "cic:/Coq/Init/Peano/ge.con");
+ DisambiguateChoices.add_binary_op "geq" "real 'greater or equal to'"
+ (const "cic:/Coq/Reals/Rdefinitions/Rge.con");
+ DisambiguateChoices.add_binary_op "lt" "natural 'less than'"
+ (const "cic:/Coq/Init/Peano/lt.con");
+ DisambiguateChoices.add_binary_op "lt" "real 'less than'"
+ (const "cic:/Coq/Reals/Rdefinitions/Rlt.con");
+ DisambiguateChoices.add_binary_op "gt" "natural 'greater than'"
+ (const "cic:/Coq/Init/Peano/gt.con");
+ DisambiguateChoices.add_binary_op "gt" "real 'greater than'"
+ (const "cic:/Coq/Reals/Rdefinitions/Rgt.con");
+ DisambiguateChoices.add_symbol_choice "neq"
+ ("not equal to (leibnitz)",
+ (fun env _ args ->
+ let t1, t2 =
+ match args with
+ | [t1; t2] -> t1, t2
+ | _ -> raise DisambiguateChoices.Invalid_choice
+ in
+ Cic.Appl [ const "cic:/Coq/Init/Logic/not.con";
+ Cic.Appl [
+ Cic.MutInd (HelmLibraryObjects.Logic.eq_URI, 0, []);
+ Cic.Implicit (Some `Type); t1; t2 ] ]));
+ DisambiguateChoices.add_symbol_choice "neq"
+ ("not equal to (sort Type)",
+ (fun env _ args ->
+ let t1, t2 =
+ match args with
+ | [t1; t2] -> t1, t2
+ | _ -> raise DisambiguateChoices.Invalid_choice
+ in
+ Cic.Appl [ const "cic:/Coq/Init/Logic/not.con";
+ Cic.Appl [
+ Cic.MutInd (HelmLibraryObjects.Logic_Type.eqt_URI, 0, []);
+ Cic.Implicit (Some `Type); t1; t2 ] ]));
Ko
let resolve (env: environment) (item: domain_item) ?(num = "") ?(args = []) () =
- snd (Environment.find item env) env num args
+ try
+ snd (Environment.find item env) env num args
+ with Not_found -> assert false
(* TODO move it to Cic *)
let find_in_environment name context =
| CicAst.AttributedTerm (_, term) -> aux loc context term
| CicAst.Appl terms ->
List.fold_left (fun dom term -> aux loc context term @ dom) [] terms
- | CicAst.Binder (_, (var, typ), body) ->
+ | CicAst.Binder (kind, (var, typ), body) ->
+ let kind_dom =
+ match kind with
+ | `Exists -> [ Symbol ("exists", 0) ]
+ | _ -> []
+ in
let type_dom = aux_option loc context typ in
let body_dom = aux loc (var :: context) body in
- body_dom @ type_dom
+ body_dom @ type_dom @ kind_dom
| CicAst.Case (term, indty_ident, outtype, branches) ->
let term_dom = aux loc context term in
let outtype_dom = aux_option loc context outtype in
in
Hashtbl.replace symbol_choices symbol (codomain_item :: current_choices)
+let add_binary_op symbol dsc appl_head =
+ add_symbol_choice symbol
+ (dsc,
+ (fun env _ args ->
+ let t1, t2 =
+ match args with
+ | [t1; t2] -> t1, t2
+ | _ -> raise Invalid_choice
+ in
+ Cic.Appl [ appl_head; t1; t2 ]))
+
+let add_unary_op symbol dsc appl_head =
+ add_symbol_choice symbol
+ (dsc,
+ (fun env _ args ->
+ let t = match args with [t] -> t | _ -> raise Invalid_choice in
+ Cic.Appl [ appl_head; t ]))
+
let add_num_choice choice = num_choices := choice :: !num_choices
let lookup_symbol_choices symbol =
List.find (has_description dsc) !num_choices
with Not_found -> raise (Choice_not_found ("Num with dsc " ^ dsc))
+ (** initial table contents *)
+
+let _ =
+ let uri s = UriManager.uri_of_string s in
+ let const s = Cic.Const (uri s, []) in
+ let mutind s = Cic.MutInd (uri s, 0, []) in
+ add_binary_op "exists" "exists" (mutind "cic:/Coq/Init/Logic/ex.ind");
+ add_binary_op "exists" "exists over terms with sort Type"
+ (mutind "cic:/Coq/Init/Logic_Type/exT.ind");
+
];
END
+(* TODO a lot of hard coded URIs, move them in HelmLibraryObjects *)
+
let _ =
+ (* TODO cut-and-pasted code: here, in arit_notation.ml and
+ * disambiguateChoices.ml *)
+ let uri s = UriManager.uri_of_string s in
+ let const s = Cic.Const (uri s, []) in
+ let mutind s = Cic.MutInd (uri s, 0, []) in
DisambiguateChoices.add_symbol_choice "eq"
("leibnitz's equality",
(fun interp _ args ->
Cic.Appl [
Cic.MutInd (HelmLibraryObjects.Logic.eq_URI, 0, []);
Cic.Implicit (Some `Type); t1; t2
- ]))
+ ]));
+ DisambiguateChoices.add_symbol_choice "eq"
+ ("equality over objects with sort Type",
+ (fun interp _ args ->
+ let t1, t2 =
+ match args with
+ | [t1; t2] -> t1, t2
+ | _ -> raise DisambiguateChoices.Invalid_choice
+ in
+ Cic.Appl [
+ Cic.MutInd (HelmLibraryObjects.Logic_Type.eqt_URI, 0, []);
+ Cic.Implicit (Some `Type); t1; t2
+ ]));
+ DisambiguateChoices.add_binary_op "and" "logical and"
+ (mutind "cic:/Coq/Init/Logic/and.ind");
+ DisambiguateChoices.add_binary_op "or" "logical or"
+ (mutind "cic:/Coq/Init/Logic/or.ind");
+ DisambiguateChoices.add_unary_op "not" "logical not"
+ (const "cic:/Coq/Init/Logic/not.con");