2015-01-10 18:11:13 +00:00
|
|
|
import data.list
|
|
|
|
open nat
|
|
|
|
|
|
|
|
definition foo (a : nat) : nat :=
|
|
|
|
match a with
|
2015-02-26 00:20:44 +00:00
|
|
|
| zero := zero
|
|
|
|
| succ n := n
|
2015-01-10 20:35:29 +00:00
|
|
|
end
|
2015-01-10 18:11:13 +00:00
|
|
|
|
|
|
|
example : foo 3 = 2 := rfl
|
|
|
|
|
|
|
|
open decidable
|
|
|
|
|
2015-02-26 00:20:44 +00:00
|
|
|
protected theorem dec_eq : ∀ x y : nat, decidable (x = y)
|
|
|
|
| dec_eq zero zero := inl rfl
|
|
|
|
| dec_eq (succ x) zero := inr (λ h, nat.no_confusion h)
|
|
|
|
| dec_eq zero (succ y) := inr (λ h, nat.no_confusion h)
|
|
|
|
| dec_eq (succ x) (succ y) :=
|
2015-01-10 18:11:13 +00:00
|
|
|
match dec_eq x y with
|
2015-02-26 00:20:44 +00:00
|
|
|
| inl H := inl (eq.rec_on H rfl)
|
|
|
|
| inr H := inr (λ h : succ x = succ y, nat.no_confusion h (λ heq : x = y, absurd heq H))
|
2015-01-10 20:35:29 +00:00
|
|
|
end
|
2015-01-10 18:11:13 +00:00
|
|
|
|
|
|
|
context
|
|
|
|
open list
|
|
|
|
parameter {A : Type}
|
|
|
|
parameter (p : A → Prop)
|
|
|
|
parameter [H : decidable_pred p]
|
|
|
|
include H
|
|
|
|
|
2015-02-26 00:20:44 +00:00
|
|
|
definition filter : list A → list A
|
|
|
|
| filter nil := nil
|
|
|
|
| filter (a :: l) :=
|
2015-01-10 18:11:13 +00:00
|
|
|
match H a with
|
2015-02-26 00:20:44 +00:00
|
|
|
| inl h := a :: filter l
|
|
|
|
| inr h := filter l
|
2015-01-10 20:35:29 +00:00
|
|
|
end
|
2015-01-10 18:11:13 +00:00
|
|
|
|
|
|
|
theorem filter_nil : filter nil = nil :=
|
|
|
|
rfl
|
|
|
|
|
|
|
|
theorem filter_cons (a : A) (l : list A) : filter (a :: l) = if p a then a :: filter l else filter l :=
|
|
|
|
rfl
|
|
|
|
end
|
|
|
|
|
|
|
|
definition sub2 (a : nat) : nat :=
|
|
|
|
match a with
|
2015-02-26 00:20:44 +00:00
|
|
|
| 0 := 0
|
|
|
|
| 1 := 0
|
|
|
|
| b+2 := b
|
2015-01-10 20:35:29 +00:00
|
|
|
end
|
2015-01-10 18:11:13 +00:00
|
|
|
|
|
|
|
example (a : nat) : sub2 (succ (succ a)) = a := rfl
|