lean4-htt/tests/elab/krivine.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

52 lines
1.6 KiB
Text
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

inductive KrivineInstruction
| Access (n: Nat)
| Grab (next: KrivineInstruction)
| Push (next: KrivineInstruction) (continuation: KrivineInstruction)
inductive KrivineClosure
| pair (i: KrivineInstruction) (e: List KrivineClosure)
namespace Ex1
def KrivineEnv := List KrivineClosure
-- We need to define a `SizeOf` instance for `KrivineEnv`. Otherwise, we cannot use the auto-generated well-founded relation in
-- recursive definitions.
noncomputable instance : SizeOf KrivineEnv := inferInstanceAs (SizeOf (List KrivineClosure))
-- We also need a `simp` theorem
@[simp] theorem KrivineEnv.sizeOf_spec (env : KrivineEnv) : sizeOf env = sizeOf (α := List KrivineClosure) env := rfl
-- It would be great to have a `deriving SizeOf` for definitions such as `KrivineEnv` above.
def KrivineEnv.depth (env : KrivineEnv) : Nat :=
match env with
| [] => 0
| KrivineClosure.pair u e :: closures => Nat.max (1 + depth e) (depth closures)
end Ex1
namespace Ex2
-- Same example, but we use `abbrev` to define `KrivineEnv`. Thus, we inherit the `SizeOf` instance for `List`s.
abbrev KrivineEnv := List KrivineClosure
def KrivineEnv.depth (env : KrivineEnv) : Nat :=
match env with
| [] => 0
| KrivineClosure.pair u e :: closures => Nat.max (1 + depth e) (depth closures)
end Ex2
namespace Ex3
-- Same example, but using `structure` instead of `def`
structure KrivineEnv where
env : List KrivineClosure
def KrivineEnv.depth (env : KrivineEnv) : Nat :=
match env with
| { env := [] } => 0
| { env := KrivineClosure.pair u e :: closures } => Nat.max (1 + depth { env := e }) (depth { env := closures })
end Ex3