src/HOL/int_arith1.ML
changeset 23400 a64b39e5809b
parent 23365 f31794033ae1
child 23881 851c74f1bb69
     1.1 --- a/src/HOL/int_arith1.ML	Fri Jun 15 19:19:23 2007 +0200
     1.2 +++ b/src/HOL/int_arith1.ML	Sat Jun 16 15:01:54 2007 +0200
     1.3 @@ -191,8 +191,7 @@
     1.4  
     1.5  fun mk_minus t = 
     1.6    let val T = Term.fastype_of t
     1.7 -  in Const (@{const_name HOL.uminus}, T --> T) $ t
     1.8 -  end;
     1.9 +  in Const (@{const_name HOL.uminus}, T --> T) $ t end;
    1.10  
    1.11  (*Thus mk_sum[t] yields t+0; longer sums don't have a trailing zero*)
    1.12  fun mk_sum T []        = mk_number T 0
    1.13 @@ -220,22 +219,28 @@
    1.14  
    1.15  val mk_times = HOLogic.mk_binop @{const_name HOL.times};
    1.16  
    1.17 +fun one_of T = Const(@{const_name HOL.one},T);
    1.18 +
    1.19 +(* build product with trailing 1 rather than Numeral 1 in order to avoid the
    1.20 +   unnecessary restriction to type class number_ring
    1.21 +   which is not required for cancellation of common factors in divisions.
    1.22 +*)
    1.23  fun mk_prod T = 
    1.24 -  let val one = mk_number T 1
    1.25 +  let val one = one_of T
    1.26    fun mk [] = one
    1.27      | mk [t] = t
    1.28      | mk (t :: ts) = if t = one then mk ts else mk_times (t, mk ts)
    1.29    in mk end;
    1.30  
    1.31  (*This version ALWAYS includes a trailing one*)
    1.32 -fun long_mk_prod T []        = mk_number T 1
    1.33 +fun long_mk_prod T []        = one_of T
    1.34    | long_mk_prod T (t :: ts) = mk_times (t, mk_prod T ts);
    1.35  
    1.36  val dest_times = HOLogic.dest_bin @{const_name HOL.times} Term.dummyT;
    1.37  
    1.38  fun dest_prod t =
    1.39        let val (t,u) = dest_times t
    1.40 -      in  dest_prod t @ dest_prod u  end
    1.41 +      in dest_prod t @ dest_prod u end
    1.42        handle TERM _ => [t];
    1.43  
    1.44  (*DON'T do the obvious simplifications; that would create special cases*)
    1.45 @@ -253,8 +258,8 @@
    1.46  fun find_first_coeff past u [] = raise TERM("find_first_coeff", [])
    1.47    | find_first_coeff past u (t::terms) =
    1.48          let val (n,u') = dest_coeff 1 t
    1.49 -        in  if u aconv u' then (n, rev past @ terms)
    1.50 -                          else find_first_coeff (t::past) u terms
    1.51 +        in if u aconv u' then (n, rev past @ terms)
    1.52 +                         else find_first_coeff (t::past) u terms
    1.53          end
    1.54          handle TERM _ => find_first_coeff (t::past) u terms;
    1.55  
    1.56 @@ -271,23 +276,23 @@
    1.57  (*Build term (p / q) * t*)
    1.58  fun mk_fcoeff ((p, q), t) =
    1.59    let val T = Term.fastype_of t
    1.60 -  in  mk_times (mk_divide (mk_number T p, mk_number T q), t) end;
    1.61 +  in mk_times (mk_divide (mk_number T p, mk_number T q), t) end;
    1.62  
    1.63  (*Express t as a product of a fraction with other sorted terms*)
    1.64  fun dest_fcoeff sign (Const (@{const_name HOL.uminus}, _) $ t) = dest_fcoeff (~sign) t
    1.65    | dest_fcoeff sign (Const (@{const_name HOL.divide}, _) $ t $ u) =
    1.66      let val (p, t') = dest_coeff sign t
    1.67          val (q, u') = dest_coeff 1 u
    1.68 -    in  (mk_frac (p, q), mk_divide (t', u')) end
    1.69 +    in (mk_frac (p, q), mk_divide (t', u')) end
    1.70    | dest_fcoeff sign t =
    1.71      let val (p, t') = dest_coeff sign t
    1.72          val T = Term.fastype_of t
    1.73 -    in  (mk_frac (p, 1), mk_divide (t', mk_number T 1)) end;
    1.74 +    in (mk_frac (p, 1), mk_divide (t', one_of T)) end;
    1.75  
    1.76  
    1.77 -(*Simplify Numeral0+n, n+Numeral0, Numeral1*n, n*Numeral1*)
    1.78 +(*Simplify Numeral0+n, n+Numeral0, Numeral1*n, n*Numeral1, 1*x, x*1, x/1 *)
    1.79  val add_0s =  thms "add_0s";
    1.80 -val mult_1s = thms "mult_1s";
    1.81 +val mult_1s = thms "mult_1s" @ [thm"mult_1_left", thm"mult_1_right", thm"divide_1"];
    1.82  
    1.83  (*Simplify inverse Numeral1, a/Numeral1*)
    1.84  val inverse_1s = [@{thm inverse_numeral_1}];