lean4-htt/tests/elab/treeNode.lean
Garmelon 08eb78a5b2
chore: switch to new test/bench suite (#12590)
This PR sets up the new integrated test/bench suite. It then migrates
all benchmarks and some related tests to the new suite. There's also
some documentation and some linting.

For now, a lot of the old tests are left alone so this PR doesn't become
even larger than it already is. Eventually, all tests should be migrated
to the new suite though so there isn't a confusing mix of two systems.
2026-02-25 13:51:53 +00:00

36 lines
1.4 KiB
Text

inductive TreeNode where
| mkLeaf (name : String) : TreeNode
| mkNode (name : String) (children : List TreeNode) : TreeNode
def treeToList (t : TreeNode) : List String :=
match t with
| .mkLeaf name => [name]
| .mkNode name children => Id.run do
let mut r := [name]
for h : child in children do
-- We will not this the following `have` in the future
have : sizeOf child < 1 + sizeOf name + sizeOf children := Nat.lt_trans (List.sizeOf_lt_of_mem h) (by simp +arith)
r := r ++ treeToList child
return r
@[simp] theorem treeToList_eq (name : String) (children : List TreeNode) : treeToList (.mkNode name children) = name :: List.flatten (children.map treeToList) := by
simp [treeToList]
mutual
def numNames : TreeNode → Nat
| .mkLeaf _ => 1
| .mkNode _ cs => 1 + numNamesLst cs
def numNamesLst : List TreeNode → Nat
| [] => 0
| a :: as => numNames a + numNamesLst as
end
theorem length_treeToList_eq_numNames (t : TreeNode) : (treeToList t).length = numNames t := by
match t with
| .mkLeaf .. => simp [treeToList, numNames]
| .mkNode _ cs => simp +arith [numNames, helper cs]
where
helper (cs : List TreeNode) : (cs.map treeToList).flatten.length = numNamesLst cs := by
match cs with
| [] => simp [List.flatten, numNamesLst]
| c::cs' => simp [List.flatten, List.map, numNamesLst, length_treeToList_eq_numNames c, helper cs']