src/HOL/Integ/int_arith1.ML
changeset 14474 00292f6f8d13
parent 14390 55fe71faadda
child 14738 83f1a514dcb4
equal deleted inserted replaced
14473:846c237bd9b3 14474:00292f6f8d13
   155 
   155 
   156 (*Maps 0 to Numeral0 and 1 to Numeral1 so that arithmetic in simprocs
   156 (*Maps 0 to Numeral0 and 1 to Numeral1 so that arithmetic in simprocs
   157   isn't complicated by the abstract 0 and 1.*)
   157   isn't complicated by the abstract 0 and 1.*)
   158 val numeral_syms = [numeral_0_eq_0 RS sym, numeral_1_eq_1 RS sym];
   158 val numeral_syms = [numeral_0_eq_0 RS sym, numeral_1_eq_1 RS sym];
   159 
   159 
   160 (*Utilities*)
   160 (** New term ordering so that AC-rewriting brings numerals to the front **)
       
   161 
       
   162 (*Order integers by absolute value and then by sign. The standard integer
       
   163   ordering is not well-founded.*)
       
   164 fun num_ord (i,j) =
       
   165       (case Int.compare (abs i, abs j) of
       
   166             EQUAL => Int.compare (Int.sign i, Int.sign j) 
       
   167           | ord => ord);
       
   168 
       
   169 (*This resembles Term.term_ord, but it puts binary numerals before other
       
   170   non-atomic terms.*)
       
   171 local open Term 
       
   172 in 
       
   173 fun numterm_ord (Abs (_, T, t), Abs(_, U, u)) =
       
   174       (case numterm_ord (t, u) of EQUAL => typ_ord (T, U) | ord => ord)
       
   175   | numterm_ord
       
   176      (Const("Numeral.number_of", _) $ v, Const("Numeral.number_of", _) $ w) =
       
   177      num_ord (HOLogic.dest_binum v, HOLogic.dest_binum w)
       
   178   | numterm_ord (Const("Numeral.number_of", _) $ _, _) = LESS
       
   179   | numterm_ord (_, Const("Numeral.number_of", _) $ _) = GREATER
       
   180   | numterm_ord (t, u) =
       
   181       (case Int.compare (size_of_term t, size_of_term u) of
       
   182         EQUAL =>
       
   183           let val (f, ts) = strip_comb t and (g, us) = strip_comb u in
       
   184             (case hd_ord (f, g) of EQUAL => numterms_ord (ts, us) | ord => ord)
       
   185           end
       
   186       | ord => ord)
       
   187 and numterms_ord (ts, us) = list_ord numterm_ord (ts, us)
       
   188 end;
       
   189 
       
   190 fun numtermless tu = (numterm_ord tu = LESS);
       
   191 
       
   192 (*Defined in this file, but perhaps needed only for simprocs of type nat.*)
       
   193 val num_ss = HOL_ss settermless numtermless;
       
   194 
       
   195 
       
   196 (** Utilities **)
   161 
   197 
   162 fun mk_numeral T n = HOLogic.number_of_const T $ HOLogic.mk_bin n;
   198 fun mk_numeral T n = HOLogic.number_of_const T $ HOLogic.mk_bin n;
   163 
   199 
   164 (*Decodes a binary INTEGER*)
   200 (*Decodes a binary INTEGER*)
   165 fun dest_numeral (Const("0", _)) = 0
   201 fun dest_numeral (Const("0", _)) = 0