Reputation: 3740
In the excellent Programming and Proving in Isabelle/HOL it says
[...] in contrast to recursive functions, there is no termination requirement for inductive definitions. (pdf p. 40)
Upvotes: 0
Views: 213
Reputation: 8278
Lars already answered the question, but I would like to expand on the coinductive predicates he mentioned. These indeed allow you to have ‘infinitely deep derivation trees’, corresponding to how codatatypes are essentially ‘possibly infinite datatypes’.
A good example is the stream
type from ~~/src/HOL/Library/Stream
:
codatatype 'a stream = SCons 'a "'a stream" (infixr "##" 65)
This is an infinite list (note that unlike e.g. Haskell lists, this stream type has to be infinitely long, like if you wrote datatype Stream a = SCons a (Stream a)
in Haskell, although Haskell-style ‘potentially infinite’ lists are also possible straightforward, cf. the lazy lists in the AFP)
You can then e.g. define the set of all streams whose values are from a given set. You could define that as streams A = {s. sset s ⊆ A}
, but in Isabelle, it is defined coinductively like this:
coinductive_set streams :: "'a set ⇒ 'a stream set" for A :: "'a set"
where "⟦a ∈ A; s ∈ streams A⟧ ⟹ a ## s ∈ streams A"
Another, perhaps easier example, would be a coinductive ‘for all elements’ predicate on streams:
coinductive sall :: "('a ⇒ bool) ⇒ 'a stream ⇒ bool" for P :: "'a ⇒ bool" where
"P x ⟹ sall P xs ⟹ sall P (x ## xs)"
As for the question of how to construct such an infinite derivation tree, i.e. showing that a coinductive predicate holds on some value, you have to do that with coinduction. E.g. we can show that if P x
holds, then sall P (sconst x)
holds, where sconst x
is just the value x
repeated infinitely:
lemma sconst_reduce: "sconst x = x ## sconst x"
by (subst siterate.code) simp_all
lemma sall_sconst: "P x ⟹ sall P (sconst x)"
proof (coinduction rule: sall.coinduct)
assume "P x"
thus "∃y ys. sconst x = y ## ys ∧ P y ∧ (ys = sconst x ∧ P x ∨ sall P ys)"
by (subst sconst_reduce) auto
qed
Upvotes: 2
Reputation: 2659
Upvotes: 2