src/HOL/Tools/numeral_simprocs.ML
changeset 35084 e25eedfc15ce
parent 35064 1bdef0c013d3
child 35092 cfe605c54e50
equal deleted inserted replaced
35083:3246e66b0874 35084:e25eedfc15ce
    94 
    94 
    95 (*Don't reduce fractions; sums must be proved by rule add_frac_eq.
    95 (*Don't reduce fractions; sums must be proved by rule add_frac_eq.
    96   Fractions are reduced later by the cancel_numeral_factor simproc.*)
    96   Fractions are reduced later by the cancel_numeral_factor simproc.*)
    97 fun add_frac ((p1, q1), (p2, q2)) = (p1 * q2 + p2 * q1, q1 * q2);
    97 fun add_frac ((p1, q1), (p2, q2)) = (p1 * q2 + p2 * q1, q1 * q2);
    98 
    98 
    99 val mk_divide = HOLogic.mk_binop @{const_name Algebras.divide};
    99 val mk_divide = HOLogic.mk_binop @{const_name Rings.divide};
   100 
   100 
   101 (*Build term (p / q) * t*)
   101 (*Build term (p / q) * t*)
   102 fun mk_fcoeff ((p, q), t) =
   102 fun mk_fcoeff ((p, q), t) =
   103   let val T = Term.fastype_of t
   103   let val T = Term.fastype_of t
   104   in mk_times (mk_divide (mk_number T p, mk_number T q), t) end;
   104   in mk_times (mk_divide (mk_number T p, mk_number T q), t) end;
   105 
   105 
   106 (*Express t as a product of a fraction with other sorted terms*)
   106 (*Express t as a product of a fraction with other sorted terms*)
   107 fun dest_fcoeff sign (Const (@{const_name Algebras.uminus}, _) $ t) = dest_fcoeff (~sign) t
   107 fun dest_fcoeff sign (Const (@{const_name Algebras.uminus}, _) $ t) = dest_fcoeff (~sign) t
   108   | dest_fcoeff sign (Const (@{const_name Algebras.divide}, _) $ t $ u) =
   108   | dest_fcoeff sign (Const (@{const_name Rings.divide}, _) $ t $ u) =
   109     let val (p, t') = dest_coeff sign t
   109     let val (p, t') = dest_coeff sign t
   110         val (q, u') = dest_coeff 1 u
   110         val (q, u') = dest_coeff 1 u
   111     in (mk_frac (p, q), mk_divide (t', u')) end
   111     in (mk_frac (p, q), mk_divide (t', u')) end
   112   | dest_fcoeff sign t =
   112   | dest_fcoeff sign t =
   113     let val (p, t') = dest_coeff sign t
   113     let val (p, t') = dest_coeff sign t
   389 
   389 
   390 (*Version for fields*)
   390 (*Version for fields*)
   391 structure DivideCancelNumeralFactor = CancelNumeralFactorFun
   391 structure DivideCancelNumeralFactor = CancelNumeralFactorFun
   392  (open CancelNumeralFactorCommon
   392  (open CancelNumeralFactorCommon
   393   val prove_conv = Arith_Data.prove_conv
   393   val prove_conv = Arith_Data.prove_conv
   394   val mk_bal   = HOLogic.mk_binop @{const_name Algebras.divide}
   394   val mk_bal   = HOLogic.mk_binop @{const_name Rings.divide}
   395   val dest_bal = HOLogic.dest_bin @{const_name Algebras.divide} Term.dummyT
   395   val dest_bal = HOLogic.dest_bin @{const_name Rings.divide} Term.dummyT
   396   val cancel = @{thm mult_divide_mult_cancel_left} RS trans
   396   val cancel = @{thm mult_divide_mult_cancel_left} RS trans
   397   val neg_exchanges = false
   397   val neg_exchanges = false
   398 )
   398 )
   399 
   399 
   400 structure EqCancelNumeralFactor = CancelNumeralFactorFun
   400 structure EqCancelNumeralFactor = CancelNumeralFactorFun
   568 
   568 
   569 (*Version for all fields, including unordered ones (type complex).*)
   569 (*Version for all fields, including unordered ones (type complex).*)
   570 structure DivideCancelFactor = ExtractCommonTermFun
   570 structure DivideCancelFactor = ExtractCommonTermFun
   571  (open CancelFactorCommon
   571  (open CancelFactorCommon
   572   val prove_conv = Arith_Data.prove_conv
   572   val prove_conv = Arith_Data.prove_conv
   573   val mk_bal   = HOLogic.mk_binop @{const_name Algebras.divide}
   573   val mk_bal   = HOLogic.mk_binop @{const_name Rings.divide}
   574   val dest_bal = HOLogic.dest_bin @{const_name Algebras.divide} Term.dummyT
   574   val dest_bal = HOLogic.dest_bin @{const_name Rings.divide} Term.dummyT
   575   fun simp_conv _ _ = SOME @{thm mult_divide_mult_cancel_left_if}
   575   fun simp_conv _ _ = SOME @{thm mult_divide_mult_cancel_left_if}
   576 );
   576 );
   577 
   577 
   578 val cancel_factors =
   578 val cancel_factors =
   579   map (Arith_Data.prep_simproc @{theory})
   579   map (Arith_Data.prep_simproc @{theory})