
blanchet@33197: (*  Title:      HOL/Nitpick_Examples/Manual_Nits.thy
blanchet@33197:     Author:     Jasmin Blanchette, TU Muenchen
blanchet@33197:     Copyright   2009
blanchet@33197: 
blanchet@33197: Examples from the Nitpick manual.
blanchet@33197: *)
blanchet@33197: 
blanchet@33197: header {* Examples from the Nitpick Manual *}
blanchet@33197: 
blanchet@33197: theory Manual_Nits
blanchet@33197: imports Main Coinductive_List RealDef
blanchet@33197: begin
blanchet@33197: 
blanchet@33197: chapter {* 3. First Steps *}
blanchet@33197: 
blanchet@33197: nitpick_params [sat_solver = MiniSatJNI, max_threads = 1]
blanchet@33197: 
blanchet@33197: subsection {* 3.1. Propositional Logic *}
blanchet@33197: 
blanchet@33197: lemma "P \<longleftrightarrow> Q"
blanchet@33197: nitpick
blanchet@33197: apply auto
blanchet@33197: nitpick 1
blanchet@33197: nitpick 2
blanchet@33197: oops
blanchet@33197: 
blanchet@33197: subsection {* 3.2. Type Variables *}
blanchet@33197: 
blanchet@33197: lemma "P x \<Longrightarrow> P (THE y. P y)"
blanchet@33197: nitpick [verbose]
blanchet@33197: oops
blanchet@33197: 
blanchet@33197: subsection {* 3.3. Constants *}
blanchet@33197: 
blanchet@33197: lemma "P x \<Longrightarrow> P (THE y. P y)"
blanchet@33197: nitpick [show_consts]
blanchet@33197: nitpick [full_descrs, show_consts]
blanchet@33197: nitpick [dont_specialize, full_descrs, show_consts]
blanchet@33197: oops
blanchet@33197: 
blanchet@33197: lemma "\<exists>!x. P x \<Longrightarrow> P (THE y. P y)"
blanchet@33197: nitpick
blanchet@33197: nitpick [card 'a = 1-50]
blanchet@33197: (* sledgehammer *)
blanchet@33197: apply (metis the_equality)
blanchet@33197: done
blanchet@33197: 
blanchet@33197: subsection {* 3.4. Skolemization *}
blanchet@33197: 
blanchet@33197: lemma "\<exists>g. \<forall>x. g (f x) = x \<Longrightarrow> \<forall>y. \<exists>x. y = f x"
blanchet@33197: nitpick
blanchet@33197: oops
blanchet@33197: 
blanchet@33197: lemma "\<exists>x. \<forall>f. f x = x"
blanchet@33197: nitpick
blanchet@33197: oops
blanchet@33197: 
blanchet@33197: lemma "refl r \<Longrightarrow> sym r"
blanchet@33197: nitpick
blanchet@33197: oops
blanchet@33197: 
blanchet@34126: subsection {* 3.5. Natural Numbers and Integers *}
blanchet@33197: 
blanchet@33197: lemma "\<lbrakk>i \<le> j; n \<le> (m\<Colon>int)\<rbrakk> \<Longrightarrow> i * n + j * m \<le> i * m + j * n"
blanchet@33197: nitpick
blanchet@33197: oops
blanchet@33197: 
blanchet@33197: lemma "\<forall>n. Suc n \<noteq> n \<Longrightarrow> P"
blanchet@33197: nitpick [card nat = 100, check_potential]
blanchet@33197: oops
blanchet@33197: 
blanchet@33197: lemma "P Suc"
blanchet@33197: nitpick [card = 1-6]
blanchet@33197: oops
blanchet@33197: 
blanchet@33197: lemma "P (op +\<Colon>nat\<Rightarrow>nat\<Rightarrow>nat)"
blanchet@33197: nitpick [card nat = 1]
blanchet@33197: nitpick [card nat = 2]
blanchet@33197: oops
blanchet@33197: 
blanchet@33197: subsection {* 3.6. Inductive Datatypes *}
blanchet@33197: 
blanchet@33197: lemma "hd (xs @ [y, y]) = hd xs"
blanchet@33197: nitpick
blanchet@33197: nitpick [show_consts, show_datatypes]
blanchet@33197: oops
blanchet@33197: 
blanchet@33197: lemma "\<lbrakk>length xs = 1; length ys = 1\<rbrakk> \<Longrightarrow> xs = ys"
blanchet@33197: nitpick [show_datatypes]
blanchet@33197: oops
blanchet@33197: 
blanchet@33197: subsection {* 3.7. Typedefs, Records, Rationals, and Reals *}
blanchet@33197: 
blanchet@33197: typedef three = "{0\<Colon>nat, 1, 2}"
blanchet@33197: by blast
blanchet@33197: 
blanchet@33197: definition A :: three where "A \<equiv> Abs_three 0"
blanchet@33197: definition B :: three where "B \<equiv> Abs_three 1"
blanchet@33197: definition C :: three where "C \<equiv> Abs_three 2"
blanchet@33197: 
blanchet@33197: lemma "\<lbrakk>P A; P B\<rbrakk> \<Longrightarrow> P x"
blanchet@33197: nitpick [show_datatypes]
blanchet@33197: oops
blanchet@33197: 
blanchet@33197: record point =
blanchet@33197:   Xcoord :: int
blanchet@33197:   Ycoord :: int
blanchet@33197: 
blanchet@33197: lemma "Xcoord (p\<Colon>point) = Xcoord (q\<Colon>point)"
blanchet@33197: nitpick [show_datatypes]
blanchet@33197: oops
blanchet@33197: 
blanchet@33197: lemma "4 * x + 3 * (y\<Colon>real) \<noteq> 1 / 2"
blanchet@33197: nitpick [show_datatypes]
blanchet@33197: oops
blanchet@33197: 
blanchet@33197: subsection {* 3.8. Inductive and Coinductive Predicates *}
blanchet@33197: 
blanchet@33197: inductive even where
blanchet@33197: "even 0" |
blanchet@33197: "even n \<Longrightarrow> even (Suc (Suc n))"
blanchet@33197: 
blanchet@33197: lemma "\<exists>n. even n \<and> even (Suc n)"
blanchet@34126: nitpick [card nat = 100, unary_ints, verbose]
blanchet@33197: oops
blanchet@33197: 
blanchet@33197: lemma "\<exists>n \<le> 99. even n \<and> even (Suc n)"
blanchet@34126: nitpick [card nat = 100, unary_ints, verbose]
blanchet@33197: oops
blanchet@33197: 
blanchet@33197: inductive even' where
blanchet@33197: "even' (0\<Colon>nat)" |
blanchet@33197: "even' 2" |
blanchet@33197: "\<lbrakk>even' m; even' n\<rbrakk> \<Longrightarrow> even' (m + n)"
blanchet@33197: 
blanchet@33197: lemma "\<exists>n \<in> {0, 2, 4, 6, 8}. \<not> even' n"
blanchet@34126: nitpick [card nat = 10, unary_ints, verbose, show_consts] (* FIXME: should be genuine *)
blanchet@33197: oops
blanchet@33197: 
blanchet@33197: lemma "even' (n - 2) \<Longrightarrow> even' n"
blanchet@33197: nitpick [card nat = 10, show_consts]
blanchet@33197: oops
blanchet@33197: 
blanchet@33197: coinductive nats where
blanchet@33197: "nats (x\<Colon>nat) \<Longrightarrow> nats x"
blanchet@33197: 
blanchet@33197: lemma "nats = {0, 1, 2, 3, 4}"
blanchet@33197: nitpick [card nat = 10, show_consts]
blanchet@33197: oops
blanchet@33197: 
blanchet@33197: inductive odd where
blanchet@33197: "odd 1" |
blanchet@33197: "\<lbrakk>odd m; even n\<rbrakk> \<Longrightarrow> odd (m + n)"
blanchet@33197: 
blanchet@33197: lemma "odd n \<Longrightarrow> odd (n - 2)"
blanchet@33197: nitpick [card nat = 10, show_consts]
blanchet@33197: oops
blanchet@33197: 
blanchet@33197: subsection {* 3.9. Coinductive Datatypes *}
blanchet@33197: 
blanchet@33197: lemma "xs \<noteq> LCons a xs"
blanchet@33197: nitpick
blanchet@33197: oops
blanchet@33197: 
blanchet@33197: lemma "\<lbrakk>xs = LCons a xs; ys = iterates (\<lambda>b. a) b\<rbrakk> \<Longrightarrow> xs = ys"
blanchet@33197: nitpick [verbose]
blanchet@33197: nitpick [bisim_depth = -1, verbose]
blanchet@33197: oops
blanchet@33197: 
blanchet@33197: lemma "\<lbrakk>xs = LCons a xs; ys = LCons a ys\<rbrakk> \<Longrightarrow> xs = ys"
blanchet@33197: nitpick [bisim_depth = -1, show_datatypes]
blanchet@33197: nitpick
blanchet@33197: sorry
blanchet@33197: 
blanchet@33197: subsection {* 3.10. Boxing *}
blanchet@33197: 
blanchet@33197: datatype tm = Var nat | Lam tm | App tm tm
blanchet@33197: 
blanchet@33197: primrec lift where
blanchet@33197: "lift (Var j) k = Var (if j < k then j else j + 1)" |
blanchet@33197: "lift (Lam t) k = Lam (lift t (k + 1))" |
blanchet@33197: "lift (App t u) k = App (lift t k) (lift u k)"
blanchet@33197: 
blanchet@33197: primrec loose where
blanchet@33197: "loose (Var j) k = (j \<ge> k)" |
blanchet@33197: "loose (Lam t) k = loose t (Suc k)" |
blanchet@33197: "loose (App t u) k = (loose t k \<or> loose u k)"
blanchet@33197: 
blanchet@33197: primrec subst\<^isub>1 where
blanchet@33197: "subst\<^isub>1 \<sigma> (Var j) = \<sigma> j" |
blanchet@33197: "subst\<^isub>1 \<sigma> (Lam t) =
blanchet@33197:  Lam (subst\<^isub>1 (\<lambda>n. case n of 0 \<Rightarrow> Var 0 | Suc m \<Rightarrow> lift (\<sigma> m) 1) t)" |
blanchet@33197: "subst\<^isub>1 \<sigma> (App t u) = App (subst\<^isub>1 \<sigma> t) (subst\<^isub>1 \<sigma> u)"
blanchet@33197: 
blanchet@33197: lemma "\<not> loose t 0 \<Longrightarrow> subst\<^isub>1 \<sigma> t = t"
blanchet@33197: nitpick [verbose]
blanchet@33197: nitpick [eval = "subst\<^isub>1 \<sigma> t"]
blanchet@33197: nitpick [dont_box]
blanchet@33197: oops
blanchet@33197: 
blanchet@33197: primrec subst\<^isub>2 where
blanchet@33197: "subst\<^isub>2 \<sigma> (Var j) = \<sigma> j" |
blanchet@33197: "subst\<^isub>2 \<sigma> (Lam t) =
blanchet@33197:  Lam (subst\<^isub>2 (\<lambda>n. case n of 0 \<Rightarrow> Var 0 | Suc m \<Rightarrow> lift (\<sigma> m) 0) t)" |
blanchet@33197: "subst\<^isub>2 \<sigma> (App t u) = App (subst\<^isub>2 \<sigma> t) (subst\<^isub>2 \<sigma> u)"
blanchet@33197: 
blanchet@33197: lemma "\<not> loose t 0 \<Longrightarrow> subst\<^isub>2 \<sigma> t = t"
blanchet@33197: nitpick
blanchet@33197: sorry
blanchet@33197: 
blanchet@33197: subsection {* 3.11. Scope Monotonicity *}
blanchet@33197: 
blanchet@33197: lemma "length xs = length ys \<Longrightarrow> rev (zip xs ys) = zip xs (rev ys)"
blanchet@33197: nitpick [verbose]
blanchet@33197: nitpick [card = 8, verbose]
blanchet@33197: oops
blanchet@33197: 
blanchet@33197: lemma "\<exists>g. \<forall>x\<Colon>'b. g (f x) = x \<Longrightarrow> \<forall>y\<Colon>'a. \<exists>x. y = f x"
blanchet@33197: nitpick [mono]
blanchet@33197: nitpick
blanchet@33197: oops
blanchet@33197: 
blanchet@34982: subsection {* 3.12. Inductive Properties *}
blanchet@34982: 
blanchet@34982: inductive_set reach where
blanchet@34982: "(4\<Colon>nat) \<in> reach" |
blanchet@34982: "n \<in> reach \<Longrightarrow> n < 4 \<Longrightarrow> 3 * n + 1 \<in> reach" |
blanchet@34982: "n \<in> reach \<Longrightarrow> n + 2 \<in> reach"
blanchet@34982: 
blanchet@34982: lemma "n \<in> reach \<Longrightarrow> 2 dvd n"
blanchet@34982: nitpick
blanchet@34982: apply (induct set: reach)
blanchet@34982:   apply auto
blanchet@34982:  nitpick
blanchet@34982:  apply (thin_tac "n \<in> reach")
blanchet@34982:  nitpick
blanchet@34982: oops
blanchet@34982: 
blanchet@34982: lemma "n \<in> reach \<Longrightarrow> 2 dvd n \<and> n \<noteq> 0"
blanchet@34982: nitpick
blanchet@34982: apply (induct set: reach)
blanchet@34982:   apply auto
blanchet@34982:  nitpick
blanchet@34982:  apply (thin_tac "n \<in> reach")
blanchet@34982:  nitpick
blanchet@34982: oops
blanchet@34982: 
blanchet@34982: lemma "n \<in> reach \<Longrightarrow> 2 dvd n \<and> n \<ge> 4"
blanchet@34982: by (induct set: reach) arith+
blanchet@34982: 
blanchet@34982: datatype 'a bin_tree = Leaf 'a | Branch "'a bin_tree" "'a bin_tree"
blanchet@34982: 
blanchet@34982: primrec labels where
blanchet@34982: "labels (Leaf a) = {a}" |
blanchet@34982: "labels (Branch t u) = labels t \<union> labels u"
blanchet@34982: 
blanchet@34982: primrec swap where
blanchet@34982: "swap (Leaf c) a b =
blanchet@34982:  (if c = a then Leaf b else if c = b then Leaf a else Leaf c)" |
blanchet@34982: "swap (Branch t u) a b = Branch (swap t a b) (swap u a b)"
blanchet@34982: 
blanchet@34982: lemma "\<lbrakk>a \<in> labels t; b \<in> labels t; a \<noteq> b\<rbrakk> \<Longrightarrow> labels (swap t a b) = labels t"
blanchet@34982: nitpick
blanchet@34982: proof (induct t)
blanchet@34982:   case Leaf thus ?case by simp
blanchet@34982: next
blanchet@34982:   case (Branch t u) thus ?case
blanchet@34982:   nitpick
blanchet@34982:   nitpick [non_std "'a bin_tree", show_consts]
blanchet@34982: oops
blanchet@34982: 
blanchet@34982: lemma "labels (swap t a b) =
blanchet@34982:        (if a \<in> labels t then
blanchet@34982:           if b \<in> labels t then labels t else (labels t - {a}) \<union> {b}
blanchet@34982:         else
blanchet@34982:           if b \<in> labels t then (labels t - {b}) \<union> {a} else labels t)"
blanchet@34982: nitpick
blanchet@34982: proof (induct t)
blanchet@34982:   case Leaf thus ?case by simp
blanchet@34982: next
blanchet@34982:   case (Branch t u) thus ?case
blanchet@34982:   nitpick [non_std "'a bin_tree", show_consts]
blanchet@34982:   by auto
blanchet@34982: qed
blanchet@34982: 
blanchet@33197: section {* 4. Case Studies *}
blanchet@33197: 
blanchet@33197: nitpick_params [max_potential = 0, max_threads = 2]
blanchet@33197: 
blanchet@33197: subsection {* 4.1. A Context-Free Grammar *}
blanchet@33197: 
blanchet@33197: datatype alphabet = a | b
blanchet@33197: 
blanchet@33197: inductive_set S\<^isub>1 and A\<^isub>1 and B\<^isub>1 where
blanchet@33197:   "[] \<in> S\<^isub>1"
blanchet@33197: | "w \<in> A\<^isub>1 \<Longrightarrow> b # w \<in> S\<^isub>1"
blanchet@33197: | "w \<in> B\<^isub>1 \<Longrightarrow> a # w \<in> S\<^isub>1"
blanchet@33197: | "w \<in> S\<^isub>1 \<Longrightarrow> a # w \<in> A\<^isub>1"
blanchet@33197: | "w \<in> S\<^isub>1 \<Longrightarrow> b # w \<in> S\<^isub>1"
blanchet@33197: | "\<lbrakk>v \<in> B\<^isub>1; v \<in> B\<^isub>1\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^isub>1"
blanchet@33197: 
blanchet@33197: theorem S\<^isub>1_sound:
blanchet@33197: "w \<in> S\<^isub>1 \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]"
blanchet@33197: nitpick
blanchet@33197: oops
blanchet@33197: 
blanchet@33197: inductive_set S\<^isub>2 and A\<^isub>2 and B\<^isub>2 where
blanchet@33197:   "[] \<in> S\<^isub>2"
blanchet@33197: | "w \<in> A\<^isub>2 \<Longrightarrow> b # w \<in> S\<^isub>2"
blanchet@33197: | "w \<in> B\<^isub>2 \<Longrightarrow> a # w \<in> S\<^isub>2"
blanchet@33197: | "w \<in> S\<^isub>2 \<Longrightarrow> a # w \<in> A\<^isub>2"
blanchet@33197: | "w \<in> S\<^isub>2 \<Longrightarrow> b # w \<in> B\<^isub>2"
blanchet@33197: | "\<lbrakk>v \<in> B\<^isub>2; v \<in> B\<^isub>2\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^isub>2"
blanchet@33197: 
blanchet@33197: theorem S\<^isub>2_sound:
blanchet@33197: "w \<in> S\<^isub>2 \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]"
blanchet@33197: nitpick
blanchet@33197: oops
blanchet@33197: 
blanchet@33197: inductive_set S\<^isub>3 and A\<^isub>3 and B\<^isub>3 where
blanchet@33197:   "[] \<in> S\<^isub>3"
blanchet@33197: | "w \<in> A\<^isub>3 \<Longrightarrow> b # w \<in> S\<^isub>3"
blanchet@33197: | "w \<in> B\<^isub>3 \<Longrightarrow> a # w \<in> S\<^isub>3"
blanchet@33197: | "w \<in> S\<^isub>3 \<Longrightarrow> a # w \<in> A\<^isub>3"
blanchet@33197: | "w \<in> S\<^isub>3 \<Longrightarrow> b # w \<in> B\<^isub>3"
blanchet@33197: | "\<lbrakk>v \<in> B\<^isub>3; w \<in> B\<^isub>3\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^isub>3"
blanchet@33197: 
blanchet@33197: theorem S\<^isub>3_sound:
blanchet@33197: "w \<in> S\<^isub>3 \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]"
blanchet@33197: nitpick
blanchet@33197: sorry
blanchet@33197: 
blanchet@33197: theorem S\<^isub>3_complete:
blanchet@33197: "length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b] \<longrightarrow> w \<in> S\<^isub>3"
blanchet@33197: nitpick
blanchet@33197: oops
blanchet@33197: 
blanchet@33197: inductive_set S\<^isub>4 and A\<^isub>4 and B\<^isub>4 where
blanchet@33197:   "[] \<in> S\<^isub>4"
blanchet@33197: | "w \<in> A\<^isub>4 \<Longrightarrow> b # w \<in> S\<^isub>4"
blanchet@33197: | "w \<in> B\<^isub>4 \<Longrightarrow> a # w \<in> S\<^isub>4"
blanchet@33197: | "w \<in> S\<^isub>4 \<Longrightarrow> a # w \<in> A\<^isub>4"
blanchet@33197: | "\<lbrakk>v \<in> A\<^isub>4; w \<in> A\<^isub>4\<rbrakk> \<Longrightarrow> b # v @ w \<in> A\<^isub>4"
blanchet@33197: | "w \<in> S\<^isub>4 \<Longrightarrow> b # w \<in> B\<^isub>4"
blanchet@33197: | "\<lbrakk>v \<in> B\<^isub>4; w \<in> B\<^isub>4\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^isub>4"
blanchet@33197: 
blanchet@33197: theorem S\<^isub>4_sound:
blanchet@33197: "w \<in> S\<^isub>4 \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]"
blanchet@33197: nitpick
blanchet@33197: sorry
blanchet@33197: 
blanchet@33197: theorem S\<^isub>4_complete:
blanchet@33197: "length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b] \<longrightarrow> w \<in> S\<^isub>4"
blanchet@33197: nitpick
blanchet@33197: sorry
blanchet@33197: 
blanchet@33197: theorem S\<^isub>4_A\<^isub>4_B\<^isub>4_sound_and_complete:
blanchet@33197: "w \<in> S\<^isub>4 \<longleftrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]"
blanchet@33197: "w \<in> A\<^isub>4 \<longleftrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b] + 1"
blanchet@33197: "w \<in> B\<^isub>4 \<longleftrightarrow> length [x \<leftarrow> w. x = b] = length [x \<leftarrow> w. x = a] + 1"
blanchet@33197: nitpick
blanchet@33197: sorry
blanchet@33197: 
blanchet@33197: subsection {* 4.2. AA Trees *}
blanchet@33197: 
blanchet@34982: datatype 'a aa_tree = \<Lambda> | N "'a\<Colon>linorder" nat "'a aa_tree" "'a aa_tree"
blanchet@33197: 
blanchet@33197: primrec data where
blanchet@33197: "data \<Lambda> = undefined" |
blanchet@33197: "data (N x _ _ _) = x"
blanchet@33197: 
blanchet@33197: primrec dataset where
blanchet@33197: "dataset \<Lambda> = {}" |
blanchet@33197: "dataset (N x _ t u) = {x} \<union> dataset t \<union> dataset u"
blanchet@33197: 
blanchet@33197: primrec level where
blanchet@33197: "level \<Lambda> = 0" |
blanchet@33197: "level (N _ k _ _) = k"
blanchet@33197: 
blanchet@33197: primrec left where
blanchet@33197: "left \<Lambda> = \<Lambda>" |
blanchet@33197: "left (N _ _ t\<^isub>1 _) = t\<^isub>1"
blanchet@33197: 
blanchet@33197: primrec right where
blanchet@33197: "right \<Lambda> = \<Lambda>" |
blanchet@33197: "right (N _ _ _ t\<^isub>2) = t\<^isub>2"
blanchet@33197: 
blanchet@33197: fun wf where
blanchet@33197: "wf \<Lambda> = True" |
blanchet@33197: "wf (N _ k t u) =
blanchet@33197:  (if t = \<Lambda> then
blanchet@33197:     k = 1 \<and> (u = \<Lambda> \<or> (level u = 1 \<and> left u = \<Lambda> \<and> right u = \<Lambda>))
blanchet@33197:   else
blanchet@33197:     wf t \<and> wf u \<and> u \<noteq> \<Lambda> \<and> level t < k \<and> level u \<le> k \<and> level (right u) < k)"
blanchet@33197: 
blanchet@33197: fun skew where
blanchet@33197: "skew \<Lambda> = \<Lambda>" |
blanchet@33197: "skew (N x k t u) =
blanchet@33197:  (if t \<noteq> \<Lambda> \<and> k = level t then
blanchet@33197:     N (data t) k (left t) (N x k (right t) u)
blanchet@33197:   else
blanchet@33197:     N x k t u)"
blanchet@33197: 
blanchet@33197: fun split where
blanchet@33197: "split \<Lambda> = \<Lambda>" |
blanchet@33197: "split (N x k t u) =
blanchet@33197:  (if u \<noteq> \<Lambda> \<and> k = level (right u) then
blanchet@33197:     N (data u) (Suc k) (N x k t (left u)) (right u)
blanchet@33197:   else
blanchet@33197:     N x k t u)"
blanchet@33197: 
blanchet@33197: theorem dataset_skew_split:
blanchet@33197: "dataset (skew t) = dataset t"
blanchet@33197: "dataset (split t) = dataset t"
blanchet@33197: nitpick
blanchet@33197: sorry
blanchet@33197: 
blanchet@33197: theorem wf_skew_split:
blanchet@33197: "wf t \<Longrightarrow> skew t = t"
blanchet@33197: "wf t \<Longrightarrow> split t = t"
blanchet@33197: nitpick
blanchet@33197: sorry
blanchet@33197: 
blanchet@33197: primrec insort\<^isub>1 where
blanchet@33197: "insort\<^isub>1 \<Lambda> x = N x 1 \<Lambda> \<Lambda>" |
blanchet@33197: "insort\<^isub>1 (N y k t u) x =
blanchet@33197:  (* (split \<circ> skew) *) (N y k (if x < y then insort\<^isub>1 t x else t)
blanchet@33197:                              (if x > y then insort\<^isub>1 u x else u))"
blanchet@33197: 
blanchet@33197: theorem wf_insort\<^isub>1: "wf t \<Longrightarrow> wf (insort\<^isub>1 t x)"
blanchet@33197: nitpick
blanchet@33197: oops
blanchet@33197: 
blanchet@33197: theorem wf_insort\<^isub>1_nat: "wf t \<Longrightarrow> wf (insort\<^isub>1 t (x\<Colon>nat))"
blanchet@33197: nitpick [eval = "insort\<^isub>1 t x"]
blanchet@33197: oops
blanchet@33197: 
blanchet@33197: primrec insort\<^isub>2 where
blanchet@33197: "insort\<^isub>2 \<Lambda> x = N x 1 \<Lambda> \<Lambda>" |
blanchet@33197: "insort\<^isub>2 (N y k t u) x =
blanchet@33197:  (split \<circ> skew) (N y k (if x < y then insort\<^isub>2 t x else t)
blanchet@33197:                        (if x > y then insort\<^isub>2 u x else u))"
blanchet@33197: 
blanchet@33197: theorem wf_insort\<^isub>2: "wf t \<Longrightarrow> wf (insort\<^isub>2 t x)"
blanchet@33197: nitpick
blanchet@33197: sorry
blanchet@33197: 
blanchet@33197: theorem dataset_insort\<^isub>2: "dataset (insort\<^isub>2 t x) = {x} \<union> dataset t"
blanchet@33197: nitpick
blanchet@33197: sorry
blanchet@33197: 
blanchet@33197: end




