src/HOL/Semiring_Normalization.thy
 author hoelzl Tue May 11 19:21:39 2010 +0200 (2010-05-11) changeset 36845 d778c64fc35d parent 36756 c1ae8a0b4265 child 36871 3763c349c8c1 permissions -rw-r--r--
```     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 {* FIXME prelude *}
```
```    14
```
```    15 class comm_semiring_1_cancel_norm (*FIXME name*) = comm_semiring_1_cancel +
```
```    16   assumes add_mult_solve: "w * y + x * z = w * z + x * y \<longleftrightarrow> w = x \<or> y = z"
```
```    17
```
```    18 sublocale idom < comm_semiring_1_cancel_norm
```
```    19 proof
```
```    20   fix w x y z
```
```    21   show "w * y + x * z = w * z + x * y \<longleftrightarrow> w = x \<or> y = z"
```
```    22   proof
```
```    23     assume "w * y + x * z = w * z + x * y"
```
```    24     then have "w * y + x * z - w * z - x * y = 0" by (simp add: algebra_simps)
```
```    25     then have "w * (y - z) - x * (y - z) = 0" by (simp add: algebra_simps)
```
```    26     then have "(y - z) * (w - x) = 0" by (simp add: algebra_simps)
```
```    27     then have "y - z = 0 \<or> w - x = 0" by (rule divisors_zero)
```
```    28     then show "w = x \<or> y = z" by auto
```
```    29   qed (auto simp add: add_ac)
```
```    30 qed
```
```    31
```
```    32 instance nat :: comm_semiring_1_cancel_norm
```
```    33 proof
```
```    34   fix w x y z :: nat
```
```    35   { assume p: "w * y + x * z = w * z + x * y" and ynz: "y \<noteq> z"
```
```    36     hence "y < z \<or> y > z" by arith
```
```    37     moreover {
```
```    38       assume lt:"y <z" hence "\<exists>k. z = y + k \<and> k > 0" by (rule_tac x="z - y" in exI, auto)
```
```    39       then obtain k where kp: "k>0" and yz:"z = y + k" by blast
```
```    40       from p have "(w * y + x *y) + x*k = (w * y + x*y) + w*k" by (simp add: yz algebra_simps)
```
```    41       hence "x*k = w*k" by simp
```
```    42       hence "w = x" using kp by simp }
```
```    43     moreover {
```
```    44       assume lt: "y >z" hence "\<exists>k. y = z + k \<and> k>0" by (rule_tac x="y - z" in exI, auto)
```
```    45       then obtain k where kp: "k>0" and yz:"y = z + k" by blast
```
```    46       from p have "(w * z + x *z) + w*k = (w * z + x*z) + x*k" by (simp add: yz algebra_simps)
```
```    47       hence "w*k = x*k" by simp
```
```    48       hence "w = x" using kp by simp }
```
```    49     ultimately have "w=x" by blast }
```
```    50   then show "w * y + x * z = w * z + x * y \<longleftrightarrow> w = x \<or> y = z" by auto
```
```    51 qed
```
```    52
```
```    53 setup Semiring_Normalizer.setup
```
```    54
```
```    55 lemma (in comm_semiring_1) semiring_ops:
```
```    56   shows "TERM (x + y)" and "TERM (x * y)" and "TERM (x ^ n)"
```
```    57     and "TERM 0" and "TERM 1" .
```
```    58
```
```    59 lemma (in comm_semiring_1) semiring_rules:
```
```    60   "(a * m) + (b * m) = (a + b) * m"
```
```    61   "(a * m) + m = (a + 1) * m"
```
```    62   "m + (a * m) = (a + 1) * m"
```
```    63   "m + m = (1 + 1) * m"
```
```    64   "0 + a = a"
```
```    65   "a + 0 = a"
```
```    66   "a * b = b * a"
```
```    67   "(a + b) * c = (a * c) + (b * c)"
```
```    68   "0 * a = 0"
```
```    69   "a * 0 = 0"
```
```    70   "1 * a = a"
```
```    71   "a * 1 = a"
```
```    72   "(lx * ly) * (rx * ry) = (lx * rx) * (ly * ry)"
```
```    73   "(lx * ly) * (rx * ry) = lx * (ly * (rx * ry))"
```
```    74   "(lx * ly) * (rx * ry) = rx * ((lx * ly) * ry)"
```
```    75   "(lx * ly) * rx = (lx * rx) * ly"
```
```    76   "(lx * ly) * rx = lx * (ly * rx)"
```
```    77   "lx * (rx * ry) = (lx * rx) * ry"
```
```    78   "lx * (rx * ry) = rx * (lx * ry)"
```
```    79   "(a + b) + (c + d) = (a + c) + (b + d)"
```
```    80   "(a + b) + c = a + (b + c)"
```
```    81   "a + (c + d) = c + (a + d)"
```
```    82   "(a + b) + c = (a + c) + b"
```
```    83   "a + c = c + a"
```
```    84   "a + (c + d) = (a + c) + d"
```
```    85   "(x ^ p) * (x ^ q) = x ^ (p + q)"
```
```    86   "x * (x ^ q) = x ^ (Suc q)"
```
```    87   "(x ^ q) * x = x ^ (Suc q)"
```
```    88   "x * x = x ^ 2"
```
```    89   "(x * y) ^ q = (x ^ q) * (y ^ q)"
```
```    90   "(x ^ p) ^ q = x ^ (p * q)"
```
```    91   "x ^ 0 = 1"
```
```    92   "x ^ 1 = x"
```
```    93   "x * (y + z) = (x * y) + (x * z)"
```
```    94   "x ^ (Suc q) = x * (x ^ q)"
```
```    95   "x ^ (2*n) = (x ^ n) * (x ^ n)"
```
```    96   "x ^ (Suc (2*n)) = x * ((x ^ n) * (x ^ n))"
```
```    97   by (simp_all add: algebra_simps power_add power2_eq_square power_mult_distrib power_mult)
```
```    98
```
```    99 lemmas (in comm_semiring_1) normalizing_comm_semiring_1_axioms =
```
```   100   comm_semiring_1_axioms [normalizer
```
```   101     semiring ops: semiring_ops
```
```   102     semiring rules: semiring_rules]
```
```   103
```
```   104 declaration (in comm_semiring_1)
```
```   105   {* Semiring_Normalizer.semiring_funs @{thm normalizing_comm_semiring_1_axioms} *}
```
```   106
```
```   107 lemma (in comm_ring_1) ring_ops: shows "TERM (x- y)" and "TERM (- x)" .
```
```   108
```
```   109 lemma (in comm_ring_1) ring_rules:
```
```   110   "- x = (- 1) * x"
```
```   111   "x - y = x + (- y)"
```
```   112   by (simp_all add: diff_minus)
```
```   113
```
```   114 lemmas (in comm_ring_1) normalizing_comm_ring_1_axioms =
```
```   115   comm_ring_1_axioms [normalizer
```
```   116     semiring ops: semiring_ops
```
```   117     semiring rules: semiring_rules
```
```   118     ring ops: ring_ops
```
```   119     ring rules: ring_rules]
```
```   120
```
```   121 declaration (in comm_ring_1)
```
```   122   {* Semiring_Normalizer.semiring_funs @{thm normalizing_comm_ring_1_axioms} *}
```
```   123
```
```   124 lemma (in comm_semiring_1_cancel_norm) noteq_reduce:
```
```   125   "a \<noteq> b \<and> c \<noteq> d \<longleftrightarrow> (a * c) + (b * d) \<noteq> (a * d) + (b * c)"
```
```   126 proof-
```
```   127   have "a \<noteq> b \<and> c \<noteq> d \<longleftrightarrow> \<not> (a = b \<or> c = d)" by simp
```
```   128   also have "\<dots> \<longleftrightarrow> (a * c) + (b * d) \<noteq> (a * d) + (b * c)"
```
```   129     using add_mult_solve by blast
```
```   130   finally show "a \<noteq> b \<and> c \<noteq> d \<longleftrightarrow> (a * c) + (b * d) \<noteq> (a * d) + (b * c)"
```
```   131     by simp
```
```   132 qed
```
```   133
```
```   134 lemma (in comm_semiring_1_cancel_norm) add_scale_eq_noteq:
```
```   135   "\<lbrakk>r \<noteq> 0 ; a = b \<and> c \<noteq> d\<rbrakk> \<Longrightarrow> a + (r * c) \<noteq> b + (r * d)"
```
```   136 proof(clarify)
```
```   137   assume nz: "r\<noteq> 0" and cnd: "c\<noteq>d"
```
```   138     and eq: "b + (r * c) = b + (r * d)"
```
```   139   have "(0 * d) + (r * c) = (0 * c) + (r * d)"
```
```   140     using add_imp_eq eq mult_zero_left by simp
```
```   141   thus "False" using add_mult_solve[of 0 d] nz cnd by simp
```
```   142 qed
```
```   143
```
```   144 lemma (in comm_semiring_1_cancel_norm) add_0_iff:
```
```   145   "x = x + a \<longleftrightarrow> a = 0"
```
```   146 proof-
```
```   147   have "a = 0 \<longleftrightarrow> x + a = x + 0" using add_imp_eq[of x a 0] by auto
```
```   148   thus "x = x + a \<longleftrightarrow> a = 0" by (auto simp add: add_commute)
```
```   149 qed
```
```   150
```
```   151 declare (in comm_semiring_1_cancel_norm)
```
```   152   normalizing_comm_semiring_1_axioms [normalizer del]
```
```   153
```
```   154 lemmas (in comm_semiring_1_cancel_norm)
```
```   155   normalizing_comm_semiring_1_cancel_norm_axioms =
```
```   156   comm_semiring_1_cancel_norm_axioms [normalizer
```
```   157     semiring ops: semiring_ops
```
```   158     semiring rules: semiring_rules
```
```   159     idom rules: noteq_reduce add_scale_eq_noteq]
```
```   160
```
```   161 declaration (in comm_semiring_1_cancel_norm)
```
```   162   {* Semiring_Normalizer.semiring_funs @{thm normalizing_comm_semiring_1_cancel_norm_axioms} *}
```
```   163
```
```   164 declare (in idom) normalizing_comm_ring_1_axioms [normalizer del]
```
```   165
```
```   166 lemmas (in idom) normalizing_idom_axioms = idom_axioms [normalizer
```
```   167   semiring ops: semiring_ops
```
```   168   semiring rules: semiring_rules
```
```   169   ring ops: ring_ops
```
```   170   ring rules: ring_rules
```
```   171   idom rules: noteq_reduce add_scale_eq_noteq
```
```   172   ideal rules: right_minus_eq add_0_iff]
```
```   173
```
```   174 declaration (in idom)
```
```   175   {* Semiring_Normalizer.semiring_funs @{thm normalizing_idom_axioms} *}
```
```   176
```
```   177 lemma (in field) field_ops:
```
```   178   shows "TERM (x / y)" and "TERM (inverse x)" .
```
```   179
```
```   180 lemmas (in field) field_rules = divide_inverse inverse_eq_divide
```
```   181
```
```   182 lemmas (in field) normalizing_field_axioms =
```
```   183   field_axioms [normalizer
```
```   184     semiring ops: semiring_ops
```
```   185     semiring rules: semiring_rules
```
```   186     ring ops: ring_ops
```
```   187     ring rules: ring_rules
```
```   188     field ops: field_ops
```
```   189     field rules: field_rules
```
```   190     idom rules: noteq_reduce add_scale_eq_noteq
```
```   191     ideal rules: right_minus_eq add_0_iff]
```
```   192
```
```   193 declaration (in field)
```
```   194   {* Semiring_Normalizer.field_funs @{thm normalizing_field_axioms} *}
```
```   195
```
```   196 hide_fact (open) normalizing_comm_semiring_1_axioms
```
```   197   normalizing_comm_semiring_1_cancel_norm_axioms semiring_ops semiring_rules
```
```   198
```
```   199 hide_fact (open) normalizing_comm_ring_1_axioms
```
```   200   normalizing_idom_axioms ring_ops ring_rules
```
```   201
```
```   202 hide_fact (open)  normalizing_field_axioms field_ops field_rules
```
```   203
```
```   204 hide_fact (open) add_scale_eq_noteq noteq_reduce
```
```   205
```
```   206 end
```