chars
int64
40
24k
content_type
stringclasses
9 values
id
stringlengths
13
64
source
stringclasses
5 values
subset
stringclasses
31 values
text
stringlengths
40
24k
225
leanexplore_declaration
leanexplore:386389
leanexplore_sqlite
leanexplore_declarations
/-- A Beurling integer is a number of the form `∏ i, (a i) ^ (k i)` for a given sequence `a` and a finitely-supported sequence of naturals `k`. -/ def beurlingInteger (a : ℕ → ℝ) (k : ℕ →₀ ℕ) : ℝ := k.prod fun x y ↦ (a x) ^ y
228
leanexplore_declaration
leanexplore:386390
leanexplore_sqlite
leanexplore_declarations
/-- A sequence of real numbers `1 < a 0 < a 1 < ...` is called a set of Beurling prime numbers if it tends to infinity. -/ noncomputable def IsBeurlingPrimes (a : ℕ → ℝ) : Prop := 1 < a 0 ∧ StrictMono a ∧ Tendsto a atTop atTop
99
leanexplore_declaration
leanexplore:386391
leanexplore_sqlite
leanexplore_declarations
@[simp] theorem iUnion_cosets (c : CoveringSystem R) : ⋃ i, c.coset i = Set.univ := c.unionCovers
82
leanexplore_declaration
leanexplore:386392
leanexplore_sqlite
leanexplore_declarations
def coset (c : CoveringSystem R) (i : c.ι) : Set R := {c.residue i} + c.moduli i
499
leanexplore_declaration
leanexplore:386394
leanexplore_sqlite
leanexplore_declarations
/-- We say a covering system is strict if all the congruence relations that define it are take modulo a different ideal (or number). Note: this corresponds to the notion of a covering system that Erdos was using in [ErGr80] Erdős, P. and Graham, R., Old and new problems and results in combinatorial number theory. Mono...
75
leanexplore_declaration
leanexplore:386397
leanexplore_sqlite
leanexplore_declarations
unionCovers : ⋃ i, ({residue i} : Set R) + (moduli i : Set R) = @Set.univ R
558
leanexplore_declaration
leanexplore:386402
leanexplore_sqlite
leanexplore_declarations
/-- A covering system of a semiring `R` is a finite set of cosets of non-zero ideals whose union covers the whole ring. In the case where `R = ℤ`, this corresponds to a choice of finitely many congruence relations such that every integer satisfies at least one of the relations. -/ structure CoveringSystem (R : Type*) [...
155
leanexplore_declaration
leanexplore:386403
leanexplore_sqlite
leanexplore_declarations
instance {S : Type*} [DecidableEq S] [CommRing S] {m : ℕ} : DecidablePred (Even (S := S) (m := m)) := fun ψ ↦ decidable_of_iff (ψ (-1) = 1) <| by rfl
155
leanexplore_declaration
leanexplore:386404
leanexplore_sqlite
leanexplore_declarations
instance {S : Type*} [DecidableEq S] [CommRing S] {m : ℕ} : DecidablePred (Odd (S := S) (m := m)) := fun ψ ↦ decidable_of_iff (ψ (-1) = -1) <| by rfl
317
leanexplore_declaration
leanexplore:386405
leanexplore_sqlite
leanexplore_declarations
/-- Every lacunary sequence is eventually strictly increasing. -/ lemma IsLacunary.eventually_lt {n : ℕ → ℕ} (hn : IsLacunary n) : ∀ᶠ k in atTop, n k < n (k + 1) := by obtain ⟨c, hc, h⟩ := hn obtain ⟨N, h⟩ := eventually_atTop.1 h refine eventually_atTop.2 ⟨N, fun b hb ↦ ?_⟩ grw [hc] at h simpa using h _ hb
221
leanexplore_declaration
leanexplore:386406
leanexplore_sqlite
leanexplore_declarations
/-- Say a sequence is lacunary if there exists some $\lambda > 1$ such that $a_{n+1}/a_n > \lambda$ for all sufficiently large $n$. -/ def IsLacunary (n : ℕ → ℕ) : Prop := ∃ c > (1 : ℝ), ∀ᶠ k in atTop, c * n k < n (k + 1)
89
leanexplore_declaration
leanexplore:386407
leanexplore_sqlite
leanexplore_declarations
@[inherit_doc] scoped[NumberTheorySymbols] notation "L(" a " | " p ")" => legendreSym p a
208
leanexplore_declaration
leanexplore:386408
leanexplore_sqlite
leanexplore_declarations
/-- A natural number $n$ is *practical* if every positive integer $m ≤ n$ can be represented as a sum of distinct divisors of $n$. -/ def IsPractical (n : ℕ) : Prop := ∀ m, m ≤ n → m ∈ subsetSums n.divisors
157
leanexplore_declaration
leanexplore:386409
leanexplore_sqlite
leanexplore_declarations
/-- The prime gap: the difference between the $n+1$-th and $n$-th prime. -/ noncomputable def primeGap (n : ℕ) : ℕ := (n + 1).nth Nat.Prime - n.nth Nat.Prime
152
leanexplore_declaration
leanexplore:386410
leanexplore_sqlite
leanexplore_declarations
theorem prime_isPrimitive_iff {S : Set ℕ} {p : ℕ} (hp : p.Prime) : S.IsPrimitive p ↔ p ∈ S ∧ 1 ∉ S := by simp [isPrimitive_iff, hp.properDivisors]
120
leanexplore_declaration
leanexplore:386411
leanexplore_sqlite
leanexplore_declarations
theorem one_isPrimitive_iff {S : Set ℕ} : S.IsPrimitive 1 ↔ 1 ∈ S := by simp [isPrimitive_iff, Nat.properDivisors_one]
84
leanexplore_declaration
leanexplore:386412
leanexplore_sqlite
leanexplore_declarations
@[simp] theorem primitives_subset {S : Set ℕ} : S.primitives ⊆ S := fun _ h => h.mem
94
leanexplore_declaration
leanexplore:386413
leanexplore_sqlite
leanexplore_declarations
theorem mem_primitives_iff {S : Set ℕ} {n : ℕ} : n ∈ S.primitives ↔ S.IsPrimitive n := Iff.rfl
366
leanexplore_declaration
leanexplore:386414
leanexplore_sqlite
leanexplore_declarations
theorem isPrimitive_iff' {S : Set ℕ} {n : ℕ} (_hn : 0 < n) : S.IsPrimitive n ↔ n ∈ S ∧ ∀ d, d ∣ n → d < n → d ∉ S := by rw [isPrimitive_iff] constructor <;> intro ⟨hmem, hdiv⟩ · exact ⟨hmem, fun d hd hlt => hdiv d (Nat.mem_properDivisors.mpr ⟨hd, hlt⟩)⟩ · exact ⟨hmem, fun d hd => hdiv d (Nat.mem_properDivis...
172
leanexplore_declaration
leanexplore:386415
leanexplore_sqlite
leanexplore_declarations
theorem isPrimitive_iff {S : Set ℕ} {n : ℕ} : S.IsPrimitive n ↔ n ∈ S ∧ ∀ d ∈ n.properDivisors, d ∉ S := by simp only [IsPrimitive, Set.disjoint_left, Finset.mem_coe]
198
leanexplore_declaration
leanexplore:386416
leanexplore_sqlite
leanexplore_declarations
theorem IsPrimitive.not_mem_of_dvd_of_lt {S : Set ℕ} {n d : ℕ} (h : S.IsPrimitive n) (hdvd : d ∣ n) (hlt : d < n) : d ∉ S := h.not_mem_of_properDivisor (Nat.mem_properDivisors.mpr ⟨hdvd, hlt⟩)
161
leanexplore_declaration
leanexplore:386417
leanexplore_sqlite
leanexplore_declarations
theorem IsPrimitive.not_mem_of_properDivisor {S : Set ℕ} {n d : ℕ} (h : S.IsPrimitive n) (hd : d ∈ n.properDivisors) : d ∉ S := Set.disjoint_left.mp h.2 hd
136
leanexplore_declaration
leanexplore:386418
leanexplore_sqlite
leanexplore_declarations
theorem IsPrimitive.disjoint_properDivisors {S : Set ℕ} {n : ℕ} (h : S.IsPrimitive n) : Disjoint (n.properDivisors : Set ℕ) S := h.2
80
leanexplore_declaration
leanexplore:386419
leanexplore_sqlite
leanexplore_declarations
theorem IsPrimitive.mem {S : Set ℕ} {n : ℕ} (h : S.IsPrimitive n) : n ∈ S := h.1
106
leanexplore_declaration
leanexplore:386420
leanexplore_sqlite
leanexplore_declarations
/-- The set of primitive elements of `S`. -/ def primitives (S : Set ℕ) : Set ℕ := {n | S.IsPrimitive n}
198
leanexplore_declaration
leanexplore:386421
leanexplore_sqlite
leanexplore_declarations
/-- An element `n` is *primitive* in a set `S ⊆ ℕ` if `n ∈ S` and no proper divisor of `n` is in `S`. -/ def IsPrimitive (S : Set ℕ) (n : ℕ) : Prop := n ∈ S ∧ Disjoint (n.properDivisors : Set ℕ) S
354
leanexplore_declaration
leanexplore:386422
leanexplore_sqlite
leanexplore_declarations
/-- A positive odd integer $k$ is a [Sierpiński number](https://en.wikipedia.org/wiki/Sierpi%C5%84ski_number) if $k \cdot 2^n + 1$ is composite for all natural numbers $n$. In other words, every member of the set $\{k \cdot 2^n + 1 : n \in \mathbb{N}\}$ is composite. -/ def IsSierpinskiNumber (k : ℕ) : Prop := ¬ 2 ∣ ...
73
leanexplore_declaration
leanexplore:386423
leanexplore_sqlite
leanexplore_declarations
modeq : LucasSequence.U a b (p - J(a^2 - 4*b | p)).toNat ≡ 0 [ZMOD (p^2)]
729
leanexplore_declaration
leanexplore:386427
leanexplore_sqlite
leanexplore_declarations
/-- **Lucas–Wieferich prime** A Lucas–Wieferich prime associated with $(a,b)$ is an odd prime $p$, not dividing $a^2 - 4b$, such that $U_{p-\varepsilon}(a,b) \equiv 0 \pmod{p^2}$ where $U(a,b)$ is the Lucas sequence of the first kind and $\varepsilon$ is the Legendre symbol $\left({\tfrac {a^{2}-4b}{p}}\right)$. See f...
52
leanexplore_declaration
leanexplore:386428
leanexplore_sqlite
leanexplore_declarations
lucasNumber_modeq : lucasNumber p ≡ 1 [ZMOD (p ^ 2)]
269
leanexplore_declaration
leanexplore:386430
leanexplore_sqlite
leanexplore_declarations
/-- **Wall–Sun–Sun prime** A prime $p$ is a Wall–Sun–Sun prime if and only if $L_p \equiv 1 \pmod{p^2}$, where $L_p$ is the $p$-th Lucas number. -/ structure IsWallSunSunPrime (p : ℕ) : Prop where prime : p.Prime lucasNumber_modeq : lucasNumber p ≡ 1 [ZMOD (p ^ 2)]
122
leanexplore_declaration
leanexplore:386431
leanexplore_sqlite
leanexplore_declarations
/-- **The Lucas numbers** $L_0 = 2$, $L_1=1$, $L_{n+2} = L_{n+1}+L_n$ -/ def lucasNumber : ℕ → ℤ := LucasSequence.V 1 (-1)
255
leanexplore_declaration
leanexplore:386432
leanexplore_sqlite
leanexplore_declarations
/-- **The Lucas sequence of the second kind** $V_0(P, Q) = 0$, $V_1(P, Q)=P$, $V_{n+2}(P, Q)=PV_{n+1}(P, Q)-QV_n(P, Q)$ -/ def LucasSequence.V (P Q : ℤ) : ℕ → ℤ | 0 => 2 | 1 => P | n + 2 => P * LucasSequence.V P Q (n + 1) - Q * LucasSequence.V P Q n
254
leanexplore_declaration
leanexplore:386433
leanexplore_sqlite
leanexplore_declarations
/-- **The Lucas sequence of the first kind** $U_0(P, Q) = 0$, $U_1(P, Q)=1$, $U_{n+2}(P, Q)=PU_{n+1}(P, Q)-QU_n(P, Q)$ -/ def LucasSequence.U (P Q : ℤ) : ℕ → ℤ | 0 => 0 | 1 => 1 | n + 2 => P * LucasSequence.U P Q (n + 1) - Q * LucasSequence.U P Q n
248
leanexplore_declaration
leanexplore:386434
leanexplore_sqlite
leanexplore_declarations
theorem cofinite_eq_atTop {α : Type*} [LinearOrder α] [LocallyFiniteOrder α] [OrderBot α] [SuccOrder α] [NoMaxOrder α] : @cofinite α = atTop := by simp only [atTop_eq_generate_Ici, HasBasis.eq_generate cofinite_hasBasis_Ici, true_and] rfl
820
leanexplore_declaration
leanexplore:386435
leanexplore_sqlite
leanexplore_declarations
/-- Note(csonne): According to a TODO in `Mathlib.Order.Interval.Finset.Defs`, Assuming `SuccOrder α` should not be necessary as an instance should follow from `[LocallyFiniteOrder α] [OrderBot α]`. This has not been implemented in mathlib however. -/ lemma cofinite_hasBasis_Ici {α : Type*} [LinearOrder α] [LocallyFini...
481
leanexplore_declaration
leanexplore:386436
leanexplore_sqlite
leanexplore_declarations
lemma cofinite_hasBasis_Ioi {α : Type*} [LinearOrder α] [LocallyFiniteOrder α] [OrderBot α] : cofinite.HasBasis (fun (_ : α) ↦ True) (Set.Ioi ·) := by constructor intro A simp only [mem_cofinite, true_and] constructor · intro hA obtain ⟨a, ha⟩ := Set.Finite.bddAbove hA use a rw [← Set.compl_su...
407
leanexplore_declaration
leanexplore:386437
leanexplore_sqlite
leanexplore_declarations
theorem Finset.tendsto_card_atTop {α : Type*} [Infinite α] : atTop.Tendsto (Finset.card (α := α)) atTop := by classical apply tendsto_atTop_atTop_of_monotone Finset.card_mono fun n ↦ ?_ obtain ⟨S, hS⟩ := (Set.infinite_univ (α := α)).exists_subset_card_eq n obtain ⟨g, hg⟩ := (Set.infinite_univ (α := α)).exis...
310
leanexplore_declaration
leanexplore:386438
leanexplore_sqlite
leanexplore_declarations
theorem Set.Iio_eventually_ncard_ne_zero (β : Type*) [PartialOrder β] [LocallyFiniteOrder β] [OrderBot β] [Nontrivial β] : ∃ (b : β), ∀ n ≥ b, (Set.Iio n).ncard ≠ 0 := let ⟨b, hb⟩ := Finset.Iio_eventually_card_ne_zero β ⟨b, fun n hn => by rw [← Finset.coe_Iio, Set.ncard_coe_finset]; exact hb n hn⟩
286
leanexplore_declaration
leanexplore:386439
leanexplore_sqlite
leanexplore_declarations
theorem Finset.Iio_eventually_card_ne_zero (β : Type*) [PartialOrder β] [LocallyFiniteOrder β] [OrderBot β] [Nontrivial β] : ∃ (b : β), ∀ n ≥ b, (Finset.Iio n).card ≠ 0 := let ⟨b, hb⟩ := Iio_eventually_nonempty β ⟨b, fun n hn => by simp [nonempty_iff_ne_empty.1 <| hb n hn]⟩
261
leanexplore_declaration
leanexplore:386440
leanexplore_sqlite
leanexplore_declarations
theorem Finset.Iio_eventually_nonempty (β : Type*) [PartialOrder β] [LocallyFiniteOrder β] [OrderBot β] [Nontrivial β] : ∃ (b : β), ∀ n ≥ b, (Finset.Iio n).Nonempty := let ⟨b, hb⟩ := exists_ne (⊥ : β) ⟨b, fun n hn => by simp [ne_bot_of_le_ne_bot hb hn]⟩
136
leanexplore_declaration
leanexplore:386441
leanexplore_sqlite
leanexplore_declarations
@[simp] theorem Nat.ncard_Iio (b : ℕ) : (Set.Iio b).ncard = b := by rw [← Finset.coe_Iio, Set.ncard_coe_finset] exact Nat.card_Iio _
163
leanexplore_declaration
leanexplore:386442
leanexplore_sqlite
leanexplore_declarations
@[simp] lemma mk_diff_eq_left_of_finite (hs : s.Infinite) (ht : t.Finite) : #↑(s \ t) = #s := mk_diff_eq_left hs <| (aleph0_le_mk_set.2 hs).trans_lt' <| by simpa
172
leanexplore_declaration
leanexplore:386443
leanexplore_sqlite
leanexplore_declarations
@[simp] lemma mk_diff_eq_left_of_finite' (hs : s.Infinite) (hst : (s ∩ t).Finite) : #↑(s \ t) = #s := mk_diff_eq_left' hs <| (aleph0_le_mk_set.2 hs).trans_lt' <| by simpa
164
leanexplore_declaration
leanexplore:386444
leanexplore_sqlite
leanexplore_declarations
@[simp] lemma mk_diff_eq_left (hs : s.Infinite) (hts : #t < #s) : #↑(s \ t) = #s := mk_diff_eq_left' hs <| hts.trans_le' <| mk_subtype_mono Set.inter_subset_right
254
leanexplore_declaration
leanexplore:386445
leanexplore_sqlite
leanexplore_declarations
@[simp] lemma mk_diff_eq_left' (hs : s.Infinite) (hst : #↑(s ∩ t) < #s) : #↑(s \ t) = #s := by refine (mk_le_mk_of_subset Set.diff_subset).eq_of_not_lt fun h ↦ (add_lt_of_lt (by simpa) hst h).not_ge ?_ grw [← mk_union_le .., Set.inter_union_diff]
105
leanexplore_declaration
leanexplore:386446
leanexplore_sqlite
leanexplore_declarations
@[simp] lemma aleph0_le_mk_set : ℵ₀ ≤ #s ↔ s.Infinite := by rw [aleph0_le_mk_iff, Set.infinite_coe_iff]
593
leanexplore_declaration
leanexplore:386447
leanexplore_sqlite
leanexplore_declarations
/-- This proposition asserts the ordinal Ramsey property `α → (β, c)²`. It states that for any 2-coloring of the complete graph on the ordinal `α`, one of the following must hold: * There is a red clique which is order-isomorphic to `β`. * There is a blue clique of cardinality `c`. -/ def OrdinalCardinalRamsey (α β : ...
1,688
leanexplore_declaration
leanexplore:386448
leanexplore_sqlite
leanexplore_declarations
/-- A linter that applies to terms. The `lint` argument receives both the original syntax and elaborated expression, provided the option is enabled. Note that the linter lives in `StateT σ`, so that it can build up state inherited from parent trees. This doesn't return a `Linter`, as then the caller would have to rem...
1,089
leanexplore_declaration
leanexplore:386449
leanexplore_sqlite
leanexplore_declarations
/-- A copy of `ContextInfo.runMetaM` that keeps the messages and passes in the same filename. -/ def Lean.Elab.ContextInfo.runMetaMInCommandElabM {α} (info : ContextInfo) (lctx : LocalContext) (x : MetaM α) : Command.CommandElabM α := do let x := (withLocalInstances lctx.decls.toList.reduceOption x).run { lctx :=...
158
leanexplore_declaration
leanexplore:386450
leanexplore_sqlite
leanexplore_declarations
@[to_additive] lemma Multipliable.tendsto_tprod_one (hf : Multipliable f) (hs : ∀ b, ∀ᶠ i in l, b ∉ s i) : Tendsto (fun i ↦ ∏' b : s i, f b) l (𝓝 1) := by
353
leanexplore_declaration
leanexplore:386451
leanexplore_sqlite
leanexplore_declarations
@[to_additive] lemma Multipliable.tendsto_tprod_one (hf : Multipliable f) (hs : ∀ b, ∀ᶠ i in l, b ∉ s i) : Tendsto (fun i ↦ ∏' b : s i, f b) l (𝓝 1) := by rw [tendsto_iff_eventually] rintro p hp obtain ⟨t, ht⟩ := hf.tprod_vanishing hp filter_upwards [t.eventually_all.2 fun b _ ↦ hs b] with i hi exact ht ...
110
leanexplore_declaration
leanexplore:386452
leanexplore_sqlite
leanexplore_declarations
@[to_additive] protected lemma Multipliable.prod_le_tprod_set (hst : ↑s ⊆ t) (hfst : ∀ i ∉ s, i ∈ t → 1 ≤ f i)
351
leanexplore_declaration
leanexplore:386453
leanexplore_sqlite
leanexplore_declarations
@[to_additive] protected lemma Multipliable.prod_le_tprod_set (hst : ↑s ⊆ t) (hfst : ∀ i ∉ s, i ∈ t → 1 ≤ f i) (hf : Multipliable f) : ∏ i ∈ s, f i ≤ ∏' i : t, f i := by rw [tprod_subtype, Finset.prod_congr rfl] refine (hf.mulIndicator t).prod_le_tprod _ (by simpa [Set.mulIndicator, apply_ite]) rintro i hi ...
296
leanexplore_declaration
leanexplore:386454
leanexplore_sqlite
leanexplore_declarations
/-- A bijection between discrete topoligical spaces is a homeomorpism. -/ theorem IsHomeomorph.equiv_of_discreteTopology {X Y : Type*} [TopologicalSpace X] [DiscreteTopology X] [TopologicalSpace Y] [DiscreteTopology Y] (f : X ≃ Y) : IsHomeomorph f := (Homeomorph.OfDiscrete f).isHomeomorph
277
leanexplore_declaration
leanexplore:386455
leanexplore_sqlite
leanexplore_declarations
def Homeomorph.OfDiscrete {X Y : Type*} [TopologicalSpace X] [DiscreteTopology X] [TopologicalSpace Y] [DiscreteTopology Y] (f : X ≃ Y) : X ≃ₜ Y where toEquiv := f continuous_toFun := continuous_of_discreteTopology continuous_invFun := continuous_of_discreteTopology
250
leanexplore_declaration
leanexplore:386456
leanexplore_sqlite
leanexplore_declarations
/-- Singletons are Gδ in first-countable T₁ spaces. -/ instance HasGδSingletons.of_t1Space_firstCountableTopology (X : Type*) [TopologicalSpace X] [FirstCountableTopology X] [T1Space X] : HasGδSingletons X where isGδ_singleton := IsGδ.singleton
155
leanexplore_declaration
leanexplore:386458
leanexplore_sqlite
leanexplore_declarations
/-- A space where all singletons are Gδ sets. -/ class HasGδSingletons (X : Type*) [TopologicalSpace X] : Prop where isGδ_singleton : ∀ ⦃x : X⦄, IsGδ {x}
195
leanexplore_declaration
leanexplore:386459
leanexplore_sqlite
leanexplore_declarations
/-- A set `s` is `≥ ε`-separated if its elements are pairwise at distance greater or equal to `ε` from each other. -/ def IsSeparated' (ε : ℝ≥0∞) (s : Set X) : Prop := s.Pairwise (ε ≤ edist · ·)
466
leanexplore_declaration
leanexplore:386460
leanexplore_sqlite
leanexplore_declarations
/-- Merges two lists into a single list, counting comparisons as time cost. Returns a `TimeM ℕ (List α)` where the time represents the number of comparisons performed. -/ def merge : List α → List α → TimeM ℕ (List α) | [], ys => return ys | xs, [] => return xs | x::xs', y::ys' => do ✓ let c := (x ≤ y : Bool...
468
leanexplore_declaration
leanexplore:386461
leanexplore_sqlite
leanexplore_declarations
/-- Sorts a list using the merge sort algorithm, counting comparisons as time cost. Returns a `TimeM ℕ (List α)` where the time represents the total number of comparisons. -/ def mergeSort (xs : List α) : TimeM ℕ (List α) := do if xs.length < 2 then return xs else let half := xs.length / 2 let left := xs...
216
leanexplore_declaration
leanexplore:386462
leanexplore_sqlite
leanexplore_declarations
/-- Our merge computes the one already in mathlib. -/ @[simp, grind =] theorem ret_merge (xs ys : List α) : ⟪merge xs ys⟫ = xs.merge ys := by fun_induction merge with grind [nil_merge, merge_right, cons_merge_cons]
136
leanexplore_declaration
leanexplore:386463
leanexplore_sqlite
leanexplore_declarations
/-- A list is sorted if it satisfies the `Pairwise (· ≤ ·)` predicate. -/ abbrev IsSorted (l : List α) : Prop := List.Pairwise (· ≤ ·) l
134
leanexplore_declaration
leanexplore:386464
leanexplore_sqlite
leanexplore_declarations
/-- `x` is a minimum element of list `l` if `x ≤ b` for all `b ∈ l`. -/ abbrev MinOfList (x : α) (l : List α) : Prop := ∀ b ∈ l, x ≤ b
134
leanexplore_declaration
leanexplore:386465
leanexplore_sqlite
leanexplore_declarations
@[grind →] theorem mem_either_merge (xs ys : List α) (z : α) (hz : z ∈ ⟪merge xs ys⟫) : z ∈ xs ∨ z ∈ ys := by grind [List.mem_merge]
138
leanexplore_declaration
leanexplore:386466
leanexplore_sqlite
leanexplore_declarations
theorem min_all_merge (x : α) (xs ys : List α) (hxs : MinOfList x xs) (hys : MinOfList x ys) : MinOfList x ⟪merge xs ys⟫ := by grind
136
leanexplore_declaration
leanexplore:386467
leanexplore_sqlite
leanexplore_declarations
theorem sorted_merge {l1 l2 : List α} (hxs : IsSorted l1) (hys : IsSorted l2) : IsSorted ⟪merge l1 l2⟫ := by grind [hxs.merge hys]
228
leanexplore_declaration
leanexplore:386468
leanexplore_sqlite
leanexplore_declarations
theorem mergeSort_sorted (xs : List α) : IsSorted ⟪mergeSort xs⟫ := by fun_induction mergeSort xs with | case1 x => rcases x with _ | ⟨a, _ | ⟨b, rest⟩⟩ <;> grind | case2 _ _ _ _ _ ih2 ih1 => exact sorted_merge ih2 ih1
124
leanexplore_declaration
leanexplore:386469
leanexplore_sqlite
leanexplore_declarations
lemma merge_perm (l₁ l₂ : List α) : ⟪merge l₁ l₂⟫ ~ l₁ ++ l₂ := by fun_induction merge with grind [List.merge_perm_append]
424
leanexplore_declaration
leanexplore:386470
leanexplore_sqlite
leanexplore_declarations
theorem mergeSort_perm (xs : List α) : ⟪mergeSort xs⟫ ~ xs := by fun_induction mergeSort xs with | case1 => simp | case2 x _ _ left right ih2 ih1 => simp only [ret_bind] calc ⟪merge ⟪mergeSort left⟫ ⟪mergeSort right⟫⟫ ~ ⟪mergeSort left⟫ ++ ⟪mergeSort right⟫ := by apply merge_perm _ ~ l...
175
leanexplore_declaration
leanexplore:386471
leanexplore_sqlite
leanexplore_declarations
/-- MergeSort is functionally correct. -/ theorem mergeSort_correct (xs : List α) : IsSorted ⟪mergeSort xs⟫ ∧ ⟪mergeSort xs⟫ ~ xs := ⟨mergeSort_sorted xs, mergeSort_perm xs⟩
414
leanexplore_declaration
leanexplore:386472
leanexplore_sqlite
leanexplore_declarations
/-- Recurrence relation for the time complexity of merge sort. For a list of length `n`, this counts the total number of comparisons: - Base cases: 0 comparisons for lists of length 0 or 1 - Recursive case: split the list, sort both halves, then merge (which takes at most `n` comparisons) -/ def timeMergeSortRec : ℕ ...
192
leanexplore_declaration
leanexplore:386473
leanexplore_sqlite
leanexplore_declarations
/-- Key Lemma: ⌈log2 ⌈n/2⌉⌉ ≤ ⌈log2 n⌉ - 1 for n > 1 -/ @[grind →] lemma clog2_half_le (n : ℕ) (h : n > 1) : clog 2 ((n + 1) / 2) ≤ clog 2 n - 1 := by grind [Nat.clog_of_one_lt one_lt_two h]
237
leanexplore_declaration
leanexplore:386474
leanexplore_sqlite
leanexplore_declarations
/-- Same logic for the floor half: ⌈log2 ⌊n/2⌋⌉ ≤ ⌈log2 n⌉ - 1 -/ @[grind →] lemma clog2_floor_half_le (n : ℕ) (h : n > 1) : clog 2 (n / 2) ≤ clog 2 n - 1 := by apply Nat.le_trans _ (clog2_half_le n h) apply Nat.clog_monotone grind
118
leanexplore_declaration
leanexplore:386475
leanexplore_sqlite
leanexplore_declarations
/-- Upper bound function for merge sort time complexity: `T(n) = n * ⌈log₂ n⌉` -/ abbrev T (n : ℕ) : ℕ := n * clog 2 n
270
leanexplore_declaration
leanexplore:386476
leanexplore_sqlite
leanexplore_declarations
/-- Solve the recurrence -/ theorem timeMergeSortRec_le (n : ℕ) : timeMergeSortRec n ≤ T n := by fun_induction timeMergeSortRec with | case1 => grind | case2 => grind | case3 n ih2 ih1 => grw [ih1,ih2] have := some_algebra n grind [Nat.add_div_right]
112
leanexplore_declaration
leanexplore:386477
leanexplore_sqlite
leanexplore_declarations
theorem merge_ret_length_eq_sum (xs ys : List α) : ⟪merge xs ys⟫.length = xs.length + ys.length := by simp
162
leanexplore_declaration
leanexplore:386478
leanexplore_sqlite
leanexplore_declarations
@[simp] theorem mergeSort_same_length (xs : List α) : ⟪mergeSort xs⟫.length = xs.length := by fun_induction mergeSort · simp · grind [List.length_merge]
158
leanexplore_declaration
leanexplore:386479
leanexplore_sqlite
leanexplore_declarations
@[simp] theorem merge_time (xs ys : List α) : (merge xs ys).time ≤ xs.length + ys.length := by fun_induction merge with | case3 => grind | _ => simp
308
leanexplore_declaration
leanexplore:386480
leanexplore_sqlite
leanexplore_declarations
theorem mergeSort_time_le (xs : List α) : (mergeSort xs).time ≤ timeMergeSortRec xs.length := by fun_induction mergeSort with | case1 => grind | case2 _ _ _ _ _ ih2 ih1 => simp only [time_bind] grw [merge_time] simp only [mergeSort_same_length] unfold timeMergeSortRec grind
191
leanexplore_declaration
leanexplore:386481
leanexplore_sqlite
leanexplore_declarations
/-- Time complexity of mergeSort -/ theorem mergeSort_time (xs : List α) : let n := xs.length (mergeSort xs).time ≤ n * clog 2 n := by grind [mergeSort_time_le, timeMergeSortRec_le]
375
leanexplore_declaration
leanexplore:386482
leanexplore_sqlite
leanexplore_declarations
/-- A monad for tracking time complexity of computations. `TimeM T α` represents a computation that returns a value of type `α` and accumulates a time cost (represented as a type `T`, typically `ℕ`). -/ @[ext] structure TimeM (T : Type*) (α : Type*) where /-- The return value of the computation -/ ret : α /-- The...
366
leanexplore_declaration
leanexplore:386483
leanexplore_sqlite
leanexplore_declarations
@[ext] structure TimeM (T : Type*) (α : Type*) where /-- The return value of the computation -/ ret : α /-- The accumulated time cost of the computation -/ time : T namespace TimeM /-- Lifts a pure value into a `TimeM` computation with zero time cost. Prefer to use `pure` instead of `TimeM.pure`. -/ protecte...
184
leanexplore_declaration
leanexplore:386485
leanexplore_sqlite
leanexplore_declarations
/-- Lifts a pure value into a `TimeM` computation with zero time cost. Prefer to use `pure` instead of `TimeM.pure`. -/ protected def pure [Zero T] {α} (a : α) : TimeM T α := ⟨a, 0⟩
61
leanexplore_declaration
leanexplore:386486
leanexplore_sqlite
leanexplore_declarations
instance [Zero T] : Pure (TimeM T) where pure := TimeM.pure
245
leanexplore_declaration
leanexplore:386487
leanexplore_sqlite
leanexplore_declarations
/-- Sequentially composes two `TimeM` computations, summing their time costs. Prefer to use the `>>=` notation. -/ protected def bind {α β} [Add T] (m : TimeM T α) (f : α → TimeM T β) : TimeM T β := let r := f m.ret ⟨r.ret, m.time + r.time⟩
60
leanexplore_declaration
leanexplore:386488
leanexplore_sqlite
leanexplore_declarations
instance [Add T] : Bind (TimeM T) where bind := TimeM.bind
65
leanexplore_declaration
leanexplore:386489
leanexplore_sqlite
leanexplore_declarations
instance : Functor (TimeM T) where map f x := ⟨f x.ret, x.time⟩
92
leanexplore_declaration
leanexplore:386490
leanexplore_sqlite
leanexplore_declarations
instance [Add T] : Seq (TimeM T) where seq f x := ⟨f.ret (x ()).ret, f.time + (x ()).time⟩
89
leanexplore_declaration
leanexplore:386491
leanexplore_sqlite
leanexplore_declarations
instance [Add T] : SeqLeft (TimeM T) where seqLeft x y := ⟨x.ret, x.time + (y ()).time⟩
96
leanexplore_declaration
leanexplore:386492
leanexplore_sqlite
leanexplore_declarations
instance [Add T] : SeqRight (TimeM T) where seqRight x y := ⟨(y ()).ret, x.time + (y ()).time⟩
183
leanexplore_declaration
leanexplore:386493
leanexplore_sqlite
leanexplore_declarations
instance [AddZero T] : Monad (TimeM T) where pure := Pure.pure bind := Bind.bind map := Functor.map seq := Seq.seq seqLeft := SeqLeft.seqLeft seqRight := SeqRight.seqRight
178
leanexplore_declaration
leanexplore:386494
leanexplore_sqlite
leanexplore_declarations
@[simp, grind =] theorem ret_pure {α} [Zero T] (a : α) : (pure a : TimeM T α).ret = a := rfl @[simp, grind =] theorem ret_bind {α β} [Add T] (m : TimeM T α) (f : α → TimeM T β) :
226
leanexplore_declaration
leanexplore:386495
leanexplore_sqlite
leanexplore_declarations
@[simp, grind =] theorem ret_bind {α β} [Add T] (m : TimeM T α) (f : α → TimeM T β) : (m >>= f).ret = (f m.ret).ret := rfl @[simp, grind =] theorem ret_map {α β} (f : α → β) (x : TimeM T α) : (f <$> x).ret = f x.ret := rfl
181
leanexplore_declaration
leanexplore:386496
leanexplore_sqlite
leanexplore_declarations
@[simp, grind =] theorem ret_map {α β} (f : α → β) (x : TimeM T α) : (f <$> x).ret = f x.ret := rfl @[simp] theorem ret_seqRight {α} (x : TimeM T α) (y : Unit → TimeM T β) [Add T] :
214
leanexplore_declaration
leanexplore:386497
leanexplore_sqlite
leanexplore_declarations
@[simp] theorem ret_seqRight {α} (x : TimeM T α) (y : Unit → TimeM T β) [Add T] : (SeqRight.seqRight x y).ret = (y ()).ret := rfl @[simp] theorem ret_seqLeft {α} [Add T] (x : TimeM T α) (y : Unit → TimeM T β) :
210
leanexplore_declaration
leanexplore:386498
leanexplore_sqlite
leanexplore_declarations
@[simp] theorem ret_seqLeft {α} [Add T] (x : TimeM T α) (y : Unit → TimeM T β) : (SeqLeft.seqLeft x y).ret = x.ret := rfl @[simp] theorem ret_seq {α β} [Add T] (f : TimeM T (α → β)) (x : Unit → TimeM T α) :
132
leanexplore_declaration
leanexplore:386499
leanexplore_sqlite
leanexplore_declarations
@[simp] theorem ret_seq {α β} [Add T] (f : TimeM T (α → β)) (x : Unit → TimeM T α) : (Seq.seq f x).ret = f.ret (x ()).ret := rfl
233
leanexplore_declaration
leanexplore:386500
leanexplore_sqlite
leanexplore_declarations
@[simp, grind =] theorem time_bind {α β} [Add T] (m : TimeM T α) (f : α → TimeM T β) : (m >>= f).time = m.time + (f m.ret).time := rfl @[simp, grind =] theorem time_pure {α} [Zero T] (a : α) : (pure a : TimeM T α).time = 0 := rfl
195
leanexplore_declaration
leanexplore:386501
leanexplore_sqlite
leanexplore_declarations
@[simp, grind =] theorem time_pure {α} [Zero T] (a : α) : (pure a : TimeM T α).time = 0 := rfl @[simp, grind =] theorem time_map {α β} (f : α → β) (x : TimeM T α) : (f <$> x).time = x.time := rfl