src/Provers/Arith/combine_numerals.ML
changeset 23058 c722004c5a22
parent 20114 a1bb4bc68ff3
child 35762 af3ff2ba4c54
equal deleted inserted replaced
23057:68b152e8ea86 23058:c722004c5a22
    17 *)
    17 *)
    18 
    18 
    19 signature COMBINE_NUMERALS_DATA =
    19 signature COMBINE_NUMERALS_DATA =
    20 sig
    20 sig
    21   (*abstract syntax*)
    21   (*abstract syntax*)
    22   val add: IntInf.int * IntInf.int -> IntInf.int     (*addition (or multiplication) *)
    22   eqtype coeff
       
    23   val iszero: coeff -> bool
       
    24   val add: coeff * coeff -> coeff     (*addition (or multiplication) *)
    23   val mk_sum: typ -> term list -> term
    25   val mk_sum: typ -> term list -> term
    24   val dest_sum: term -> term list
    26   val dest_sum: term -> term list
    25   val mk_coeff: IntInf.int * term -> term
    27   val mk_coeff: coeff * term -> term
    26   val dest_coeff: term -> IntInf.int * term
    28   val dest_coeff: term -> coeff * term
    27   (*rules*)
    29   (*rules*)
    28   val left_distrib: thm
    30   val left_distrib: thm
    29   (*proof tools*)
    31   (*proof tools*)
    30   val prove_conv: tactic list -> Proof.context -> term * term -> thm option
    32   val prove_conv: tactic list -> Proof.context -> term * term -> thm option
    31   val trans_tac: simpset -> thm option -> tactic (*applies the initial lemma*)
    33   val trans_tac: simpset -> thm option -> tactic (*applies the initial lemma*)
    73     val (u,m,n,terms) = find_repeated (Termtab.empty, [], Data.dest_sum t')
    75     val (u,m,n,terms) = find_repeated (Termtab.empty, [], Data.dest_sum t')
    74     val T = Term.fastype_of u
    76     val T = Term.fastype_of u
    75 
    77 
    76     val reshape =  (*Move i*u to the front and put j*u into standard form
    78     val reshape =  (*Move i*u to the front and put j*u into standard form
    77                        i + #m + j + k == #m + i + (j + k) *)
    79                        i + #m + j + k == #m + i + (j + k) *)
    78       if m=0 orelse n=0 then   (*trivial, so do nothing*)
    80       if Data.iszero m orelse Data.iszero n then   (*trivial, so do nothing*)
    79         raise TERM("combine_numerals", [])
    81         raise TERM("combine_numerals", [])
    80       else Data.prove_conv [Data.norm_tac ss] ctxt
    82       else Data.prove_conv [Data.norm_tac ss] ctxt
    81         (t', Data.mk_sum T ([Data.mk_coeff (m, u), Data.mk_coeff (n, u)] @ terms))
    83         (t', Data.mk_sum T ([Data.mk_coeff (m, u), Data.mk_coeff (n, u)] @ terms))
    82   in
    84   in
    83     Option.map (export o Data.simplify_meta_eq ss)
    85     Option.map (export o Data.simplify_meta_eq ss)