(* Title: HOL/Nitpick_Examples/Manual_Nits.thy Author: Jasmin Blanchette, TU Muenchen Copyright 2009-2014 Examples from the Nitpick manual. *)
section‹Examples from the Nitpick Manual›
(* The "expect" arguments to Nitpick in this theory and the other example theories are there so that the example can also serve as a regression test suite. *)
theory Manual_Nits imports HOL.Real "HOL-Library.Quotient_Product" begin
primrec lift where "lift (Var j) k = Var (if j < k then j else j + 1)" | "lift (Lam t) k = Lam (lift t (k + 1))" | "lift (App t u) k = App (lift t k) (lift u k)"
primrec loose where "loose (Var j) k = (j ≥ k)" | "loose (Lam t) k = loose t (Suc k)" | "loose (App t u) k = (loose t k ∨ loose u k)"
primrec subst🪙1 where "subst🪙1 σ (Var j) = σ j" | "subst🪙1 σ (Lam t) = Lam (subst🪙1 (λn. case n of 0 ==> Var 0 | Suc m ==> lift (σ m) 1) t)" | "subst🪙1 σ (App t u) = App (subst🪙1 σ t) (subst🪙1 σ u)"
lemma"n ∈ reach ==> 2 dvd n ∧ n ≠ 0" (* nitpick *) apply (induct set: reach) apply auto
nitpick [card = 1-4, bits = 1-4, expect = none] apply (thin_tac "n ∈ reach")
nitpick [expect = genuine] oops
lemma"n ∈ reach ==> 2 dvd n ∧ n ≥ 4" by (induct set: reach) arith+
section‹3. Case Studies›
nitpick_params [max_potential = 0]
subsection‹3.1. A Context-Free Grammar›
datatype alphabet = a | b
inductive_set S🪙1 and A🪙1 and B🪙1 where "[] ∈ S🪙1"
| "w ∈ A🪙1 ==> b # w ∈ S🪙1"
| "w ∈ B🪙1 ==> a # w ∈ S🪙1"
| "w ∈ S🪙1 ==> a # w ∈ A🪙1"
| "w ∈ S🪙1 ==> b # w ∈ S🪙1"
| "[v ∈ B🪙1; v ∈ B🪙1]==> a # v @ w ∈ B🪙1"
theorem S🪙1_sound: "w ∈ S🪙1 ⟶ length [x ← w. x = a] = length [x ← w. x = b]"
nitpick [expect = genuine] oops
inductive_set S🪙2 and A🪙2 and B🪙2 where "[] ∈ S🪙2"
| "w ∈ A🪙2 ==> b # w ∈ S🪙2"
| "w ∈ B🪙2 ==> a # w ∈ S🪙2"
| "w ∈ S🪙2 ==> a # w ∈ A🪙2"
| "w ∈ S🪙2 ==> b # w ∈ B🪙2"
| "[v ∈ B🪙2; v ∈ B🪙2]==> a # v @ w ∈ B🪙2"
theorem S🪙2_sound: "w ∈ S🪙2 ⟶ length [x ← w. x = a] = length [x ← w. x = b]"
nitpick [expect = genuine] oops
inductive_set S🪙3 and A🪙3 and B🪙3 where "[] ∈ S🪙3"
| "w ∈ A🪙3 ==> b # w ∈ S🪙3"
| "w ∈ B🪙3 ==> a # w ∈ S🪙3"
| "w ∈ S🪙3 ==> a # w ∈ A🪙3"
| "w ∈ S🪙3 ==> b # w ∈ B🪙3"
| "[v ∈ B🪙3; w ∈ B🪙3]==> a # v @ w ∈ B🪙3"
theorem S🪙3_sound: "w ∈ S🪙3 ⟶ length [x ← w. x = a] = length [x ← w. x = b]"
nitpick [card = 1-5, expect = none] sorry
theorem S🪙3_complete: "length [x ← w. x = a] = length [x ← w. x = b] ⟶ w ∈ S🪙3"
nitpick [expect = genuine] oops
inductive_set S🪙4 and A🪙4 and B🪙4 where "[] ∈ S🪙4"
| "w ∈ A🪙4 ==> b # w ∈ S🪙4"
| "w ∈ B🪙4 ==> a # w ∈ S🪙4"
| "w ∈ S🪙4 ==> a # w ∈ A🪙4"
| "[v ∈ A🪙4; w ∈ A🪙4]==> b # v @ w ∈ A🪙4"
| "w ∈ S🪙4 ==> b # w ∈ B🪙4"
| "[v ∈ B🪙4; w ∈ B🪙4]==> a # v @ w ∈ B🪙4"
theorem S🪙4_sound: "w ∈ S🪙4 ⟶ length [x ← w. x = a] = length [x ← w. x = b]"
nitpick [card = 1-5, expect = none] sorry
theorem S🪙4_complete: "length [x ← w. x = a] = length [x ← w. x = b] ⟶ w ∈ S🪙4"
nitpick [card = 1-5, expect = none] sorry
theorem S🪙4_A🪙4_B🪙4_sound_and_complete: "w ∈ S🪙4 ⟷ length [x ← w. x = a] = length [x ← w. x = b]" "w ∈ A🪙4 ⟷ length [x ← w. x = a] = length [x ← w. x = b] + 1" "w ∈ B🪙4 ⟷ length [x ← w. x = b] = length [x ← w. x = a] + 1"
nitpick [card = 1-5, expect = none] sorry
subsection‹3.2. AA Trees›
datatype 'a aa_tree = Λ | N "'a::linorder" nat "'a aa_tree""'a aa_tree"
primrec data where "data Λ = undefined" | "data (N x _ _ _) = x"
primrec dataset where "dataset Λ = {}" | "dataset (N x _ t u) = {x} ∪ dataset t ∪ dataset u"
primrec level where "level Λ = 0" | "level (N _ k _ _) = k"
primrec left where "left Λ = Λ" | "left (N _ _ t🪙1 _) = t🪙1"
primrec right where "right Λ = Λ" | "right (N _ _ _ t🪙2) = t🪙2"
fun wf where "wf Λ = True" | "wf (N _ k t u) = (if t = Λ then k = 1 ∧ (u = Λ ∨ (level u = 1 ∧ left u = Λ ∧ right u = Λ)) else wf t ∧ wf u ∧ u ≠ Λ ∧ level t < k ∧ level u ≤ k ∧ level (right u) < k)"
fun skew where "skew Λ = Λ" | "skew (N x k t u) = (if t ≠ Λ ∧ k = level t then N (data t) k (left t) (N x k (right t) u) else N x k t u)"
fun split where "split Λ = Λ" | "split (N x k t u) = (if u ≠ Λ ∧ k = level (right u) then N (data u) (Suc k) (N x k t (left u)) (right u) else N x k t u)"
theorem wf_skew_split: "wf t ==> skew t = t" "wf t ==> split t = t"
nitpick [card = 1-5, expect = none] sorry
primrec insort🪙1 where "insort🪙1 Λ x = N x 1 Λ Λ" | "insort🪙1 (N y k t u) x = 🍋‹(split ∘ skew)› (N y k (if x < y then insort🪙1 t x else t) (if x > y then insort🪙1 u x else u))"
theorem wf_insort🪙1: "wf t ==> wf (insort🪙1 t x)"
nitpick [expect = genuine] oops
theorem wf_insort🪙1_nat: "wf t ==> wf (insort🪙1 t (x::nat))"
nitpick [eval = "insort🪙1 t x", expect = genuine] oops
primrec insort🪙2 where "insort🪙2 Λ x = N x 1 Λ Λ" | "insort🪙2 (N y k t u) x = (split ∘ skew) (N y k (if x < y then insort🪙2 t x else t) (if x > y then insort🪙2 u x else u))"
theorem wf_insort🪙2: "wf t ==> wf (insort🪙2 t x)"
nitpick [card = 1-5, expect = none] sorry
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.