equal
deleted
inserted
replaced
189 *} |
189 *} |
190 |
190 |
191 instantiation nat :: semigroup |
191 instantiation nat :: semigroup |
192 begin |
192 begin |
193 |
193 |
194 definition |
194 primrec mult_nat where |
195 mult_nat_def: "m \<otimes> n = m + (n\<Colon>nat)" |
195 "(0\<Colon>nat) \<otimes> n = n" |
|
196 | "Suc m \<otimes> n = Suc (m \<otimes> n)" |
196 |
197 |
197 instance proof |
198 instance proof |
198 fix m n q :: nat |
199 fix m n q :: nat |
199 show "m \<otimes> n \<otimes> q = m \<otimes> (n \<otimes> q)" |
200 show "m \<otimes> n \<otimes> q = m \<otimes> (n \<otimes> q)" |
200 unfolding mult_nat_def by simp |
201 by (induct m) auto |
201 qed |
202 qed |
202 |
203 |
203 end |
204 end |
|
205 |
|
206 text {* |
|
207 \noindent Note the occurence of the name @{text mult_nat} |
|
208 in the primrec declaration; by default, the local name of |
|
209 a class operation @{text f} to instantiate on type constructor |
|
210 @{text \<kappa>} are mangled as @{text f_\<kappa>}. In case of uncertainty, |
|
211 these names may be inspected using the @{text "\<PRINTCONTEXT>"} command |
|
212 or the corresponding ProofGeneral button. |
|
213 *} |
204 |
214 |
205 subsection {* Lifting and parametric types *} |
215 subsection {* Lifting and parametric types *} |
206 |
216 |
207 text {* |
217 text {* |
208 Overloaded definitions giving on class instantiation |
218 Overloaded definitions giving on class instantiation |
304 begin |
314 begin |
305 |
315 |
306 instance proof |
316 instance proof |
307 fix n :: nat |
317 fix n :: nat |
308 show "n \<otimes> \<one> = n" |
318 show "n \<otimes> \<one> = n" |
309 unfolding neutral_nat_def mult_nat_def by simp |
319 unfolding neutral_nat_def by (induct n) simp_all |
310 next |
320 next |
311 fix k :: int |
321 fix k :: int |
312 show "k \<otimes> \<one> = k" |
322 show "k \<otimes> \<one> = k" |
313 unfolding neutral_int_def mult_int_def by simp |
323 unfolding neutral_int_def mult_int_def by simp |
314 qed |
324 qed |
433 text {* |
443 text {* |
434 Isabelle locales support a concept of local definitions |
444 Isabelle locales support a concept of local definitions |
435 in locales: |
445 in locales: |
436 *} |
446 *} |
437 |
447 |
438 fun (in monoid) |
448 primrec (in monoid) |
439 pow_nat :: "nat \<Rightarrow> \<alpha> \<Rightarrow> \<alpha>" where |
449 pow_nat :: "nat \<Rightarrow> \<alpha> \<Rightarrow> \<alpha>" where |
440 "pow_nat 0 x = \<one>" |
450 "pow_nat 0 x = \<one>" |
441 | "pow_nat (Suc n) x = x \<otimes> pow_nat n x" |
451 | "pow_nat (Suc n) x = x \<otimes> pow_nat n x" |
442 |
452 |
443 text {* |
453 text {* |