src/HOL/Integ/int_arith1.ML
author paulson
Thu, 25 Dec 2003 22:48:32 +0100
changeset 14329 ff3210fe968f
parent 14273 e33ffff0123c
child 14331 8dbbb7cf3637
permissions -rw-r--r--
re-organized some hyperreal and real lemmas
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
     1
(*  Title:      HOL/Integ/int_arith1.ML
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
     3
    Authors:    Larry Paulson and Tobias Nipkow
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
     4
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
     5
Simprocs and decision procedure for linear arithmetic.
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
     6
*)
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
     7
14329
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
     8
(** Misc ML bindings **)
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
     9
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
    10
val left_inverse = thm "left_inverse";
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
    11
val right_inverse = thm "right_inverse";
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
    12
val inverse_less_iff_less = thm"Ring_and_Field.inverse_less_iff_less";
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
    13
val inverse_eq_divide = thm"Ring_and_Field.inverse_eq_divide";
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
    14
val inverse_minus_eq = thm "inverse_minus_eq";
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
    15
val inverse_mult_distrib = thm "inverse_mult_distrib";
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
    16
val inverse_add = thm "inverse_add";
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
    17
val inverse_inverse_eq = thm "inverse_inverse_eq";
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
    18
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
    19
val add_right_mono = thm"Ring_and_Field.add_right_mono";
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
    20
val times_divide_eq_left = thm "times_divide_eq_left";
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
    21
val times_divide_eq_right = thm "times_divide_eq_right";
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
    22
val minus_minus = thm "minus_minus";
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
    23
val minus_mult_left = thm "minus_mult_left";
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
    24
val minus_mult_right = thm "minus_mult_right";
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
    25
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
    26
val pos_real_less_divide_eq = thm"pos_less_divide_eq";
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
    27
val pos_real_divide_less_eq = thm"pos_divide_less_eq";
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
    28
val pos_real_le_divide_eq = thm"pos_le_divide_eq";
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
    29
val pos_real_divide_le_eq = thm"pos_divide_le_eq";
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
    30
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
    31
val mult_less_cancel_left = thm"Ring_and_Field.mult_less_cancel_left";
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
    32
val mult_le_cancel_left = thm"Ring_and_Field.mult_le_cancel_left";
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
    33
val mult_less_cancel_right = thm"Ring_and_Field.mult_less_cancel_right";
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
    34
val mult_le_cancel_right = thm"Ring_and_Field.mult_le_cancel_right";
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
    35
val mult_cancel_left = thm"Ring_and_Field.mult_cancel_left";
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
    36
val mult_cancel_right = thm"Ring_and_Field.mult_cancel_right";
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
    37
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
    38
val field_mult_cancel_left = thm "field_mult_cancel_left";
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
    39
val field_mult_cancel_right = thm "field_mult_cancel_right";
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
    40
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
    41
val mult_divide_cancel_left = thm"Ring_and_Field.mult_divide_cancel_left";
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
    42
val mult_divide_cancel_right = thm "Ring_and_Field.mult_divide_cancel_right";
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
    43
val mult_divide_cancel_eq_if = thm"Ring_and_Field.mult_divide_cancel_eq_if";
ff3210fe968f re-organized some hyperreal and real lemmas
paulson
parents: 14273
diff changeset
    44
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    45
val NCons_Pls = thm"NCons_Pls";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    46
val NCons_Min = thm"NCons_Min";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    47
val NCons_BIT = thm"NCons_BIT";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    48
val number_of_Pls = thm"number_of_Pls";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    49
val number_of_Min = thm"number_of_Min";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    50
val number_of_BIT = thm"number_of_BIT";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    51
val bin_succ_Pls = thm"bin_succ_Pls";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    52
val bin_succ_Min = thm"bin_succ_Min";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    53
val bin_succ_BIT = thm"bin_succ_BIT";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    54
val bin_pred_Pls = thm"bin_pred_Pls";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    55
val bin_pred_Min = thm"bin_pred_Min";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    56
val bin_pred_BIT = thm"bin_pred_BIT";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    57
val bin_minus_Pls = thm"bin_minus_Pls";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    58
val bin_minus_Min = thm"bin_minus_Min";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    59
val bin_minus_BIT = thm"bin_minus_BIT";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    60
val bin_add_Pls = thm"bin_add_Pls";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    61
val bin_add_Min = thm"bin_add_Min";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    62
val bin_mult_Pls = thm"bin_mult_Pls";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    63
val bin_mult_Min = thm"bin_mult_Min";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    64
val bin_mult_BIT = thm"bin_mult_BIT";
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
    65
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    66
val zadd_ac = thms "Ring_and_Field.add_ac"
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    67
val zmult_ac = thms "Ring_and_Field.mult_ac"
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    68
val NCons_Pls_0 = thm"NCons_Pls_0";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    69
val NCons_Pls_1 = thm"NCons_Pls_1";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    70
val NCons_Min_0 = thm"NCons_Min_0";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    71
val NCons_Min_1 = thm"NCons_Min_1";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    72
val bin_succ_1 = thm"bin_succ_1";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    73
val bin_succ_0 = thm"bin_succ_0";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    74
val bin_pred_1 = thm"bin_pred_1";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    75
val bin_pred_0 = thm"bin_pred_0";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    76
val bin_minus_1 = thm"bin_minus_1";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    77
val bin_minus_0 = thm"bin_minus_0";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    78
val bin_add_BIT_11 = thm"bin_add_BIT_11";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    79
val bin_add_BIT_10 = thm"bin_add_BIT_10";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    80
val bin_add_BIT_0 = thm"bin_add_BIT_0";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    81
val bin_add_Pls_right = thm"bin_add_Pls_right";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    82
val bin_add_Min_right = thm"bin_add_Min_right";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    83
val bin_add_BIT_BIT = thm"bin_add_BIT_BIT";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    84
val bin_mult_1 = thm"bin_mult_1";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    85
val bin_mult_0 = thm"bin_mult_0";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    86
val number_of_NCons = thm"number_of_NCons";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    87
val number_of_succ = thm"number_of_succ";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    88
val number_of_pred = thm"number_of_pred";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    89
val number_of_minus = thm"number_of_minus";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    90
val number_of_add = thm"number_of_add";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    91
val diff_number_of_eq = thm"diff_number_of_eq";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    92
val number_of_mult = thm"number_of_mult";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    93
val double_number_of_BIT = thm"double_number_of_BIT";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    94
val int_numeral_0_eq_0 = thm"int_numeral_0_eq_0";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    95
val int_numeral_1_eq_1 = thm"int_numeral_1_eq_1";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    96
val zmult_minus1 = thm"zmult_minus1";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    97
val zmult_minus1_right = thm"zmult_minus1_right";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    98
val zminus_number_of_zmult = thm"zminus_number_of_zmult";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
    99
val zminus_1_eq_m1 = thm"zminus_1_eq_m1";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   100
val zero_less_nat_eq = thm"zero_less_nat_eq";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   101
val eq_number_of_eq = thm"eq_number_of_eq";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   102
val iszero_number_of_Pls = thm"iszero_number_of_Pls";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   103
val nonzero_number_of_Min = thm"nonzero_number_of_Min";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   104
val iszero_number_of_BIT = thm"iszero_number_of_BIT";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   105
val iszero_number_of_0 = thm"iszero_number_of_0";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   106
val iszero_number_of_1 = thm"iszero_number_of_1";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   107
val less_number_of_eq_neg = thm"less_number_of_eq_neg";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   108
val not_neg_number_of_Pls = thm"not_neg_number_of_Pls";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   109
val neg_number_of_Min = thm"neg_number_of_Min";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   110
val neg_number_of_BIT = thm"neg_number_of_BIT";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   111
val le_number_of_eq_not_less = thm"le_number_of_eq_not_less";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   112
val zabs_number_of = thm"zabs_number_of";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   113
val zabs_0 = thm"zabs_0";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   114
val zabs_1 = thm"zabs_1";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   115
val number_of_reorient = thm"number_of_reorient";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   116
val add_number_of_left = thm"add_number_of_left";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   117
val mult_number_of_left = thm"mult_number_of_left";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   118
val add_number_of_diff1 = thm"add_number_of_diff1";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   119
val add_number_of_diff2 = thm"add_number_of_diff2";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   120
val less_iff_diff_less_0 = thm"less_iff_diff_less_0";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   121
val eq_iff_diff_eq_0 = thm"eq_iff_diff_eq_0";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   122
val le_iff_diff_le_0 = thm"le_iff_diff_le_0";
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   123
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   124
val bin_mult_simps = thms"bin_mult_simps";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   125
val NCons_simps = thms"NCons_simps";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   126
val bin_arith_extra_simps = thms"bin_arith_extra_simps";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   127
val bin_arith_simps = thms"bin_arith_simps";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   128
val bin_rel_simps = thms"bin_rel_simps";
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   129
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   130
val zless_imp_add1_zle = thm "zless_imp_add1_zle";
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   131
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   132
val combine_common_factor = thm"combine_common_factor";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   133
val eq_add_iff1 = thm"eq_add_iff1";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   134
val eq_add_iff2 = thm"eq_add_iff2";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   135
val less_add_iff1 = thm"less_add_iff1";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   136
val less_add_iff2 = thm"less_add_iff2";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   137
val le_add_iff1 = thm"le_add_iff1";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   138
val le_add_iff2 = thm"le_add_iff2";
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   139
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   140
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   141
structure Bin_Simprocs =
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   142
  struct
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   143
  fun prove_conv tacs sg (hyps: thm list) xs (t, u) =
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   144
    if t aconv u then None
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   145
    else
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   146
      let val eq = HOLogic.mk_Trueprop (HOLogic.mk_eq (t, u))
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   147
      in Some (Tactic.prove sg xs [] eq (K (EVERY tacs))) end
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   148
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   149
  fun prove_conv_nohyps tacs sg = prove_conv tacs sg [];
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   150
  fun prove_conv_nohyps_novars tacs sg = prove_conv tacs sg [] [];
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   151
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   152
  fun prep_simproc (name, pats, proc) =
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   153
    Simplifier.simproc (Theory.sign_of (the_context())) name pats proc;
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   154
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   155
  fun is_numeral (Const("Numeral.number_of", _) $ w) = true
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   156
    | is_numeral _ = false
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   157
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   158
  fun simplify_meta_eq f_number_of_eq f_eq =
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   159
      mk_meta_eq ([f_eq, f_number_of_eq] MRS trans)
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   160
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   161
  structure IntAbstractNumeralsData =
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   162
    struct
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   163
    val dest_eq		= HOLogic.dest_eq o HOLogic.dest_Trueprop o concl_of
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   164
    val is_numeral	= is_numeral
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   165
    val numeral_0_eq_0    = int_numeral_0_eq_0
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   166
    val numeral_1_eq_1    = int_numeral_1_eq_1
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   167
    val prove_conv	= prove_conv_nohyps_novars
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   168
    fun norm_tac simps	= ALLGOALS (simp_tac (HOL_ss addsimps simps))
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   169
    val simplify_meta_eq  = simplify_meta_eq 
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   170
    end
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   171
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   172
  structure IntAbstractNumerals = AbstractNumeralsFun (IntAbstractNumeralsData)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   173
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   174
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   175
  (*For addition, we already have rules for the operand 0.
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   176
    Multiplication is omitted because there are already special rules for 
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   177
    both 0 and 1 as operands.  Unary minus is trivial, just have - 1 = -1.
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   178
    For the others, having three patterns is a compromise between just having
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   179
    one (many spurious calls) and having nine (just too many!) *)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   180
  val eval_numerals = 
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   181
    map prep_simproc
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   182
     [("int_add_eval_numerals",
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   183
       ["(m::int) + 1", "(m::int) + number_of v"], 
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   184
       IntAbstractNumerals.proc (number_of_add RS sym)),
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   185
      ("int_diff_eval_numerals",
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   186
       ["(m::int) - 1", "(m::int) - number_of v"], 
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   187
       IntAbstractNumerals.proc diff_number_of_eq),
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   188
      ("int_eq_eval_numerals",
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   189
       ["(m::int) = 0", "(m::int) = 1", "(m::int) = number_of v"], 
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   190
       IntAbstractNumerals.proc eq_number_of_eq),
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   191
      ("int_less_eval_numerals",
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   192
       ["(m::int) < 0", "(m::int) < 1", "(m::int) < number_of v"], 
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   193
       IntAbstractNumerals.proc less_number_of_eq_neg),
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   194
      ("int_le_eval_numerals",
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   195
       ["(m::int) <= 0", "(m::int) <= 1", "(m::int) <= number_of v"],
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   196
       IntAbstractNumerals.proc le_number_of_eq_not_less)]
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   197
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   198
  (*reorientation simprules using ==, for the following simproc*)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   199
  val meta_zero_reorient = zero_reorient RS eq_reflection
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   200
  val meta_one_reorient = one_reorient RS eq_reflection
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   201
  val meta_number_of_reorient = number_of_reorient RS eq_reflection
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   202
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   203
  (*reorientation simplification procedure: reorients (polymorphic) 
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   204
    0 = x, 1 = x, nnn = x provided x isn't 0, 1 or a numeral.*)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   205
  fun reorient_proc sg _ (_ $ t $ u) =
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   206
    case u of
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   207
	Const("0", _) => None
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   208
      | Const("1", _) => None
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   209
      | Const("Numeral.number_of", _) $ _ => None
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   210
      | _ => Some (case t of
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   211
		  Const("0", _) => meta_zero_reorient
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   212
		| Const("1", _) => meta_one_reorient
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   213
		| Const("Numeral.number_of", _) $ _ => meta_number_of_reorient)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   214
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   215
  val reorient_simproc = 
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   216
      prep_simproc ("reorient_simproc", ["0=x", "1=x", "number_of w = x"], reorient_proc)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   217
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   218
  end;
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   219
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   220
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   221
Addsimprocs Bin_Simprocs.eval_numerals;
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   222
Addsimprocs [Bin_Simprocs.reorient_simproc];
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   223
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   224
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   225
structure Int_Numeral_Simprocs =
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   226
struct
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   227
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11713
diff changeset
   228
(*Maps 0 to Numeral0 and 1 to Numeral1 so that arithmetic in simprocs
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11713
diff changeset
   229
  isn't complicated by the abstract 0 and 1.*)
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11713
diff changeset
   230
val numeral_syms = [int_numeral_0_eq_0 RS sym, int_numeral_1_eq_1 RS sym];
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11713
diff changeset
   231
val numeral_sym_ss = HOL_ss addsimps numeral_syms;
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11713
diff changeset
   232
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   233
fun rename_numerals th =
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11713
diff changeset
   234
    simplify numeral_sym_ss (Thm.transfer (the_context ()) th);
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11713
diff changeset
   235
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   236
(*Utilities*)
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   237
10693
9e4a0e84d0d6 moved mk_bin from Numerals to HOLogic
nipkow
parents: 10574
diff changeset
   238
fun mk_numeral n = HOLogic.number_of_const HOLogic.intT $ HOLogic.mk_bin n;
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   239
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   240
(*Decodes a binary INTEGER*)
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11713
diff changeset
   241
fun dest_numeral (Const("0", _)) = 0
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11713
diff changeset
   242
  | dest_numeral (Const("1", _)) = 1
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   243
  | dest_numeral (Const("Numeral.number_of", _) $ w) =
10890
0b4e916f51ed HOLogic.dest_binum;
wenzelm
parents: 10834
diff changeset
   244
     (HOLogic.dest_binum w
0b4e916f51ed HOLogic.dest_binum;
wenzelm
parents: 10834
diff changeset
   245
      handle TERM _ => raise TERM("Int_Numeral_Simprocs.dest_numeral:1", [w]))
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   246
  | dest_numeral t = raise TERM("Int_Numeral_Simprocs.dest_numeral:2", [t]);
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   247
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   248
fun find_first_numeral past (t::terms) =
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   249
        ((dest_numeral t, rev past @ terms)
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   250
         handle TERM _ => find_first_numeral (t::past) terms)
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   251
  | find_first_numeral past [] = raise TERM("find_first_numeral", []);
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   252
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   253
val zero = mk_numeral 0;
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   254
val mk_plus = HOLogic.mk_binop "op +";
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   255
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   256
val uminus_const = Const ("uminus", HOLogic.intT --> HOLogic.intT);
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   257
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11713
diff changeset
   258
(*Thus mk_sum[t] yields t+0; longer sums don't have a trailing zero*)
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   259
fun mk_sum []        = zero
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   260
  | mk_sum [t,u]     = mk_plus (t, u)
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   261
  | mk_sum (t :: ts) = mk_plus (t, mk_sum ts);
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   262
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   263
(*this version ALWAYS includes a trailing zero*)
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   264
fun long_mk_sum []        = zero
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   265
  | long_mk_sum (t :: ts) = mk_plus (t, mk_sum ts);
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   266
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   267
val dest_plus = HOLogic.dest_bin "op +" HOLogic.intT;
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   268
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   269
(*decompose additions AND subtractions as a sum*)
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   270
fun dest_summing (pos, Const ("op +", _) $ t $ u, ts) =
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   271
        dest_summing (pos, t, dest_summing (pos, u, ts))
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   272
  | dest_summing (pos, Const ("op -", _) $ t $ u, ts) =
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   273
        dest_summing (pos, t, dest_summing (not pos, u, ts))
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   274
  | dest_summing (pos, t, ts) =
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   275
        if pos then t::ts else uminus_const$t :: ts;
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   276
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   277
fun dest_sum t = dest_summing (true, t, []);
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   278
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   279
val mk_diff = HOLogic.mk_binop "op -";
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   280
val dest_diff = HOLogic.dest_bin "op -" HOLogic.intT;
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   281
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   282
val one = mk_numeral 1;
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   283
val mk_times = HOLogic.mk_binop "op *";
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   284
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   285
fun mk_prod [] = one
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   286
  | mk_prod [t] = t
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   287
  | mk_prod (t :: ts) = if t = one then mk_prod ts
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   288
                        else mk_times (t, mk_prod ts);
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   289
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   290
val dest_times = HOLogic.dest_bin "op *" HOLogic.intT;
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   291
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   292
fun dest_prod t =
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   293
      let val (t,u) = dest_times t
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   294
      in  dest_prod t @ dest_prod u  end
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   295
      handle TERM _ => [t];
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   296
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   297
(*DON'T do the obvious simplifications; that would create special cases*)
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   298
fun mk_coeff (k, ts) = mk_times (mk_numeral k, ts);
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   299
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   300
(*Express t as a product of (possibly) a numeral with other sorted terms*)
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   301
fun dest_coeff sign (Const ("uminus", _) $ t) = dest_coeff (~sign) t
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   302
  | dest_coeff sign t =
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   303
    let val ts = sort Term.term_ord (dest_prod t)
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   304
        val (n, ts') = find_first_numeral [] ts
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   305
                          handle TERM _ => (1, ts)
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   306
    in (sign*n, mk_prod ts') end;
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   307
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   308
(*Find first coefficient-term THAT MATCHES u*)
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   309
fun find_first_coeff past u [] = raise TERM("find_first_coeff", [])
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   310
  | find_first_coeff past u (t::terms) =
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   311
        let val (n,u') = dest_coeff 1 t
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   312
        in  if u aconv u' then (n, rev past @ terms)
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   313
                          else find_first_coeff (t::past) u terms
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   314
        end
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   315
        handle TERM _ => find_first_coeff (t::past) u terms;
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   316
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   317
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11713
diff changeset
   318
(*Simplify Numeral0+n, n+Numeral0, Numeral1*n, n*Numeral1*)
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11713
diff changeset
   319
val add_0s =  map rename_numerals [zadd_0, zadd_0_right];
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11713
diff changeset
   320
val mult_1s = map rename_numerals [zmult_1, zmult_1_right] @
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11713
diff changeset
   321
              [zmult_minus1, zmult_minus1_right];
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   322
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11713
diff changeset
   323
(*To perform binary arithmetic.  The "left" rewriting handles patterns
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11713
diff changeset
   324
  created by the simprocs, such as 3 * (5 * x). *)
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11713
diff changeset
   325
val bin_simps = [int_numeral_0_eq_0 RS sym, int_numeral_1_eq_1 RS sym,
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   326
                 add_number_of_left, mult_number_of_left] @
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11713
diff changeset
   327
                bin_arith_simps @ bin_rel_simps;
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   328
14113
7b3513ba0f86 Fixing a simproc bug
paulson
parents: 13499
diff changeset
   329
(*Binary arithmetic BUT NOT ADDITION since it may collapse adjacent terms
7b3513ba0f86 Fixing a simproc bug
paulson
parents: 13499
diff changeset
   330
  during re-arrangement*)
7b3513ba0f86 Fixing a simproc bug
paulson
parents: 13499
diff changeset
   331
val non_add_bin_simps = 
7b3513ba0f86 Fixing a simproc bug
paulson
parents: 13499
diff changeset
   332
    bin_simps \\ [add_number_of_left, number_of_add RS sym];
7b3513ba0f86 Fixing a simproc bug
paulson
parents: 13499
diff changeset
   333
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   334
(*To evaluate binary negations of coefficients*)
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   335
val zminus_simps = NCons_simps @
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   336
                   [zminus_1_eq_m1, number_of_minus RS sym,
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   337
                    bin_minus_1, bin_minus_0, bin_minus_Pls, bin_minus_Min,
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   338
                    bin_pred_1, bin_pred_0, bin_pred_Pls, bin_pred_Min];
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   339
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   340
(*To let us treat subtraction as addition*)
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   341
val diff_simps = [zdiff_def, zminus_zadd_distrib, zminus_zminus];
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   342
10713
69c9fc1d11f2 simproc bug fix: negative literals and large terms
paulson
parents: 10693
diff changeset
   343
(*push the unary minus down: - x * y = x * - y *)
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   344
val int_minus_mult_eq_1_to_2 =
10713
69c9fc1d11f2 simproc bug fix: negative literals and large terms
paulson
parents: 10693
diff changeset
   345
    [zmult_zminus, zmult_zminus_right RS sym] MRS trans |> standard;
69c9fc1d11f2 simproc bug fix: negative literals and large terms
paulson
parents: 10693
diff changeset
   346
69c9fc1d11f2 simproc bug fix: negative literals and large terms
paulson
parents: 10693
diff changeset
   347
(*to extract again any uncancelled minuses*)
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   348
val int_minus_from_mult_simps =
10713
69c9fc1d11f2 simproc bug fix: negative literals and large terms
paulson
parents: 10693
diff changeset
   349
    [zminus_zminus, zmult_zminus, zmult_zminus_right];
69c9fc1d11f2 simproc bug fix: negative literals and large terms
paulson
parents: 10693
diff changeset
   350
69c9fc1d11f2 simproc bug fix: negative literals and large terms
paulson
parents: 10693
diff changeset
   351
(*combine unary minus with numeric literals, however nested within a product*)
69c9fc1d11f2 simproc bug fix: negative literals and large terms
paulson
parents: 10693
diff changeset
   352
val int_mult_minus_simps =
69c9fc1d11f2 simproc bug fix: negative literals and large terms
paulson
parents: 10693
diff changeset
   353
    [zmult_assoc, zmult_zminus RS sym, int_minus_mult_eq_1_to_2];
69c9fc1d11f2 simproc bug fix: negative literals and large terms
paulson
parents: 10693
diff changeset
   354
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   355
(*Apply the given rewrite (if present) just once*)
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   356
fun trans_tac None      = all_tac
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   357
  | trans_tac (Some th) = ALLGOALS (rtac (th RS trans));
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   358
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   359
fun simplify_meta_eq rules =
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   360
    simplify (HOL_basic_ss addeqcongs[eq_cong2] addsimps rules)
12975
d796a2fd6c69 fixing nat_combine_numerals simprocs (again)
paulson
parents: 12482
diff changeset
   361
    o mk_meta_eq;
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   362
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   363
structure CancelNumeralsCommon =
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   364
  struct
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   365
  val mk_sum            = mk_sum
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   366
  val dest_sum          = dest_sum
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   367
  val mk_coeff          = mk_coeff
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   368
  val dest_coeff        = dest_coeff 1
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   369
  val find_first_coeff  = find_first_coeff []
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   370
  val trans_tac         = trans_tac
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   371
  val norm_tac =
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11713
diff changeset
   372
     ALLGOALS (simp_tac (HOL_ss addsimps numeral_syms@add_0s@mult_1s@
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11713
diff changeset
   373
                                         diff_simps@zminus_simps@zadd_ac))
14113
7b3513ba0f86 Fixing a simproc bug
paulson
parents: 13499
diff changeset
   374
     THEN ALLGOALS (simp_tac (HOL_ss addsimps non_add_bin_simps@int_mult_minus_simps))
10713
69c9fc1d11f2 simproc bug fix: negative literals and large terms
paulson
parents: 10693
diff changeset
   375
     THEN ALLGOALS (simp_tac (HOL_ss addsimps int_minus_from_mult_simps@
69c9fc1d11f2 simproc bug fix: negative literals and large terms
paulson
parents: 10693
diff changeset
   376
                                              zadd_ac@zmult_ac))
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   377
  val numeral_simp_tac  = ALLGOALS (simp_tac (HOL_ss addsimps add_0s@bin_simps))
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   378
  val simplify_meta_eq  = simplify_meta_eq (add_0s@mult_1s)
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   379
  end;
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   380
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   381
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   382
structure EqCancelNumerals = CancelNumeralsFun
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   383
 (open CancelNumeralsCommon
13485
acf39e924091 tuned prove_conv (error reporting done within meta_simplifier.ML);
wenzelm
parents: 13462
diff changeset
   384
  val prove_conv = Bin_Simprocs.prove_conv
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   385
  val mk_bal   = HOLogic.mk_eq
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   386
  val dest_bal = HOLogic.dest_bin "op =" HOLogic.intT
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   387
  val bal_add1 = eq_add_iff1 RS trans
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   388
  val bal_add2 = eq_add_iff2 RS trans
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   389
);
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   390
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   391
structure LessCancelNumerals = CancelNumeralsFun
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   392
 (open CancelNumeralsCommon
13485
acf39e924091 tuned prove_conv (error reporting done within meta_simplifier.ML);
wenzelm
parents: 13462
diff changeset
   393
  val prove_conv = Bin_Simprocs.prove_conv
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   394
  val mk_bal   = HOLogic.mk_binrel "op <"
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   395
  val dest_bal = HOLogic.dest_bin "op <" HOLogic.intT
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   396
  val bal_add1 = less_add_iff1 RS trans
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   397
  val bal_add2 = less_add_iff2 RS trans
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   398
);
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   399
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   400
structure LeCancelNumerals = CancelNumeralsFun
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   401
 (open CancelNumeralsCommon
13485
acf39e924091 tuned prove_conv (error reporting done within meta_simplifier.ML);
wenzelm
parents: 13462
diff changeset
   402
  val prove_conv = Bin_Simprocs.prove_conv
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   403
  val mk_bal   = HOLogic.mk_binrel "op <="
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   404
  val dest_bal = HOLogic.dest_bin "op <=" HOLogic.intT
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   405
  val bal_add1 = le_add_iff1 RS trans
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   406
  val bal_add2 = le_add_iff2 RS trans
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   407
);
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   408
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   409
val cancel_numerals =
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11713
diff changeset
   410
  map Bin_Simprocs.prep_simproc
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   411
   [("inteq_cancel_numerals",
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   412
     ["(l::int) + m = n", "(l::int) = m + n",
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   413
      "(l::int) - m = n", "(l::int) = m - n",
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   414
      "(l::int) * m = n", "(l::int) = m * n"],
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   415
     EqCancelNumerals.proc),
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   416
    ("intless_cancel_numerals",
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   417
     ["(l::int) + m < n", "(l::int) < m + n",
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   418
      "(l::int) - m < n", "(l::int) < m - n",
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   419
      "(l::int) * m < n", "(l::int) < m * n"],
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   420
     LessCancelNumerals.proc),
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   421
    ("intle_cancel_numerals",
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   422
     ["(l::int) + m <= n", "(l::int) <= m + n",
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   423
      "(l::int) - m <= n", "(l::int) <= m - n",
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   424
      "(l::int) * m <= n", "(l::int) <= m * n"],
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   425
     LeCancelNumerals.proc)];
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   426
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   427
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   428
structure CombineNumeralsData =
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   429
  struct
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   430
  val add               = op + : int*int -> int
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   431
  val mk_sum            = long_mk_sum    (*to work for e.g. 2*x + 3*x *)
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   432
  val dest_sum          = dest_sum
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   433
  val mk_coeff          = mk_coeff
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   434
  val dest_coeff        = dest_coeff 1
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   435
  val left_distrib      = combine_common_factor RS trans
13485
acf39e924091 tuned prove_conv (error reporting done within meta_simplifier.ML);
wenzelm
parents: 13462
diff changeset
   436
  val prove_conv        = Bin_Simprocs.prove_conv_nohyps
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   437
  val trans_tac          = trans_tac
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   438
  val norm_tac =
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11713
diff changeset
   439
     ALLGOALS (simp_tac (HOL_ss addsimps numeral_syms@add_0s@mult_1s@
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11713
diff changeset
   440
                                         diff_simps@zminus_simps@zadd_ac))
14113
7b3513ba0f86 Fixing a simproc bug
paulson
parents: 13499
diff changeset
   441
     THEN ALLGOALS (simp_tac (HOL_ss addsimps non_add_bin_simps@int_mult_minus_simps))
10713
69c9fc1d11f2 simproc bug fix: negative literals and large terms
paulson
parents: 10693
diff changeset
   442
     THEN ALLGOALS (simp_tac (HOL_ss addsimps int_minus_from_mult_simps@
69c9fc1d11f2 simproc bug fix: negative literals and large terms
paulson
parents: 10693
diff changeset
   443
                                              zadd_ac@zmult_ac))
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   444
  val numeral_simp_tac  = ALLGOALS
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   445
                    (simp_tac (HOL_ss addsimps add_0s@bin_simps))
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   446
  val simplify_meta_eq  = simplify_meta_eq (add_0s@mult_1s)
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   447
  end;
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   448
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   449
structure CombineNumerals = CombineNumeralsFun(CombineNumeralsData);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   450
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   451
val combine_numerals =
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   452
  Bin_Simprocs.prep_simproc
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   453
    ("int_combine_numerals", ["(i::int) + j", "(i::int) - j"], CombineNumerals.proc);
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   454
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   455
end;
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   456
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   457
Addsimprocs Int_Numeral_Simprocs.cancel_numerals;
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   458
Addsimprocs [Int_Numeral_Simprocs.combine_numerals];
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   459
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   460
(*examples:
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   461
print_depth 22;
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   462
set timing;
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   463
set trace_simp;
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   464
fun test s = (Goal s, by (Simp_tac 1));
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   465
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   466
test "l + 2 + 2 + 2 + (l + 2) + (oo + 2) = (uu::int)";
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   467
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   468
test "2*u = (u::int)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   469
test "(i + j + 12 + (k::int)) - 15 = y";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   470
test "(i + j + 12 + (k::int)) - 5 = y";
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   471
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   472
test "y - b < (b::int)";
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   473
test "y - (3*b + c) < (b::int) - 2*c";
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   474
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   475
test "(2*x - (u*v) + y) - v*3*u = (w::int)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   476
test "(2*x*u*v + (u*v)*4 + y) - v*u*4 = (w::int)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   477
test "(2*x*u*v + (u*v)*4 + y) - v*u = (w::int)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   478
test "u*v - (x*u*v + (u*v)*4 + y) = (w::int)";
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   479
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   480
test "(i + j + 12 + (k::int)) = u + 15 + y";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   481
test "(i + j*2 + 12 + (k::int)) = j + 5 + y";
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   482
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   483
test "2*y + 3*z + 6*w + 2*y + 3*z + 2*u = 2*y' + 3*z' + 6*w' + 2*y' + 3*z' + u + (vv::int)";
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   484
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   485
test "a + -(b+c) + b = (d::int)";
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   486
test "a + -(b+c) - b = (d::int)";
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   487
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   488
(*negative numerals*)
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   489
test "(i + j + -2 + (k::int)) - (u + 5 + y) = zz";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   490
test "(i + j + -3 + (k::int)) < u + 5 + y";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   491
test "(i + j + 3 + (k::int)) < u + -6 + y";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   492
test "(i + j + -12 + (k::int)) - 15 = y";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   493
test "(i + j + 12 + (k::int)) - -15 = y";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   494
test "(i + j + -12 + (k::int)) - -15 = y";
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   495
*)
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   496
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   497
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   498
(** Constant folding for integer plus and times **)
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   499
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   500
(*We do not need
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   501
    structure Nat_Plus_Assoc = Assoc_Fold (Nat_Plus_Assoc_Data);
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   502
    structure Int_Plus_Assoc = Assoc_Fold (Int_Plus_Assoc_Data);
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   503
  because combine_numerals does the same thing*)
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   504
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   505
structure Int_Times_Assoc_Data : ASSOC_FOLD_DATA =
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   506
struct
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   507
  val ss                = HOL_ss
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   508
  val eq_reflection     = eq_reflection
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   509
  val sg_ref = Sign.self_ref (Theory.sign_of (the_context ()))
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   510
  val T      = HOLogic.intT
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   511
  val plus   = Const ("op *", [HOLogic.intT,HOLogic.intT] ---> HOLogic.intT);
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   512
  val add_ac = zmult_ac
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   513
end;
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   514
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   515
structure Int_Times_Assoc = Assoc_Fold (Int_Times_Assoc_Data);
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   516
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   517
Addsimprocs [Int_Times_Assoc.conv];
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   518
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   519
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   520
(** The same for the naturals **)
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   521
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   522
structure Nat_Times_Assoc_Data : ASSOC_FOLD_DATA =
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   523
struct
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   524
  val ss                = HOL_ss
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   525
  val eq_reflection     = eq_reflection
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   526
  val sg_ref = Sign.self_ref (Theory.sign_of (the_context ()))
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   527
  val T      = HOLogic.natT
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   528
  val plus   = Const ("op *", [HOLogic.natT,HOLogic.natT] ---> HOLogic.natT);
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   529
  val add_ac = mult_ac
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   530
end;
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   531
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   532
structure Nat_Times_Assoc = Assoc_Fold (Nat_Times_Assoc_Data);
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   533
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   534
Addsimprocs [Nat_Times_Assoc.conv];
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   535
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   536
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   537
(*** decision procedure for linear arithmetic ***)
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   538
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   539
(*---------------------------------------------------------------------------*)
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   540
(* Linear arithmetic                                                         *)
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   541
(*---------------------------------------------------------------------------*)
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   542
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   543
(*
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   544
Instantiation of the generic linear arithmetic package for int.
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   545
*)
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   546
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   547
(* Update parameters of arithmetic prover *)
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   548
local
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   549
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   550
(* reduce contradictory <= to False *)
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   551
val add_rules =
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   552
    simp_thms @ bin_arith_simps @ bin_rel_simps @
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11713
diff changeset
   553
    [int_numeral_0_eq_0, int_numeral_1_eq_1,
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11868
diff changeset
   554
     zminus_0, zadd_0, zadd_0_right, zdiff_def,
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   555
     zadd_zminus_inverse, zadd_zminus_inverse2,
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   556
     zmult_0, zmult_0_right,
12482
d2848ccc9757 new rewrite rules for use by arith_tac to take care of uminus.
nipkow
parents: 12018
diff changeset
   557
     zmult_1, zmult_1_right,
d2848ccc9757 new rewrite rules for use by arith_tac to take care of uminus.
nipkow
parents: 12018
diff changeset
   558
     zmult_zminus, zmult_zminus_right,
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11713
diff changeset
   559
     zminus_zadd_distrib, zminus_zminus, zmult_assoc,
13499
f95f5818f24f Counter example generation mods.
nipkow
parents: 13485
diff changeset
   560
     int_0, int_1, int_Suc, zadd_int RS sym, zmult_int RS sym];
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   561
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   562
val simprocs = [Int_Times_Assoc.conv, Int_Numeral_Simprocs.combine_numerals]@
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   563
               Int_Numeral_Simprocs.cancel_numerals @
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11713
diff changeset
   564
               Bin_Simprocs.eval_numerals;
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   565
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   566
val add_mono_thms_int =
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   567
  map (fn s => prove_goal (the_context ()) s
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   568
                 (fn prems => [cut_facts_tac prems 1,
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   569
                      asm_simp_tac (simpset() addsimps [zadd_zle_mono]) 1]))
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   570
    ["(i <= j) & (k <= l) ==> i + k <= j + (l::int)",
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   571
     "(i  = j) & (k <= l) ==> i + k <= j + (l::int)",
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   572
     "(i <= j) & (k  = l) ==> i + k <= j + (l::int)",
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   573
     "(i  = j) & (k  = l) ==> i + k  = j + (l::int)"
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   574
    ];
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   575
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   576
in
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   577
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   578
val int_arith_setup =
10693
9e4a0e84d0d6 moved mk_bin from Numerals to HOLogic
nipkow
parents: 10574
diff changeset
   579
 [Fast_Arith.map_data (fn {add_mono_thms, mult_mono_thms, inj_thms, lessD, simpset} =>
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   580
   {add_mono_thms = add_mono_thms @ add_mono_thms_int,
10693
9e4a0e84d0d6 moved mk_bin from Numerals to HOLogic
nipkow
parents: 10574
diff changeset
   581
    mult_mono_thms = mult_mono_thms,
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents: 9571
diff changeset
   582
    inj_thms = [zle_int RS iffD2,int_int_eq RS iffD2] @ inj_thms,
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14271
diff changeset
   583
    lessD = lessD @ [zless_imp_add1_zle],
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   584
    simpset = simpset addsimps add_rules
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   585
                      addsimprocs simprocs
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   586
                      addcongs [if_weak_cong]}),
10834
a7897aebbffc *** empty log message ***
nipkow
parents: 10719
diff changeset
   587
  arith_inj_const ("IntDef.int", HOLogic.natT --> HOLogic.intT),
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   588
  arith_discrete ("IntDef.int", true)];
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   589
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   590
end;
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   591
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   592
val fast_int_arith_simproc =
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   593
  Simplifier.simproc (Theory.sign_of (the_context()))
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   594
  "fast_int_arith" ["(m::int) < n","(m::int) <= n", "(m::int) = n"] Fast_Arith.lin_arith_prover;
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   595
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   596
Addsimprocs [fast_int_arith_simproc]
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12975
diff changeset
   597
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   598
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   599
(* Some test data
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   600
Goal "!!a::int. [| a <= b; c <= d; x+y<z |] ==> a+c <= b+d";
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   601
by (fast_arith_tac 1);
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   602
Goal "!!a::int. [| a < b; c < d |] ==> a-d+ 2 <= b+(-c)";
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   603
by (fast_arith_tac 1);
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11713
diff changeset
   604
Goal "!!a::int. [| a < b; c < d |] ==> a+c+ 1 < b+d";
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   605
by (fast_arith_tac 1);
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   606
Goal "!!a::int. [| a <= b; b+b <= c |] ==> a+a <= c";
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   607
by (fast_arith_tac 1);
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   608
Goal "!!a::int. [| a+b <= i+j; a<=b; i<=j |] \
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   609
\     ==> a+a <= j+j";
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   610
by (fast_arith_tac 1);
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   611
Goal "!!a::int. [| a+b < i+j; a<b; i<j |] \
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   612
\     ==> a+a - - -1 < j+j - 3";
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   613
by (fast_arith_tac 1);
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   614
Goal "!!a::int. a+b+c <= i+j+k & a<=b & b<=c & i<=j & j<=k --> a+a+a <= k+k+k";
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   615
by (arith_tac 1);
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   616
Goal "!!a::int. [| a+b+c+d <= i+j+k+l; a<=b; b<=c; c<=d; i<=j; j<=k; k<=l |] \
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   617
\     ==> a <= l";
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   618
by (fast_arith_tac 1);
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   619
Goal "!!a::int. [| a+b+c+d <= i+j+k+l; a<=b; b<=c; c<=d; i<=j; j<=k; k<=l |] \
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   620
\     ==> a+a+a+a <= l+l+l+l";
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   621
by (fast_arith_tac 1);
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   622
Goal "!!a::int. [| a+b+c+d <= i+j+k+l; a<=b; b<=c; c<=d; i<=j; j<=k; k<=l |] \
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   623
\     ==> a+a+a+a+a <= l+l+l+l+i";
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   624
by (fast_arith_tac 1);
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   625
Goal "!!a::int. [| a+b+c+d <= i+j+k+l; a<=b; b<=c; c<=d; i<=j; j<=k; k<=l |] \
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   626
\     ==> a+a+a+a+a+a <= l+l+l+l+i+l";
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   627
by (fast_arith_tac 1);
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   628
Goal "!!a::int. [| a+b+c+d <= i+j+k+l; a<=b; b<=c; c<=d; i<=j; j<=k; k<=l |] \
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   629
\     ==> 6*a <= 5*l+i";
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   630
by (fast_arith_tac 1);
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   631
*)