src/HOL/Arith_Tools.thy
author chaieb
Sun, 22 Jul 2007 17:53:42 +0200
changeset 23901 7392193f9ecf
parent 23881 851c74f1bb69
child 24075 366d4d234814
permissions -rw-r--r--
Tunes Proof
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23462
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
     1
(*  Title:      HOL/Arith_Tools.thy
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
     4
    Author:     Amine Chaieb, TU Muenchen
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
     5
*)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
     6
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
     7
header {* Setup of arithmetic tools *}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
     8
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
     9
theory Arith_Tools
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents: 23462
diff changeset
    10
imports Groebner_Basis Dense_Linear_Order
23462
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    11
uses
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    12
  "~~/src/Provers/Arith/cancel_numeral_factor.ML"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    13
  "~~/src/Provers/Arith/extract_common_term.ML"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    14
  "int_factor_simprocs.ML"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    15
  "nat_simprocs.ML"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    16
begin
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    17
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    18
subsection {* Simprocs for the Naturals *}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    19
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    20
setup nat_simprocs_setup
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    21
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    22
subsubsection{*For simplifying @{term "Suc m - K"} and  @{term "K - Suc m"}*}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    23
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    24
text{*Where K above is a literal*}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    25
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    26
lemma Suc_diff_eq_diff_pred: "Numeral0 < n ==> Suc m - n = m - (n - Numeral1)"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    27
by (simp add: numeral_0_eq_0 numeral_1_eq_1 split add: nat_diff_split)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    28
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    29
text {*Now just instantiating @{text n} to @{text "number_of v"} does
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    30
  the right simplification, but with some redundant inequality
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    31
  tests.*}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    32
lemma neg_number_of_pred_iff_0:
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    33
  "neg (number_of (Numeral.pred v)::int) = (number_of v = (0::nat))"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    34
apply (subgoal_tac "neg (number_of (Numeral.pred v)) = (number_of v < Suc 0) ")
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    35
apply (simp only: less_Suc_eq_le le_0_eq)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    36
apply (subst less_number_of_Suc, simp)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    37
done
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    38
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    39
text{*No longer required as a simprule because of the @{text inverse_fold}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    40
   simproc*}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    41
lemma Suc_diff_number_of:
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    42
     "neg (number_of (uminus v)::int) ==>
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    43
      Suc m - (number_of v) = m - (number_of (Numeral.pred v))"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    44
apply (subst Suc_diff_eq_diff_pred)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    45
apply simp
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    46
apply (simp del: nat_numeral_1_eq_1)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    47
apply (auto simp only: diff_nat_number_of less_0_number_of [symmetric]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    48
                        neg_number_of_pred_iff_0)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    49
done
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    50
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    51
lemma diff_Suc_eq_diff_pred: "m - Suc n = (m - 1) - n"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    52
by (simp add: numerals split add: nat_diff_split)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    53
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    54
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    55
subsubsection{*For @{term nat_case} and @{term nat_rec}*}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    56
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    57
lemma nat_case_number_of [simp]:
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    58
     "nat_case a f (number_of v) =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    59
        (let pv = number_of (Numeral.pred v) in
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    60
         if neg pv then a else f (nat pv))"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    61
by (simp split add: nat.split add: Let_def neg_number_of_pred_iff_0)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    62
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    63
lemma nat_case_add_eq_if [simp]:
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    64
     "nat_case a f ((number_of v) + n) =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    65
       (let pv = number_of (Numeral.pred v) in
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    66
         if neg pv then nat_case a f n else f (nat pv + n))"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    67
apply (subst add_eq_if)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    68
apply (simp split add: nat.split
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    69
            del: nat_numeral_1_eq_1
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    70
            add: numeral_1_eq_Suc_0 [symmetric] Let_def
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    71
                 neg_imp_number_of_eq_0 neg_number_of_pred_iff_0)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    72
done
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    73
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    74
lemma nat_rec_number_of [simp]:
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    75
     "nat_rec a f (number_of v) =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    76
        (let pv = number_of (Numeral.pred v) in
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    77
         if neg pv then a else f (nat pv) (nat_rec a f (nat pv)))"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    78
apply (case_tac " (number_of v) ::nat")
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    79
apply (simp_all (no_asm_simp) add: Let_def neg_number_of_pred_iff_0)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    80
apply (simp split add: split_if_asm)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    81
done
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    82
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    83
lemma nat_rec_add_eq_if [simp]:
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    84
     "nat_rec a f (number_of v + n) =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    85
        (let pv = number_of (Numeral.pred v) in
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    86
         if neg pv then nat_rec a f n
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    87
                   else f (nat pv + n) (nat_rec a f (nat pv + n)))"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    88
apply (subst add_eq_if)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    89
apply (simp split add: nat.split
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    90
            del: nat_numeral_1_eq_1
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    91
            add: numeral_1_eq_Suc_0 [symmetric] Let_def neg_imp_number_of_eq_0
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    92
                 neg_number_of_pred_iff_0)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    93
done
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    94
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    95
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    96
subsubsection{*Various Other Lemmas*}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    97
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    98
text {*Evens and Odds, for Mutilated Chess Board*}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
    99
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   100
text{*Lemmas for specialist use, NOT as default simprules*}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   101
lemma nat_mult_2: "2 * z = (z+z::nat)"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   102
proof -
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   103
  have "2*z = (1 + 1)*z" by simp
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   104
  also have "... = z+z" by (simp add: left_distrib)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   105
  finally show ?thesis .
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   106
qed
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   107
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   108
lemma nat_mult_2_right: "z * 2 = (z+z::nat)"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   109
by (subst mult_commute, rule nat_mult_2)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   110
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   111
text{*Case analysis on @{term "n<2"}*}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   112
lemma less_2_cases: "(n::nat) < 2 ==> n = 0 | n = Suc 0"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   113
by arith
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   114
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   115
lemma div2_Suc_Suc [simp]: "Suc(Suc m) div 2 = Suc (m div 2)"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   116
by arith
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   117
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   118
lemma add_self_div_2 [simp]: "(m + m) div 2 = (m::nat)"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   119
by (simp add: nat_mult_2 [symmetric])
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   120
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   121
lemma mod2_Suc_Suc [simp]: "Suc(Suc(m)) mod 2 = m mod 2"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   122
apply (subgoal_tac "m mod 2 < 2")
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   123
apply (erule less_2_cases [THEN disjE])
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   124
apply (simp_all (no_asm_simp) add: Let_def mod_Suc nat_1)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   125
done
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   126
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   127
lemma mod2_gr_0 [simp]: "!!m::nat. (0 < m mod 2) = (m mod 2 = 1)"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   128
apply (subgoal_tac "m mod 2 < 2")
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   129
apply (force simp del: mod_less_divisor, simp)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   130
done
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   131
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   132
text{*Removal of Small Numerals: 0, 1 and (in additive positions) 2*}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   133
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   134
lemma add_2_eq_Suc [simp]: "2 + n = Suc (Suc n)"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   135
by simp
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   136
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   137
lemma add_2_eq_Suc' [simp]: "n + 2 = Suc (Suc n)"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   138
by simp
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   139
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   140
text{*Can be used to eliminate long strings of Sucs, but not by default*}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   141
lemma Suc3_eq_add_3: "Suc (Suc (Suc n)) = 3 + n"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   142
by simp
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   143
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   144
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   145
text{*These lemmas collapse some needless occurrences of Suc:
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   146
    at least three Sucs, since two and fewer are rewritten back to Suc again!
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   147
    We already have some rules to simplify operands smaller than 3.*}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   148
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   149
lemma div_Suc_eq_div_add3 [simp]: "m div (Suc (Suc (Suc n))) = m div (3+n)"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   150
by (simp add: Suc3_eq_add_3)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   151
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   152
lemma mod_Suc_eq_mod_add3 [simp]: "m mod (Suc (Suc (Suc n))) = m mod (3+n)"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   153
by (simp add: Suc3_eq_add_3)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   154
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   155
lemma Suc_div_eq_add3_div: "(Suc (Suc (Suc m))) div n = (3+m) div n"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   156
by (simp add: Suc3_eq_add_3)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   157
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   158
lemma Suc_mod_eq_add3_mod: "(Suc (Suc (Suc m))) mod n = (3+m) mod n"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   159
by (simp add: Suc3_eq_add_3)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   160
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   161
lemmas Suc_div_eq_add3_div_number_of =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   162
    Suc_div_eq_add3_div [of _ "number_of v", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   163
declare Suc_div_eq_add3_div_number_of [simp]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   164
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   165
lemmas Suc_mod_eq_add3_mod_number_of =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   166
    Suc_mod_eq_add3_mod [of _ "number_of v", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   167
declare Suc_mod_eq_add3_mod_number_of [simp]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   168
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   169
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   170
subsubsection{*Special Simplification for Constants*}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   171
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   172
text{*These belong here, late in the development of HOL, to prevent their
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   173
interfering with proofs of abstract properties of instances of the function
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   174
@{term number_of}*}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   175
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   176
text{*These distributive laws move literals inside sums and differences.*}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   177
lemmas left_distrib_number_of = left_distrib [of _ _ "number_of v", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   178
declare left_distrib_number_of [simp]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   179
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   180
lemmas right_distrib_number_of = right_distrib [of "number_of v", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   181
declare right_distrib_number_of [simp]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   182
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   183
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   184
lemmas left_diff_distrib_number_of =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   185
    left_diff_distrib [of _ _ "number_of v", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   186
declare left_diff_distrib_number_of [simp]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   187
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   188
lemmas right_diff_distrib_number_of =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   189
    right_diff_distrib [of "number_of v", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   190
declare right_diff_distrib_number_of [simp]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   191
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   192
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   193
text{*These are actually for fields, like real: but where else to put them?*}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   194
lemmas zero_less_divide_iff_number_of =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   195
    zero_less_divide_iff [of "number_of w", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   196
declare zero_less_divide_iff_number_of [simp]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   197
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   198
lemmas divide_less_0_iff_number_of =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   199
    divide_less_0_iff [of "number_of w", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   200
declare divide_less_0_iff_number_of [simp]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   201
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   202
lemmas zero_le_divide_iff_number_of =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   203
    zero_le_divide_iff [of "number_of w", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   204
declare zero_le_divide_iff_number_of [simp]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   205
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   206
lemmas divide_le_0_iff_number_of =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   207
    divide_le_0_iff [of "number_of w", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   208
declare divide_le_0_iff_number_of [simp]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   209
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   210
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   211
(****
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   212
IF times_divide_eq_right and times_divide_eq_left are removed as simprules,
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   213
then these special-case declarations may be useful.
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   214
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   215
text{*These simprules move numerals into numerators and denominators.*}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   216
lemma times_recip_eq_right [simp]: "a * (1/c) = a / (c::'a::field)"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   217
by (simp add: times_divide_eq)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   218
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   219
lemma times_recip_eq_left [simp]: "(1/c) * a = a / (c::'a::field)"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   220
by (simp add: times_divide_eq)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   221
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   222
lemmas times_divide_eq_right_number_of =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   223
    times_divide_eq_right [of "number_of w", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   224
declare times_divide_eq_right_number_of [simp]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   225
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   226
lemmas times_divide_eq_right_number_of =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   227
    times_divide_eq_right [of _ _ "number_of w", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   228
declare times_divide_eq_right_number_of [simp]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   229
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   230
lemmas times_divide_eq_left_number_of =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   231
    times_divide_eq_left [of _ "number_of w", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   232
declare times_divide_eq_left_number_of [simp]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   233
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   234
lemmas times_divide_eq_left_number_of =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   235
    times_divide_eq_left [of _ _ "number_of w", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   236
declare times_divide_eq_left_number_of [simp]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   237
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   238
****)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   239
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   240
text {*Replaces @{text "inverse #nn"} by @{text "1/#nn"}.  It looks
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   241
  strange, but then other simprocs simplify the quotient.*}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   242
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   243
lemmas inverse_eq_divide_number_of =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   244
    inverse_eq_divide [of "number_of w", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   245
declare inverse_eq_divide_number_of [simp]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   246
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   247
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   248
text {*These laws simplify inequalities, moving unary minus from a term
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   249
into the literal.*}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   250
lemmas less_minus_iff_number_of =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   251
    less_minus_iff [of "number_of v", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   252
declare less_minus_iff_number_of [simp]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   253
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   254
lemmas le_minus_iff_number_of =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   255
    le_minus_iff [of "number_of v", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   256
declare le_minus_iff_number_of [simp]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   257
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   258
lemmas equation_minus_iff_number_of =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   259
    equation_minus_iff [of "number_of v", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   260
declare equation_minus_iff_number_of [simp]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   261
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   262
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   263
lemmas minus_less_iff_number_of =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   264
    minus_less_iff [of _ "number_of v", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   265
declare minus_less_iff_number_of [simp]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   266
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   267
lemmas minus_le_iff_number_of =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   268
    minus_le_iff [of _ "number_of v", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   269
declare minus_le_iff_number_of [simp]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   270
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   271
lemmas minus_equation_iff_number_of =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   272
    minus_equation_iff [of _ "number_of v", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   273
declare minus_equation_iff_number_of [simp]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   274
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   275
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   276
text{*To Simplify Inequalities Where One Side is the Constant 1*}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   277
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   278
lemma less_minus_iff_1 [simp]:
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   279
  fixes b::"'b::{ordered_idom,number_ring}"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   280
  shows "(1 < - b) = (b < -1)"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   281
by auto
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   282
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   283
lemma le_minus_iff_1 [simp]:
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   284
  fixes b::"'b::{ordered_idom,number_ring}"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   285
  shows "(1 \<le> - b) = (b \<le> -1)"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   286
by auto
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   287
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   288
lemma equation_minus_iff_1 [simp]:
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   289
  fixes b::"'b::number_ring"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   290
  shows "(1 = - b) = (b = -1)"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   291
by (subst equation_minus_iff, auto)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   292
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   293
lemma minus_less_iff_1 [simp]:
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   294
  fixes a::"'b::{ordered_idom,number_ring}"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   295
  shows "(- a < 1) = (-1 < a)"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   296
by auto
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   297
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   298
lemma minus_le_iff_1 [simp]:
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   299
  fixes a::"'b::{ordered_idom,number_ring}"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   300
  shows "(- a \<le> 1) = (-1 \<le> a)"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   301
by auto
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   302
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   303
lemma minus_equation_iff_1 [simp]:
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   304
  fixes a::"'b::number_ring"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   305
  shows "(- a = 1) = (a = -1)"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   306
by (subst minus_equation_iff, auto)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   307
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   308
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   309
text {*Cancellation of constant factors in comparisons (@{text "<"} and @{text "\<le>"}) *}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   310
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   311
lemmas mult_less_cancel_left_number_of =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   312
    mult_less_cancel_left [of "number_of v", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   313
declare mult_less_cancel_left_number_of [simp]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   314
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   315
lemmas mult_less_cancel_right_number_of =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   316
    mult_less_cancel_right [of _ "number_of v", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   317
declare mult_less_cancel_right_number_of [simp]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   318
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   319
lemmas mult_le_cancel_left_number_of =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   320
    mult_le_cancel_left [of "number_of v", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   321
declare mult_le_cancel_left_number_of [simp]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   322
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   323
lemmas mult_le_cancel_right_number_of =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   324
    mult_le_cancel_right [of _ "number_of v", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   325
declare mult_le_cancel_right_number_of [simp]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   326
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   327
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   328
text {*Multiplying out constant divisors in comparisons (@{text "<"}, @{text "\<le>"} and @{text "="}) *}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   329
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   330
lemmas le_divide_eq_number_of = le_divide_eq [of _ _ "number_of w", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   331
declare le_divide_eq_number_of [simp]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   332
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   333
lemmas divide_le_eq_number_of = divide_le_eq [of _ "number_of w", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   334
declare divide_le_eq_number_of [simp]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   335
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   336
lemmas less_divide_eq_number_of = less_divide_eq [of _ _ "number_of w", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   337
declare less_divide_eq_number_of [simp]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   338
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   339
lemmas divide_less_eq_number_of = divide_less_eq [of _ "number_of w", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   340
declare divide_less_eq_number_of [simp]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   341
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   342
lemmas eq_divide_eq_number_of = eq_divide_eq [of _ _ "number_of w", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   343
declare eq_divide_eq_number_of [simp]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   344
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   345
lemmas divide_eq_eq_number_of = divide_eq_eq [of _ "number_of w", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   346
declare divide_eq_eq_number_of [simp]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   347
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   348
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   349
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   350
subsubsection{*Optional Simplification Rules Involving Constants*}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   351
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   352
text{*Simplify quotients that are compared with a literal constant.*}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   353
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   354
lemmas le_divide_eq_number_of = le_divide_eq [of "number_of w", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   355
lemmas divide_le_eq_number_of = divide_le_eq [of _ _ "number_of w", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   356
lemmas less_divide_eq_number_of = less_divide_eq [of "number_of w", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   357
lemmas divide_less_eq_number_of = divide_less_eq [of _ _ "number_of w", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   358
lemmas eq_divide_eq_number_of = eq_divide_eq [of "number_of w", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   359
lemmas divide_eq_eq_number_of = divide_eq_eq [of _ _ "number_of w", standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   360
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   361
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   362
text{*Not good as automatic simprules because they cause case splits.*}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   363
lemmas divide_const_simps =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   364
  le_divide_eq_number_of divide_le_eq_number_of less_divide_eq_number_of
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   365
  divide_less_eq_number_of eq_divide_eq_number_of divide_eq_eq_number_of
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   366
  le_divide_eq_1 divide_le_eq_1 less_divide_eq_1 divide_less_eq_1
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   367
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   368
text{*Division By @{text "-1"}*}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   369
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   370
lemma divide_minus1 [simp]:
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   371
     "x/-1 = -(x::'a::{field,division_by_zero,number_ring})"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   372
by simp
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   373
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   374
lemma minus1_divide [simp]:
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   375
     "-1 / (x::'a::{field,division_by_zero,number_ring}) = - (1/x)"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   376
by (simp add: divide_inverse inverse_minus_eq)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   377
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   378
lemma half_gt_zero_iff:
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   379
     "(0 < r/2) = (0 < (r::'a::{ordered_field,division_by_zero,number_ring}))"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   380
by auto
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   381
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   382
lemmas half_gt_zero = half_gt_zero_iff [THEN iffD2, standard]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   383
declare half_gt_zero [simp]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   384
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   385
(* The following lemma should appear in Divides.thy, but there the proof
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   386
   doesn't work. *)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   387
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   388
lemma nat_dvd_not_less:
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   389
  "[| 0 < m; m < n |] ==> \<not> n dvd (m::nat)"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   390
  by (unfold dvd_def) auto
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   391
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   392
ML {*
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   393
val divide_minus1 = @{thm divide_minus1};
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   394
val minus1_divide = @{thm minus1_divide};
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   395
*}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   396
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   397
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   398
subsection{* Groebner Bases for fields *}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   399
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   400
interpretation class_fieldgb:
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   401
  fieldgb["op +" "op *" "op ^" "0::'a::{field,recpower,number_ring}" "1" "op -" "uminus" "op /" "inverse"] apply (unfold_locales) by (simp_all add: divide_inverse)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   402
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   403
lemma divide_Numeral1: "(x::'a::{field,number_ring}) / Numeral1 = x" by simp
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   404
lemma divide_Numeral0: "(x::'a::{field,number_ring, division_by_zero}) / Numeral0 = 0"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   405
  by simp
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   406
lemma mult_frac_frac: "((x::'a::{field,division_by_zero}) / y) * (z / w) = (x*z) / (y*w)"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   407
  by simp
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   408
lemma mult_frac_num: "((x::'a::{field, division_by_zero}) / y) * z  = (x*z) / y"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   409
  by simp
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   410
lemma mult_num_frac: "((x::'a::{field, division_by_zero}) / y) * z  = (x*z) / y"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   411
  by simp
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   412
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   413
lemma Numeral1_eq1_nat: "(1::nat) = Numeral1" by simp
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   414
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   415
lemma add_frac_num: "y\<noteq> 0 \<Longrightarrow> (x::'a::{field, division_by_zero}) / y + z = (x + z*y) / y"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   416
  by (simp add: add_divide_distrib)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   417
lemma add_num_frac: "y\<noteq> 0 \<Longrightarrow> z + (x::'a::{field, division_by_zero}) / y = (x + z*y) / y"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   418
  by (simp add: add_divide_distrib)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   419
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   420
declaration{*
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   421
let
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   422
 val zr = @{cpat "0"}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   423
 val zT = ctyp_of_term zr
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   424
 val geq = @{cpat "op ="}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   425
 val eqT = Thm.dest_ctyp (ctyp_of_term geq) |> hd
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   426
 val add_frac_eq = mk_meta_eq @{thm "add_frac_eq"}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   427
 val add_frac_num = mk_meta_eq @{thm "add_frac_num"}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   428
 val add_num_frac = mk_meta_eq @{thm "add_num_frac"}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   429
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   430
 fun prove_nz ctxt =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   431
  let val ss = local_simpset_of ctxt
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   432
  in fn T => fn t =>
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   433
    let
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   434
      val z = instantiate_cterm ([(zT,T)],[]) zr
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   435
      val eq = instantiate_cterm ([(eqT,T)],[]) geq
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   436
      val th = Simplifier.rewrite (ss addsimps simp_thms)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   437
           (Thm.capply @{cterm "Trueprop"} (Thm.capply @{cterm "Not"}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   438
                  (Thm.capply (Thm.capply eq t) z)))
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   439
    in equal_elim (symmetric th) TrueI
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   440
    end
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   441
  end
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   442
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   443
 fun proc ctxt phi ss ct =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   444
  let
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   445
    val ((x,y),(w,z)) =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   446
         (Thm.dest_binop #> (fn (a,b) => (Thm.dest_binop a, Thm.dest_binop b))) ct
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   447
    val _ = map (HOLogic.dest_number o term_of) [x,y,z,w]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   448
    val T = ctyp_of_term x
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   449
    val [y_nz, z_nz] = map (prove_nz ctxt T) [y, z]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   450
    val th = instantiate' [SOME T] (map SOME [y,z,x,w]) add_frac_eq
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   451
  in SOME (implies_elim (implies_elim th y_nz) z_nz)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   452
  end
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   453
  handle CTERM _ => NONE | TERM _ => NONE | THM _ => NONE
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   454
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   455
 fun proc2 ctxt phi ss ct =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   456
  let
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   457
    val (l,r) = Thm.dest_binop ct
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   458
    val T = ctyp_of_term l
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   459
  in (case (term_of l, term_of r) of
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   460
      (Const(@{const_name "HOL.divide"},_)$_$_, _) =>
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   461
        let val (x,y) = Thm.dest_binop l val z = r
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   462
            val _ = map (HOLogic.dest_number o term_of) [x,y,z]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   463
            val ynz = prove_nz ctxt T y
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   464
        in SOME (implies_elim (instantiate' [SOME T] (map SOME [y,x,z]) add_frac_num) ynz)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   465
        end
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   466
     | (_, Const (@{const_name "HOL.divide"},_)$_$_) =>
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   467
        let val (x,y) = Thm.dest_binop r val z = l
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   468
            val _ = map (HOLogic.dest_number o term_of) [x,y,z]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   469
            val ynz = prove_nz ctxt T y
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   470
        in SOME (implies_elim (instantiate' [SOME T] (map SOME [y,z,x]) add_num_frac) ynz)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   471
        end
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   472
     | _ => NONE)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   473
  end
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   474
  handle CTERM _ => NONE | TERM _ => NONE | THM _ => NONE
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   475
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   476
 fun is_number (Const(@{const_name "HOL.divide"},_)$a$b) = is_number a andalso is_number b
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   477
   | is_number t = can HOLogic.dest_number t
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   478
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   479
 val is_number = is_number o term_of
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   480
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   481
 fun proc3 phi ss ct =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   482
  (case term_of ct of
23881
851c74f1bb69 moved class ord from Orderings.thy to HOL.thy
haftmann
parents: 23572
diff changeset
   483
    Const(@{const_name HOL.less},_)$(Const(@{const_name "HOL.divide"},_)$_$_)$_ =>
23462
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   484
      let
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   485
        val ((a,b),c) = Thm.dest_binop ct |>> Thm.dest_binop
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   486
        val _ = map is_number [a,b,c]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   487
        val T = ctyp_of_term c
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   488
        val th = instantiate' [SOME T] (map SOME [a,b,c]) @{thm "divide_less_eq"}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   489
      in SOME (mk_meta_eq th) end
23881
851c74f1bb69 moved class ord from Orderings.thy to HOL.thy
haftmann
parents: 23572
diff changeset
   490
  | Const(@{const_name HOL.less_eq},_)$(Const(@{const_name "HOL.divide"},_)$_$_)$_ =>
23462
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   491
      let
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   492
        val ((a,b),c) = Thm.dest_binop ct |>> Thm.dest_binop
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   493
        val _ = map is_number [a,b,c]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   494
        val T = ctyp_of_term c
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   495
        val th = instantiate' [SOME T] (map SOME [a,b,c]) @{thm "divide_le_eq"}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   496
      in SOME (mk_meta_eq th) end
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   497
  | Const("op =",_)$(Const(@{const_name "HOL.divide"},_)$_$_)$_ =>
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   498
      let
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   499
        val ((a,b),c) = Thm.dest_binop ct |>> Thm.dest_binop
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   500
        val _ = map is_number [a,b,c]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   501
        val T = ctyp_of_term c
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   502
        val th = instantiate' [SOME T] (map SOME [a,b,c]) @{thm "divide_eq_eq"}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   503
      in SOME (mk_meta_eq th) end
23881
851c74f1bb69 moved class ord from Orderings.thy to HOL.thy
haftmann
parents: 23572
diff changeset
   504
  | Const(@{const_name HOL.less},_)$_$(Const(@{const_name "HOL.divide"},_)$_$_) =>
23462
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   505
    let
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   506
      val (a,(b,c)) = Thm.dest_binop ct ||> Thm.dest_binop
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   507
        val _ = map is_number [a,b,c]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   508
        val T = ctyp_of_term c
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   509
        val th = instantiate' [SOME T] (map SOME [a,b,c]) @{thm "less_divide_eq"}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   510
      in SOME (mk_meta_eq th) end
23881
851c74f1bb69 moved class ord from Orderings.thy to HOL.thy
haftmann
parents: 23572
diff changeset
   511
  | Const(@{const_name HOL.less_eq},_)$_$(Const(@{const_name "HOL.divide"},_)$_$_) =>
23462
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   512
    let
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   513
      val (a,(b,c)) = Thm.dest_binop ct ||> Thm.dest_binop
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   514
        val _ = map is_number [a,b,c]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   515
        val T = ctyp_of_term c
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   516
        val th = instantiate' [SOME T] (map SOME [a,b,c]) @{thm "le_divide_eq"}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   517
      in SOME (mk_meta_eq th) end
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   518
  | Const("op =",_)$_$(Const(@{const_name "HOL.divide"},_)$_$_) =>
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   519
    let
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   520
      val (a,(b,c)) = Thm.dest_binop ct ||> Thm.dest_binop
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   521
        val _ = map is_number [a,b,c]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   522
        val T = ctyp_of_term c
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   523
        val th = instantiate' [SOME T] (map SOME [a,b,c]) @{thm "eq_divide_eq"}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   524
      in SOME (mk_meta_eq th) end
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   525
  | _ => NONE)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   526
  handle TERM _ => NONE | CTERM _ => NONE | THM _ => NONE
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   527
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   528
fun add_frac_frac_simproc ctxt =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   529
       make_simproc {lhss = [@{cpat "(?x::?'a::field)/?y + (?w::?'a::field)/?z"}],
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   530
                     name = "add_frac_frac_simproc",
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   531
                     proc = proc ctxt, identifier = []}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   532
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   533
fun add_frac_num_simproc ctxt =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   534
       make_simproc {lhss = [@{cpat "(?x::?'a::field)/?y + ?z"}, @{cpat "?z + (?x::?'a::field)/?y"}],
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   535
                     name = "add_frac_num_simproc",
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   536
                     proc = proc2 ctxt, identifier = []}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   537
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   538
val ord_frac_simproc =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   539
  make_simproc
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   540
    {lhss = [@{cpat "(?a::(?'a::{field, ord}))/?b < ?c"},
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   541
             @{cpat "(?a::(?'a::{field, ord}))/?b \<le> ?c"},
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   542
             @{cpat "?c < (?a::(?'a::{field, ord}))/?b"},
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   543
             @{cpat "?c \<le> (?a::(?'a::{field, ord}))/?b"},
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   544
             @{cpat "?c = ((?a::(?'a::{field, ord}))/?b)"},
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   545
             @{cpat "((?a::(?'a::{field, ord}))/ ?b) = ?c"}],
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   546
             name = "ord_frac_simproc", proc = proc3, identifier = []}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   547
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   548
val nat_arith = map thm ["add_nat_number_of", "diff_nat_number_of",
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   549
               "mult_nat_number_of", "eq_nat_number_of", "less_nat_number_of"]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   550
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   551
val comp_arith = (map thm ["Let_def", "if_False", "if_True", "add_0",
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   552
                 "add_Suc", "add_number_of_left", "mult_number_of_left",
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   553
                 "Suc_eq_add_numeral_1"])@
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   554
                 (map (fn s => thm s RS sym) ["numeral_1_eq_1", "numeral_0_eq_0"])
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   555
                 @ arith_simps@ nat_arith @ rel_simps
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   556
val ths = [@{thm "mult_numeral_1"}, @{thm "mult_numeral_1_right"},
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   557
           @{thm "divide_Numeral1"},
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   558
           @{thm "Ring_and_Field.divide_zero"}, @{thm "divide_Numeral0"},
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   559
           @{thm "divide_divide_eq_left"}, @{thm "mult_frac_frac"},
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   560
           @{thm "mult_num_frac"}, @{thm "mult_frac_num"},
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   561
           @{thm "mult_frac_frac"}, @{thm "times_divide_eq_right"},
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   562
           @{thm "times_divide_eq_left"}, @{thm "divide_divide_eq_right"},
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   563
           @{thm "diff_def"}, @{thm "minus_divide_left"},
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   564
           @{thm "Numeral1_eq1_nat"}, @{thm "add_divide_distrib"} RS sym]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   565
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   566
local
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   567
open Conv
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   568
in
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   569
fun comp_conv ctxt = (Simplifier.rewrite
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   570
(HOL_basic_ss addsimps @{thms "Groebner_Basis.comp_arith"}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   571
              addsimps ths addsimps comp_arith addsimps simp_thms
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   572
              addsimprocs field_cancel_numeral_factors
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   573
               addsimprocs [add_frac_frac_simproc ctxt, add_frac_num_simproc ctxt,
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   574
                            ord_frac_simproc]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   575
                addcongs [@{thm "if_weak_cong"}]))
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   576
then_conv (Simplifier.rewrite (HOL_basic_ss addsimps
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   577
  [@{thm numeral_1_eq_1},@{thm numeral_0_eq_0}] @ @{thms numerals(1-2)}))
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   578
end
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   579
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   580
fun numeral_is_const ct =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   581
  case term_of ct of
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   582
   Const (@{const_name "HOL.divide"},_) $ a $ b =>
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   583
     numeral_is_const (Thm.dest_arg1 ct) andalso numeral_is_const (Thm.dest_arg ct)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   584
 | Const (@{const_name "HOL.uminus"},_)$t => numeral_is_const (Thm.dest_arg ct)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   585
 | t => can HOLogic.dest_number t
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   586
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   587
fun dest_const ct = case term_of ct of
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   588
   Const (@{const_name "HOL.divide"},_) $ a $ b=>
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   589
    Rat.rat_of_quotient (snd (HOLogic.dest_number a), snd (HOLogic.dest_number b))
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   590
 | t => Rat.rat_of_int (snd (HOLogic.dest_number t))
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   591
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   592
fun mk_const phi cT x =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   593
 let val (a, b) = Rat.quotient_of_rat x
23572
b3ce27bd211f Numeral.mk_cnumber;
wenzelm
parents: 23477
diff changeset
   594
 in if b = 1 then Numeral.mk_cnumber cT a
23462
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   595
    else Thm.capply
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   596
         (Thm.capply (Drule.cterm_rule (instantiate' [SOME cT] []) @{cpat "op /"})
23572
b3ce27bd211f Numeral.mk_cnumber;
wenzelm
parents: 23477
diff changeset
   597
                     (Numeral.mk_cnumber cT a))
b3ce27bd211f Numeral.mk_cnumber;
wenzelm
parents: 23477
diff changeset
   598
         (Numeral.mk_cnumber cT b)
23462
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   599
  end
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   600
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   601
in
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   602
 NormalizerData.funs @{thm class_fieldgb.axioms}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   603
   {is_const = K numeral_is_const,
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   604
    dest_const = K dest_const,
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   605
    mk_const = mk_const,
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   606
    conv = K comp_conv}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   607
end
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   608
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   609
*}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   610
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   611
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   612
subsection {* Ferrante and Rackoff algorithm over ordered fields *}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   613
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   614
lemma neg_prod_lt:"(c\<Colon>'a\<Colon>ordered_field) < 0 \<Longrightarrow> ((c*x < 0) == (x > 0))"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   615
proof-
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   616
  assume H: "c < 0"
23477
f4b83f03cac9 tuned and renamed group_eq_simps and ring_eq_simps
nipkow
parents: 23465
diff changeset
   617
  have "c*x < 0 = (0/c < x)" by (simp only: neg_divide_less_eq[OF H] ring_simps)
23462
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   618
  also have "\<dots> = (0 < x)" by simp
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   619
  finally show  "(c*x < 0) == (x > 0)" by simp
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   620
qed
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   621
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   622
lemma pos_prod_lt:"(c\<Colon>'a\<Colon>ordered_field) > 0 \<Longrightarrow> ((c*x < 0) == (x < 0))"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   623
proof-
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   624
  assume H: "c > 0"
23477
f4b83f03cac9 tuned and renamed group_eq_simps and ring_eq_simps
nipkow
parents: 23465
diff changeset
   625
  hence "c*x < 0 = (0/c > x)" by (simp only: pos_less_divide_eq[OF H] ring_simps)
23462
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   626
  also have "\<dots> = (0 > x)" by simp
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   627
  finally show  "(c*x < 0) == (x < 0)" by simp
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   628
qed
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   629
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   630
lemma neg_prod_sum_lt: "(c\<Colon>'a\<Colon>ordered_field) < 0 \<Longrightarrow> ((c*x + t< 0) == (x > (- 1/c)*t))"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   631
proof-
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   632
  assume H: "c < 0"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   633
  have "c*x + t< 0 = (c*x < -t)" by (subst less_iff_diff_less_0 [of "c*x" "-t"], simp)
23477
f4b83f03cac9 tuned and renamed group_eq_simps and ring_eq_simps
nipkow
parents: 23465
diff changeset
   634
  also have "\<dots> = (-t/c < x)" by (simp only: neg_divide_less_eq[OF H] ring_simps)
23462
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   635
  also have "\<dots> = ((- 1/c)*t < x)" by simp
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   636
  finally show  "(c*x + t < 0) == (x > (- 1/c)*t)" by simp
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   637
qed
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   638
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   639
lemma pos_prod_sum_lt:"(c\<Colon>'a\<Colon>ordered_field) > 0 \<Longrightarrow> ((c*x + t < 0) == (x < (- 1/c)*t))"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   640
proof-
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   641
  assume H: "c > 0"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   642
  have "c*x + t< 0 = (c*x < -t)"  by (subst less_iff_diff_less_0 [of "c*x" "-t"], simp)
23477
f4b83f03cac9 tuned and renamed group_eq_simps and ring_eq_simps
nipkow
parents: 23465
diff changeset
   643
  also have "\<dots> = (-t/c > x)" by (simp only: pos_less_divide_eq[OF H] ring_simps)
23462
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   644
  also have "\<dots> = ((- 1/c)*t > x)" by simp
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   645
  finally show  "(c*x + t < 0) == (x < (- 1/c)*t)" by simp
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   646
qed
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   647
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   648
lemma sum_lt:"((x::'a::pordered_ab_group_add) + t < 0) == (x < - t)"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   649
  using less_diff_eq[where a= x and b=t and c=0] by simp
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   650
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   651
lemma neg_prod_le:"(c\<Colon>'a\<Colon>ordered_field) < 0 \<Longrightarrow> ((c*x <= 0) == (x >= 0))"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   652
proof-
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   653
  assume H: "c < 0"
23477
f4b83f03cac9 tuned and renamed group_eq_simps and ring_eq_simps
nipkow
parents: 23465
diff changeset
   654
  have "c*x <= 0 = (0/c <= x)" by (simp only: neg_divide_le_eq[OF H] ring_simps)
23462
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   655
  also have "\<dots> = (0 <= x)" by simp
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   656
  finally show  "(c*x <= 0) == (x >= 0)" by simp
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   657
qed
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   658
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   659
lemma pos_prod_le:"(c\<Colon>'a\<Colon>ordered_field) > 0 \<Longrightarrow> ((c*x <= 0) == (x <= 0))"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   660
proof-
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   661
  assume H: "c > 0"
23477
f4b83f03cac9 tuned and renamed group_eq_simps and ring_eq_simps
nipkow
parents: 23465
diff changeset
   662
  hence "c*x <= 0 = (0/c >= x)" by (simp only: pos_le_divide_eq[OF H] ring_simps)
23462
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   663
  also have "\<dots> = (0 >= x)" by simp
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   664
  finally show  "(c*x <= 0) == (x <= 0)" by simp
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   665
qed
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   666
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   667
lemma neg_prod_sum_le: "(c\<Colon>'a\<Colon>ordered_field) < 0 \<Longrightarrow> ((c*x + t <= 0) == (x >= (- 1/c)*t))"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   668
proof-
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   669
  assume H: "c < 0"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   670
  have "c*x + t <= 0 = (c*x <= -t)"  by (subst le_iff_diff_le_0 [of "c*x" "-t"], simp)
23477
f4b83f03cac9 tuned and renamed group_eq_simps and ring_eq_simps
nipkow
parents: 23465
diff changeset
   671
  also have "\<dots> = (-t/c <= x)" by (simp only: neg_divide_le_eq[OF H] ring_simps)
23462
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   672
  also have "\<dots> = ((- 1/c)*t <= x)" by simp
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   673
  finally show  "(c*x + t <= 0) == (x >= (- 1/c)*t)" by simp
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   674
qed
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   675
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   676
lemma pos_prod_sum_le:"(c\<Colon>'a\<Colon>ordered_field) > 0 \<Longrightarrow> ((c*x + t <= 0) == (x <= (- 1/c)*t))"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   677
proof-
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   678
  assume H: "c > 0"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   679
  have "c*x + t <= 0 = (c*x <= -t)" by (subst le_iff_diff_le_0 [of "c*x" "-t"], simp)
23477
f4b83f03cac9 tuned and renamed group_eq_simps and ring_eq_simps
nipkow
parents: 23465
diff changeset
   680
  also have "\<dots> = (-t/c >= x)" by (simp only: pos_le_divide_eq[OF H] ring_simps)
23462
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   681
  also have "\<dots> = ((- 1/c)*t >= x)" by simp
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   682
  finally show  "(c*x + t <= 0) == (x <= (- 1/c)*t)" by simp
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   683
qed
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   684
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   685
lemma sum_le:"((x::'a::pordered_ab_group_add) + t <= 0) == (x <= - t)"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   686
  using le_diff_eq[where a= x and b=t and c=0] by simp
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   687
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   688
lemma nz_prod_eq:"(c\<Colon>'a\<Colon>ordered_field) \<noteq> 0 \<Longrightarrow> ((c*x = 0) == (x = 0))" by simp
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   689
lemma nz_prod_sum_eq: "(c\<Colon>'a\<Colon>ordered_field) \<noteq> 0 \<Longrightarrow> ((c*x + t = 0) == (x = (- 1/c)*t))"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   690
proof-
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   691
  assume H: "c \<noteq> 0"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   692
  have "c*x + t = 0 = (c*x = -t)" by (subst eq_iff_diff_eq_0 [of "c*x" "-t"], simp)
23477
f4b83f03cac9 tuned and renamed group_eq_simps and ring_eq_simps
nipkow
parents: 23465
diff changeset
   693
  also have "\<dots> = (x = -t/c)" by (simp only: nonzero_eq_divide_eq[OF H] ring_simps)
23462
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   694
  finally show  "(c*x + t = 0) == (x = (- 1/c)*t)" by simp
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   695
qed
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   696
lemma sum_eq:"((x::'a::pordered_ab_group_add) + t = 0) == (x = - t)"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   697
  using eq_diff_eq[where a= x and b=t and c=0] by simp
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   698
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   699
23901
7392193f9ecf Tunes Proof
chaieb
parents: 23881
diff changeset
   700
interpretation class_ordered_field_dense_linear_order: constr_dense_linear_order
23462
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   701
 ["op <=" "op <"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   702
   "\<lambda> x y. 1/2 * ((x::'a::{ordered_field,recpower,number_ring}) + y)"]
23901
7392193f9ecf Tunes Proof
chaieb
parents: 23881
diff changeset
   703
proof (unfold_locales, dlo, dlo, auto)
23462
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   704
  fix x y::'a assume lt: "x < y"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   705
  from  less_half_sum[OF lt] show "x < (x + y) /2" by simp
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   706
next
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   707
  fix x y::'a assume lt: "x < y"
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   708
  from  gt_half_sum[OF lt] show "(x + y) /2 < y" by simp
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   709
qed
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   710
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   711
declaration{*
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   712
let
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   713
fun earlier [] x y = false
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   714
        | earlier (h::t) x y =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   715
    if h aconvc y then false else if h aconvc x then true else earlier t x y;
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   716
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   717
fun dest_frac ct = case term_of ct of
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   718
   Const (@{const_name "HOL.divide"},_) $ a $ b=>
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   719
    Rat.rat_of_quotient (snd (HOLogic.dest_number a), snd (HOLogic.dest_number b))
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   720
 | t => Rat.rat_of_int (snd (HOLogic.dest_number t))
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   721
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   722
fun mk_frac phi cT x =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   723
 let val (a, b) = Rat.quotient_of_rat x
23572
b3ce27bd211f Numeral.mk_cnumber;
wenzelm
parents: 23477
diff changeset
   724
 in if b = 1 then Numeral.mk_cnumber cT a
23462
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   725
    else Thm.capply
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   726
         (Thm.capply (Drule.cterm_rule (instantiate' [SOME cT] []) @{cpat "op /"})
23572
b3ce27bd211f Numeral.mk_cnumber;
wenzelm
parents: 23477
diff changeset
   727
                     (Numeral.mk_cnumber cT a))
b3ce27bd211f Numeral.mk_cnumber;
wenzelm
parents: 23477
diff changeset
   728
         (Numeral.mk_cnumber cT b)
23462
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   729
 end
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   730
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   731
fun whatis x ct = case term_of ct of
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   732
  Const(@{const_name "HOL.plus"}, _)$(Const(@{const_name "HOL.times"},_)$_$y)$_ =>
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   733
     if y aconv term_of x then ("c*x+t",[(funpow 2 Thm.dest_arg1) ct, Thm.dest_arg ct])
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   734
     else ("Nox",[])
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   735
| Const(@{const_name "HOL.plus"}, _)$y$_ =>
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   736
     if y aconv term_of x then ("x+t",[Thm.dest_arg ct])
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   737
     else ("Nox",[])
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   738
| Const(@{const_name "HOL.times"}, _)$_$y =>
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   739
     if y aconv term_of x then ("c*x",[Thm.dest_arg1 ct])
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   740
     else ("Nox",[])
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   741
| t => if t aconv term_of x then ("x",[]) else ("Nox",[]);
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   742
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   743
fun xnormalize_conv ctxt [] ct = reflexive ct
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   744
| xnormalize_conv ctxt (vs as (x::_)) ct =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   745
   case term_of ct of
23881
851c74f1bb69 moved class ord from Orderings.thy to HOL.thy
haftmann
parents: 23572
diff changeset
   746
   Const(@{const_name HOL.less},_)$_$Const(@{const_name "HOL.zero"},_) =>
23462
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   747
    (case whatis x (Thm.dest_arg1 ct) of
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   748
    ("c*x+t",[c,t]) =>
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   749
       let
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   750
        val cr = dest_frac c
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   751
        val clt = Thm.dest_fun2 ct
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   752
        val cz = Thm.dest_arg ct
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   753
        val neg = cr </ Rat.zero
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   754
        val cthp = Simplifier.rewrite (local_simpset_of ctxt)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   755
               (Thm.capply @{cterm "Trueprop"}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   756
                  (if neg then Thm.capply (Thm.capply clt c) cz
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   757
                    else Thm.capply (Thm.capply clt cz) c))
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   758
        val cth = equal_elim (symmetric cthp) TrueI
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   759
        val th = implies_elim (instantiate' [SOME (ctyp_of_term x)] (map SOME [c,x,t])
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   760
             (if neg then @{thm neg_prod_sum_lt} else @{thm pos_prod_sum_lt})) cth
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   761
        val rth = Conv.fconv_rule (Conv.arg_conv (Conv.binop_conv
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   762
                   (Normalizer.semiring_normalize_ord_conv ctxt (earlier vs)))) th
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   763
      in rth end
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   764
    | ("x+t",[t]) =>
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   765
       let
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   766
        val T = ctyp_of_term x
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   767
        val th = instantiate' [SOME T] [SOME x, SOME t] @{thm "sum_lt"}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   768
        val rth = Conv.fconv_rule (Conv.arg_conv (Conv.binop_conv
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   769
              (Normalizer.semiring_normalize_ord_conv ctxt (earlier vs)))) th
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   770
       in  rth end
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   771
    | ("c*x",[c]) =>
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   772
       let
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   773
        val cr = dest_frac c
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   774
        val clt = Thm.dest_fun2 ct
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   775
        val cz = Thm.dest_arg ct
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   776
        val neg = cr </ Rat.zero
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   777
        val cthp = Simplifier.rewrite (local_simpset_of ctxt)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   778
               (Thm.capply @{cterm "Trueprop"}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   779
                  (if neg then Thm.capply (Thm.capply clt c) cz
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   780
                    else Thm.capply (Thm.capply clt cz) c))
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   781
        val cth = equal_elim (symmetric cthp) TrueI
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   782
        val th = implies_elim (instantiate' [SOME (ctyp_of_term x)] (map SOME [c,x])
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   783
             (if neg then @{thm neg_prod_lt} else @{thm pos_prod_lt})) cth
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   784
        val rth = th
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   785
      in rth end
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   786
    | _ => reflexive ct)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   787
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   788
23881
851c74f1bb69 moved class ord from Orderings.thy to HOL.thy
haftmann
parents: 23572
diff changeset
   789
|  Const(@{const_name HOL.less_eq},_)$_$Const(@{const_name "HOL.zero"},_) =>
23462
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   790
   (case whatis x (Thm.dest_arg1 ct) of
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   791
    ("c*x+t",[c,t]) =>
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   792
       let
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   793
        val T = ctyp_of_term x
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   794
        val cr = dest_frac c
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   795
        val clt = Drule.cterm_rule (instantiate' [SOME T] []) @{cpat "op <"}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   796
        val cz = Thm.dest_arg ct
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   797
        val neg = cr </ Rat.zero
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   798
        val cthp = Simplifier.rewrite (local_simpset_of ctxt)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   799
               (Thm.capply @{cterm "Trueprop"}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   800
                  (if neg then Thm.capply (Thm.capply clt c) cz
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   801
                    else Thm.capply (Thm.capply clt cz) c))
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   802
        val cth = equal_elim (symmetric cthp) TrueI
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   803
        val th = implies_elim (instantiate' [SOME T] (map SOME [c,x,t])
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   804
             (if neg then @{thm neg_prod_sum_le} else @{thm pos_prod_sum_le})) cth
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   805
        val rth = Conv.fconv_rule (Conv.arg_conv (Conv.binop_conv
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   806
                   (Normalizer.semiring_normalize_ord_conv ctxt (earlier vs)))) th
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   807
      in rth end
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   808
    | ("x+t",[t]) =>
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   809
       let
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   810
        val T = ctyp_of_term x
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   811
        val th = instantiate' [SOME T] [SOME x, SOME t] @{thm "sum_le"}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   812
        val rth = Conv.fconv_rule (Conv.arg_conv (Conv.binop_conv
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   813
              (Normalizer.semiring_normalize_ord_conv ctxt (earlier vs)))) th
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   814
       in  rth end
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   815
    | ("c*x",[c]) =>
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   816
       let
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   817
        val T = ctyp_of_term x
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   818
        val cr = dest_frac c
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   819
        val clt = Drule.cterm_rule (instantiate' [SOME T] []) @{cpat "op <"}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   820
        val cz = Thm.dest_arg ct
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   821
        val neg = cr </ Rat.zero
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   822
        val cthp = Simplifier.rewrite (local_simpset_of ctxt)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   823
               (Thm.capply @{cterm "Trueprop"}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   824
                  (if neg then Thm.capply (Thm.capply clt c) cz
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   825
                    else Thm.capply (Thm.capply clt cz) c))
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   826
        val cth = equal_elim (symmetric cthp) TrueI
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   827
        val th = implies_elim (instantiate' [SOME (ctyp_of_term x)] (map SOME [c,x])
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   828
             (if neg then @{thm neg_prod_le} else @{thm pos_prod_le})) cth
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   829
        val rth = th
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   830
      in rth end
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   831
    | _ => reflexive ct)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   832
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   833
|  Const("op =",_)$_$Const(@{const_name "HOL.zero"},_) =>
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   834
   (case whatis x (Thm.dest_arg1 ct) of
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   835
    ("c*x+t",[c,t]) =>
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   836
       let
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   837
        val T = ctyp_of_term x
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   838
        val cr = dest_frac c
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   839
        val ceq = Thm.dest_fun2 ct
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   840
        val cz = Thm.dest_arg ct
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   841
        val cthp = Simplifier.rewrite (local_simpset_of ctxt)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   842
            (Thm.capply @{cterm "Trueprop"}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   843
             (Thm.capply @{cterm "Not"} (Thm.capply (Thm.capply ceq c) cz)))
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   844
        val cth = equal_elim (symmetric cthp) TrueI
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   845
        val th = implies_elim
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   846
                 (instantiate' [SOME T] (map SOME [c,x,t]) @{thm nz_prod_sum_eq}) cth
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   847
        val rth = Conv.fconv_rule (Conv.arg_conv (Conv.binop_conv
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   848
                   (Normalizer.semiring_normalize_ord_conv ctxt (earlier vs)))) th
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   849
      in rth end
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   850
    | ("x+t",[t]) =>
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   851
       let
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   852
        val T = ctyp_of_term x
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   853
        val th = instantiate' [SOME T] [SOME x, SOME t] @{thm "sum_eq"}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   854
        val rth = Conv.fconv_rule (Conv.arg_conv (Conv.binop_conv
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   855
              (Normalizer.semiring_normalize_ord_conv ctxt (earlier vs)))) th
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   856
       in  rth end
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   857
    | ("c*x",[c]) =>
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   858
       let
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   859
        val T = ctyp_of_term x
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   860
        val cr = dest_frac c
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   861
        val ceq = Thm.dest_fun2 ct
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   862
        val cz = Thm.dest_arg ct
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   863
        val cthp = Simplifier.rewrite (local_simpset_of ctxt)
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   864
            (Thm.capply @{cterm "Trueprop"}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   865
             (Thm.capply @{cterm "Not"} (Thm.capply (Thm.capply ceq c) cz)))
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   866
        val cth = equal_elim (symmetric cthp) TrueI
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   867
        val rth = implies_elim
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   868
                 (instantiate' [SOME T] (map SOME [c,x]) @{thm nz_prod_eq}) cth
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   869
      in rth end
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   870
    | _ => reflexive ct);
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   871
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   872
local
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   873
  val less_iff_diff_less_0 = mk_meta_eq @{thm "less_iff_diff_less_0"}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   874
  val le_iff_diff_le_0 = mk_meta_eq @{thm "le_iff_diff_le_0"}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   875
  val eq_iff_diff_eq_0 = mk_meta_eq @{thm "eq_iff_diff_eq_0"}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   876
in
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   877
fun field_isolate_conv phi ctxt vs ct = case term_of ct of
23881
851c74f1bb69 moved class ord from Orderings.thy to HOL.thy
haftmann
parents: 23572
diff changeset
   878
  Const(@{const_name HOL.less},_)$a$b =>
23462
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   879
   let val (ca,cb) = Thm.dest_binop ct
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   880
       val T = ctyp_of_term ca
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   881
       val th = instantiate' [SOME T] [SOME ca, SOME cb] less_iff_diff_less_0
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   882
       val nth = Conv.fconv_rule
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   883
         (Conv.arg_conv (Conv.arg1_conv
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   884
              (Normalizer.semiring_normalize_ord_conv @{context} (earlier vs)))) th
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   885
       val rth = transitive nth (xnormalize_conv ctxt vs (Thm.rhs_of nth))
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   886
   in rth end
23881
851c74f1bb69 moved class ord from Orderings.thy to HOL.thy
haftmann
parents: 23572
diff changeset
   887
| Const(@{const_name HOL.less_eq},_)$a$b =>
23462
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   888
   let val (ca,cb) = Thm.dest_binop ct
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   889
       val T = ctyp_of_term ca
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   890
       val th = instantiate' [SOME T] [SOME ca, SOME cb] le_iff_diff_le_0
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   891
       val nth = Conv.fconv_rule
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   892
         (Conv.arg_conv (Conv.arg1_conv
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   893
              (Normalizer.semiring_normalize_ord_conv @{context} (earlier vs)))) th
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   894
       val rth = transitive nth (xnormalize_conv ctxt vs (Thm.rhs_of nth))
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   895
   in rth end
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   896
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   897
| Const("op =",_)$a$b =>
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   898
   let val (ca,cb) = Thm.dest_binop ct
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   899
       val T = ctyp_of_term ca
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   900
       val th = instantiate' [SOME T] [SOME ca, SOME cb] eq_iff_diff_eq_0
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   901
       val nth = Conv.fconv_rule
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   902
         (Conv.arg_conv (Conv.arg1_conv
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   903
              (Normalizer.semiring_normalize_ord_conv @{context} (earlier vs)))) th
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   904
       val rth = transitive nth (xnormalize_conv ctxt vs (Thm.rhs_of nth))
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   905
   in rth end
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   906
| @{term "Not"} $(Const("op =",_)$a$b) => Conv.arg_conv (field_isolate_conv phi ctxt vs) ct
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   907
| _ => reflexive ct
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   908
end;
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   909
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   910
fun classfield_whatis phi =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   911
 let
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   912
  fun h x t =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   913
   case term_of t of
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   914
     Const("op =", _)$y$z => if term_of x aconv y then Ferrante_Rackoff_Data.Eq
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   915
                            else Ferrante_Rackoff_Data.Nox
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   916
   | @{term "Not"}$(Const("op =", _)$y$z) => if term_of x aconv y then Ferrante_Rackoff_Data.NEq
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   917
                            else Ferrante_Rackoff_Data.Nox
23881
851c74f1bb69 moved class ord from Orderings.thy to HOL.thy
haftmann
parents: 23572
diff changeset
   918
   | Const(@{const_name HOL.less},_)$y$z =>
23462
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   919
       if term_of x aconv y then Ferrante_Rackoff_Data.Lt
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   920
        else if term_of x aconv z then Ferrante_Rackoff_Data.Gt
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   921
        else Ferrante_Rackoff_Data.Nox
23881
851c74f1bb69 moved class ord from Orderings.thy to HOL.thy
haftmann
parents: 23572
diff changeset
   922
   | Const (@{const_name HOL.less_eq},_)$y$z =>
23462
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   923
         if term_of x aconv y then Ferrante_Rackoff_Data.Le
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   924
         else if term_of x aconv z then Ferrante_Rackoff_Data.Ge
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   925
         else Ferrante_Rackoff_Data.Nox
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   926
   | _ => Ferrante_Rackoff_Data.Nox
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   927
 in h end;
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   928
fun class_field_ss phi =
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   929
   HOL_basic_ss addsimps ([@{thm "linorder_not_less"}, @{thm "linorder_not_le"}])
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   930
   addsplits [@{thm "abs_split"},@{thm "split_max"}, @{thm "split_min"}]
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   931
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   932
in
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   933
Ferrante_Rackoff_Data.funs @{thm "class_ordered_field_dense_linear_order.ferrack_axiom"}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   934
  {isolate_conv = field_isolate_conv, whatis = classfield_whatis, simpset = class_field_ss}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   935
end
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   936
*}
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   937
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents:
diff changeset
   938
end