theory ComposeNInClass
imports Main
begin
(*
definition
primrec
primitive recursive
function package
types:
nat
type => type
nat => nat
nat => (nat => nat)
nat => nat => nat
(nat => nat) => nat
datatype nat =
0
| Suc "nat"
1= Suc 0
2= Suc (Suc 0)
*)
primrec compose_n :: "(nat => nat) => nat => nat => nat" where
"compose_n f 0 x = x" |
"compose_n f (Suc n) x = compose_n f n (f x)"
(* The following dispays the induction principle for natural numbers *)
thm nat_induct
lemma compose_add[rule_format]:
"ALL x. compose_n f (m + n) x = compose_n f n (compose_n f m x)"
apply (induct m)
apply auto
done
(* Which variable to do induction on? f, n, x, m? *)
theorem compose_cycle: "compose_n f n x = x --> compose_n f (m * n) x = x"
apply (induct m)
apply simp
apply (auto simp: compose_add)
done
(* What happens if we choose the wrong variable? *)
theorem compose_cycle_wrong: "compose_n f n x = x --> compose_n f (m * n) x = x"
apply (induct n)
apply simp
apply auto
oops
end