95 fix k l :: int |
95 fix k l :: int |
96 from monoid_comm_num_def show "k \<otimes> l = l \<otimes> k" by simp |
96 from monoid_comm_num_def show "k \<otimes> l = l \<otimes> k" by simp |
97 qed |
97 qed |
98 |
98 |
99 definition (in monoid) |
99 definition (in monoid) |
100 units :: "'a set" |
100 units :: "'a set" where |
101 units_def: "units = { y. \<exists>x. x \<^loc>\<otimes> y = \<^loc>\<one> \<and> y \<^loc>\<otimes> x = \<^loc>\<one> }" |
101 "units = { y. \<exists>x. x \<^loc>\<otimes> y = \<^loc>\<one> \<and> y \<^loc>\<otimes> x = \<^loc>\<one> }" |
102 |
102 |
103 lemma (in monoid) inv_obtain: |
103 lemma (in monoid) inv_obtain: |
104 assumes ass: "x \<in> units" |
104 assumes ass: "x \<in> units" |
105 obtains y where "y \<^loc>\<otimes> x = \<^loc>\<one>" and "x \<^loc>\<otimes> y = \<^loc>\<one>" |
105 obtains y where "y \<^loc>\<otimes> x = \<^loc>\<one>" and "x \<^loc>\<otimes> y = \<^loc>\<one>" |
106 proof - |
106 proof - |
137 primrec |
137 primrec |
138 "reduce f g 0 x = g" |
138 "reduce f g 0 x = g" |
139 "reduce f g (Suc n) x = f x (reduce f g n x)" |
139 "reduce f g (Suc n) x = f x (reduce f g n x)" |
140 |
140 |
141 definition (in monoid) |
141 definition (in monoid) |
142 npow :: "nat \<Rightarrow> 'a \<Rightarrow> 'a" |
142 npow :: "nat \<Rightarrow> 'a \<Rightarrow> 'a" where |
143 npow_def_prim: "npow n x = reduce (op \<^loc>\<otimes>) \<^loc>\<one> n x" |
143 npow_def_prim: "npow n x = reduce (op \<^loc>\<otimes>) \<^loc>\<one> n x" |
144 |
144 |
145 abbreviation (in monoid) |
145 abbreviation (in monoid) |
146 abbrev_npow :: "'a \<Rightarrow> nat \<Rightarrow> 'a" (infix "\<^loc>\<up>" 75) |
146 abbrev_npow :: "'a \<Rightarrow> nat \<Rightarrow> 'a" (infix "\<^loc>\<up>" 75) where |
147 "x \<^loc>\<up> n \<equiv> npow n x" |
147 "x \<^loc>\<up> n \<equiv> npow n x" |
148 |
148 |
149 lemma (in monoid) npow_def: |
149 lemma (in monoid) npow_def: |
150 "x \<^loc>\<up> 0 = \<^loc>\<one>" |
150 "x \<^loc>\<up> 0 = \<^loc>\<one>" |
151 "x \<^loc>\<up> Suc n = x \<^loc>\<otimes> x \<^loc>\<up> n" |
151 "x \<^loc>\<up> Suc n = x \<^loc>\<otimes> x \<^loc>\<up> n" |
270 lemma (in group) inv_comm: |
270 lemma (in group) inv_comm: |
271 "x \<^loc>\<otimes> \<^loc>\<div> x = \<^loc>\<div> x \<^loc>\<otimes> x" |
271 "x \<^loc>\<otimes> \<^loc>\<div> x = \<^loc>\<div> x \<^loc>\<otimes> x" |
272 using invr invl by simp |
272 using invr invl by simp |
273 |
273 |
274 definition (in group) |
274 definition (in group) |
275 pow :: "int \<Rightarrow> 'a \<Rightarrow> 'a" |
275 pow :: "int \<Rightarrow> 'a \<Rightarrow> 'a" where |
276 pow_def: "pow k x = (if k < 0 then \<^loc>\<div> (monoid.npow (op \<^loc>\<otimes>) \<^loc>\<one> (nat (-k)) x) |
276 "pow k x = (if k < 0 then \<^loc>\<div> (monoid.npow (op \<^loc>\<otimes>) \<^loc>\<one> (nat (-k)) x) |
277 else (monoid.npow (op \<^loc>\<otimes>) \<^loc>\<one> (nat k) x))" |
277 else (monoid.npow (op \<^loc>\<otimes>) \<^loc>\<one> (nat k) x))" |
278 |
278 |
279 abbreviation (in group) |
279 abbreviation (in group) |
280 abbrev_pow :: "'a \<Rightarrow> int \<Rightarrow> 'a" (infix "\<^loc>\<up>" 75) |
280 abbrev_pow :: "'a \<Rightarrow> int \<Rightarrow> 'a" (infix "\<^loc>\<up>" 75) where |
281 "x \<^loc>\<up> k \<equiv> pow k x" |
281 "x \<^loc>\<up> k \<equiv> pow k x" |
282 |
282 |
283 lemma (in group) int_pow_zero: |
283 lemma (in group) int_pow_zero: |
284 "x \<^loc>\<up> (0\<Colon>int) = \<^loc>\<one>" |
284 "x \<^loc>\<up> (0\<Colon>int) = \<^loc>\<one>" |
285 using npow_def pow_def by simp |
285 using npow_def pow_def by simp |
310 instance group_comm_prod_def: * :: (group_comm, group_comm) group_comm |
310 instance group_comm_prod_def: * :: (group_comm, group_comm) group_comm |
311 by default (simp_all add: split_paired_all group_prod_def comm) |
311 by default (simp_all add: split_paired_all group_prod_def comm) |
312 |
312 |
313 definition |
313 definition |
314 "X a b c = (a \<otimes> \<one> \<otimes> b, a \<otimes> \<one> \<otimes> b, [a, b] \<otimes> \<one> \<otimes> [a, b, c])" |
314 "X a b c = (a \<otimes> \<one> \<otimes> b, a \<otimes> \<one> \<otimes> b, [a, b] \<otimes> \<one> \<otimes> [a, b, c])" |
|
315 definition |
315 "Y a b c = (a, \<div> a) \<otimes> \<one> \<otimes> \<div> (b, \<div> c)" |
316 "Y a b c = (a, \<div> a) \<otimes> \<one> \<otimes> \<div> (b, \<div> c)" |
316 |
317 |
317 definition |
318 definition "x1 = X (1::nat) 2 3" |
318 "x1 = X (1::nat) 2 3" |
319 definition "x2 = X (1::int) 2 3" |
319 "x2 = X (1::int) 2 3" |
320 definition "y2 = Y (1::int) 2 3" |
320 "y2 = Y (1::int) 2 3" |
|
321 |
321 |
322 code_gen "op \<otimes>" \<one> inv |
322 code_gen "op \<otimes>" \<one> inv |
323 code_gen X Y (SML) (Haskell) |
323 code_gen X Y (SML) (Haskell) |
324 code_gen x1 x2 y2 (SML) (Haskell) |
324 code_gen x1 x2 y2 (SML) (Haskell) |
325 |
325 |