(* Title: HOL/HOLCF/Tutorial/Fixrec_ex.thy Author: Brian Huffman *)
section‹Fixrec package examples›
theory Fixrec_ex imports HOLCF begin
subsection‹Basic ‹fixrec›examples›
text‹ Fixrec patterns can mention any constructor defined by the domain package, as well as any of the following built-in constructors: Pair, spair, sinl, sinr, up, ONE, TT, FF. ›
text‹Typical usage is with lazy constructors.›
fixrec down :: "'a u → 'a" where"down⋅(up⋅x) = x"
text‹With strict constructors, rewrite rules may require side conditions.›
text‹ As an alternative to using ‹fixrec_simp›, it is also possible to use bottom as a constructor pattern. When using a bottom pattern, the right-hand-side must also be bottom; otherwise, ‹fixrec›will not be able to prove the equation. ›
text‹ If the function is already strict in that argument, then the bottom pattern does not change the meaning of the function. For example, in the definition of 🍋‹from_sinr_up›, the first equation is actually redundant, and could have been proven separately by ‹fixrec_simp›. ›
text‹ A bottom pattern can also be used to make a function strict in a certain argument, similar to a bang-pattern in Haskell. ›
text‹ Notice that this version has overlapping patterns. The second equation cannot be proved as a theorem because it only applies when the first pattern fails. ›
text‹ Usually fixrec tries to prove all equations as theorems. The "unchecked" option overrides this behavior, so fixrec does not attempt to prove that particular equation. ›
text‹Simp rules can be generated later using ‹fixrec_simp›.›
text‹ The defining equations of a fixrec definition are declared as simp rules by default. In some cases, especially for constants with no arguments or functions with variable patterns, the defining equations may cause the simplifier to loop. In these cases it will be necessary to use a ‹[simp del]›declaration. ›
fixrec
repeat :: "'a → 'a llist" where
[simp del]: "repeat⋅x = lCons⋅x⋅(repeat⋅x)"
text‹ We can derive other non-looping simp rules for 🍋‹repeat›by using the ‹subst›method with the ‹repeat.simps› rule. ›
lemma repeat_simps [simp]: "repeat⋅x ≠⊥" "repeat⋅x ≠ lNil" "repeat⋅x = lCons⋅y⋅ys ⟷ x = y ∧ repeat⋅x = ys" by (subst repeat.simps, simp)+
lemma llist_case_repeat [simp]: "llist_case⋅z⋅f⋅(repeat⋅x) = f⋅x⋅(repeat⋅x)" by (subst repeat.simps, simp)
text‹ For mutually-recursive constants, looping might only occur if all equations are in the simpset at the same time. In such cases it may only be necessary to declare ‹[simp del]›on one equation. ›
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.