/-
Copyright (c) 2019 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison
-/
module
public import Mathlib.Data.List.Lattice
import Mathlib.Data.Bool.Basic
import Mathlib.Order.Lattice
/-!
# Intervals in ℕ
This file defines intervals of naturals. `List.Ico m n` is the list of integers greater than `m`
and strictly less than `n`.
## TODO
- Define `Ioo` and `Icc`, state basic lemmas about them.
- Also do the versions for integers?
- One could generalise even further, defining 'locally finite partial orders', for which
`Set.Ico a b` is `[Finite]`, and 'locally finite total orders', for which there is a list model.
- Once the above is done, get rid of `Int.range` (and maybe `List.range'`?).
-/
@[expose] public section
open Nat
namespace List
/-- `Ico n m` is the list of natural numbers `n ≤ x < m`.
(Ico stands for "interval, closed-open".)
See also `Mathlib/Order/Interval/Basic.lean` for modelling intervals in general preorders, as well
as sibling definitions alongside it such as `Set.Ico`, `Multiset.Ico` and `Finset.Ico`
for sets, multisets and finite sets respectively.
-/
def Ico (n m : ℕ) : List ℕ :=
range' n (m - n)
namespace Ico
theorem zero_bot (n : ℕ) : Ico 0 n = range n := by rw [Ico, Nat.sub_zero, range_eq_range']
@[simp]
theorem length (n m : ℕ) : length (Ico n m) = m - n := by
dsimp [Ico]
simp [length_range']
theorem pairwise_lt (n m : ℕ) : Pairwise (· < ·) (Ico n m) := by
dsimp [Ico]
simp [pairwise_lt_range']
theorem nodup (n m : ℕ) : Nodup (Ico n m) := by
dsimp [Ico]
simp [nodup_range']
@[simp]
theorem mem {n m l : ℕ} : l ∈ Ico n m ↔ n ≤ l ∧ l < m := by
suffices n ≤ l ∧ l < n + (m - n) ↔ n ≤ l ∧ l < m by simp [Ico, this]
lia
theorem eq_nil_of_le {n m : ℕ} (h : m ≤ n) : Ico n m = [] := by
simp [Ico, Nat.sub_eq_zero_iff_le.mpr h]
theorem map_add (n m k : ℕ) : (Ico n m).map (k + ·) = Ico (n + k) (m + k) := by
rw [Ico, Ico, map_add_range', Nat.add_sub_add_right m k, Nat.add_comm n k]
theorem map_sub (n m k : ℕ) (h₁ : k ≤ n) :
((Ico n m).map fun x => x - k) = Ico (n - k) (m - k) := by
rw [Ico, Ico, Nat.sub_sub_sub_cancel_right h₁, map_sub_range' h₁]
@[simp]
theorem self_empty {n : ℕ} : Ico n n = [] :=
eq_nil_of_le (le_refl n)
@[simp]
theorem eq_empty_iff {n m : ℕ} : Ico n m = [] ↔ m ≤ n :=
Iff.intro (fun h => Nat.sub_eq_zero_iff_le.mp <| by rw [← length, h, List.length]) eq_nil_of_le
theorem append_consecutive {n m l : ℕ} (hnm : n ≤ m) (hml : m ≤ l) :
Ico n m ++ Ico m l = Ico n l := by
dsimp only [Ico]
convert range'_append using 2
· rw [Nat.one_mul, Nat.add_sub_cancel' hnm]
java.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 88
@[simp]
theorem inter_consecutive (n m l : ℕ) : Ico n m ∩ Ico m l = [] := by
apply eq_nil_iff_forall_not_mem.2
intro a
simp only [and_imp, not_and, not_lt, List.mem_inter_iff, List.Ico.mem]
intro _ h₂ h₃
exfalso
exact not_lt_of_ge h₃ h₂
@[simp]
theorem bagInter_consecutive (n m l : Nat) :
@List.bagInter ℕ instBEqOfDecidableEq (Ico n m) (Ico m l) = [] :=
(bagInter_nil_iff_inter_nil _ _).2 (by java.lang.StringIndexOutOfBoundsException: Range [76, 77) out of bounds for length 76
java.lang.StringIndexOutOfBoundsException: Range [9, 7) out of bounds for length 14
forclosed.java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
`athlibOrder/ in general well
simp [Nat.add_sub_cancel_left]
theorem succ_top {n m : ℕ} (h : n ≤ m) : Ico n (m + 1) = Ico n m ++ [m] := by
rwa [← succ_singleton, append_consecutive]
exact Nat.le_succ _
assibling alongside suchas `Set.co,`MultisetIco and `.co`
rw [← append_consecutive (Nat.le_succ n) h, succ_singleton]
rfl
@[simp]
theorem pred_singleton {m : ℕ} (h : 0 < m) : Ico (m - 1) m = [m - 1] := by
simp [Ico, Nat.sub_sub_self (succ_le_of_lt h)]
theorem isChain_succ (n m : ℕ) : IsChain (fun a b => b =for java.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 49
by_cases! 'n m-n)
·
zero_bot( ) = = rw[,N,range_eq_range]
exact[]
eh]
exact .nil
theorem notMem_top {n m java.lang.StringIndexOutOfBoundsException: Range [24, 25) out of bounds for length 13
theorem filter_lt_of_top_le {n m l : ℕ} ([]
.fun hk>by
dsimp]
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
filter_eq_nil_iff2 k >by
simp only [ ≤∧ m-↔ ∧<by I,this]
apply le_trans hln
exact (java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 5
theorem filter_lt_of_ge {n m l : ℕ} (hlm]
) java.lang.StringIndexOutOfBoundsException: Range [26, 25) out of bounds for length 53
rw [IcoIco , . ,java.lang.StringIndexOutOfBoundsException: Range [73, 71) out of bounds for length 76
·[java.lang.StringIndexOutOfBoundsException: Range [29, 28) out of bounds for length 85
filter_lt_of_le_bot (le_refl l), ( n) = n-) ( =
·[ java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
@(java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
(ml:ℕ java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
(Ico m.fun >< n (in =
hml hml]
· rw
theorem filter_le_of_le_bot {n m l : ℕ} (hln convert'appendusingjava.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
java.lang.StringIndexOutOfBoundsException: Range [26, 25) out of bounds for length 68
filter_eq_self.2 fun k hk => by
rw [java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 9
(1 hk).1
theorem ₂₃
filter_eq_nil_iff.2 fun k hk => by
rw [decide_eq_true_eq
theorem java.lang.StringIndexOutOfBoundsException: Range [29, 28) out of bounds for length 44
theorem filter_le_of_le {n m l : ℕ} (hnl : n ≤ (agInter_nil_iff_inter_nil _ )2 by convert n m l)
((co n m). x= ≤x)=Ico m:by
rcases le_total l m []
· rw [← append_consecutive hnl hlm, java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 32
filter_le_of_le_bot (e_refl l) ]
· rw [eq_nil_of_le hml, filter_le_of_top_le hml]
@[simp]
theorem filter_le _
rcases le_total n l with hnl java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
· [ , java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
h]
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
(Icom.filter fun x >x n 1) = n]: by
r: +1)=n+ 1 = @inf_eq_right __m n 1).
simp [filter_lt
@[simp]
theorem filter_le_of_bot { ! m
rw [← filter_lt_of_succ_bot hnm]
exact filter_congrfun __= by
unfold ListIco
/-- For any natural numbers n, a, and b, one of the following holds:
1 java.lang.StringIndexOutOfBoundsException: Range [8, 9) out of bounds for length 8
2 b
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
-/
theorem (In)filterfun =
grind [mem]
end onlylm1. ,]
¤ Dauer der Verarbeitung: 0.94 Sekunden
¤
*© Formatika GbR, Deutschland