fact stringlengths 6 3.84k | type stringclasses 11
values | library stringclasses 32
values | imports listlengths 1 14 | filename stringlengths 20 95 | symbolic_name stringlengths 1 90 | docstring stringlengths 7 20k ⌀ |
|---|---|---|---|---|---|---|
id₁? (e : Expr) : MonoidalM (Option Obj) := do
let ctx ← read
match ctx.instMonoidal? with
| some _monoidal => do
if ← withDefault <| isDefEq e (q(𝟙_ _) : Q($ctx.C)) then
return some ⟨none⟩
else
return none
| _ => return none | def | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.Datatypes",
"Mathlib.Tactic.CategoryTheory.MonoidalComp"
] | Mathlib/Tactic/CategoryTheory/Monoidal/Datatypes.lean | id₁ | Check that `e` is definitionally equal to `𝟙_ C`. |
comp? (e : Expr) : MonoidalM (Option (Mor₁ × Mor₁)) := do
let ctx ← read
let f ← mkFreshExprMVarQ ctx.C
let g ← mkFreshExprMVarQ ctx.C
match ctx.instMonoidal? with
| some _monoidal => do
if ← withDefault <| isDefEq e q($f ⊗ $g) then
let f ← instantiateMVars f
let g ← instantiateMVars g... | def | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.Datatypes",
"Mathlib.Tactic.CategoryTheory.MonoidalComp"
] | Mathlib/Tactic/CategoryTheory/Monoidal/Datatypes.lean | comp | Return `(f, g)` if `e` is definitionally equal to `f ⊗ g`. |
partial mor₁OfExpr (e : Expr) : MonoidalM Mor₁ := do
if let some f := (← get).cache.find? e then
return f
let f ←
if let some a ← id₁? e then
MonadMor₁.id₁M a
else if let some (f, g) ← comp? e then
MonadMor₁.comp₁M (← mor₁OfExpr f.e) (← mor₁OfExpr g.e)
else
return Mor₁.of ⟨e, ⟨none... | def | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.Datatypes",
"Mathlib.Tactic.CategoryTheory.MonoidalComp"
] | Mathlib/Tactic/CategoryTheory/Monoidal/Datatypes.lean | mor₁OfExpr | Construct a `Mor₁` expression from a Lean expression. |
partial Mor₂IsoOfExpr (e : Expr) : MonoidalM Mor₂Iso := do
match (← whnfR e).getAppFnArgs with
| (``MonoidalCategoryStruct.associator, #[_, _, _, f, g, h]) =>
associatorM' (← MkMor₁.ofExpr f) (← MkMor₁.ofExpr g) (← MkMor₁.ofExpr h)
| (``MonoidalCategoryStruct.leftUnitor, #[_, _, _, f]) =>
leftUnitorM' (← ... | def | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.Datatypes",
"Mathlib.Tactic.CategoryTheory.MonoidalComp"
] | Mathlib/Tactic/CategoryTheory/Monoidal/Datatypes.lean | Mor₂IsoOfExpr | Construct a `Mor₂Iso` term from a Lean expression. |
partial Mor₂OfExpr (e : Expr) : MonoidalM Mor₂ := do
match ← whnfR e with
| .proj ``Iso 0 η => homM (← Mor₂IsoOfExpr η)
| .proj ``Iso 1 η => invM (← Mor₂IsoOfExpr η)
| .app .. => match (← whnfR e).getAppFnArgs with
| (``CategoryStruct.id, #[_, _, f]) => id₂M (← MkMor₁.ofExpr f)
| (``CategoryStruct.comp,... | def | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.Datatypes",
"Mathlib.Tactic.CategoryTheory.MonoidalComp"
] | Mathlib/Tactic/CategoryTheory/Monoidal/Datatypes.lean | Mor₂OfExpr | Construct a `Mor₂` term from a Lean expression. |
@[nolint synTaut]
evalComp_nil_nil {f g h : C} (α : f ≅ g) (β : g ≅ h) :
(α ≪≫ β).hom = (α ≪≫ β).hom := by
simp | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.Normalize",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/Normalize.lean | evalComp_nil_nil | null |
evalComp_nil_cons {f g h i j : C} (α : f ≅ g) (β : g ≅ h) (η : h ⟶ i) (ηs : i ⟶ j) :
α.hom ≫ (β.hom ≫ η ≫ ηs) = (α ≪≫ β).hom ≫ η ≫ ηs := by
simp | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.Normalize",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/Normalize.lean | evalComp_nil_cons | null |
evalComp_cons {f g h i j : C} (α : f ≅ g) (η : g ⟶ h) {ηs : h ⟶ i} {θ : i ⟶ j} {ι : h ⟶ j}
(e_ι : ηs ≫ θ = ι) :
(α.hom ≫ η ≫ ηs) ≫ θ = α.hom ≫ η ≫ ι := by
simp [e_ι] | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.Normalize",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/Normalize.lean | evalComp_cons | null |
eval_comp
{η η' : f ⟶ g} {θ θ' : g ⟶ h} {ι : f ⟶ h}
(e_η : η = η') (e_θ : θ = θ') (e_ηθ : η' ≫ θ' = ι) :
η ≫ θ = ι := by
simp [e_η, e_θ, e_ηθ] | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.Normalize",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/Normalize.lean | eval_comp | null |
eval_of (η : f ⟶ g) :
η = (Iso.refl _).hom ≫ η ≫ (Iso.refl _).hom := by
simp | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.Normalize",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/Normalize.lean | eval_of | null |
eval_monoidalComp
{η η' : f ⟶ g} {α : g ≅ h} {θ θ' : h ⟶ i} {αθ : g ⟶ i} {ηαθ : f ⟶ i}
(e_η : η = η') (e_θ : θ = θ') (e_αθ : α.hom ≫ θ' = αθ) (e_ηαθ : η' ≫ αθ = ηαθ) :
η ≫ α.hom ≫ θ = ηαθ := by
simp [e_η, e_θ, e_αθ, e_ηαθ]
variable [MonoidalCategory C]
@[nolint synTaut] | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.Normalize",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/Normalize.lean | eval_monoidalComp | null |
evalWhiskerLeft_nil (f : C) {g h : C} (α : g ≅ h) :
(whiskerLeftIso f α).hom = (whiskerLeftIso f α).hom := by
simp | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.Normalize",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/Normalize.lean | evalWhiskerLeft_nil | null |
evalWhiskerLeft_of_cons {f g h i j : C}
(α : g ≅ h) (η : h ⟶ i) {ηs : i ⟶ j} {θ : f ⊗ i ⟶ f ⊗ j} (e_θ : f ◁ ηs = θ) :
f ◁ (α.hom ≫ η ≫ ηs) = (whiskerLeftIso f α).hom ≫ f ◁ η ≫ θ := by
simp [e_θ] | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.Normalize",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/Normalize.lean | evalWhiskerLeft_of_cons | null |
evalWhiskerLeft_comp {f g h i : C}
{η : h ⟶ i} {η₁ : g ⊗ h ⟶ g ⊗ i} {η₂ : f ⊗ g ⊗ h ⟶ f ⊗ g ⊗ i}
{η₃ : f ⊗ g ⊗ h ⟶ (f ⊗ g) ⊗ i} {η₄ : (f ⊗ g) ⊗ h ⟶ (f ⊗ g) ⊗ i}
(e_η₁ : g ◁ η = η₁) (e_η₂ : f ◁ η₁ = η₂)
(e_η₃ : η₂ ≫ (α_ _ _ _).inv = η₃) (e_η₄ : (α_ _ _ _).hom ≫ η₃ = η₄) :
(f ⊗ g) ◁ η = η₄ := by
sim... | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.Normalize",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/Normalize.lean | evalWhiskerLeft_comp | null |
evalWhiskerLeft_id {f g : C} {η : f ⟶ g}
{η₁ : f ⟶ 𝟙_ C ⊗ g} {η₂ : 𝟙_ C ⊗ f ⟶ 𝟙_ C ⊗ g}
(e_η₁ : η ≫ (λ_ _).inv = η₁) (e_η₂ : (λ_ _).hom ≫ η₁ = η₂) :
𝟙_ C ◁ η = η₂ := by
simp [e_η₁, e_η₂] | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.Normalize",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/Normalize.lean | evalWhiskerLeft_id | null |
eval_whiskerLeft {f g h : C}
{η η' : g ⟶ h} {θ : f ⊗ g ⟶ f ⊗ h}
(e_η : η = η') (e_θ : f ◁ η' = θ) :
f ◁ η = θ := by
simp [e_η, e_θ] | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.Normalize",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/Normalize.lean | eval_whiskerLeft | null |
eval_whiskerRight {f g h : C}
{η η' : f ⟶ g} {θ : f ⊗ h ⟶ g ⊗ h}
(e_η : η = η') (e_θ : η' ▷ h = θ) :
η ▷ h = θ := by
simp [e_η, e_θ] | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.Normalize",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/Normalize.lean | eval_whiskerRight | null |
eval_tensorHom {f g h i : C}
{η η' : f ⟶ g} {θ θ' : h ⟶ i} {ι : f ⊗ h ⟶ g ⊗ i}
(e_η : η = η') (e_θ : θ = θ') (e_ι : η' ⊗ₘ θ' = ι) :
η ⊗ₘ θ = ι := by
simp [e_η, e_θ, e_ι]
@[nolint synTaut] | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.Normalize",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/Normalize.lean | eval_tensorHom | null |
evalWhiskerRight_nil {f g : C} (α : f ≅ g) (h : C) :
(whiskerRightIso α h).hom = (whiskerRightIso α h).hom := by
simp | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.Normalize",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/Normalize.lean | evalWhiskerRight_nil | null |
evalWhiskerRight_cons_of_of {f g h i j : C}
{α : f ≅ g} {η : g ⟶ h} {ηs : h ⟶ i} {ηs₁ : h ⊗ j ⟶ i ⊗ j}
{η₁ : g ⊗ j ⟶ h ⊗ j} {η₂ : g ⊗ j ⟶ i ⊗ j} {η₃ : f ⊗ j ⟶ i ⊗ j}
(e_ηs₁ : ηs ▷ j = ηs₁) (e_η₁ : η ▷ j = η₁)
(e_η₂ : η₁ ≫ ηs₁ = η₂) (e_η₃ : (whiskerRightIso α j).hom ≫ η₂ = η₃) :
(α.hom ≫ η ≫ ηs) ▷ j ... | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.Normalize",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/Normalize.lean | evalWhiskerRight_cons_of_of | null |
evalWhiskerRight_cons_whisker {f g h i j k : C}
{α : g ≅ f ⊗ h} {η : h ⟶ i} {ηs : f ⊗ i ⟶ j}
{η₁ : h ⊗ k ⟶ i ⊗ k} {η₂ : f ⊗ (h ⊗ k) ⟶ f ⊗ (i ⊗ k)} {ηs₁ : (f ⊗ i) ⊗ k ⟶ j ⊗ k}
{ηs₂ : f ⊗ (i ⊗ k) ⟶ j ⊗ k} {η₃ : f ⊗ (h ⊗ k) ⟶ j ⊗ k} {η₄ : (f ⊗ h) ⊗ k ⟶ j ⊗ k}
{η₅ : g ⊗ k ⟶ j ⊗ k}
(e_η₁ : ((Iso.refl _).... | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.Normalize",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/Normalize.lean | evalWhiskerRight_cons_whisker | null |
evalWhiskerRight_comp {f f' g h : C}
{η : f ⟶ f'} {η₁ : f ⊗ g ⟶ f' ⊗ g} {η₂ : (f ⊗ g) ⊗ h ⟶ (f' ⊗ g) ⊗ h}
{η₃ : (f ⊗ g) ⊗ h ⟶ f' ⊗ (g ⊗ h)} {η₄ : f ⊗ (g ⊗ h) ⟶ f' ⊗ (g ⊗ h)}
(e_η₁ : η ▷ g = η₁) (e_η₂ : η₁ ▷ h = η₂)
(e_η₃ : η₂ ≫ (α_ _ _ _).hom = η₃) (e_η₄ : (α_ _ _ _).inv ≫ η₃ = η₄) :
η ▷ (g ⊗ h) = η... | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.Normalize",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/Normalize.lean | evalWhiskerRight_comp | null |
evalWhiskerRight_id {f g : C}
{η : f ⟶ g} {η₁ : f ⟶ g ⊗ 𝟙_ C} {η₂ : f ⊗ 𝟙_ C ⟶ g ⊗ 𝟙_ C}
(e_η₁ : η ≫ (ρ_ _).inv = η₁) (e_η₂ : (ρ_ _).hom ≫ η₁ = η₂) :
η ▷ 𝟙_ C = η₂ := by
simp [e_η₁, e_η₂] | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.Normalize",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/Normalize.lean | evalWhiskerRight_id | null |
evalWhiskerRightAux_of {f g : C} (η : f ⟶ g) (h : C) :
η ▷ h = (Iso.refl _).hom ≫ η ▷ h ≫ (Iso.refl _).hom := by
simp | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.Normalize",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/Normalize.lean | evalWhiskerRightAux_of | null |
evalWhiskerRightAux_cons {f g h i j : C} {η : g ⟶ h} {ηs : i ⟶ j}
{ηs' : i ⊗ f ⟶ j ⊗ f} {η₁ : g ⊗ (i ⊗ f) ⟶ h ⊗ (j ⊗ f)}
{η₂ : g ⊗ (i ⊗ f) ⟶ (h ⊗ j) ⊗ f} {η₃ : (g ⊗ i) ⊗ f ⟶ (h ⊗ j) ⊗ f}
(e_ηs' : ηs ▷ f = ηs') (e_η₁ : ((Iso.refl _).hom ≫ η ≫ (Iso.refl _).hom) ⊗ₘ ηs' = η₁)
(e_η₂ : η₁ ≫ (α_ _ _ _).inv = η... | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.Normalize",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/Normalize.lean | evalWhiskerRightAux_cons | null |
evalWhiskerRight_cons_of {f f' g h i : C} {α : f' ≅ g} {η : g ⟶ h} {ηs : h ⟶ i}
{ηs₁ : h ⊗ f ⟶ i ⊗ f} {η₁ : g ⊗ f ⟶ h ⊗ f} {η₂ : g ⊗ f ⟶ i ⊗ f}
{η₃ : f' ⊗ f ⟶ i ⊗ f}
(e_ηs₁ : ηs ▷ f = ηs₁) (e_η₁ : η ▷ f = η₁)
(e_η₂ : η₁ ≫ ηs₁ = η₂) (e_η₃ : (whiskerRightIso α f).hom ≫ η₂ = η₃) :
(α.hom ≫ η ≫ ηs) ▷ f ... | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.Normalize",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/Normalize.lean | evalWhiskerRight_cons_of | null |
evalHorizontalCompAux_of {f g h i : C} (η : f ⟶ g) (θ : h ⟶ i) :
η ⊗ₘ θ = (Iso.refl _).hom ≫ (η ⊗ₘ θ) ≫ (Iso.refl _).hom := by
simp | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.Normalize",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/Normalize.lean | evalHorizontalCompAux_of | null |
evalHorizontalCompAux_cons {f f' g g' h i : C} {η : f ⟶ g} {ηs : f' ⟶ g'} {θ : h ⟶ i}
{ηθ : f' ⊗ h ⟶ g' ⊗ i} {η₁ : f ⊗ (f' ⊗ h) ⟶ g ⊗ (g' ⊗ i)}
{ηθ₁ : f ⊗ (f' ⊗ h) ⟶ (g ⊗ g') ⊗ i} {ηθ₂ : (f ⊗ f') ⊗ h ⟶ (g ⊗ g') ⊗ i}
(e_ηθ : ηs ⊗ₘ θ = ηθ) (e_η₁ : ((Iso.refl _).hom ≫ η ≫ (Iso.refl _).hom) ⊗ₘ ηθ = η₁)
(e_η... | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.Normalize",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/Normalize.lean | evalHorizontalCompAux_cons | null |
evalHorizontalCompAux'_whisker {f f' g g' h : C} {η : g ⟶ h} {θ : f' ⟶ g'}
{ηθ : g ⊗ f' ⟶ h ⊗ g'} {η₁ : f ⊗ (g ⊗ f') ⟶ f ⊗ (h ⊗ g')}
{η₂ : f ⊗ (g ⊗ f') ⟶ (f ⊗ h) ⊗ g'} {η₃ : (f ⊗ g) ⊗ f' ⟶ (f ⊗ h) ⊗ g'}
(e_ηθ : η ⊗ₘ θ = ηθ) (e_η₁ : f ◁ ηθ = η₁)
(e_η₂ : η₁ ≫ (α_ _ _ _).inv = η₂) (e_η₃ : (α_ _ _ _).hom ≫ ... | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.Normalize",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/Normalize.lean | evalHorizontalCompAux'_whisker | null |
evalHorizontalCompAux'_of_whisker {f f' g g' h : C} {η : g ⟶ h} {θ : f' ⟶ g'}
{η₁ : g ⊗ f ⟶ h ⊗ f} {ηθ : (g ⊗ f) ⊗ f' ⟶ (h ⊗ f) ⊗ g'}
{ηθ₁ : (g ⊗ f) ⊗ f' ⟶ h ⊗ (f ⊗ g')}
{ηθ₂ : g ⊗ (f ⊗ f') ⟶ h ⊗ (f ⊗ g')}
(e_η₁ : η ▷ f = η₁) (e_ηθ : η₁ ⊗ₘ ((Iso.refl _).hom ≫ θ ≫ (Iso.refl _).hom) = ηθ)
(e_ηθ₁ : ηθ ... | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.Normalize",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/Normalize.lean | evalHorizontalCompAux'_of_whisker | null |
evalHorizontalComp_nil_nil {f g h i : C} (α : f ≅ g) (β : h ≅ i) :
(α ⊗ᵢ β).hom = (α ⊗ᵢ β).hom := by
simp | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.Normalize",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/Normalize.lean | evalHorizontalComp_nil_nil | null |
evalHorizontalComp_nil_cons {f f' g g' h i : C}
{α : f ≅ g} {β : f' ≅ g'} {η : g' ⟶ h} {ηs : h ⟶ i}
{η₁ : g ⊗ g' ⟶ g ⊗ h} {ηs₁ : g ⊗ h ⟶ g ⊗ i}
{η₂ : g ⊗ g' ⟶ g ⊗ i} {η₃ : f ⊗ f' ⟶ g ⊗ i}
(e_η₁ : g ◁ ((Iso.refl _).hom ≫ η ≫ (Iso.refl _).hom) = η₁)
(e_ηs₁ : g ◁ ηs = ηs₁) (e_η₂ : η₁ ≫ ηs₁ = η₂)
(e... | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.Normalize",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/Normalize.lean | evalHorizontalComp_nil_cons | null |
evalHorizontalComp_cons_nil {f f' g g' h i : C}
{α : f ≅ g} {η : g ⟶ h} {ηs : h ⟶ i} {β : f' ≅ g'}
{η₁ : g ⊗ g' ⟶ h ⊗ g'} {ηs₁ : h ⊗ g' ⟶ i ⊗ g'} {η₂ : g ⊗ g' ⟶ i ⊗ g'} {η₃ : f ⊗ f' ⟶ i ⊗ g'}
(e_η₁ : ((Iso.refl _).hom ≫ η ≫ (Iso.refl _).hom) ▷ g' = η₁) (e_ηs₁ : ηs ▷ g' = ηs₁)
(e_η₂ : η₁ ≫ ηs₁ = η₂) (e_η... | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.Normalize",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/Normalize.lean | evalHorizontalComp_cons_nil | null |
evalHorizontalComp_cons_cons {f f' g g' h h' i i' : C}
{α : f ≅ g} {η : g ⟶ h} {ηs : h ⟶ i}
{β : f' ≅ g'} {θ : g' ⟶ h'} {θs : h' ⟶ i'}
{ηθ : g ⊗ g' ⟶ h ⊗ h'} {ηθs : h ⊗ h' ⟶ i ⊗ i'}
{ηθ₁ : g ⊗ g' ⟶ i ⊗ i'} {ηθ₂ : f ⊗ f' ⟶ i ⊗ i'}
(e_ηθ : η ⊗ₘ θ = ηθ) (e_ηθs : ηs ⊗ₘ θs = ηθs)
(e_ηθ₁ : ηθ ≫ ηθs = ... | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.Normalize",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/Normalize.lean | evalHorizontalComp_cons_cons | null |
normalizeIsoComp {p f g pf pfg : C} (η_f : p ⊗ f ≅ pf) (η_g : pf ⊗ g ≅ pfg) :=
(α_ _ _ _).symm ≪≫ whiskerRightIso η_f g ≪≫ η_g | abbrev | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.PureCoherence",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/PureCoherence.lean | normalizeIsoComp | The composition of the normalizing isomorphisms `η_f : p ⊗ f ≅ pf` and `η_g : pf ⊗ g ≅ pfg`. |
naturality_associator {p f g h pf pfg pfgh : C}
(η_f : p ⊗ f ≅ pf) (η_g : pf ⊗ g ≅ pfg) (η_h : pfg ⊗ h ≅ pfgh) :
p ◁ (α_ f g h) ≪≫ normalizeIsoComp η_f (normalizeIsoComp η_g η_h) =
normalizeIsoComp (normalizeIsoComp η_f η_g) η_h :=
Iso.ext (by simp) | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.PureCoherence",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/PureCoherence.lean | naturality_associator | null |
naturality_leftUnitor {p f pf : C} (η_f : p ⊗ f ≅ pf) :
p ◁ (λ_ f) ≪≫ η_f = normalizeIsoComp (ρ_ p) η_f :=
Iso.ext (by simp) | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.PureCoherence",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/PureCoherence.lean | naturality_leftUnitor | null |
naturality_rightUnitor {p f pf : C} (η_f : p ⊗ f ≅ pf) :
p ◁ (ρ_ f) ≪≫ η_f = normalizeIsoComp η_f (ρ_ pf) :=
Iso.ext (by simp) | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.PureCoherence",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/PureCoherence.lean | naturality_rightUnitor | null |
naturality_id {p f pf : C} (η_f : p ⊗ f ≅ pf) :
p ◁ Iso.refl f ≪≫ η_f = η_f := by
simp | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.PureCoherence",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/PureCoherence.lean | naturality_id | null |
naturality_comp {p f g h pf : C} {η : f ≅ g} {θ : g ≅ h}
(η_f : p ⊗ f ≅ pf) (η_g : p ⊗ g ≅ pf) (η_h : p ⊗ h ≅ pf)
(ih_η : p ◁ η ≪≫ η_g = η_f) (ih_θ : p ◁ θ ≪≫ η_h = η_g) :
p ◁ (η ≪≫ θ) ≪≫ η_h = η_f := by
simp_all | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.PureCoherence",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/PureCoherence.lean | naturality_comp | null |
naturality_whiskerLeft {p f g h pf pfg : C} {η : g ≅ h}
(η_f : p ⊗ f ≅ pf) (η_fg : pf ⊗ g ≅ pfg) (η_fh : (pf ⊗ h) ≅ pfg)
(ih_η : pf ◁ η ≪≫ η_fh = η_fg) :
p ◁ (f ◁ η) ≪≫ normalizeIsoComp η_f η_fh = normalizeIsoComp η_f η_fg := by
rw [← ih_η]
apply Iso.ext
simp [← whisker_exchange_assoc] | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.PureCoherence",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/PureCoherence.lean | naturality_whiskerLeft | null |
naturality_whiskerRight {p f g h pf pfh : C} {η : f ≅ g}
(η_f : p ⊗ f ≅ pf) (η_g : p ⊗ g ≅ pf) (η_fh : (pf ⊗ h) ≅ pfh)
(ih_η : p ◁ η ≪≫ η_g = η_f) :
p ◁ (η ▷ h) ≪≫ normalizeIsoComp η_g η_fh = normalizeIsoComp η_f η_fh := by
rw [← ih_η]
apply Iso.ext
simp | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.PureCoherence",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/PureCoherence.lean | naturality_whiskerRight | null |
naturality_tensorHom {p f₁ g₁ f₂ g₂ pf₁ pf₁f₂ : C} {η : f₁ ≅ g₁} {θ : f₂ ≅ g₂}
(η_f₁ : p ⊗ f₁ ≅ pf₁) (η_g₁ : p ⊗ g₁ ≅ pf₁) (η_f₂ : pf₁ ⊗ f₂ ≅ pf₁f₂) (η_g₂ : pf₁ ⊗ g₂ ≅ pf₁f₂)
(ih_η : p ◁ η ≪≫ η_g₁ = η_f₁)
(ih_θ : pf₁ ◁ θ ≪≫ η_g₂ = η_f₂) :
p ◁ (η ⊗ᵢ θ) ≪≫ normalizeIsoComp η_g₁ η_g₂ = normalizeIsoComp η_f... | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.PureCoherence",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/PureCoherence.lean | naturality_tensorHom | null |
naturality_inv {p f g pf : C} {η : f ≅ g}
(η_f : p ⊗ f ≅ pf) (η_g : p ⊗ g ≅ pf) (ih : p ◁ η ≪≫ η_g = η_f) :
p ◁ η.symm ≪≫ η_f = η_g := by
rw [← ih]
apply Iso.ext
simp | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.PureCoherence",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/PureCoherence.lean | naturality_inv | null |
of_normalize_eq {f g f' : C} {η θ : f ≅ g} (η_f : 𝟙_ C ⊗ f ≅ f') (η_g : 𝟙_ C ⊗ g ≅ f')
(h_η : 𝟙_ C ◁ η ≪≫ η_g = η_f)
(h_θ : 𝟙_ C ◁ θ ≪≫ η_g = η_f) : η = θ := by
apply Iso.ext
calc
η.hom = (λ_ f).inv ≫ η_f.hom ≫ η_g.inv ≫ (λ_ g).hom := by
simp [← reassoc_of% (congrArg Iso.hom h_η)]
_ = θ.ho... | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.PureCoherence",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/PureCoherence.lean | of_normalize_eq | null |
mk_eq_of_naturality {f g f' : C} {η θ : f ⟶ g} {η' θ' : f ≅ g}
(η_f : 𝟙_ C ⊗ f ≅ f') (η_g : 𝟙_ C ⊗ g ≅ f')
(η_hom : η'.hom = η) (Θ_hom : θ'.hom = θ)
(Hη : whiskerLeftIso (𝟙_ C) η' ≪≫ η_g = η_f)
(Hθ : whiskerLeftIso (𝟙_ C) θ' ≪≫ η_g = η_f) : η = θ :=
calc
η = η'.hom := η_hom.symm
_ = (λ_ f)... | theorem | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.PureCoherence",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/PureCoherence.lean | mk_eq_of_naturality | null |
pureCoherence (mvarId : MVarId) : MetaM (List MVarId) :=
BicategoryLike.pureCoherence Monoidal.Context `monoidal mvarId
@[inherit_doc pureCoherence]
elab "monoidal_coherence" : tactic => withMainContext do
replaceMainGoal <| ← Monoidal.pureCoherence <| ← getMainGoal | def | Tactic | [
"Mathlib.Tactic.CategoryTheory.Coherence.PureCoherence",
"Mathlib.Tactic.CategoryTheory.Monoidal.Datatypes"
] | Mathlib/Tactic/CategoryTheory/Monoidal/PureCoherence.lean | pureCoherence | Close the goal of the form `η = θ`, where `η` and `θ` are 2-isomorphisms made up only of
associators, unitors, and identities.
```lean
example {C : Type} [Category C] [MonoidalCategory C] :
(λ_ (𝟙_ C)).hom = (ρ_ (𝟙_ C)).hom := by
monoidal_coherence
``` |
union (t₁ t₂ : TreeSet α cmp) : TreeSet α cmp :=
t₂.foldl .insert t₁ | def | Tactic | [
"Batteries.Lean.HashMap",
"Mathlib.Tactic.Linarith.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/FourierMotzkin.lean | union | `O(n₂ * log (n₁ + n₂))`. Merges the maps `t₁` and `t₂`.
If equal keys exist in both, the key from `t₂` is preferred. |
sdiff (t₁ t₂ : TreeSet α cmp) : TreeSet α cmp := t₁.filter (!t₂.contains ·) | def | Tactic | [
"Batteries.Lean.HashMap",
"Mathlib.Tactic.Linarith.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/FourierMotzkin.lean | sdiff | `O(n₁ * (log n₁ + log n₂))`. Constructs the set of all elements of `t₁` that are not in `t₂`. |
CompSource : Type
| assump : Nat → CompSource
| add : CompSource → CompSource → CompSource
| scale : Nat → CompSource → CompSource
deriving Inhabited | inductive | Tactic | [
"Batteries.Lean.HashMap",
"Mathlib.Tactic.Linarith.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/FourierMotzkin.lean | CompSource | `CompSource` tracks the source of a comparison.
The atomic source of a comparison is an assumption, indexed by a natural number.
Two comparisons can be added to produce a new comparison,
and one comparison can be scaled by a natural number to produce a new comparison. |
CompSource.flatten : CompSource → Std.HashMap Nat Nat
| (CompSource.assump n) => (∅ : Std.HashMap Nat Nat).insert n 1
| (CompSource.add c1 c2) =>
(CompSource.flatten c1).mergeWith (fun _ b b' => b + b') (CompSource.flatten c2)
| (CompSource.scale n c) => (CompSource.flatten c).map (fun _ v => v * n) | def | Tactic | [
"Batteries.Lean.HashMap",
"Mathlib.Tactic.Linarith.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/FourierMotzkin.lean | CompSource.flatten | Given a `CompSource` `cs`, `cs.flatten` maps an assumption index
to the number of copies of that assumption that appear in the history of `cs`.
For example, suppose `cs` is produced by scaling assumption 2 by 5,
and adding to that the sum of assumptions 1 and 2.
`cs.flatten` maps `1 ↦ 1, 2 ↦ 6`. |
CompSource.toString : CompSource → String
| (CompSource.assump e) => ToString.toString e
| (CompSource.add c1 c2) => CompSource.toString c1 ++ " + " ++ CompSource.toString c2
| (CompSource.scale n c) => ToString.toString n ++ " * " ++ CompSource.toString c | def | Tactic | [
"Batteries.Lean.HashMap",
"Mathlib.Tactic.Linarith.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/FourierMotzkin.lean | CompSource.toString | Formats a `CompSource` for printing. |
PComp : Type where
/-- The comparison `Σ cᵢ*xᵢ R 0`. -/
c : Comp
/-- We track how the comparison was constructed by adding and scaling previous comparisons,
back to the original assumptions. -/
src : CompSource
/-- The set of original assumptions which have been used in constructing this comparison. -/
hi... | structure | Tactic | [
"Batteries.Lean.HashMap",
"Mathlib.Tactic.Linarith.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/FourierMotzkin.lean | PComp | A `PComp` stores a linear comparison `Σ cᵢ*xᵢ R 0`,
along with information about how this comparison was derived.
The original expressions fed into `linarith` are each assigned a unique natural number label.
The *historical set* `PComp.history` stores the labels of expressions
that were used in deriving the current `PC... |
PComp.maybeMinimal (c : PComp) (elimedGE : ℕ) : Bool :=
c.history.size ≤ 1 + ((c.implicit.filter (· ≥ elimedGE)).union c.effective).size | def | Tactic | [
"Batteries.Lean.HashMap",
"Mathlib.Tactic.Linarith.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/FourierMotzkin.lean | PComp.maybeMinimal | Any comparison whose history is not minimal is redundant,
and need not be included in the new set of comparisons.
`elimedGE : ℕ` is a natural number such that all variables with index ≥ `elimedGE` have been
removed from the system.
This test is an overapproximation to minimality. It gives necessary but not sufficient ... |
PComp.cmp (p1 p2 : PComp) : Ordering := p1.c.cmp p2.c | def | Tactic | [
"Batteries.Lean.HashMap",
"Mathlib.Tactic.Linarith.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/FourierMotzkin.lean | PComp.cmp | The `src : CompSource` field is ignored when comparing `PComp`s. Two `PComp`s proving the same
comparison, with different sources, are considered equivalent. |
PComp.scale (c : PComp) (n : ℕ) : PComp :=
{ c with c := c.c.scale n, src := c.src.scale n } | def | Tactic | [
"Batteries.Lean.HashMap",
"Mathlib.Tactic.Linarith.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/FourierMotzkin.lean | PComp.scale | `PComp.scale c n` scales the coefficients of `c` by `n` and notes this in the `CompSource`. |
PComp.add (c1 c2 : PComp) (elimVar : ℕ) : PComp :=
let c := c1.c.add c2.c
let src := c1.src.add c2.src
let history := c1.history.union c2.history
let vars := c1.vars.union c2.vars
let effective := (c1.effective.union c2.effective).insert elimVar
let implicit := (vars.sdiff (.ofList c.vars _)).sdiff effectiv... | def | Tactic | [
"Batteries.Lean.HashMap",
"Mathlib.Tactic.Linarith.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/FourierMotzkin.lean | PComp.add | `PComp.add c1 c2 elimVar` creates the result of summing the linear comparisons `c1` and `c2`,
during the process of eliminating the variable `elimVar`.
The computation assumes, but does not enforce, that `elimVar` appears in both `c1` and `c2`
and does not appear in the sum.
Computing the sum of the two comparisons is ... |
PComp.assump (c : Comp) (n : ℕ) : PComp where
c := c
src := CompSource.assump n
history := {n}
effective := .empty
implicit := .empty
vars := .ofList c.vars _ | def | Tactic | [
"Batteries.Lean.HashMap",
"Mathlib.Tactic.Linarith.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/FourierMotzkin.lean | PComp.assump | `PComp.assump c n` creates a `PComp` whose comparison is `c` and whose source is
`CompSource.assump n`, that is, `c` is derived from the `n`th hypothesis.
The history is the singleton set `{n}`.
No variables have been eliminated (effectively or implicitly). |
PCompSet := TreeSet PComp PComp.cmp
/-! ### Elimination procedure -/ | abbrev | Tactic | [
"Batteries.Lean.HashMap",
"Mathlib.Tactic.Linarith.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/FourierMotzkin.lean | PCompSet | A collection of comparisons. |
elimVar (c1 c2 : Comp) (a : ℕ) : Option (ℕ × ℕ) :=
let v1 := c1.coeffOf a
let v2 := c2.coeffOf a
if v1 * v2 < 0 then
let vlcm := Nat.lcm v1.natAbs v2.natAbs
some ⟨vlcm / v1.natAbs, vlcm / v2.natAbs⟩
else none | def | Tactic | [
"Batteries.Lean.HashMap",
"Mathlib.Tactic.Linarith.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/FourierMotzkin.lean | elimVar | If `c1` and `c2` both contain variable `a` with opposite coefficients,
produces `v1` and `v2` such that `a` has been cancelled in `v1*c1 + v2*c2`. |
pelimVar (p1 p2 : PComp) (a : ℕ) : Option PComp := do
let (n1, n2) ← elimVar p1.c p2.c a
return (p1.scale n1).add (p2.scale n2) a | def | Tactic | [
"Batteries.Lean.HashMap",
"Mathlib.Tactic.Linarith.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/FourierMotzkin.lean | pelimVar | `pelimVar p1 p2` calls `elimVar` on the `Comp` components of `p1` and `p2`.
If this returns `v1` and `v2`, it creates a new `PComp` equal to `v1*p1 + v2*p2`,
and tracks this in the `CompSource`. |
PComp.isContr (p : PComp) : Bool := p.c.isContr | def | Tactic | [
"Batteries.Lean.HashMap",
"Mathlib.Tactic.Linarith.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/FourierMotzkin.lean | PComp.isContr | A `PComp` represents a contradiction if its `Comp` field represents a contradiction. |
elimWithSet (a : ℕ) (p : PComp) (comps : PCompSet) : PCompSet :=
comps.foldl (fun s pc =>
match pelimVar p pc a with
| some pc => if pc.maybeMinimal a then s.insert pc else s
| none => s) TreeSet.empty | def | Tactic | [
"Batteries.Lean.HashMap",
"Mathlib.Tactic.Linarith.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/FourierMotzkin.lean | elimWithSet | `elimWithSet a p comps` collects the result of calling `pelimVar p p' a`
for every `p' ∈ comps`. |
LinarithData : Type where
/-- The largest variable index that has not been (officially) eliminated. -/
maxVar : ℕ
/-- The set of comparisons. -/
comps : PCompSet | structure | Tactic | [
"Batteries.Lean.HashMap",
"Mathlib.Tactic.Linarith.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/FourierMotzkin.lean | LinarithData | The state for the elimination monad.
* `maxVar`: the largest variable index that has not been eliminated.
* `comps`: a set of comparisons
The elimination procedure proceeds by eliminating variable `v` from `comps` progressively
in decreasing order. |
LinarithM : Type → Type :=
StateT LinarithData (ExceptT PComp Lean.Core.CoreM) | abbrev | Tactic | [
"Batteries.Lean.HashMap",
"Mathlib.Tactic.Linarith.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/FourierMotzkin.lean | LinarithM | The linarith monad extends an exceptional monad with a `LinarithData` state.
An exception produces a contradictory `PComp`. |
getMaxVar : LinarithM ℕ :=
LinarithData.maxVar <$> get | def | Tactic | [
"Batteries.Lean.HashMap",
"Mathlib.Tactic.Linarith.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/FourierMotzkin.lean | getMaxVar | Returns the current max variable. |
getPCompSet : LinarithM PCompSet :=
LinarithData.comps <$> get | def | Tactic | [
"Batteries.Lean.HashMap",
"Mathlib.Tactic.Linarith.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/FourierMotzkin.lean | getPCompSet | Return the current comparison set. |
validate : LinarithM Unit := do
match (← getPCompSet).toList.find? (fun p : PComp => p.isContr) with
| none => return ()
| some c => throwThe _ c | def | Tactic | [
"Batteries.Lean.HashMap",
"Mathlib.Tactic.Linarith.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/FourierMotzkin.lean | validate | Throws an exception if a contradictory `PComp` is contained in the current state. |
update (maxVar : ℕ) (comps : PCompSet) : LinarithM Unit := do
StateT.set ⟨maxVar, comps⟩
validate | def | Tactic | [
"Batteries.Lean.HashMap",
"Mathlib.Tactic.Linarith.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/FourierMotzkin.lean | update | Updates the current state with a new max variable and comparisons,
and calls `validate` to check for a contradiction. |
splitSetByVarSign (a : ℕ) (comps : PCompSet) : PCompSet × PCompSet × PCompSet :=
comps.foldl (fun ⟨pos, neg, notPresent⟩ pc =>
let n := pc.c.coeffOf a
if n > 0 then ⟨pos.insert pc, neg, notPresent⟩
else if n < 0 then ⟨pos, neg.insert pc, notPresent⟩
else ⟨pos, neg, notPresent.insert pc⟩)
⟨TreeSet.... | def | Tactic | [
"Batteries.Lean.HashMap",
"Mathlib.Tactic.Linarith.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/FourierMotzkin.lean | splitSetByVarSign | `splitSetByVarSign a comps` partitions the set `comps` into three parts.
* `pos` contains the elements of `comps` in which `a` has a positive coefficient.
* `neg` contains the elements of `comps` in which `a` has a negative coefficient.
* `notPresent` contains the elements of `comps` in which `a` has coefficient 0.
Re... |
elimVarM (a : ℕ) : LinarithM Unit := do
let vs ← getMaxVar
if (a ≤ vs) then
Lean.Core.checkSystem decl_name%.toString
let ⟨pos, neg, notPresent⟩ := splitSetByVarSign a (← getPCompSet)
update (vs - 1) (← pos.foldlM (fun s p => do
Lean.Core.checkSystem decl_name%.toString
pure (s.union (elimWi... | def | Tactic | [
"Batteries.Lean.HashMap",
"Mathlib.Tactic.Linarith.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/FourierMotzkin.lean | elimVarM | `elimVarM a` performs one round of Fourier-Motzkin elimination, eliminating the variable `a`
from the `linarith` state. |
elimAllVarsM : LinarithM Unit := do
for i in (List.range ((← getMaxVar) + 1)).reverse do
elimVarM i | def | Tactic | [
"Batteries.Lean.HashMap",
"Mathlib.Tactic.Linarith.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/FourierMotzkin.lean | elimAllVarsM | `elimAllVarsM` eliminates all variables from the linarith state, leaving it with a set of
ground comparisons. If this succeeds without exception, the original `linarith` state is consistent. |
mkLinarithData (hyps : List Comp) (maxVar : ℕ) : LinarithData :=
⟨maxVar, .ofList (hyps.mapIdx fun n cmp => PComp.assump cmp n) _⟩ | def | Tactic | [
"Batteries.Lean.HashMap",
"Mathlib.Tactic.Linarith.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/FourierMotzkin.lean | mkLinarithData | `mkLinarithData hyps vars` takes a list of hypotheses and the largest variable present in
those hypotheses. It produces an initial state for the elimination monad. |
CertificateOracle.fourierMotzkin : CertificateOracle where
produceCertificate hyps maxVar := do
let linarithData := mkLinarithData hyps maxVar
let result ←
(ExceptT.run (StateT.run (do validate; elimAllVarsM : LinarithM Unit) linarithData) :)
match result with
| (Except.ok _) => failure
| (... | def | Tactic | [
"Batteries.Lean.HashMap",
"Mathlib.Tactic.Linarith.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/FourierMotzkin.lean | CertificateOracle.fourierMotzkin | An oracle that uses Fourier-Motzkin elimination. |
preprocess (matType : ℕ → ℕ → Type) [UsableInSimplexAlgorithm matType] (hyps : List Comp)
(maxVar : ℕ) : matType (maxVar + 1) (hyps.length) × List Nat :=
let values : List (ℕ × ℕ × ℚ) := hyps.foldlIdx (init := []) fun idx cur comp =>
cur ++ comp.coeffs.map fun (var, c) => (var, idx, c)
let strictIndexes := ... | def | Tactic | [
"Mathlib.Tactic.Linarith.Datatypes",
"Mathlib.Tactic.Linarith.Oracle.SimplexAlgorithm.PositiveVector"
] | Mathlib/Tactic/Linarith/Oracle/SimplexAlgorithm.lean | preprocess | Preprocess the goal to pass it to `Linarith.SimplexAlgorithm.findPositiveVector`. |
postprocess (vec : Array ℚ) : Std.HashMap ℕ ℕ :=
let common_den : ℕ := vec.foldl (fun acc item => acc.lcm item.den) 1
let vecNat : Array ℕ := vec.map (fun x : ℚ => (x * common_den).floor.toNat)
(∅ : Std.HashMap Nat Nat).insertMany <| vecNat.zipIdx.filterMap
fun ⟨item, idx⟩ => if item != 0 then some (idx, item... | def | Tactic | [
"Mathlib.Tactic.Linarith.Datatypes",
"Mathlib.Tactic.Linarith.Oracle.SimplexAlgorithm.PositiveVector"
] | Mathlib/Tactic/Linarith/Oracle/SimplexAlgorithm.lean | postprocess | Extract the certificate from the `vec` found by `Linarith.SimplexAlgorithm.findPositiveVector`. |
CertificateOracle.simplexAlgorithmSparse : CertificateOracle where
produceCertificate hyps maxVar := do
let (A, strictIndexes) := preprocess SparseMatrix hyps maxVar
let vec ← findPositiveVector A strictIndexes
return postprocess vec | def | Tactic | [
"Mathlib.Tactic.Linarith.Datatypes",
"Mathlib.Tactic.Linarith.Oracle.SimplexAlgorithm.PositiveVector"
] | Mathlib/Tactic/Linarith/Oracle/SimplexAlgorithm.lean | CertificateOracle.simplexAlgorithmSparse | An oracle that uses the Simplex Algorithm. |
CertificateOracle.simplexAlgorithmDense : CertificateOracle where
produceCertificate hyps maxVar := do
let (A, strictIndexes) := preprocess DenseMatrix hyps maxVar
let vec ← findPositiveVector A strictIndexes
return postprocess vec | def | Tactic | [
"Mathlib.Tactic.Linarith.Datatypes",
"Mathlib.Tactic.Linarith.Oracle.SimplexAlgorithm.PositiveVector"
] | Mathlib/Tactic/Linarith/Oracle/SimplexAlgorithm.lean | CertificateOracle.simplexAlgorithmDense | The same oracle as `CertificateOracle.simplexAlgorithmSparse`, but uses dense matrices. Works faster
on dense states. |
UsableInSimplexAlgorithm (α : Nat → Nat → Type) where
/-- Returns `mat[i, j]`. -/
getElem {n m : Nat} (mat : α n m) (i j : Nat) : Rat
/-- Sets `mat[i, j]`. -/
setElem {n m : Nat} (mat : α n m) (i j : Nat) (v : Rat) : α n m
/-- Returns the list of elements of `mat` in the form `(i, j, mat[i, j])`. -/
getValu... | class | Tactic | [
"Mathlib.Init",
"Std.Data.HashMap.Basic"
] | Mathlib/Tactic/Linarith/Oracle/SimplexAlgorithm/Datatypes.lean | UsableInSimplexAlgorithm | Specification for matrix types over ℚ which can be used in the Gauss Elimination and the Simplex
Algorithm. It was introduced to unify dense matrices and sparse matrices. |
DenseMatrix (n m : Nat) where
/-- The content of the matrix. -/
data : Array (Array Rat) | structure | Tactic | [
"Mathlib.Init",
"Std.Data.HashMap.Basic"
] | Mathlib/Tactic/Linarith/Oracle/SimplexAlgorithm/Datatypes.lean | DenseMatrix | Structure for matrices over ℚ.
So far it is just a 2d-array carrying dimensions (that are supposed to match with the actual
dimensions of `data`), but the plan is to add some `Prop`-data and make the structure strict and
safe.
Note: we avoid using `Matrix` because it is far more efficient to store a matrix as its ent... |
SparseMatrix (n m : Nat) where
/-- The content of the matrix. -/
data : Array <| Std.HashMap Nat Rat | structure | Tactic | [
"Mathlib.Init",
"Std.Data.HashMap.Basic"
] | Mathlib/Tactic/Linarith/Oracle/SimplexAlgorithm/Datatypes.lean | SparseMatrix | Structure for sparse matrices over ℚ, implemented as an array of hashmaps, containing only nonzero
values. |
Tableau (matType : Nat → Nat → Type) [UsableInSimplexAlgorithm matType] where
/-- Array containing the basic variables' indexes -/
basic : Array Nat
/-- Array containing the free variables' indexes -/
free : Array Nat
/-- Matrix of coefficients the basic variables expressed through the free ones. -/
mat : m... | structure | Tactic | [
"Mathlib.Init",
"Std.Data.HashMap.Basic"
] | Mathlib/Tactic/Linarith/Oracle/SimplexAlgorithm/Datatypes.lean | Tableau | `Tableau` is a structure the Simplex Algorithm operates on. The `i`-th row of `mat` expresses the
variable `basic[i]` as a linear combination of variables from `free`. |
GaussM (n m : Nat) (matType : Nat → Nat → Type) := StateT (matType n m) Lean.CoreM
variable {n m : Nat} {matType : Nat → Nat → Type} [UsableInSimplexAlgorithm matType] | abbrev | Tactic | [
"Mathlib.Tactic.Linarith.Oracle.SimplexAlgorithm.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/SimplexAlgorithm/Gauss.lean | GaussM | The monad for the Gaussian Elimination algorithm. |
findNonzeroRow (rowStart col : Nat) : GaussM n m matType <| Option Nat := do
for i in [rowStart:n] do
if (← get)[(i, col)]! != 0 then
return i
return none | def | Tactic | [
"Mathlib.Tactic.Linarith.Oracle.SimplexAlgorithm.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/SimplexAlgorithm/Gauss.lean | findNonzeroRow | Finds the first row starting from the `rowStart` with nonzero element in the column `col`. |
getTableauImp : GaussM n m matType <| Tableau matType := do
let mut free : Array Nat := #[]
let mut basic : Array Nat := #[]
let mut row : Nat := 0
let mut col : Nat := 0
while row < n && col < m do
Lean.Core.checkSystem decl_name%.toString
match ← findNonzeroRow row col with
| none =>
free ... | def | Tactic | [
"Mathlib.Tactic.Linarith.Oracle.SimplexAlgorithm.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/SimplexAlgorithm/Gauss.lean | getTableauImp | Implementation of `getTableau` in `GaussM` monad. |
getTableau (A : matType n m) : Lean.CoreM (Tableau matType) := do
return (← getTableauImp.run A).fst | def | Tactic | [
"Mathlib.Tactic.Linarith.Oracle.SimplexAlgorithm.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/SimplexAlgorithm/Gauss.lean | getTableau | Given matrix `A`, solves the linear equation `A x = 0` and returns the solution as a tableau where
some variables are free and others (basic) variable are expressed as linear combinations of the free
ones. |
stateLP {n m : Nat} (A : matType n m) (strictIndexes : List Nat) : matType (n + 2) (m + 3) :=
/- +2 due to shifting by `f` and `z` -/
let objectiveRow : List (Nat × Nat × Rat) :=
(0, 0, -1) :: strictIndexes.map fun idx => (0, idx + 2, 1)
let constraintRow : List (Nat × Nat × Rat) :=
[(1, 1, 1), (1, m + 2,... | def | Tactic | [
"Lean.Meta.Basic",
"Mathlib.Tactic.Linarith.Oracle.SimplexAlgorithm.SimplexAlgorithm",
"Mathlib.Tactic.Linarith.Oracle.SimplexAlgorithm.Gauss"
] | Mathlib/Tactic/Linarith/Oracle/SimplexAlgorithm/PositiveVector.lean | stateLP | Given matrix `A` and list `strictIndexes` of strict inequalities' indexes, we want to state the
Linear Programming problem which solution would give us a solution for the initial problem (see
`findPositiveVector`).
As an objective function (that we are trying to maximize) we use sum of coordinates from
`strictIndexes`... |
extractSolution (tableau : Tableau matType) : Array Rat := Id.run do
let mut ans : Array Rat := Array.replicate (tableau.basic.size + tableau.free.size - 3) 0
for h : i in [1:tableau.basic.size] do
ans := ans.set! (tableau.basic[i] - 2) <| tableau.mat[(i, tableau.free.size - 1)]!
return ans | def | Tactic | [
"Lean.Meta.Basic",
"Mathlib.Tactic.Linarith.Oracle.SimplexAlgorithm.SimplexAlgorithm",
"Mathlib.Tactic.Linarith.Oracle.SimplexAlgorithm.Gauss"
] | Mathlib/Tactic/Linarith/Oracle/SimplexAlgorithm/PositiveVector.lean | extractSolution | Extracts target vector from the tableau, putting auxiliary variables aside (see `stateLP`). |
findPositiveVector {n m : Nat} {matType : Nat → Nat → Type} [UsableInSimplexAlgorithm matType]
(A : matType n m) (strictIndexes : List Nat) : Lean.Meta.MetaM <| Array Rat := do
/- State the linear programming problem. -/
let B := stateLP A strictIndexes
/- Using Gaussian elimination split variable into free a... | def | Tactic | [
"Lean.Meta.Basic",
"Mathlib.Tactic.Linarith.Oracle.SimplexAlgorithm.SimplexAlgorithm",
"Mathlib.Tactic.Linarith.Oracle.SimplexAlgorithm.Gauss"
] | Mathlib/Tactic/Linarith/Oracle/SimplexAlgorithm/PositiveVector.lean | findPositiveVector | Finds a nonnegative vector `v`, such that `A v = 0` and some of its coordinates from
`strictCoords`
are positive, in the case such `v` exists. If not, throws the error. The latter prevents
`linarith` from doing useless post-processing. |
SimplexAlgorithmException
/-- The solution is infeasible. -/
| infeasible : SimplexAlgorithmException | inductive | Tactic | [
"Mathlib.Tactic.Linarith.Oracle.SimplexAlgorithm.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/SimplexAlgorithm/SimplexAlgorithm.lean | SimplexAlgorithmException | An exception in the `SimplexAlgorithmM` monad. |
SimplexAlgorithmM (matType : Nat → Nat → Type) [UsableInSimplexAlgorithm matType] :=
ExceptT SimplexAlgorithmException <| StateT (Tableau matType) Lean.CoreM
variable {matType : Nat → Nat → Type} [UsableInSimplexAlgorithm matType] | abbrev | Tactic | [
"Mathlib.Tactic.Linarith.Oracle.SimplexAlgorithm.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/SimplexAlgorithm/SimplexAlgorithm.lean | SimplexAlgorithmM | The monad for the Simplex Algorithm. |
doPivotOperation (exitIdx enterIdx : Nat) : SimplexAlgorithmM matType Unit :=
modify fun s : Tableau matType => Id.run do
let mut mat := s.mat
let intersectCoef := mat[(exitIdx, enterIdx)]!
for i in [:s.basic.size] do
if i == exitIdx then
continue
let coef := mat[(i, enterIdx)]! / inte... | def | Tactic | [
"Mathlib.Tactic.Linarith.Oracle.SimplexAlgorithm.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/SimplexAlgorithm/SimplexAlgorithm.lean | doPivotOperation | Given indexes `exitIdx` and `enterIdx` of exiting and entering variables in the `basic` and `free`
arrays, performs pivot operation, i.e. expresses one through the other and makes the free one basic
and vice versa. |
checkSuccess : SimplexAlgorithmM matType Bool := do
let lastIdx := (← get).free.size - 1
return (← get).mat[(0, lastIdx)]! > 0 &&
(← (← get).basic.size.allM (fun i _ => do return (← get).mat[(i, lastIdx)]! ≥ 0)) | def | Tactic | [
"Mathlib.Tactic.Linarith.Oracle.SimplexAlgorithm.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/SimplexAlgorithm/SimplexAlgorithm.lean | checkSuccess | Check if the solution is found: the objective function is positive and all basic variables are
nonnegative. |
chooseEnteringVar : SimplexAlgorithmM matType Nat := do
let mut enterIdxOpt : Option Nat := none -- index of entering variable in the `free` array
let mut minIdx := 0
for i in [:(← get).free.size - 1] do
if (← get).mat[(0, i)]! > 0 &&
(enterIdxOpt.isNone || (← get).free[i]! < minIdx) then
enterI... | def | Tactic | [
"Mathlib.Tactic.Linarith.Oracle.SimplexAlgorithm.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/SimplexAlgorithm/SimplexAlgorithm.lean | chooseEnteringVar | Chooses an entering variable: among the variables with a positive coefficient in the objective
function, the one with the smallest index (in the initial indexing). |
chooseExitingVar (enterIdx : Nat) : SimplexAlgorithmM matType Nat := do
let mut exitIdxOpt : Option Nat := none -- index of entering variable in the `basic` array
let mut minCoef := 0
let mut minIdx := 0
for i in [1:(← get).basic.size] do
if (← get).mat[(i, enterIdx)]! >= 0 then
continue
let lastI... | def | Tactic | [
"Mathlib.Tactic.Linarith.Oracle.SimplexAlgorithm.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/SimplexAlgorithm/SimplexAlgorithm.lean | chooseExitingVar | Chooses an exiting variable: the variable imposing the strictest limit on the increase of the
entering variable, breaking ties by choosing the variable with smallest index. |
choosePivots : SimplexAlgorithmM matType (Nat × Nat) := do
let enterIdx ← chooseEnteringVar
let exitIdx ← chooseExitingVar enterIdx
return ⟨exitIdx, enterIdx⟩ | def | Tactic | [
"Mathlib.Tactic.Linarith.Oracle.SimplexAlgorithm.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/SimplexAlgorithm/SimplexAlgorithm.lean | choosePivots | Chooses entering and exiting variables using
(Bland's rule)[(https://en.wikipedia.org/wiki/Bland%27s_rule)] that guarantees that the Simplex
Algorithm terminates. |
runSimplexAlgorithm : SimplexAlgorithmM matType Unit := do
while !(← checkSuccess) do
Lean.Core.checkSystem decl_name%.toString
let ⟨exitIdx, enterIdx⟩ ← choosePivots
doPivotOperation exitIdx enterIdx | def | Tactic | [
"Mathlib.Tactic.Linarith.Oracle.SimplexAlgorithm.Datatypes"
] | Mathlib/Tactic/Linarith/Oracle/SimplexAlgorithm/SimplexAlgorithm.lean | runSimplexAlgorithm | Runs the Simplex Algorithm inside the `SimplexAlgorithmM`. It always terminates, finding solution if
such exists. |
Edge where
/-- Source of the edge. -/
src : Nat
/-- Destination of the edge. -/
dst : Nat
/-- Proof of `atomToIdx[src] ≤ atomToIdx[dst]`. -/
proof : Expr | structure | Tactic | [
"Mathlib.Tactic.Order.CollectFacts"
] | Mathlib/Tactic/Order/Graph/Basic.lean | Edge | An edge in a graph. In the `order` tactic, the `proof` field stores the of
`atomToIdx[src] ≤ atomToIdx[dst]`. |
Graph := Array (Array Edge) | abbrev | Tactic | [
"Mathlib.Tactic.Order.CollectFacts"
] | Mathlib/Tactic/Order/Graph/Basic.lean | Graph | If `g` is a `Graph`, then for a vertex with index `v`, `g[v]` is an array containing
the edges starting from this vertex. |
addEdge (g : Graph) (edge : Edge) : Graph :=
g.modify edge.src fun edges => edges.push edge | def | Tactic | [
"Mathlib.Tactic.Order.CollectFacts"
] | Mathlib/Tactic/Order/Graph/Basic.lean | addEdge | Adds an `edge` to the graph. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.