feat(data/list): add missing theorems

This commit is contained in:
Rob Lewis 2016-02-01 15:39:40 -05:00 committed by Leonardo de Moura
parent dcfc496992
commit ffed988a34
3 changed files with 36 additions and 1 deletions

View file

@ -68,6 +68,16 @@ theorem length_map [simp] (f : A → B) : ∀ l : list A, length (map f l) = len
show length (map f l) + 1 = length l + 1,
by rewrite (length_map l)
theorem map_ne_nil_of_ne_nil (f : A → B) {l : list A} (H : l ≠ nil) : map f l ≠ nil :=
suppose map f l = nil,
have length (map f l) = length l, from !length_map,
have 0 = length l, from calc
0 = length nil : length_nil
... = length (map f l) : {eq.symm `map f l = nil`}
... = length l : this,
have l = nil, from eq_nil_of_length_eq_zero (eq.symm this),
H this
theorem mem_map {A B : Type} (f : A → B) : ∀ {a l}, a ∈ l → f a ∈ map f l
| a [] i := absurd i !not_mem_nil
| a (x::xs) i := or.elim (eq_or_mem_of_mem_cons i)

View file

@ -462,6 +462,15 @@ theorem length_upto : ∀ n, length (upto n) = n
| 0 := rfl
| (succ n) := by rewrite [upto_succ, length_cons, length_upto]
theorem upto_ne_nil_of_ne_zero {n : } (H : n ≠ 0) : upto n ≠ nil :=
suppose upto n = nil,
have upto n = upto 0, from upto_nil ▸ this,
have n = 0, from calc
n = length (upto n) : length_upto
... = length (upto 0) : this
... = 0 : length_upto,
H this
theorem upto_less : ∀ n, all (upto n) (λ i, i < n)
| 0 := trivial
| (succ n) :=

View file

@ -10,7 +10,7 @@ import data.list.comb data.list.set data.list.perm data.list.sorted logic.connec
namespace list
open decidable nat
variable {A : Type}
variables {B A : Type}
variable (R : A → A → Prop)
variable [decR : decidable_rel R]
include decR
@ -112,6 +112,22 @@ lemma min_mem : ∀ (l : list A) (h : l ≠ nil), min R l h ∈ l
suppose min_core R l a = a, by rewrite this; apply mem_cons
end
lemma min_map (f : B → A) {l : list B} (h : l ≠ nil) :
all l (λ b, (R (min R (map f l) (map_ne_nil_of_ne_nil _ h))) (f b)):=
using to tr rf,
begin
apply all_of_forall,
intro b Hb,
have Hfa : all (map f l) (R (min R (map f l) (map_ne_nil_of_ne_nil _ h))), from min_lemma to tr rf _,
have Hfb : f b ∈ map f l, from mem_map _ Hb,
exact of_mem_of_all Hfb Hfa
end
lemma min_map_all (f : B → A) {l : list B} (h : l ≠ nil) {b : B} (Hb : b ∈ l) :
R (min R (map f l) ((map_ne_nil_of_ne_nil _ h))) (f b) :=
of_mem_of_all Hb (min_map _ to tr rf f h)
omit decR
private lemma ne_nil {l : list A} {n : nat} : length l = succ n → l ≠ nil :=
assume h₁ h₂, by rewrite h₂ at h₁; contradiction