Download bst_zig.lean from lizn-zn/algoveri-lean: direct link, hf CLI and curl.
- Browser
- Download file 2.32 kB
-
https://huggingface.co/datasets/lizn-zn/algoveri-lean/resolve/main/bst_zig.lean
- Command line
-
hf download hf://datasets/lizn-zn/algoveri-lean/bst_zig.lean
-
curl -L -o bst_zig.lean https://huggingface.co/datasets/lizn-zn/algoveri-lean/resolve/main/bst_zig.lean
2.32 kB
| import Mathlib | |
| inductive BinarySearchTree : Type | |
| | Empty : BinarySearchTree | |
| | Node : Int → BinarySearchTree → BinarySearchTree → BinarySearchTree | |
| deriving Inhabited | |
| def view (t : BinarySearchTree) : Set Int := | |
| match t with | |
| | BinarySearchTree.Empty => ∅ | |
| | BinarySearchTree.Node v l r => view l ∪ view r ∪ {v} | |
| def is_bst (t : BinarySearchTree) : Prop := | |
| match t with | |
| | BinarySearchTree.Empty => True | |
| | BinarySearchTree.Node v l r => | |
| (∀ x ∈ view l, x < v) ∧ | |
| is_bst l ∧ | |
| (∀ x ∈ view r, x > v) ∧ | |
| is_bst r | |
| def get_left (t : BinarySearchTree) : Option BinarySearchTree := | |
| match t with | |
| | BinarySearchTree.Node _ l _ => some l | |
| | _ => none | |
| def get_right (t : BinarySearchTree) : Option BinarySearchTree := | |
| match t with | |
| | BinarySearchTree.Node _ _ r => some r | |
| | _ => none | |
| def get_val (t : BinarySearchTree) : Option Int := | |
| match t with | |
| | BinarySearchTree.Node v _ _ => some v | |
| | _ => none | |
| def BinarySearchTree.is_node (t : BinarySearchTree) : Prop := | |
| match t with | |
| | BinarySearchTree.Node _ _ _ => True | |
| | _ => False | |
| -- Precondition definitions | |
| @[reducible, simp] | |
| def zig_precond (t : BinarySearchTree) : Prop := | |
| -- !benchmark @start precond | |
| is_bst t ∧ | |
| BinarySearchTree.is_node t ∧ | |
| (match get_left t with | some l => BinarySearchTree.is_node l | none => False) | |
| -- !benchmark @end precond | |
| -- !benchmark @start auxcode | |
| -- !benchmark @end auxcode | |
| -- Main function definition | |
| def zig (t : BinarySearchTree) | |
| (h_precond : zig_precond t) : BinarySearchTree := | |
| -- !benchmark @start code | |
| sorry | |
| -- !benchmark @end code | |
| -- Postcondition definitions | |
| @[reducible, simp] | |
| def zig_postcond (t : BinarySearchTree) (result : BinarySearchTree) | |
| (_ : zig_precond t) : Prop := | |
| -- !benchmark @start postcond | |
| is_bst result ∧ | |
| view result = view t ∧ | |
| -- Structural properties | |
| get_val result = get_val (get_left t).get! ∧ | |
| BinarySearchTree.is_node (get_right result).get! ∧ | |
| get_val (get_right result).get! = get_val t | |
| -- !benchmark @end postcond | |
| -- !benchmark @start lemma | |
| -- !benchmark @end lemma | |
| -- Proof content | |
| theorem zig_postcond_satisfied (t : BinarySearchTree) | |
| (h_precond : zig_precond t) : | |
| zig_postcond t (zig t h_precond) h_precond := by | |
| -- !benchmark @start proof | |
| sorry | |
| -- !benchmark @end proof | |