src/HOL/Semiring_Normalization.thy
 author bulwahn Fri Oct 21 11:17:14 2011 +0200 (2011-10-21) changeset 45231 d85a2fdc586c parent 37946 be3c0df7bb90 child 47108 2a1953f0d20d permissions -rw-r--r--
replacing code_inline by code_unfold, removing obsolete code_unfold, code_inline del now that the ancient code generator is removed
```     1 (*  Title:      HOL/Semiring_Normalization.thy
```
```     2     Author:     Amine Chaieb, TU Muenchen
```
```     3 *)
```
```     4
```
```     5 header {* Semiring normalization *}
```
```     6
```
```     7 theory Semiring_Normalization
```
```     8 imports Numeral_Simprocs Nat_Transfer
```
```     9 uses
```
```    10   "Tools/semiring_normalizer.ML"
```
```    11 begin
```
```    12
```
```    13 text {* Prelude *}
```
```    14
```
```    15 class comm_semiring_1_cancel_crossproduct = comm_semiring_1_cancel +
```
```    16   assumes crossproduct_eq: "w * y + x * z = w * z + x * y \<longleftrightarrow> w = x \<or> y = z"
```
```    17 begin
```
```    18
```
```    19 lemma crossproduct_noteq:
```
```    20   "a \<noteq> b \<and> c \<noteq> d \<longleftrightarrow> a * c + b * d \<noteq> a * d + b * c"
```
```    21   by (simp add: crossproduct_eq)
```
```    22
```
```    23 lemma add_scale_eq_noteq:
```
```    24   "r \<noteq> 0 \<Longrightarrow> a = b \<and> c \<noteq> d \<Longrightarrow> a + r * c \<noteq> b + r * d"
```
```    25 proof (rule notI)
```
```    26   assume nz: "r\<noteq> 0" and cnd: "a = b \<and> c\<noteq>d"
```
```    27     and eq: "a + (r * c) = b + (r * d)"
```
```    28   have "(0 * d) + (r * c) = (0 * c) + (r * d)"
```
```    29     using add_imp_eq eq mult_zero_left by (simp add: cnd)
```
```    30   then show False using crossproduct_eq [of 0 d] nz cnd by simp
```
```    31 qed
```
```    32
```
```    33 lemma add_0_iff:
```
```    34   "b = b + a \<longleftrightarrow> a = 0"
```
```    35   using add_imp_eq [of b a 0] by auto
```
```    36
```
```    37 end
```
```    38
```
```    39 subclass (in idom) comm_semiring_1_cancel_crossproduct
```
```    40 proof
```
```    41   fix w x y z
```
```    42   show "w * y + x * z = w * z + x * y \<longleftrightarrow> w = x \<or> y = z"
```
```    43   proof
```
```    44     assume "w * y + x * z = w * z + x * y"
```
```    45     then have "w * y + x * z - w * z - x * y = 0" by (simp add: algebra_simps)
```
```    46     then have "w * (y - z) - x * (y - z) = 0" by (simp add: algebra_simps)
```
```    47     then have "(y - z) * (w - x) = 0" by (simp add: algebra_simps)
```
```    48     then have "y - z = 0 \<or> w - x = 0" by (rule divisors_zero)
```
```    49     then show "w = x \<or> y = z" by auto
```
```    50   qed (auto simp add: add_ac)
```
```    51 qed
```
```    52
```
```    53 instance nat :: comm_semiring_1_cancel_crossproduct
```
```    54 proof
```
```    55   fix w x y z :: nat
```
```    56   have aux: "\<And>y z. y < z \<Longrightarrow> w * y + x * z = w * z + x * y \<Longrightarrow> w = x"
```
```    57   proof -
```
```    58     fix y z :: nat
```
```    59     assume "y < z" then have "\<exists>k. z = y + k \<and> k \<noteq> 0" by (intro exI [of _ "z - y"]) auto
```
```    60     then obtain k where "z = y + k" and "k \<noteq> 0" by blast
```
```    61     assume "w * y + x * z = w * z + x * y"
```
```    62     then have "(w * y + x * y) + x * k = (w * y + x * y) + w * k" by (simp add: `z = y + k` algebra_simps)
```
```    63     then have "x * k = w * k" by simp
```
```    64     then show "w = x" using `k \<noteq> 0` by simp
```
```    65   qed
```
```    66   show "w * y + x * z = w * z + x * y \<longleftrightarrow> w = x \<or> y = z"
```
```    67     by (auto simp add: neq_iff dest!: aux)
```
```    68 qed
```
```    69
```
```    70 text {* Semiring normalization proper *}
```
```    71
```
```    72 setup Semiring_Normalizer.setup
```
```    73
```
```    74 context comm_semiring_1
```
```    75 begin
```
```    76
```
```    77 lemma normalizing_semiring_ops:
```
```    78   shows "TERM (x + y)" and "TERM (x * y)" and "TERM (x ^ n)"
```
```    79     and "TERM 0" and "TERM 1" .
```
```    80
```
```    81 lemma normalizing_semiring_rules:
```
```    82   "(a * m) + (b * m) = (a + b) * m"
```
```    83   "(a * m) + m = (a + 1) * m"
```
```    84   "m + (a * m) = (a + 1) * m"
```
```    85   "m + m = (1 + 1) * m"
```
```    86   "0 + a = a"
```
```    87   "a + 0 = a"
```
```    88   "a * b = b * a"
```
```    89   "(a + b) * c = (a * c) + (b * c)"
```
```    90   "0 * a = 0"
```
```    91   "a * 0 = 0"
```
```    92   "1 * a = a"
```
```    93   "a * 1 = a"
```
```    94   "(lx * ly) * (rx * ry) = (lx * rx) * (ly * ry)"
```
```    95   "(lx * ly) * (rx * ry) = lx * (ly * (rx * ry))"
```
```    96   "(lx * ly) * (rx * ry) = rx * ((lx * ly) * ry)"
```
```    97   "(lx * ly) * rx = (lx * rx) * ly"
```
```    98   "(lx * ly) * rx = lx * (ly * rx)"
```
```    99   "lx * (rx * ry) = (lx * rx) * ry"
```
```   100   "lx * (rx * ry) = rx * (lx * ry)"
```
```   101   "(a + b) + (c + d) = (a + c) + (b + d)"
```
```   102   "(a + b) + c = a + (b + c)"
```
```   103   "a + (c + d) = c + (a + d)"
```
```   104   "(a + b) + c = (a + c) + b"
```
```   105   "a + c = c + a"
```
```   106   "a + (c + d) = (a + c) + d"
```
```   107   "(x ^ p) * (x ^ q) = x ^ (p + q)"
```
```   108   "x * (x ^ q) = x ^ (Suc q)"
```
```   109   "(x ^ q) * x = x ^ (Suc q)"
```
```   110   "x * x = x ^ 2"
```
```   111   "(x * y) ^ q = (x ^ q) * (y ^ q)"
```
```   112   "(x ^ p) ^ q = x ^ (p * q)"
```
```   113   "x ^ 0 = 1"
```
```   114   "x ^ 1 = x"
```
```   115   "x * (y + z) = (x * y) + (x * z)"
```
```   116   "x ^ (Suc q) = x * (x ^ q)"
```
```   117   "x ^ (2*n) = (x ^ n) * (x ^ n)"
```
```   118   "x ^ (Suc (2*n)) = x * ((x ^ n) * (x ^ n))"
```
```   119   by (simp_all add: algebra_simps power_add power2_eq_square power_mult_distrib power_mult)
```
```   120
```
```   121 lemmas normalizing_comm_semiring_1_axioms =
```
```   122   comm_semiring_1_axioms [normalizer
```
```   123     semiring ops: normalizing_semiring_ops
```
```   124     semiring rules: normalizing_semiring_rules]
```
```   125
```
```   126 declaration
```
```   127   {* Semiring_Normalizer.semiring_funs @{thm normalizing_comm_semiring_1_axioms} *}
```
```   128
```
```   129 end
```
```   130
```
```   131 context comm_ring_1
```
```   132 begin
```
```   133
```
```   134 lemma normalizing_ring_ops: shows "TERM (x- y)" and "TERM (- x)" .
```
```   135
```
```   136 lemma normalizing_ring_rules:
```
```   137   "- x = (- 1) * x"
```
```   138   "x - y = x + (- y)"
```
```   139   by (simp_all add: diff_minus)
```
```   140
```
```   141 lemmas normalizing_comm_ring_1_axioms =
```
```   142   comm_ring_1_axioms [normalizer
```
```   143     semiring ops: normalizing_semiring_ops
```
```   144     semiring rules: normalizing_semiring_rules
```
```   145     ring ops: normalizing_ring_ops
```
```   146     ring rules: normalizing_ring_rules]
```
```   147
```
```   148 declaration
```
```   149   {* Semiring_Normalizer.semiring_funs @{thm normalizing_comm_ring_1_axioms} *}
```
```   150
```
```   151 end
```
```   152
```
```   153 context comm_semiring_1_cancel_crossproduct
```
```   154 begin
```
```   155
```
```   156 declare
```
```   157   normalizing_comm_semiring_1_axioms [normalizer del]
```
```   158
```
```   159 lemmas
```
```   160   normalizing_comm_semiring_1_cancel_crossproduct_axioms =
```
```   161   comm_semiring_1_cancel_crossproduct_axioms [normalizer
```
```   162     semiring ops: normalizing_semiring_ops
```
```   163     semiring rules: normalizing_semiring_rules
```
```   164     idom rules: crossproduct_noteq add_scale_eq_noteq]
```
```   165
```
```   166 declaration
```
```   167   {* Semiring_Normalizer.semiring_funs @{thm normalizing_comm_semiring_1_cancel_crossproduct_axioms} *}
```
```   168
```
```   169 end
```
```   170
```
```   171 context idom
```
```   172 begin
```
```   173
```
```   174 declare normalizing_comm_ring_1_axioms [normalizer del]
```
```   175
```
```   176 lemmas normalizing_idom_axioms = idom_axioms [normalizer
```
```   177   semiring ops: normalizing_semiring_ops
```
```   178   semiring rules: normalizing_semiring_rules
```
```   179   ring ops: normalizing_ring_ops
```
```   180   ring rules: normalizing_ring_rules
```
```   181   idom rules: crossproduct_noteq add_scale_eq_noteq
```
```   182   ideal rules: right_minus_eq add_0_iff]
```
```   183
```
```   184 declaration
```
```   185   {* Semiring_Normalizer.semiring_funs @{thm normalizing_idom_axioms} *}
```
```   186
```
```   187 end
```
```   188
```
```   189 context field
```
```   190 begin
```
```   191
```
```   192 lemma normalizing_field_ops:
```
```   193   shows "TERM (x / y)" and "TERM (inverse x)" .
```
```   194
```
```   195 lemmas normalizing_field_rules = divide_inverse inverse_eq_divide
```
```   196
```
```   197 lemmas normalizing_field_axioms =
```
```   198   field_axioms [normalizer
```
```   199     semiring ops: normalizing_semiring_ops
```
```   200     semiring rules: normalizing_semiring_rules
```
```   201     ring ops: normalizing_ring_ops
```
```   202     ring rules: normalizing_ring_rules
```
```   203     field ops: normalizing_field_ops
```
```   204     field rules: normalizing_field_rules
```
```   205     idom rules: crossproduct_noteq add_scale_eq_noteq
```
```   206     ideal rules: right_minus_eq add_0_iff]
```
```   207
```
```   208 declaration
```
```   209   {* Semiring_Normalizer.field_funs @{thm normalizing_field_axioms} *}
```
```   210
```
```   211 end
```
```   212
```
```   213 hide_fact (open) normalizing_comm_semiring_1_axioms
```
```   214   normalizing_comm_semiring_1_cancel_crossproduct_axioms normalizing_semiring_ops normalizing_semiring_rules
```
```   215
```
```   216 hide_fact (open) normalizing_comm_ring_1_axioms
```
```   217   normalizing_idom_axioms normalizing_ring_ops normalizing_ring_rules
```
```   218
```
```   219 hide_fact (open) normalizing_field_axioms normalizing_field_ops normalizing_field_rules
```
```   220
```
```   221 end
```