test(tests/lean/run): add definition package tests
This commit is contained in:
parent
167675a397
commit
4904f7657f
2 changed files with 62 additions and 0 deletions
30
tests/lean/run/interp.lean
Normal file
30
tests/lean/run/interp.lean
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
import algebra.function
|
||||||
|
open bool nat
|
||||||
|
open function
|
||||||
|
|
||||||
|
inductive univ :=
|
||||||
|
| ubool : univ
|
||||||
|
| unat : univ
|
||||||
|
| uarrow : univ → univ → univ
|
||||||
|
|
||||||
|
open univ
|
||||||
|
|
||||||
|
definition interp : univ → Type₁
|
||||||
|
| ubool := bool
|
||||||
|
| unat := nat
|
||||||
|
| (uarrow fr to) := interp fr → interp to
|
||||||
|
|
||||||
|
definition foo : Π (u : univ) (el : interp u), interp u
|
||||||
|
| ubool tt := ff
|
||||||
|
| ubool ff := tt
|
||||||
|
| unat n := succ n
|
||||||
|
| (uarrow fr to) f := λ x : interp fr, f (foo fr x)
|
||||||
|
|
||||||
|
definition is_even : nat → bool
|
||||||
|
| zero := tt
|
||||||
|
| (succ n) := bnot (is_even n)
|
||||||
|
|
||||||
|
example : foo unat 10 = 11 := rfl
|
||||||
|
example : foo ubool tt = ff := rfl
|
||||||
|
example : foo (uarrow unat ubool) (λ x : nat, is_even x) 3 = tt := rfl
|
||||||
|
example : foo (uarrow unat ubool) (λ x : nat, is_even x) 4 = ff := rfl
|
32
tests/lean/run/parity.lean
Normal file
32
tests/lean/run/parity.lean
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
import data.nat
|
||||||
|
open nat
|
||||||
|
|
||||||
|
inductive Parity : nat → Type :=
|
||||||
|
| even : ∀ n : nat, Parity (2 * n)
|
||||||
|
| odd : ∀ n : nat, Parity (2 * n + 1)
|
||||||
|
|
||||||
|
open Parity
|
||||||
|
|
||||||
|
definition parity : Π (n : nat), Parity n
|
||||||
|
| parity 0 := even 0
|
||||||
|
| parity (n+1) :=
|
||||||
|
begin
|
||||||
|
have aux : Parity n, from parity n,
|
||||||
|
cases aux with (k, k),
|
||||||
|
begin
|
||||||
|
apply (odd k)
|
||||||
|
end,
|
||||||
|
begin
|
||||||
|
change (Parity (2*k + 2*1)),
|
||||||
|
rewrite -mul.left_distrib,
|
||||||
|
apply (even (k+1))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
print definition parity
|
||||||
|
|
||||||
|
definition half (n : nat) : nat :=
|
||||||
|
match ⟨n, parity n⟩ with
|
||||||
|
| ⟨⌞2 * k⌟, even k⟩ := k
|
||||||
|
| ⟨⌞2 * k + 1⌟, odd k⟩ := k
|
||||||
|
end
|
Loading…
Reference in a new issue