Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Algorithm/Algebra/BigOperators/DFinsupp'.lean
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,15 @@ variable {R S : Type*}
variable [∀ (i) (x : β i), Decidable (x ≠ d i)]

@[to_additive (attr := simp, norm_cast)]
theorem coe_dfinsupp'_prod [Monoid R] [CommMonoid S] (f : Π₀' i, [β i, d i]) (g : ∀ i, β i → R →* S) :
theorem coe_dfinsupp'_prod [Monoid R] [CommMonoid S]
(f : Π₀' i, [β i, d i]) (g : ∀ i, β i → R →* S) :
⇑(f.prod g) = f.prod fun a b => ⇑(g a b) :=
coe_finset_prod _ _

@[to_additive]
theorem dfinsupp'_prod_apply [Monoid R] [CommMonoid S] (f : Π₀' i, [β i, d i]) (g : ∀ i, β i → R →* S)
(r : R) : (f.prod g) r = f.prod fun a b => (g a b) r :=
theorem dfinsupp'_prod_apply [Monoid R] [CommMonoid S]
(f : Π₀' i, [β i, d i]) (g : ∀ i, β i → R →* S) (r : R) :
(f.prod g) r = f.prod fun a b => (g a b) r :=
finset_prod_apply _ _ _

end MonoidHom
Expand Down
1 change: 1 addition & 0 deletions Algorithm/Data/Classes/IndexedMinHeap.lean
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Authors: Yuyang Zhao
import Algorithm.Data.Classes.AssocArray
import Algorithm.Data.Classes.MinHeap
import Algorithm.Data.Classes.ToList
import Mathlib.Data.Finset.Lattice.Fold
import Mathlib.Data.Prod.Lex

class IndexedMinHeap (C : Type*) [Inhabited C] (ι : outParam Type*)
Expand Down
4 changes: 2 additions & 2 deletions Algorithm/Data/Classes/MinHeap.lean
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ lemma coe_eq_head?_of_forall_le (p : α → Prop) (hc : ¬isEmpty c) (pc : p (he
(x : α) (hx : x ∈ c) (h : ∀ y ∈ c, p y → y ≠ x → x < y) :
x = head? c := by
contrapose! h
exact ⟨head c (ToMultiset.not_isEmpty_of_mem hx), MinHeap.head_mem _ _, pc, by intro h'; simp [← h'] at h,
fun h' ↦ (h'.trans_le (head_le c _ hx)).ne rfl⟩
exact ⟨head c (ToMultiset.not_isEmpty_of_mem hx), MinHeap.head_mem _ _, pc,
by intro h'; simp [← h'] at h, fun h' ↦ (h'.trans_le (head_le c _ hx)).ne rfl⟩

lemma eq_head_of_forall_le (p : α → Prop) (hc : ¬isEmpty c) (pc : p (head c hc))
(x : α) (hx : x ∈ c) (h : ∀ y ∈ c, p y → y ≠ x → x < y) :
Expand Down
9 changes: 5 additions & 4 deletions Algorithm/Data/DFinsupp'/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,14 @@ def comapDomain' (h : κ → ι) {h' : ι → κ} (hh' : Function.LeftInverse h'
(s.prop (h x)).imp_left fun hx => Multiset.mem_map.mpr ⟨_, hx, hh' _⟩⟩

@[simp]
theorem comapDomain'_apply (h : κ → ι) {h' : ι → κ}
(hh' : Function.LeftInverse h' h) (f : Π₀' i, [β i, d i]) (k : κ) : comapDomain' h hh' f k = f (h k) :=
theorem comapDomain'_apply (h : κ → ι) {h' : ι → κ} (hh' : Function.LeftInverse h' h)
(f : Π₀' i, [β i, d i]) (k : κ) :
comapDomain' h hh' f k = f (h k) :=
rfl

@[simp]
theorem comapDomain'_default (h : κ → ι) {h' : ι → κ}
(hh' : Function.LeftInverse h' h) : comapDomain' h hh' (default : Π₀' i, [β i, d i]) = default := by
theorem comapDomain'_default (h : κ → ι) {h' : ι → κ} (hh' : Function.LeftInverse h' h) :
comapDomain' h hh' (default : Π₀' i, [β i, d i]) = default := by
ext
rw [default_apply, comapDomain'_apply, default_apply]

Expand Down
13 changes: 6 additions & 7 deletions Algorithm/Data/DFinsupp'/Defs.lean
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Copyright (c) 2024 Yuyang Zhao. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yuyang Zhao
-/
import Mathlib.Data.Set.Finite
import Mathlib.Data.Set.Finite.Basic

/-!
Modified from `Mathlib.Data.DFinsupp.Basic`
Expand Down Expand Up @@ -276,9 +276,8 @@ theorem single_eq_of_ne {i i' b} (h : i ≠ i') : single d i b i' = d i' := by
theorem single_injective {i} : Function.Injective (single d i) := fun _ _ H =>
Function.update_injective _ i <| DFunLike.coe_injective.eq_iff.mpr H

/-- Like `Finsupp'.single_eq_single_iff`, but with a `HEq` due to dependent types -/
theorem single_eq_single_iff (i j : ι) (xi : β i) (xj : β j) :
DFinsupp'.single d i xi = DFinsupp'.single d j xj ↔ i = j ∧ HEq xi xj ∨ xi = d i ∧ xj = d j := by
single d i xi = single d j xj ↔ i = j ∧ HEq xi xj ∨ xi = d i ∧ xj = d j := by
constructor
· intro h
by_cases hij : i = j
Expand Down Expand Up @@ -314,14 +313,14 @@ theorem single_eq_of_sigma_eq {i j} {xi : β i} {xj : β j} (h : (⟨i, xi⟩ :

@[simp]
theorem equivFunOnFintype_single [Fintype ι] (i : ι) (m : β i) :
(@DFinsupp'.equivFunOnFintype ι β _ _) (DFinsupp'.single d i m) = Function.update d i m := by
DFinsupp'.equivFunOnFintype (DFinsupp'.single d i m) = Function.update d i m := by
ext x
dsimp [Pi.single, Function.update]
simp [DFinsupp'.single_eq_functionUpdate, @eq_comm _ i]

@[simp]
theorem equivFunOnFintype_symm_single [Fintype ι] (i : ι) (m : β i) :
(@DFinsupp'.equivFunOnFintype ι β _ _).symm (Function.update d i m) = DFinsupp'.single d i m := by
DFinsupp'.equivFunOnFintype.symm (Function.update d i m) = DFinsupp'.single d i m := by
ext i'
simp only [← single_eq_functionUpdate, equivFunOnFintype_symm_coe]

Expand Down Expand Up @@ -605,9 +604,9 @@ theorem support_erase (i : ι) (f : Π₀' i, [β i, d i]) :
(f.erase i).support = f.support.erase i := by
ext j
by_cases h1 : j = i
simp only [h1, mem_support_toFun, erase_apply, ite_true, ne_eq, not_true, not_not,
· simp only [h1, mem_support_toFun, erase_apply, ite_true, ne_eq, not_true, not_not,
Finset.mem_erase, false_and]
by_cases h2 : f j ≠ d j <;> simp at h2 <;> simp [h1, h2]
· by_cases h2 : f j ≠ d j <;> simp at h2 <;> simp [h1, h2]

theorem support_update_ne (f : Π₀' i, [β i, d i]) (i : ι) {b : β i} (h : b ≠ d i) :
support (f.update i b) = insert i f.support := by
Expand Down
2 changes: 1 addition & 1 deletion Algorithm/Data/DFinsupp'/Fintype.lean
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yuyang Zhao
-/
import Algorithm.Data.DFinsupp'.Defs
import Mathlib.Data.Fintype.Basic
import Mathlib.Data.Fintype.Pi

/-!
Modified from `Mathlib.Data.DFinsupp.Basic`
Expand Down
3 changes: 2 additions & 1 deletion Algorithm/Data/Graph/IsDFSForest.lean
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ lemma sound (hf : g..IsDFSForest i o f) :
rintro w (rfl | hw | hw)
· exact ⟨w, .inl rfl, .refl _ _⟩
· obtain ⟨r, hr, hrw⟩ := ihc w hw
exact ⟨_, .inl rfl, (mem_succSet_singleton_iff.mp (roots_subset_succ hr)).to_reachable.trans hrw⟩
exact ⟨_, .inl rfl,
(mem_succSet_singleton_iff.mp (roots_subset_succ hr)).to_reachable.trans hrw⟩
· obtain ⟨r, hr, hrw⟩ := ihs w hw
exact ⟨r, .inr hr, hrw⟩

Expand Down
2 changes: 2 additions & 0 deletions Algorithm/Data/PairingHeap.lean
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,5 @@ instance [Preorder α] [IsTotal α (· ≤ ·)] [DecidableRel (α := α) (· ≤
change _ = Multiset.erase _ a
simp
deleteMin_def x := by match x with | ⟨.nil, _⟩ | ⟨.node _ _ _, _⟩ => rfl

end Batteries.PairingHeap
2 changes: 2 additions & 0 deletions Algorithm/Graph/DFS.lean
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,5 @@ lemma dfsTR_spec (g : G)
trans g..traversal {v | (g..dfsTR vs (default : BoolArray))[v]} ∅
· convert g..dfsTR_spec' vs (default : BoolArray) <;> aesop
· simp

end AdjListClass
10 changes: 6 additions & 4 deletions Algorithm/Graph/Dijkstra.lean
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ lemma dijkstraStep_fst_getElem' (g : G) (c : Info → CostType)
decreaseKeysD_getElem, toMultiset_list, ← Multiset.filterMap_coe, coe_toList, ne_eq]
split_ifs with h
· simp? [Function.update_apply] says
simp only [Function.update_apply, min_eq_top, ite_eq_left_iff, Multiset.inf_eq_top,
simp only [Function.update_apply, inf_eq_top_iff, ite_eq_left_iff, Multiset.inf_eq_top,
Multiset.mem_filterMap, mem_toMultiset, Option.ite_none_right_eq_some, Option.some.injEq,
Prod.exists, Prod.mk.injEq, exists_eq_right_right, exists_eq_right, forall_exists_index,
and_imp]
Expand Down Expand Up @@ -506,7 +506,7 @@ lemma dijkstraStep_fst_getElem_eq_top (g : G) (c : Info → CostType)
dsimp
rw [dijkstraStep_fst_getElem (spec₁ := spec₁)]
simp? [hMinIdx, - not_or] says
simp only [ne_eq, ite_eq_left_iff, min_eq_top, Finset.inf_eq_top_iff, Finset.mem_univ,
simp only [ne_eq, ite_eq_left_iff, inf_eq_top_iff, Finset.inf_eq_top_iff, Finset.mem_univ,
WithTop.add_eq_top, hMinIdx, WithTop.coe_ne_top, or_self, imp_false, not_true_eq_false,
succSet_singleton, Set.mem_setOf_eq]
rw [← or_iff_not_imp_right]
Expand Down Expand Up @@ -682,7 +682,8 @@ def dijkstra (g : G) (c : Info → CostType)
(go init default spec_init).val.2
where
go (heap : DistHeap) (res : DistArray) (spec : dijkstraStep.Spec g c init heap res) :
{ hr : DistHeap × DistArray // dijkstraStep.Spec g c init hr.1 hr.2 ∧ hr.1[minIdx hr.1] = ⊤ } :=
{ hr : DistHeap × DistArray //
dijkstraStep.Spec g c init hr.1 hr.2 ∧ hr.1[minIdx hr.1] = ⊤ } :=
if hh : heap[minIdx heap] = ⊤ then
⟨(heap, res), spec, hh⟩
else
Expand All @@ -691,7 +692,8 @@ where
letI : DecidableEq V := by classical infer_instance
simp only [dijkstraStep_snd_getElem_eq_top, ne_eq, Set.coe_setOf, Set.mem_setOf_eq, hr]
exact Fintype.card_lt_of_injective_of_not_mem (fun ⟨v, hv⟩ ↦ ⟨v, hv.2⟩)
(by intro ⟨v, hv⟩ ⟨w, hw⟩; simp) (b := ⟨minIdx heap, (spec.1 _).resolve_left hh⟩) (by simp)
(by intro ⟨v, hv⟩ ⟨w, hw⟩; simp)
(b := ⟨minIdx heap, (spec.1 _).resolve_left hh⟩) (by simp)
go hr.1 hr.2 (g..dijkstraStep_spec c init heap res spec hh)
termination_by Fintype.card {v : V | res[v] = ⊤}
spec_init : dijkstraStep.Spec g c init init default := by
Expand Down
10 changes: 5 additions & 5 deletions lake-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "git",
"subDir": null,
"scope": "leanprover-community",
"rev": "401646a0c432318bd679969e8870c9331bf7e37b",
"rev": "c933dd9b00271d869e22b802a015092d1e8e454a",
"name": "batteries",
"manifestFile": "lake-manifest.json",
"inputRev": "main",
Expand All @@ -25,7 +25,7 @@
"type": "git",
"subDir": null,
"scope": "leanprover-community",
"rev": "93bcfd774f89d3874903cab06abfbf69f327cbd9",
"rev": "de91b59101763419997026c35a41432ac8691f15",
"name": "aesop",
"manifestFile": "lake-manifest.json",
"inputRev": "master",
Expand Down Expand Up @@ -55,7 +55,7 @@
"type": "git",
"subDir": null,
"scope": "leanprover-community",
"rev": "ac7b989cbf99169509433124ae484318e953d201",
"rev": "119b022b3ea88ec810a677888528e50f8144a26e",
"name": "importGraph",
"manifestFile": "lake-manifest.json",
"inputRev": "main",
Expand All @@ -65,7 +65,7 @@
"type": "git",
"subDir": null,
"scope": "leanprover-community",
"rev": "7bedaed1ef024add1e171cc17706b012a9a37802",
"rev": "d7caecce0d0f003fd5e9cce9a61f1dd6ba83142b",
"name": "LeanSearchClient",
"manifestFile": "lake-manifest.json",
"inputRev": "main",
Expand All @@ -85,7 +85,7 @@
"type": "git",
"subDir": null,
"scope": "leanprover-community",
"rev": "4c285ebed4a964dcac8e9cf809143ca52f8d93f9",
"rev": "698148763dd29cf98dd2c56b8a44ac8e825461ae",
"name": "mathlib",
"manifestFile": "lake-manifest.json",
"inputRev": "master",
Expand Down
40 changes: 29 additions & 11 deletions lakefile.lean
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
import Lake
open Lake DSL

package algorithm where
leanOptions := #[
abbrev algorithmOnlyLinters : Array LeanOption := #[
⟨`linter.hashCommand, true⟩,
⟨`linter.oldObtain, true,⟩,
⟨`linter.refine, true⟩,
⟨`linter.style.cdot, true⟩,
⟨`linter.style.dollarSyntax, true⟩,
⟨`linter.style.header, true⟩,
⟨`linter.style.lambdaSyntax, true⟩,
⟨`linter.style.longLine, true⟩,
⟨`linter.style.longFile, .ofNat 1500⟩,
-- `latest_import.yml` uses this comment: if you edit it, make sure that the workflow still works
⟨`linter.style.missingEnd, true⟩,
⟨`linter.style.multiGoal, true⟩,
⟨`linter.style.setOption, true⟩
]

abbrev algorithmLeanOptions := #[
⟨`pp.unicode.fun, true⟩, -- pretty-prints `fun a ↦ b`
⟨`pp.proofs.withType, false⟩,
⟨`autoImplicit, false⟩,
⟨`relaxedAutoImplicit, false⟩
]
moreLinkArgs := #[
"-L./.lake/build/lib",
"-lstdc++"
]
⟨`autoImplicit, false⟩
] ++ -- options that are used in `lake build`
algorithmOnlyLinters.map fun s ↦ { s with name := `weak ++ s.name }

package algorithm where

require "leanprover-community" / "mathlib" @ git "master"
require "leanprover" / "doc-gen4" @ git "main"
Expand All @@ -22,7 +34,13 @@ lean_lib Mutable where

@[default_target]
lean_lib Algorithm where
roots := #[`Algorithm]
leanOptions := algorithmLeanOptions
-- Mathlib also enforces these linter options, which are not active by default.
moreServerOptions := algorithmOnlyLinters
moreLinkArgs := #[
"-L./.lake/build/lib",
"-lstdc++"
]

target ffi.o pkg : System.FilePath := do
let oFile := pkg.buildDir / "cpp" / "ffi.o"
Expand Down
2 changes: 1 addition & 1 deletion lean-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
leanprover/lean4:v4.14.0-rc1
leanprover/lean4:v4.14.0-rc2