src/HOL/hologic.ML
changeset 22994 02440636214f
parent 22391 56861fe9c22c
child 23247 b99dce43d252
equal deleted inserted replaced
22993:838c66e760b5 22994:02440636214f
    71   val mk_Suc: term -> term
    71   val mk_Suc: term -> term
    72   val dest_Suc: term -> term
    72   val dest_Suc: term -> term
    73   val Suc_zero: term
    73   val Suc_zero: term
    74   val mk_nat: IntInf.int -> term
    74   val mk_nat: IntInf.int -> term
    75   val dest_nat: term -> IntInf.int
    75   val dest_nat: term -> IntInf.int
       
    76   val class_size: string
       
    77   val size_const: typ -> term
    76   val bitT: typ
    78   val bitT: typ
    77   val B0_const: term
    79   val B0_const: term
    78   val B1_const: term
    80   val B1_const: term
    79   val mk_bit: int -> term
    81   val mk_bit: int -> term
    80   val dest_bit: term -> int
    82   val dest_bit: term -> int
   279 
   281 
   280 (* nat *)
   282 (* nat *)
   281 
   283 
   282 val natT = Type ("nat", []);
   284 val natT = Type ("nat", []);
   283 
   285 
   284 val zero = Const ("HOL.zero", natT);
   286 val zero = Const ("HOL.zero_class.zero", natT);
   285 
   287 
   286 fun is_zero (Const ("HOL.zero", _)) = true
   288 fun is_zero (Const ("HOL.zero_class.zero", _)) = true
   287   | is_zero _ = false;
   289   | is_zero _ = false;
   288 
   290 
   289 fun mk_Suc t = Const ("Suc", natT --> natT) $ t;
   291 fun mk_Suc t = Const ("Suc", natT --> natT) $ t;
   290 
   292 
   291 fun dest_Suc (Const ("Suc", _) $ t) = t
   293 fun dest_Suc (Const ("Suc", _) $ t) = t
   292   | dest_Suc t = raise TERM ("dest_Suc", [t]);
   294   | dest_Suc t = raise TERM ("dest_Suc", [t]);
   293 
   295 
   294 val Suc_zero = mk_Suc zero;
   296 val Suc_zero = mk_Suc zero;
   295 
   297 
   296 fun mk_nat 0 = zero
   298 fun mk_nat n =
   297   | mk_nat n = mk_Suc (mk_nat (IntInf.- (n, 1)));
   299   let
   298 
   300     fun mk 0 = zero
   299 fun dest_nat (Const ("HOL.zero", _)) = 0
   301       | mk n = mk_Suc (mk (IntInf.- (n, 1)));
       
   302   in if IntInf.< (n, 0)
       
   303     then error "mk_nat: negative numeral"
       
   304     else mk n
       
   305   end;
       
   306 
       
   307 fun dest_nat (Const ("HOL.zero_class.zero", _)) = 0
   300   | dest_nat (Const ("Suc", _) $ t) = IntInf.+ (dest_nat t, 1)
   308   | dest_nat (Const ("Suc", _) $ t) = IntInf.+ (dest_nat t, 1)
   301   | dest_nat t = raise TERM ("dest_nat", [t]);
   309   | dest_nat t = raise TERM ("dest_nat", [t]);
       
   310 
       
   311 val class_size = "Nat.size";
       
   312 
       
   313 fun size_const T = Const ("Nat.size_class.size", T --> natT);
   302 
   314 
   303 
   315 
   304 (* bit *)
   316 (* bit *)
   305 
   317 
   306 val bitT = Type ("Numeral.bit", []);
   318 val bitT = Type ("Numeral.bit", []);
   335   | dest_numeral (Const ("Numeral.Min", _)) = ~1
   347   | dest_numeral (Const ("Numeral.Min", _)) = ~1
   336   | dest_numeral (Const ("Numeral.Bit", _) $ bs $ b) =
   348   | dest_numeral (Const ("Numeral.Bit", _) $ bs $ b) =
   337       2 * dest_numeral bs + IntInf.fromInt (dest_bit b)
   349       2 * dest_numeral bs + IntInf.fromInt (dest_bit b)
   338   | dest_numeral t = raise TERM ("dest_numeral", [t]);
   350   | dest_numeral t = raise TERM ("dest_numeral", [t]);
   339 
   351 
   340 fun number_of_const T = Const ("Numeral.number_of", intT --> T);
   352 fun number_of_const T = Const ("Numeral.number_class.number_of", intT --> T);
   341 
   353 
   342 fun add_numerals_of (Const _) =
   354 fun add_numerals_of (Const _) =
   343       I
   355       I
   344   | add_numerals_of (Var _) =
   356   | add_numerals_of (Var _) =
   345       I
   357       I
   349       I
   361       I
   350   | add_numerals_of (Abs (_, _, t)) =
   362   | add_numerals_of (Abs (_, _, t)) =
   351       add_numerals_of t
   363       add_numerals_of t
   352   | add_numerals_of (t as _ $ _) =
   364   | add_numerals_of (t as _ $ _) =
   353       case strip_comb t
   365       case strip_comb t
   354        of (Const ("Numeral.number_of",
   366        of (Const ("Numeral.number_class.number_of",
   355            Type (_, [_, T])), ts) => fold (cons o rpair T) ts
   367            Type (_, [_, T])), ts) => fold (cons o rpair T) ts
   356         | (t', ts) => add_numerals_of t' #> fold add_numerals_of ts;
   368         | (t', ts) => add_numerals_of t' #> fold add_numerals_of ts;
   357 
   369 
   358 fun mk_number T 0 = Const ("HOL.zero", T)
   370 fun mk_number T 0 = Const ("HOL.zero_class.zero", T)
   359   | mk_number T 1 = Const ("HOL.one", T)
   371   | mk_number T 1 = Const ("HOL.one_class.one", T)
   360   | mk_number T i = number_of_const T $ mk_numeral i;
   372   | mk_number T i = number_of_const T $ mk_numeral i;
   361 
   373 
   362 fun dest_number (Const ("HOL.zero", T)) = (T, 0)
   374 fun dest_number (Const ("HOL.zero_class.zero", T)) = (T, 0)
   363   | dest_number (Const ("HOL.one", T)) = (T, 1)
   375   | dest_number (Const ("HOL.one_class.one", T)) = (T, 1)
   364   | dest_number (Const ("Numeral.number_of", Type ("fun", [_, T])) $ t) = (T, dest_numeral t)
   376   | dest_number (Const ("Numeral.number_class.number_of", Type ("fun", [_, T])) $ t) =
       
   377       (T, dest_numeral t)
   365   | dest_number t = raise TERM ("dest_number", [t]);
   378   | dest_number t = raise TERM ("dest_number", [t]);
   366 
   379 
   367 
   380 
   368 (* real *)
   381 (* real *)
   369 
   382