src/HOL/arith_data.ML
changeset 21621 f9fd69d96c4e
parent 21415 39f98c88f88a
child 21820 2f2b6a965ccc
equal deleted inserted replaced
21620:3d4bfc7f6363 21621:f9fd69d96c4e
    14 
    14 
    15 (** abstract syntax of structure nat: 0, Suc, + **)
    15 (** abstract syntax of structure nat: 0, Suc, + **)
    16 
    16 
    17 (* mk_sum, mk_norm_sum *)
    17 (* mk_sum, mk_norm_sum *)
    18 
    18 
    19 val one = HOLogic.mk_nat 1;
       
    20 val mk_plus = HOLogic.mk_binop "HOL.plus";
    19 val mk_plus = HOLogic.mk_binop "HOL.plus";
    21 
    20 
    22 fun mk_sum [] = HOLogic.zero
    21 fun mk_sum [] = HOLogic.zero
    23   | mk_sum [t] = t
    22   | mk_sum [t] = t
    24   | mk_sum (t :: ts) = mk_plus (t, mk_sum ts);
    23   | mk_sum (t :: ts) = mk_plus (t, mk_sum ts);
    25 
    24 
    26 (*normal form of sums: Suc (... (Suc (a + (b + ...))))*)
    25 (*normal form of sums: Suc (... (Suc (a + (b + ...))))*)
    27 fun mk_norm_sum ts =
    26 fun mk_norm_sum ts =
    28   let val (ones, sums) = List.partition (equal one) ts in
    27   let val (ones, sums) = List.partition (equal HOLogic.Suc_zero) ts in
    29     funpow (length ones) HOLogic.mk_Suc (mk_sum sums)
    28     funpow (length ones) HOLogic.mk_Suc (mk_sum sums)
    30   end;
    29   end;
    31 
    30 
    32 (* dest_sum *)
    31 (* dest_sum *)
    33 
    32 
    35 
    34 
    36 fun dest_sum tm =
    35 fun dest_sum tm =
    37   if HOLogic.is_zero tm then []
    36   if HOLogic.is_zero tm then []
    38   else
    37   else
    39     (case try HOLogic.dest_Suc tm of
    38     (case try HOLogic.dest_Suc tm of
    40       SOME t => one :: dest_sum t
    39       SOME t => HOLogic.Suc_zero :: dest_sum t
    41     | NONE =>
    40     | NONE =>
    42         (case try dest_plus tm of
    41         (case try dest_plus tm of
    43           SOME (t, u) => dest_sum t @ dest_sum u
    42           SOME (t, u) => dest_sum t @ dest_sum u
    44         | NONE => [tm]));
    43         | NONE => [tm]));
    45 
    44