src/HOL/Library/Function_Algebras.thy
 author paulson Tue Jun 23 16:55:28 2015 +0100 (2015-06-23) changeset 60562 24af00b010cf parent 60500 903bb1495239 child 60679 ade12ef2773c permissions -rw-r--r--
Amalgamation of the class comm_semiring_1_diff_distrib into comm_semiring_1_cancel. Moving axiom le_add_diff_inverse2 from semiring_numeral_div to linordered_semidom.
```     1 (*  Title:      HOL/Library/Function_Algebras.thy
```
```     2     Author:     Jeremy Avigad and Kevin Donnelly; Florian Haftmann, TUM
```
```     3 *)
```
```     4
```
```     5 section \<open>Pointwise instantiation of functions to algebra type classes\<close>
```
```     6
```
```     7 theory Function_Algebras
```
```     8 imports Main
```
```     9 begin
```
```    10
```
```    11 text \<open>Pointwise operations\<close>
```
```    12
```
```    13 instantiation "fun" :: (type, plus) plus
```
```    14 begin
```
```    15
```
```    16 definition "f + g = (\<lambda>x. f x + g x)"
```
```    17 instance ..
```
```    18
```
```    19 end
```
```    20
```
```    21 lemma plus_fun_apply [simp]:
```
```    22   "(f + g) x = f x + g x"
```
```    23   by (simp add: plus_fun_def)
```
```    24
```
```    25 instantiation "fun" :: (type, zero) zero
```
```    26 begin
```
```    27
```
```    28 definition "0 = (\<lambda>x. 0)"
```
```    29 instance ..
```
```    30
```
```    31 end
```
```    32
```
```    33 lemma zero_fun_apply [simp]:
```
```    34   "0 x = 0"
```
```    35   by (simp add: zero_fun_def)
```
```    36
```
```    37 instantiation "fun" :: (type, times) times
```
```    38 begin
```
```    39
```
```    40 definition "f * g = (\<lambda>x. f x * g x)"
```
```    41 instance ..
```
```    42
```
```    43 end
```
```    44
```
```    45 lemma times_fun_apply [simp]:
```
```    46   "(f * g) x = f x * g x"
```
```    47   by (simp add: times_fun_def)
```
```    48
```
```    49 instantiation "fun" :: (type, one) one
```
```    50 begin
```
```    51
```
```    52 definition "1 = (\<lambda>x. 1)"
```
```    53 instance ..
```
```    54
```
```    55 end
```
```    56
```
```    57 lemma one_fun_apply [simp]:
```
```    58   "1 x = 1"
```
```    59   by (simp add: one_fun_def)
```
```    60
```
```    61
```
```    62 text \<open>Additive structures\<close>
```
```    63
```
```    64 instance "fun" :: (type, semigroup_add) semigroup_add
```
```    65   by default (simp add: fun_eq_iff add.assoc)
```
```    66
```
```    67 instance "fun" :: (type, cancel_semigroup_add) cancel_semigroup_add
```
```    68   by default (simp_all add: fun_eq_iff)
```
```    69
```
```    70 instance "fun" :: (type, ab_semigroup_add) ab_semigroup_add
```
```    71   by default (simp add: fun_eq_iff add.commute)
```
```    72
```
```    73 instance "fun" :: (type, cancel_ab_semigroup_add) cancel_ab_semigroup_add
```
```    74   by default (simp_all add: fun_eq_iff diff_diff_eq)
```
```    75
```
```    76 instance "fun" :: (type, monoid_add) monoid_add
```
```    77   by default (simp_all add: fun_eq_iff)
```
```    78
```
```    79 instance "fun" :: (type, comm_monoid_add) comm_monoid_add
```
```    80   by default simp
```
```    81
```
```    82 instance "fun" :: (type, cancel_comm_monoid_add) cancel_comm_monoid_add ..
```
```    83
```
```    84 instance "fun" :: (type, group_add) group_add
```
```    85   by default
```
```    86     (simp_all add: fun_eq_iff)
```
```    87
```
```    88 instance "fun" :: (type, ab_group_add) ab_group_add
```
```    89   by default simp_all
```
```    90
```
```    91
```
```    92 text \<open>Multiplicative structures\<close>
```
```    93
```
```    94 instance "fun" :: (type, semigroup_mult) semigroup_mult
```
```    95   by default (simp add: fun_eq_iff mult.assoc)
```
```    96
```
```    97 instance "fun" :: (type, ab_semigroup_mult) ab_semigroup_mult
```
```    98   by default (simp add: fun_eq_iff mult.commute)
```
```    99
```
```   100 instance "fun" :: (type, monoid_mult) monoid_mult
```
```   101   by default (simp_all add: fun_eq_iff)
```
```   102
```
```   103 instance "fun" :: (type, comm_monoid_mult) comm_monoid_mult
```
```   104   by default simp
```
```   105
```
```   106
```
```   107 text \<open>Misc\<close>
```
```   108
```
```   109 instance "fun" :: (type, "Rings.dvd") "Rings.dvd" ..
```
```   110
```
```   111 instance "fun" :: (type, mult_zero) mult_zero
```
```   112   by default (simp_all add: fun_eq_iff)
```
```   113
```
```   114 instance "fun" :: (type, zero_neq_one) zero_neq_one
```
```   115   by default (simp add: fun_eq_iff)
```
```   116
```
```   117
```
```   118 text \<open>Ring structures\<close>
```
```   119
```
```   120 instance "fun" :: (type, semiring) semiring
```
```   121   by default (simp_all add: fun_eq_iff algebra_simps)
```
```   122
```
```   123 instance "fun" :: (type, comm_semiring) comm_semiring
```
```   124   by default (simp add: fun_eq_iff  algebra_simps)
```
```   125
```
```   126 instance "fun" :: (type, semiring_0) semiring_0 ..
```
```   127
```
```   128 instance "fun" :: (type, comm_semiring_0) comm_semiring_0 ..
```
```   129
```
```   130 instance "fun" :: (type, semiring_0_cancel) semiring_0_cancel ..
```
```   131
```
```   132 instance "fun" :: (type, comm_semiring_0_cancel) comm_semiring_0_cancel ..
```
```   133
```
```   134 instance "fun" :: (type, semiring_1) semiring_1 ..
```
```   135
```
```   136 lemma of_nat_fun: "of_nat n = (\<lambda>x::'a. of_nat n)"
```
```   137 proof -
```
```   138   have comp: "comp = (\<lambda>f g x. f (g x))"
```
```   139     by (rule ext)+ simp
```
```   140   have plus_fun: "plus = (\<lambda>f g x. f x + g x)"
```
```   141     by (rule ext, rule ext) (fact plus_fun_def)
```
```   142   have "of_nat n = (comp (plus (1::'b)) ^^ n) (\<lambda>x::'a. 0)"
```
```   143     by (simp add: of_nat_def plus_fun zero_fun_def one_fun_def comp)
```
```   144   also have "... = comp ((plus 1) ^^ n) (\<lambda>x::'a. 0)"
```
```   145     by (simp only: comp_funpow)
```
```   146   finally show ?thesis by (simp add: of_nat_def comp)
```
```   147 qed
```
```   148
```
```   149 lemma of_nat_fun_apply [simp]:
```
```   150   "of_nat n x = of_nat n"
```
```   151   by (simp add: of_nat_fun)
```
```   152
```
```   153 instance "fun" :: (type, comm_semiring_1) comm_semiring_1 ..
```
```   154
```
```   155 instance "fun" :: (type, semiring_1_cancel) semiring_1_cancel ..
```
```   156
```
```   157 instance "fun" :: (type, comm_semiring_1_cancel) comm_semiring_1_cancel
```
```   158   by default (auto simp add: times_fun_def algebra_simps)
```
```   159
```
```   160 instance "fun" :: (type, semiring_char_0) semiring_char_0
```
```   161 proof
```
```   162   from inj_of_nat have "inj (\<lambda>n (x::'a). of_nat n :: 'b)"
```
```   163     by (rule inj_fun)
```
```   164   then have "inj (\<lambda>n. of_nat n :: 'a \<Rightarrow> 'b)"
```
```   165     by (simp add: of_nat_fun)
```
```   166   then show "inj (of_nat :: nat \<Rightarrow> 'a \<Rightarrow> 'b)" .
```
```   167 qed
```
```   168
```
```   169 instance "fun" :: (type, ring) ring ..
```
```   170
```
```   171 instance "fun" :: (type, comm_ring) comm_ring ..
```
```   172
```
```   173 instance "fun" :: (type, ring_1) ring_1 ..
```
```   174
```
```   175 instance "fun" :: (type, comm_ring_1) comm_ring_1 ..
```
```   176
```
```   177 instance "fun" :: (type, ring_char_0) ring_char_0 ..
```
```   178
```
```   179
```
```   180 text \<open>Ordered structures\<close>
```
```   181
```
```   182 instance "fun" :: (type, ordered_ab_semigroup_add) ordered_ab_semigroup_add
```
```   183   by default (auto simp add: le_fun_def intro: add_left_mono)
```
```   184
```
```   185 instance "fun" :: (type, ordered_cancel_ab_semigroup_add) ordered_cancel_ab_semigroup_add ..
```
```   186
```
```   187 instance "fun" :: (type, ordered_ab_semigroup_add_imp_le) ordered_ab_semigroup_add_imp_le
```
```   188   by default (simp add: le_fun_def)
```
```   189
```
```   190 instance "fun" :: (type, ordered_comm_monoid_add) ordered_comm_monoid_add ..
```
```   191
```
```   192 instance "fun" :: (type, ordered_ab_group_add) ordered_ab_group_add ..
```
```   193
```
```   194 instance "fun" :: (type, ordered_semiring) ordered_semiring
```
```   195   by default
```
```   196     (auto simp add: le_fun_def intro: mult_left_mono mult_right_mono)
```
```   197
```
```   198 instance "fun" :: (type, ordered_comm_semiring) ordered_comm_semiring
```
```   199   by default (fact mult_left_mono)
```
```   200
```
```   201 instance "fun" :: (type, ordered_cancel_semiring) ordered_cancel_semiring ..
```
```   202
```
```   203 instance "fun" :: (type, ordered_cancel_comm_semiring) ordered_cancel_comm_semiring ..
```
```   204
```
```   205 instance "fun" :: (type, ordered_ring) ordered_ring ..
```
```   206
```
```   207 instance "fun" :: (type, ordered_comm_ring) ordered_comm_ring ..
```
```   208
```
```   209
```
```   210 lemmas func_plus = plus_fun_def
```
```   211 lemmas func_zero = zero_fun_def
```
```   212 lemmas func_times = times_fun_def
```
```   213 lemmas func_one = one_fun_def
```
```   214
```
```   215 end
```
```   216
```