src/HOL/hologic.ML
changeset 23297 06f108974fa1
parent 23269 851b8ea067ac
child 23555 16e5fd18905c
equal deleted inserted replaced
23296:25f28f9c28a3 23297:06f108974fa1
   293 fun dest_Suc (Const ("Suc", _) $ t) = t
   293 fun dest_Suc (Const ("Suc", _) $ t) = t
   294   | dest_Suc t = raise TERM ("dest_Suc", [t]);
   294   | dest_Suc t = raise TERM ("dest_Suc", [t]);
   295 
   295 
   296 val Suc_zero = mk_Suc zero;
   296 val Suc_zero = mk_Suc zero;
   297 
   297 
   298 fun mk_nat n =
   298 fun mk_nat (n: integer) =
   299   let
   299   let
   300     fun mk 0 = zero
   300     fun mk 0 = zero
   301       | mk n = mk_Suc (mk (n -% 1));
   301       | mk n = mk_Suc (mk (n - 1));
   302   in if n < 0
   302   in if n < 0 then raise TERM ("mk_nat: negative numeral", []) else mk n end;
   303     then error "mk_nat: negative numeral"
   303 
   304     else mk n
   304 fun dest_nat (Const ("HOL.zero_class.zero", _)) = (0: integer)
   305   end;
   305   | dest_nat (Const ("Suc", _) $ t) = dest_nat t + 1
   306 
       
   307 fun dest_nat (Const ("HOL.zero_class.zero", _)) = Integer.zero
       
   308   | dest_nat (Const ("Suc", _) $ t) = Integer.inc (dest_nat t)
       
   309   | dest_nat t = raise TERM ("dest_nat", [t]);
   306   | dest_nat t = raise TERM ("dest_nat", [t]);
   310 
   307 
   311 val class_size = "Nat.size";
   308 val class_size = "Nat.size";
   312 
   309 
   313 fun size_const T = Const ("Nat.size_class.size", T --> natT);
   310 fun size_const T = Const ("Nat.size_class.size", T --> natT);
   344       in bit_const $ mk_numeral q $ mk_bit (Integer.machine_int r) end;
   341       in bit_const $ mk_numeral q $ mk_bit (Integer.machine_int r) end;
   345 
   342 
   346 fun dest_numeral (Const ("Numeral.Pls", _)) = 0
   343 fun dest_numeral (Const ("Numeral.Pls", _)) = 0
   347   | dest_numeral (Const ("Numeral.Min", _)) = ~1
   344   | dest_numeral (Const ("Numeral.Min", _)) = ~1
   348   | dest_numeral (Const ("Numeral.Bit", _) $ bs $ b) =
   345   | dest_numeral (Const ("Numeral.Bit", _) $ bs $ b) =
   349       2 *% dest_numeral bs +% Integer.int (dest_bit b)
   346       2 * dest_numeral bs + Integer.int (dest_bit b)
   350   | dest_numeral t = raise TERM ("dest_numeral", [t]);
   347   | dest_numeral t = raise TERM ("dest_numeral", [t]);
   351 
   348 
   352 fun number_of_const T = Const ("Numeral.number_class.number_of", intT --> T);
   349 fun number_of_const T = Const ("Numeral.number_class.number_of", intT --> T);
   353 
   350 
   354 fun add_numerals (Const ("Numeral.number_class.number_of", Type (_, [_, T])) $ t) = cons (t, T)
   351 fun add_numerals (Const ("Numeral.number_class.number_of", Type (_, [_, T])) $ t) = cons (t, T)