SSL Map2.lean
Interaktion und PortierbarkeitLean
|
|
/-
Copyright (c) 2014 Parikshit Khanna. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Mario Carneiro
-/
module
public import Mathlib.Data.List.Defs
public import Mathlib.Tactic.Common
import Mathlib.Tactic.Attr.Core
/-!
# Map₂ Lemmas
This file contains additional lemmas about a number of list functions related to combining zipping
Lists together. In particular, we include lemmas about:
* `map₂Left'`
* `map₂Right'`
* `zipWith`
* `zipLeft'`
* `zipRight'`
-/
public section
assert_not_exists GroupWithZero
assert_not_exists Lattice
assert_not_exists Prod.swap_eq_iff_eq_swap
assert_not_exists Ring
assert_not_exists Set.range
open Nat hiding one_pos
namespace List
universe u v w
variable {α : Type u} {β : Type v} {γ : Type w}
/-! ### map₂Left' -/
section Map₂Left'
-- The definitional equalities for `map₂Left'` can already be used by the
-- simplifier because `map₂Left'` is marked `@[simp]`.
@[simp]
theorem map₂Left'_nil_right (f : α → Option β → γ) (as) :
map₂Left' f as [] = (as.map fun a => f a none, []) := by cases as <;> rfl
end Map₂Left'
/-! ### map₂Right' -/
section Map₂Right'
variable (f : Option α → β → γ) (a : α) (as : List α) (b : β) (bs : List β)
@[simp]
theorem map₂Right'_nil_left : map₂Right' f [] bs = (bs.map (f none), []) := by cases bs <;> rfl
@[simp]
theorem map₂Right'_nil_right : map₂Right' f as [] = ([], as) :=
rfl
@[simp]
theorem map₂Right'_nil_cons : map₂Right' f [] (b :: bs) = (f none b :: bs.map (f none), []) :=
rfl
@[simp]
theorem map₂Right'_cons_cons :
map₂Right' f (a :: as) (b :: bs) =
let r := map₂Right' f as bs
(f (some a) b :: r.fst, r.snd) :=
rfl
end Map₂Right'
/-! ### zipWith -/
theorem nil_zipWith (f : α → β → γ) (l : List β) : zipWith f [] l = [] := by cases l <;> rfl
theorem zipWith_nil (f : α → β → γ) (l : List α) : zipWith f l [] = [] := by cases l <;> rfl
@[simp]
theorem zipWith_flip (f : α → β → γ) : ∀ as bs, zipWith (flip f) bs as = zipWith f as bs
| [], [] => rfl
| [], _ :: _ => rfl
| _ :: _, [] => rfl
| a :: as, b :: bs => by
simp! [zipWith_flip]
rfl
/-! ### zipLeft' -/
section ZipLeft'
variable (a : α) (as : List α) (b : β) (bs : List β)
@[simp]
theorem zipLeft'_nil_right : zipLeft' as ([] : List β) = (as.map fun a => (a, none), []) := by
cases as <;> rfl
@[simp]
theorem zipLeft'_nil_left : zipLeft' ([] : List α) bs = ([], bs) :=
rfl
@[simp]
theorem zipLeft'_cons_nil :
zipLeft' (a :: as) ([] : List β) = ((a, none) :: as.map fun a => (a, none), []) :=
rfl
@[simp]
theorem zipLeft'_cons_cons :
zipLeft' (a :: as) (b :: bs) =
let r := zipLeft' as bs
((a, some b) :: r.fst, r.snd) :=
rfl
end ZipLeft'
/-! ### zipRight' -/
section ZipRight'
variable (a : α) (as : List α) (b : β) (bs : List β)
@[simp]
theorem zipRight'_nil_left : zipRight' ([] : List α) bs = (bs.map fun b => (none, b), []) := by
cases bs <;> rfl
@[simp]
theorem zipRight'_nil_right : zipRight' as ([] : List β) = ([], as) :=
rfl
@[simp]
theorem zipRight'_nil_cons :
zipRight' ([] : List α) (b :: bs) = ((none, b) :: bs.map fun b => (none, b), []) :=
rfl
@[simp]
theorem zipRight'_cons_cons :
zipRight' (a :: as) (b :: bs) =
let r := zipRight' as bs
((some a, b) :: r.fst, r.snd) :=
rfl
end ZipRight'
/-! ### map₂Left -/
section Map₂Left
variable (f : α → Option β → γ) (as : List α)
-- The definitional equalities for `map₂Left` can already be used by the
-- simplifier because `map₂Left` is marked `@[simp]`.
@[simp]
theorem map₂Left_nil_right : map₂Left f as [] = as.map fun a => f a none := by cases as <;> rfl
theorem map₂Left_eq_map₂Left' : ∀ as bs, map₂Left f as bs = (map₂Left' f as bs).fst
| [], _ => by simp
| a :: as, [] => by simp
| a :: as, b :: bs => by simp [map₂Left_eq_map₂Left']
theorem map₂Left_eq_zipWith :
∀ as bs, length as ≤ length bs → map₂Left f as bs = zipWith (fun a b => f a (some b)) as bs
| [], [], _ => by simp
| [], _ :: _, _ => by simp
| a :: as, [], h => by
simp at h
| a :: as, b :: bs, h => by
simp only [length_cons, succ_le_succ_iff] at h
simp [h, map₂Left_eq_zipWith]
end Map₂Left
/-! ### map₂Right -/
section Map₂Right
variable (f : Option α → β → γ) (a : α) (as : List α) (b : β) (bs : List β)
@[simp]
theorem map₂Right_nil_left : map₂Right f [] bs = bs.map (f none) := by cases bs <;> rfl
@[simp]
theorem map₂Right_nil_right : map₂Right f as [] = [] :=
rfl
@[simp]
theorem map₂Right_nil_cons : map₂Right f [] (b :: bs) = f none b :: bs.map (f none) :=
rfl
@[simp]
theorem map₂Right_cons_cons :
map₂Right f (a :: as) (b :: bs) = f (some a) b :: map₂Right f as bs :=
rfl
theorem map₂Right_eq_map₂Right' : map₂Right f as bs = (map₂Right' f as bs).fst := by
simp only [map₂Right, map₂Right', map₂Left_eq_map₂Left']
theorem map₂Right_eq_zipWith (h : length bs ≤ length as) :
map₂Right f as bs = zipWith (fun a b => f (some a) b) as bs := by
have : (fun a b => flip f a (some b)) = flip fun a b => f (some a) b := rfl
simp only [map₂Right, map₂Left_eq_zipWith, zipWith_flip, *]
end Map₂Right
/-! ### zipLeft -/
section ZipLeft
variable (a : α) (as : List α) (b : β) (bs : List β)
@[simp]
theorem zipLeft_nil_right : zipLeft as ([] : List β) = as.map fun a => (a, none) := by
cases as <;> rfl
@[simp]
theorem zipLeft_nil_left : zipLeft ([] : List α) bs = [] :=
rfl
@[simp]
theorem zipLeft_cons_nil :
zipLeft (a :: as) ([] : List β) = (a, none) :: as.map fun a => (a, none) :=
rfl
@[simp]
theorem zipLeft_cons_cons : zipLeft (a :: as) (b :: bs) = (a, some b) :: zipLeft as bs :=
rfl
theorem zipLeft_eq_zipLeft' (as : List α) (bs : List β) : zipLeft as bs = (zipLeft' as bs).fst := by
rw [zipLeft, zipLeft']
cases as with
| nil => rfl
| cons _ atl =>
cases bs with
| nil => rfl
| cons _ btl =>
rw [zipWithLeft, zipWithLeft', cons_inj_right]
exact zipLeft_eq_zipLeft' atl btl
end ZipLeft
/-! ### zipRight -/
section ZipRight
variable (a : α) (as : List α) (b : β) (bs : List β)
@[simp]
theorem zipRight_nil_left : zipRight ([] : List α) bs = bs.map fun b => (none, b) := by
cases bs <;> rfl
@[simp]
theorem zipRight_nil_right : zipRight as ([] : List β) = [] :=
rfl
@[simp]
theorem zipRight_nil_cons :
zipRight ([] : List α) (b :: bs) = (none, b) :: bs.map fun b => (none, b) :=
rfl
@[simp]
theorem zipRight_cons_cons : zipRight (a :: as) (b :: bs) = (some a, b) :: zipRight as bs :=
rfl
theorem zipRight_eq_zipRight' : zipRight as bs = (zipRight' as bs).fst := by
induction as generalizing bs <;> cases bs <;> simp [*]
end ZipRight
end List
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.33Angebot
¤
*Eine klare Vorstellung vom Zielzustand
|
|
2026-11-24
|