src/HOL/TPTP/TPTP_Parser/tptp_syntax.ML
changeset 55594 eb291b215c73
parent 55588 3740fb5ec307
child 56265 785569927666
equal deleted inserted replaced
55593:c67c27f0ea94 55594:eb291b215c73
   523   | string_of_tptp_type (Sum_type (tptp_type1, tptp_type2)) = ""
   523   | string_of_tptp_type (Sum_type (tptp_type1, tptp_type2)) = ""
   524   | string_of_tptp_type (Fmla_type tptp_formula) = string_of_tptp_formula tptp_formula
   524   | string_of_tptp_type (Fmla_type tptp_formula) = string_of_tptp_formula tptp_formula
   525   | string_of_tptp_type (Subtype (symbol1, symbol2)) =
   525   | string_of_tptp_type (Subtype (symbol1, symbol2)) =
   526       string_of_symbol symbol1 ^ " << " ^ string_of_symbol symbol2
   526       string_of_symbol symbol1 ^ " << " ^ string_of_symbol symbol2
   527 
   527 
   528              
   528 (*FIXME formatting details haven't been fully worked out -- don't use this function for anything serious in its current form!*)
   529 (*FIXME clean up this code!*)
       
   530 (*TODO Add subscripting*)
   529 (*TODO Add subscripting*)
   531 (*infix symbols, including \subset, \cup, \cap*)
   530 (*infix symbols, including \subset, \cup, \cap*)
   532 fun latex_of_tptp_term x =
   531 fun latex_of_tptp_term x =
   533 ((*writeln ("term=" ^ PolyML.makestring x);*)
       
   534   case x of
   532   case x of
   535 (*
   533       Term_Func (Interpreted_Logic Equals, [tptp_t1, tptp_t2]) =>
   536       Term_Func (Uninterpreted "subset", [tptp_t1, tptp_t2]) =>
       
   537         "(" ^ latex_of_tptp_term tptp_t1 ^ " \\\\subset " ^ latex_of_tptp_term tptp_t2 ^ ")"
       
   538     | Term_Func (Uninterpreted "union", [tptp_t1, tptp_t2]) =>
       
   539         "(" ^ latex_of_tptp_term tptp_t1 ^ " \\\\cup " ^ latex_of_tptp_term tptp_t2 ^ ")"
       
   540 *)
       
   541 (*
       
   542       Term_Func (Interpreted_Logic Apply, [Term_Func (Interpreted_Logic Apply, [Uninterpreted "subset", tptp_t1]), tptp_t2]) =>
       
   543         "(" ^ latex_of_tptp_term tptp_t1 ^ " \\\\subset " ^ latex_of_tptp_term tptp_t2 ^ ")"
       
   544     | Term_Func (Interpreted_Logic Apply, [Term_Func (Interpreted_Logic Apply, [Uninterpreted "union", tptp_t1]), tptp_t2]) =>
       
   545         "(" ^ latex_of_tptp_term tptp_t1 ^ " \\\\cup " ^ latex_of_tptp_term tptp_t2 ^ ")"
       
   546 *)
       
   547 (*
       
   548       Term_Func (Interpreted_ExtraLogic Apply,
       
   549                  [Term_Func (Interpreted_ExtraLogic Apply,
       
   550                              [Term_Func (Interpreted_ExtraLogic Apply, [Term_Func (Uninterpreted "subset", []),
       
   551                                                                              tptp_t1])]), tptp_t2]) =>
       
   552         "(" ^ latex_of_tptp_term tptp_t1 ^ " \\\\subset " ^ latex_of_tptp_term tptp_t2 ^ ")"
       
   553     | Term_Func (Interpreted_ExtraLogic Apply,
       
   554                  [Term_Func (Interpreted_ExtraLogic Apply,
       
   555                              [Term_Func (Interpreted_ExtraLogic Apply, [Term_Func (Uninterpreted "union", []),
       
   556                                                                              tptp_t1])]), tptp_t2]) =>
       
   557         "(" ^ latex_of_tptp_term tptp_t1 ^ " \\\\cup " ^ latex_of_tptp_term tptp_t2 ^ ")"
       
   558 
       
   559     |*) Term_Func (Interpreted_Logic Equals, [tptp_t1, tptp_t2]) =>
       
   560         "(" ^ latex_of_tptp_term tptp_t1 ^ " = " ^ latex_of_tptp_term tptp_t2 ^ ")"
   534         "(" ^ latex_of_tptp_term tptp_t1 ^ " = " ^ latex_of_tptp_term tptp_t2 ^ ")"
   561     | Term_Func (Interpreted_Logic NEquals, [tptp_t1, tptp_t2]) =>
   535     | Term_Func (Interpreted_Logic NEquals, [tptp_t1, tptp_t2]) =>
   562         "(" ^ latex_of_tptp_term tptp_t1 ^ " \\\\neq " ^ latex_of_tptp_term tptp_t2 ^ ")"
   536         "(" ^ latex_of_tptp_term tptp_t1 ^ " \\\\neq " ^ latex_of_tptp_term tptp_t2 ^ ")"
   563     | Term_Func (Interpreted_Logic Or, [tptp_t1, tptp_t2]) =>
   537     | Term_Func (Interpreted_Logic Or, [tptp_t1, tptp_t2]) =>
   564         "(" ^ latex_of_tptp_term tptp_t1 ^ " \\\\vee " ^ latex_of_tptp_term tptp_t2 ^ ")"
   538         "(" ^ latex_of_tptp_term tptp_t1 ^ " \\\\vee " ^ latex_of_tptp_term tptp_t2 ^ ")"
   574         space_implode "\\\\, " (map latex_of_tptp_term tptp_term_list) (*^ ")"*)
   548         space_implode "\\\\, " (map latex_of_tptp_term tptp_term_list) (*^ ")"*)
   575     | Term_Var str => "\\\\mathrm{" ^ str ^ "}"
   549     | Term_Var str => "\\\\mathrm{" ^ str ^ "}"
   576     | Term_Conditional (tptp_formula, tptp_term1, tptp_term2) => "" (*FIXME*)
   550     | Term_Conditional (tptp_formula, tptp_term1, tptp_term2) => "" (*FIXME*)
   577     | Term_Num (_, str) => str
   551     | Term_Num (_, str) => str
   578     | Term_Distinct_Object str => str (*FIXME*)
   552     | Term_Distinct_Object str => str (*FIXME*)
   579 )
   553 
   580 and latex_of_symbol (Uninterpreted str) =
   554 and latex_of_symbol (Uninterpreted str) =
   581 (*    if str = "union" then "\\\\cup"
       
   582     else if str = "subset" then "\\\\subset"
       
   583     else*)
       
   584     if str = "emptyset" then "\\\\emptyset"
   555     if str = "emptyset" then "\\\\emptyset"
   585     else "\\\\mathrm{" ^ str ^ "}"
   556     else "\\\\mathrm{" ^ str ^ "}"
   586   | latex_of_symbol (Interpreted_ExtraLogic interpreted_symbol) = latex_of_interpreted_symbol interpreted_symbol
   557   | latex_of_symbol (Interpreted_ExtraLogic interpreted_symbol) = latex_of_interpreted_symbol interpreted_symbol
   587   | latex_of_symbol (Interpreted_Logic logic_symbol) = latex_of_logic_symbol logic_symbol
   558   | latex_of_symbol (Interpreted_Logic logic_symbol) = latex_of_logic_symbol logic_symbol
   588   | latex_of_symbol (TypeSymbol tptp_base_type) = latex_of_tptp_base_type tptp_base_type
   559   | latex_of_symbol (TypeSymbol tptp_base_type) = latex_of_tptp_base_type tptp_base_type
   652 and latex_of_tptp_atom (TFF_Typed_Atom (symbol, tptp_type_option)) =
   623 and latex_of_tptp_atom (TFF_Typed_Atom (symbol, tptp_type_option)) =
   653     (case tptp_type_option of
   624     (case tptp_type_option of
   654        NONE => latex_of_symbol symbol
   625        NONE => latex_of_symbol symbol
   655      | SOME tptp_type =>
   626      | SOME tptp_type =>
   656          latex_of_symbol symbol ^ " : " ^ latex_of_tptp_type tptp_type)
   627          latex_of_symbol symbol ^ " : " ^ latex_of_tptp_type tptp_type)
   657   | latex_of_tptp_atom (THF_Atom_term tptp_term) = latex_of_tptp_term tptp_term   
   628   | latex_of_tptp_atom (THF_Atom_term tptp_term) = latex_of_tptp_term tptp_term
   658   | latex_of_tptp_atom (THF_Atom_conn_term symbol) = latex_of_symbol symbol
   629   | latex_of_tptp_atom (THF_Atom_conn_term symbol) = latex_of_symbol symbol
   659 
   630 
   660 (*
   631 and latex_of_tptp_formula (Pred (Interpreted_Logic Equals, [tptp_t1, tptp_t2])) =
   661 and latex_of_tptp_formula (Pred (symbol, tptp_term_list)) =
   632       "(" ^ latex_of_tptp_term tptp_t1 ^ " = " ^ latex_of_tptp_term tptp_t2 ^ ")"
   662       "(" ^ latex_of_symbol symbol ^
   633   | latex_of_tptp_formula (Pred (Interpreted_Logic NEquals, [tptp_t1, tptp_t2])) =
   663       space_implode " " (map latex_of_tptp_term tptp_term_list) ^ ")"
   634       "(" ^ latex_of_tptp_term tptp_t1 ^ " \\\\neq " ^ latex_of_tptp_term tptp_t2 ^ ")"
   664   | latex_of_tptp_formula (Fmla (symbol, tptp_formula_list)) =
   635   | latex_of_tptp_formula (Pred (Interpreted_Logic Or, [tptp_t1, tptp_t2])) =
   665       "(" ^ latex_of_symbol symbol ^
   636       "(" ^ latex_of_tptp_term tptp_t1 ^ " \\\\vee " ^ latex_of_tptp_term tptp_t2 ^ ")"
   666       space_implode " " (map latex_of_tptp_formula tptp_formula_list) ^ ")"
   637   | latex_of_tptp_formula (Pred (Interpreted_Logic And, [tptp_t1, tptp_t2])) =
   667 *)
   638       "(" ^ latex_of_tptp_term tptp_t1 ^ " \\\\wedge " ^ latex_of_tptp_term tptp_t2 ^ ")"
   668 (*
   639   | latex_of_tptp_formula (Pred (Interpreted_Logic Iff, [tptp_t1, tptp_t2])) =
   669 and  latex_of_tptp_formula (Pred (Uninterpreted "subset", [tptp_t1, tptp_t2])) =
   640       "(" ^ latex_of_tptp_term tptp_t1 ^ " \\\\longleftrightarrow " ^ latex_of_tptp_term tptp_t2 ^ ")"
   670         "(" ^ latex_of_tptp_term tptp_t1 ^ " \\\\subset " ^ latex_of_tptp_term tptp_t2 ^ ")"
   641   | latex_of_tptp_formula (Pred (Interpreted_Logic If, [tptp_t1, tptp_t2])) =
   671     | latex_of_tptp_formula (Pred (Uninterpreted "union", [tptp_t1, tptp_t2])) =
   642       "(" ^ latex_of_tptp_term tptp_t1 ^ " \\\\longrightarrow " ^ latex_of_tptp_term tptp_t2 ^ ")"
   672         "(" ^ latex_of_tptp_term tptp_t1 ^ " \\\\cup " ^ latex_of_tptp_term tptp_t2 ^ ")"
       
   673 *)
       
   674 and  (*latex_of_tptp_formula (
       
   675       Pred (Interpreted_ExtraLogic Apply,
       
   676                  [Term_Func (Interpreted_ExtraLogic Apply,
       
   677                              [Term_Func (Interpreted_ExtraLogic Apply, [Term_Func (Uninterpreted "subset", []),
       
   678                                                                              tptp_t1])]), tptp_t2])) =
       
   679         "(" ^ latex_of_tptp_term tptp_t1 ^ " \\\\subset " ^ latex_of_tptp_term tptp_t2 ^ ")"
       
   680     | latex_of_tptp_formula (Pred (Interpreted_ExtraLogic Apply,
       
   681                  [Term_Func (Interpreted_ExtraLogic Apply,
       
   682                              [Term_Func (Interpreted_ExtraLogic Apply, [Term_Func (Uninterpreted "union", []),
       
   683                                                                              tptp_t1])]), tptp_t2])) =
       
   684         "(" ^ latex_of_tptp_term tptp_t1 ^ " \\\\cup " ^ latex_of_tptp_term tptp_t2 ^ ")"
       
   685 
       
   686     |*) latex_of_tptp_formula (Pred (Interpreted_Logic Equals, [tptp_t1, tptp_t2])) =
       
   687         "(" ^ latex_of_tptp_term tptp_t1 ^ " = " ^ latex_of_tptp_term tptp_t2 ^ ")"
       
   688     | latex_of_tptp_formula (Pred (Interpreted_Logic NEquals, [tptp_t1, tptp_t2])) =
       
   689         "(" ^ latex_of_tptp_term tptp_t1 ^ " \\\\neq " ^ latex_of_tptp_term tptp_t2 ^ ")"
       
   690     | latex_of_tptp_formula (Pred (Interpreted_Logic Or, [tptp_t1, tptp_t2])) =
       
   691         "(" ^ latex_of_tptp_term tptp_t1 ^ " \\\\vee " ^ latex_of_tptp_term tptp_t2 ^ ")"
       
   692     | latex_of_tptp_formula (Pred (Interpreted_Logic And, [tptp_t1, tptp_t2])) =
       
   693         "(" ^ latex_of_tptp_term tptp_t1 ^ " \\\\wedge " ^ latex_of_tptp_term tptp_t2 ^ ")"
       
   694     | latex_of_tptp_formula (Pred (Interpreted_Logic Iff, [tptp_t1, tptp_t2])) =
       
   695         "(" ^ latex_of_tptp_term tptp_t1 ^ " \\\\longleftrightarrow " ^ latex_of_tptp_term tptp_t2 ^ ")"
       
   696     | latex_of_tptp_formula (Pred (Interpreted_Logic If, [tptp_t1, tptp_t2])) =
       
   697         "(" ^ latex_of_tptp_term tptp_t1 ^ " \\\\longrightarrow " ^ latex_of_tptp_term tptp_t2 ^ ")"
       
   698 
   643 
   699   | latex_of_tptp_formula (x as (Pred (symbol, tptp_term_list))) =
   644   | latex_of_tptp_formula (x as (Pred (symbol, tptp_term_list))) =
   700 ((*writeln ("fmla=" ^ PolyML.makestring x);*)
   645       latex_of_symbol symbol ^
   701       (*"(" ^*) latex_of_symbol symbol ^
   646        space_implode "\\\\, " (map latex_of_tptp_term tptp_term_list)
   702       space_implode "\\\\, " (map latex_of_tptp_term tptp_term_list) (*^ ")"*)
   647 
   703 )
   648   | latex_of_tptp_formula (Fmla (Interpreted_ExtraLogic Apply, [Fmla (Interpreted_ExtraLogic Apply, [Atom (THF_Atom_term (Term_Func (Uninterpreted "union", []))), tptp_f1]), tptp_f2])) =
   704 
   649       "(" ^ latex_of_tptp_formula tptp_f1 ^ " \\\\cup " ^ latex_of_tptp_formula tptp_f2 ^ ")"
   705 (*
   650 
   706     | latex_of_tptp_formula (Fmla (Uninterpreted "subset", [tptp_f1, tptp_f2])) =
   651   | latex_of_tptp_formula (Fmla (Interpreted_ExtraLogic Apply, [Fmla (Interpreted_ExtraLogic Apply, [Atom (THF_Atom_term (Term_Func (Uninterpreted "subset", []))), tptp_f1]), tptp_f2])) =
   707         "(" ^ latex_of_tptp_formula tptp_f1 ^ " \\\\subset " ^ latex_of_tptp_formula tptp_f2 ^ ")"
   652       "(" ^ latex_of_tptp_formula tptp_f1 ^ " \\\\subset " ^ latex_of_tptp_formula tptp_f2 ^ ")"
   708     | latex_of_tptp_formula (Fmla (Uninterpreted "union", [tptp_f1, tptp_f2])) =
   653 
   709         "(" ^ latex_of_tptp_formula tptp_f1 ^ " \\\\cup " ^ latex_of_tptp_formula tptp_f2 ^ ")"
   654   | latex_of_tptp_formula (Fmla (Interpreted_Logic Equals, [tptp_f1, tptp_f2])) =
   710 *)
   655       "(" ^ latex_of_tptp_formula tptp_f1 ^ " = " ^ latex_of_tptp_formula tptp_f2 ^ ")"
   711 
   656   | latex_of_tptp_formula (Fmla (Interpreted_Logic NEquals, [tptp_f1, tptp_f2])) =
   712 (*
   657       "(" ^ latex_of_tptp_formula tptp_f1 ^ " \\\\neq " ^ latex_of_tptp_formula tptp_f2 ^ ")"
   713     | latex_of_tptp_formula (
   658   | latex_of_tptp_formula (Fmla (Interpreted_Logic Or, [tptp_f1, tptp_f2])) =
   714       Fmla (Interpreted_ExtraLogic Apply,
   659       "(" ^ latex_of_tptp_formula tptp_f1 ^ " \\\\vee " ^ latex_of_tptp_formula tptp_f2 ^ ")"
   715                  [Fmla (Interpreted_ExtraLogic Apply,
   660   | latex_of_tptp_formula (Fmla (Interpreted_Logic And, [tptp_f1, tptp_f2])) =
   716                              [Fmla (Interpreted_ExtraLogic Apply, [Fmla (Uninterpreted "subset", []),
   661       "(" ^ latex_of_tptp_formula tptp_f1 ^ " \\\\wedge " ^ latex_of_tptp_formula tptp_f2 ^ ")"
   717                                                                              tptp_t1])]), tptp_t2])) =
   662   | latex_of_tptp_formula (Fmla (Interpreted_Logic Iff, [tptp_f1, tptp_f2])) =
   718         "(" ^ latex_of_tptp_formula tptp_t1 ^ " \\\\subset " ^ latex_of_tptp_formula tptp_t2 ^ ")"
   663       "(" ^ latex_of_tptp_formula tptp_f1 ^ " \\\\longleftrightarrow " ^ latex_of_tptp_formula tptp_f2 ^ ")"
   719     | latex_of_tptp_formula (Fmla (Interpreted_ExtraLogic Apply,
   664   | latex_of_tptp_formula (Fmla (Interpreted_Logic If, [tptp_f1, tptp_f2])) =
   720                  [Fmla (Interpreted_ExtraLogic Apply,
   665       "(" ^ latex_of_tptp_formula tptp_f1 ^ " \\\\longrightarrow " ^ latex_of_tptp_formula tptp_f2 ^ ")"
   721                              [Fmla (Interpreted_ExtraLogic Apply, [Fmla (Uninterpreted "union", []),
       
   722                                                                              tptp_t1])]), tptp_t2])) =
       
   723         "(" ^ latex_of_tptp_formula tptp_t1 ^ " \\\\cup " ^ latex_of_tptp_formula tptp_t2 ^ ")"
       
   724 *)
       
   725 
       
   726     | latex_of_tptp_formula (Fmla (Interpreted_ExtraLogic Apply, [Fmla (Interpreted_ExtraLogic Apply, [Atom (THF_Atom_term (Term_Func (Uninterpreted "union", []))), tptp_f1]), tptp_f2])) =
       
   727         "(" ^ latex_of_tptp_formula tptp_f1 ^ " \\\\cup " ^ latex_of_tptp_formula tptp_f2 ^ ")"
       
   728 
       
   729     | latex_of_tptp_formula (Fmla (Interpreted_ExtraLogic Apply, [Fmla (Interpreted_ExtraLogic Apply, [Atom (THF_Atom_term (Term_Func (Uninterpreted "subset", []))), tptp_f1]), tptp_f2])) =
       
   730         "(" ^ latex_of_tptp_formula tptp_f1 ^ " \\\\subset " ^ latex_of_tptp_formula tptp_f2 ^ ")"
       
   731 
       
   732 
       
   733     | latex_of_tptp_formula (Fmla (Interpreted_Logic Equals, [tptp_f1, tptp_f2])) =
       
   734         "(" ^ latex_of_tptp_formula tptp_f1 ^ " = " ^ latex_of_tptp_formula tptp_f2 ^ ")"
       
   735     | latex_of_tptp_formula (Fmla (Interpreted_Logic NEquals, [tptp_f1, tptp_f2])) =
       
   736         "(" ^ latex_of_tptp_formula tptp_f1 ^ " \\\\neq " ^ latex_of_tptp_formula tptp_f2 ^ ")"
       
   737     | latex_of_tptp_formula (Fmla (Interpreted_Logic Or, [tptp_f1, tptp_f2])) =
       
   738         "(" ^ latex_of_tptp_formula tptp_f1 ^ " \\\\vee " ^ latex_of_tptp_formula tptp_f2 ^ ")"
       
   739     | latex_of_tptp_formula (Fmla (Interpreted_Logic And, [tptp_f1, tptp_f2])) =
       
   740         "(" ^ latex_of_tptp_formula tptp_f1 ^ " \\\\wedge " ^ latex_of_tptp_formula tptp_f2 ^ ")"
       
   741     | latex_of_tptp_formula (Fmla (Interpreted_Logic Iff, [tptp_f1, tptp_f2])) =
       
   742         "(" ^ latex_of_tptp_formula tptp_f1 ^ " \\\\longleftrightarrow " ^ latex_of_tptp_formula tptp_f2 ^ ")"
       
   743     | latex_of_tptp_formula (Fmla (Interpreted_Logic If, [tptp_f1, tptp_f2])) =
       
   744         "(" ^ latex_of_tptp_formula tptp_f1 ^ " \\\\longrightarrow " ^ latex_of_tptp_formula tptp_f2 ^ ")"
       
   745 
   666 
   746   | latex_of_tptp_formula (x as (Fmla (symbol, tptp_formula_list))) =
   667   | latex_of_tptp_formula (x as (Fmla (symbol, tptp_formula_list))) =
   747 (writeln ("fmla=" ^ PolyML.makestring x);
   668       latex_of_symbol symbol ^
   748       (*"(" ^*) latex_of_symbol symbol ^
   669         space_implode "\\\\, " (map latex_of_tptp_formula tptp_formula_list)
   749       space_implode "\\\\, " (map latex_of_tptp_formula tptp_formula_list) (*^ ")"*)
       
   750 )
       
   751 
   670 
   752   | latex_of_tptp_formula (Sequent (tptp_formula_list1, tptp_formula_list2)) = "" (*FIXME*)
   671   | latex_of_tptp_formula (Sequent (tptp_formula_list1, tptp_formula_list2)) = "" (*FIXME*)
   753   | latex_of_tptp_formula (Quant (quantifier, varlist, tptp_formula)) =
   672   | latex_of_tptp_formula (Quant (quantifier, varlist, tptp_formula)) =
   754       latex_of_quantifier quantifier ^
   673       latex_of_quantifier quantifier ^
   755       space_implode ", " (map (fn (n, ty) =>
   674       space_implode ", " (map (fn (n, ty) =>