-- Mathlib/.lake/packages/lean4/src/lean/Init/Data/Nat/Linear.lean
theorem Poly.of_denote_le_cancelAux (ctx : Context) (fuel : Nat) (m₁ m₂ r₁ r₂ : Poly)
    (h : denote_le ctx (cancelAux fuel m₁ m₂ r₁ r₂)) : denote_le ctx (r₁.reverse ++ m₁, r₂.reverse ++ m₂)

Proof state:
case neg
ctx : Context
fuel : Nat
ih :
  ∀ (m₁ m₂ r₁ r₂ : Poly),
    denote_le ctx (cancelAux fuel m₁ m₂ r₁ r₂) → denote_le ctx (List.reverse r₁ ++ m₁, List.reverse r₂ ++ m₂)
r₁ r₂ m₁✝ m₂✝ : Poly
k₁ : Nat
v₁ : Var
m₁ m₂ : List (Nat × Var)
hltv hgtv : ¬blt v₁ v₁ = true
h : denote_le ctx (cancelAux fuel m₁ m₂ r₁ r₂)
hltk hgtk : ¬k₁.blt k₁ = true
⊢ denote_le ctx (List.reverse r₁ ++ (k₁, v₁) :: m₁, List.reverse r₂ ++ (k₁, v₁) :: m₂)

Tactic:
have ih := ih (h := h)

Result:
case neg
ctx : Context
fuel : Nat
ih✝ :
  ∀ (m₁ m₂ r₁ r₂ : Poly),
    denote_le ctx (cancelAux fuel m₁ m₂ r₁ r₂) → denote_le ctx (List.reverse r₁ ++ m₁, List.reverse r₂ ++ m₂)
r₁ r₂ m₁✝ m₂✝ : Poly
k₁ : Nat
v₁ : Var
m₁ m₂ : List (Nat × Var)
hltv hgtv : ¬blt v₁ v₁ = true
h : denote_le ctx (cancelAux fuel m₁ m₂ r₁ r₂)
hltk hgtk : ¬k₁.blt k₁ = true
ih : denote_le ctx (List.reverse r₁ ++ m₁, List.reverse r₂ ++ m₂)
⊢ denote_le ctx (List.reverse r₁ ++ (k₁, v₁) :: m₁, List.reverse r₂ ++ (k₁, v₁) :: m₂)

Proof state:
case pos
ctx : Context
fuel : Nat
ih✝ :
  ∀ (m₁ m₂ r₁ r₂ : Poly),
    denote_le ctx (cancelAux fuel m₁ m₂ r₁ r₂) → denote_le ctx (List.reverse r₁ ++ m₁, List.reverse r₂ ++ m₂)
r₁ r₂ m₁✝ m₂✝ : Poly
k₁ : Nat
v₁ : Var
m₁ : List (Nat × Var)
k₂ : Nat
m₂ : List (Nat × Var)
hltv hgtv : ¬blt v₁ v₁ = true
hltk : k₁.blt k₂ = true
h : denote_le ctx (cancelAux fuel m₁ m₂ r₁ ((k₂ - k₁, v₁) :: r₂))
ih : denote_le ctx (List.reverse r₁ ++ m₁, ((k₂ - k₁, v₁) :: r₂).reverse ++ m₂)
⊢ denote_le ctx (List.reverse r₁ ++ (k₁, v₁) :: m₁, List.reverse r₂ ++ (k₂, v₁) :: m₂)

Tactic:
simp [denote_le] at ih ⊢

Result:
case pos
ctx : Context
fuel : Nat
ih✝ :
  ∀ (m₁ m₂ r₁ r₂ : Poly),
    denote_le ctx (cancelAux fuel m₁ m₂ r₁ r₂) → denote_le ctx (List.reverse r₁ ++ m₁, List.reverse r₂ ++ m₂)
r₁ r₂ m₁✝ m₂✝ : Poly
k₁ : Nat
v₁ : Var
m₁ : List (Nat × Var)
k₂ : Nat
m₂ : List (Nat × Var)
hltv hgtv : ¬blt v₁ v₁ = true
hltk : k₁.blt k₂ = true
h : denote_le ctx (cancelAux fuel m₁ m₂ r₁ ((k₂ - k₁, v₁) :: r₂))
ih : denote ctx r₁ + denote ctx m₁ ≤ denote ctx r₂ + (denote ctx m₂ + (k₂ - k₁) * Var.denote ctx v₁)
⊢ denote ctx r₁ + (denote ctx m₁ + k₁ * Var.denote ctx v₁) ≤ denote ctx r₂ + (denote ctx m₂ + k₂ * Var.denote ctx v₁)

Proof state:
case neg
ctx : Context
fuel : Nat
ih✝ :
  ∀ (m₁ m₂ r₁ r₂ : Poly),
    denote_le ctx (cancelAux fuel m₁ m₂ r₁ r₂) → denote_le ctx (List.reverse r₁ ++ m₁, List.reverse r₂ ++ m₂)
r₁ r₂ m₁✝ m₂✝ : Poly
k₁ : Nat
v₁ : Var
m₁ m₂ : List (Nat × Var)
hltv hgtv : ¬blt v₁ v₁ = true
h : denote_le ctx (cancelAux fuel m₁ m₂ r₁ r₂)
hltk hgtk : ¬k₁.blt k₁ = true
ih : denote ctx r₁ + denote ctx m₁ ≤ denote ctx r₂ + denote ctx m₂
⊢ denote ctx r₁ + (denote ctx m₁ + k₁ * Var.denote ctx v₁) ≤ denote ctx r₂ + (denote ctx m₂ + k₁ * Var.denote ctx v₁)

Tactic:
have := Nat.add_le_add_right ih (k₁ * Var.denote ctx v₁)

Result:
case neg
ctx : Context
fuel : Nat
ih✝ :
  ∀ (m₁ m₂ r₁ r₂ : Poly),
    denote_le ctx (cancelAux fuel m₁ m₂ r₁ r₂) → denote_le ctx (List.reverse r₁ ++ m₁, List.reverse r₂ ++ m₂)
r₁ r₂ m₁✝ m₂✝ : Poly
k₁ : Nat
v₁ : Var
m₁ m₂ : List (Nat × Var)
hltv hgtv : ¬blt v₁ v₁ = true
h : denote_le ctx (cancelAux fuel m₁ m₂ r₁ r₂)
hltk hgtk : ¬k₁.blt k₁ = true
ih : denote ctx r₁ + denote ctx m₁ ≤ denote ctx r₂ + denote ctx m₂
this : denote ctx r₁ + denote ctx m₁ + k₁ * Var.denote ctx v₁ ≤ denote ctx r₂ + denote ctx m₂ + k₁ * Var.denote ctx v₁
⊢ denote ctx r₁ + (denote ctx m₁ + k₁ * Var.denote ctx v₁) ≤ denote ctx r₂ + (denote ctx m₂ + k₁ * Var.denote ctx v₁)

Proof state:
case pos
ctx : Context
fuel : Nat
ih✝ :
  ∀ (m₁ m₂ r₁ r₂ : Poly),
    denote_le ctx (cancelAux fuel m₁ m₂ r₁ r₂) → denote_le ctx (List.reverse r₁ ++ m₁, List.reverse r₂ ++ m₂)
r₁ r₂ m₁✝ m₂✝ : Poly
k₁ : Nat
v₁ : Var
m₁ : List (Nat × Var)
k₂ : Nat
m₂ : List (Nat × Var)
hltv hgtv : ¬blt v₁ v₁ = true
hltk : k₁.blt k₂ = true
h : denote_le ctx (cancelAux fuel m₁ m₂ r₁ ((k₂ - k₁, v₁) :: r₂))
ih : denote ctx r₁ + denote ctx m₁ ≤ denote ctx r₂ + (denote ctx m₂ + (k₂ - k₁) * Var.denote ctx v₁)
⊢ denote ctx r₁ + (denote ctx m₁ + k₁ * Var.denote ctx v₁) ≤ denote ctx r₂ + (denote ctx m₂ + k₂ * Var.denote ctx v₁)

Tactic:
have haux : k₁ * Var.denote ctx v₁ ≤ k₂ * Var.denote ctx v₁ := Nat.mul_le_mul_right _ (Nat.le_of_lt (Nat.blt_eq.mp hltk))

Result:
case pos
ctx : Context
fuel : Nat
ih✝ :
  ∀ (m₁ m₂ r₁ r₂ : Poly),
    denote_le ctx (cancelAux fuel m₁ m₂ r₁ r₂) → denote_le ctx (List.reverse r₁ ++ m₁, List.reverse r₂ ++ m₂)
r₁ r₂ m₁✝ m₂✝ : Poly
k₁ : Nat
v₁ : Var
m₁ : List (Nat × Var)
k₂ : Nat
m₂ : List (Nat × Var)
hltv hgtv : ¬blt v₁ v₁ = true
hltk : k₁.blt k₂ = true
h : denote_le ctx (cancelAux fuel m₁ m₂ r₁ ((k₂ - k₁, v₁) :: r₂))
ih : denote ctx r₁ + denote ctx m₁ ≤ denote ctx r₂ + (denote ctx m₂ + (k₂ - k₁) * Var.denote ctx v₁)
haux : k₁ * Var.denote ctx v₁ ≤ k₂ * Var.denote ctx v₁
⊢ denote ctx r₁ + (denote ctx m₁ + k₁ * Var.denote ctx v₁) ≤ denote ctx r₂ + (denote ctx m₂ + k₂ * Var.denote ctx v₁)

Proof state:
case pos
ctx : Context
fuel : Nat
ih✝ :
  ∀ (m₁ m₂ r₁ r₂ : Poly),
    denote_le ctx (cancelAux fuel m₁ m₂ r₁ r₂) → denote_le ctx (List.reverse r₁ ++ m₁, List.reverse r₂ ++ m₂)
r₁ r₂ m₁✝ m₂✝ : Poly
k₁ : Nat
v₁ : Var
m₁ : List (Nat × Var)
k₂ : Nat
v₂ : Var
m₂ : List (Nat × Var)
hltv : blt v₁ v₂ = true
h : denote_le ctx (cancelAux fuel m₁ ((k₂, v₂) :: m₂) ((k₁, v₁) :: r₁) r₂)
ih : denote_le ctx (((k₁, v₁) :: r₁).reverse ++ m₁, List.reverse r₂ ++ (k₂, v₂) :: m₂)
⊢ denote_le ctx (List.reverse r₁ ++ (k₁, v₁) :: m₁, List.reverse r₂ ++ (k₂, v₂) :: m₂)

Tactic:
simp [denote_le] at ih ⊢

Result:
case pos
ctx : Context
fuel : Nat
ih✝ :
  ∀ (m₁ m₂ r₁ r₂ : Poly),
    denote_le ctx (cancelAux fuel m₁ m₂ r₁ r₂) → denote_le ctx (List.reverse r₁ ++ m₁, List.reverse r₂ ++ m₂)
r₁ r₂ m₁✝ m₂✝ : Poly
k₁ : Nat
v₁ : Var
m₁ : List (Nat × Var)
k₂ : Nat
v₂ : Var
m₂ : List (Nat × Var)
hltv : blt v₁ v₂ = true
h : denote_le ctx (cancelAux fuel m₁ ((k₂, v₂) :: m₂) ((k₁, v₁) :: r₁) r₂)
ih : denote ctx r₁ + (denote ctx m₁ + k₁ * Var.denote ctx v₁) ≤ denote ctx r₂ + (denote ctx m₂ + k₂ * Var.denote ctx v₂)
⊢ denote ctx r₁ + (denote ctx m₁ + k₁ * Var.denote ctx v₁) ≤ denote ctx r₂ + (denote ctx m₂ + k₂ * Var.denote ctx v₂)

Proof state:
case pos
ctx : Context
fuel : Nat
ih✝ :
  ∀ (m₁ m₂ r₁ r₂ : Poly),
    denote_le ctx (cancelAux fuel m₁ m₂ r₁ r₂) → denote_le ctx (List.reverse r₁ ++ m₁, List.reverse r₂ ++ m₂)
r₁ r₂ m₁✝ m₂✝ : Poly
k₁ : Nat
v₁ : Var
m₁ : List (Nat × Var)
k₂ : Nat
v₂ : Var
m₂ : List (Nat × Var)
hltv : ¬blt v₁ v₂ = true
hgtv : blt v₂ v₁ = true
h : denote_le ctx (cancelAux fuel ((k₁, v₁) :: m₁) m₂ r₁ ((k₂, v₂) :: r₂))
ih : denote ctx r₁ + (denote ctx m₁ + k₁ * Var.denote ctx v₁) ≤ denote ctx r₂ + (denote ctx m₂ + k₂ * Var.denote ctx v₂)
⊢ denote ctx r₁ + (denote ctx m₁ + k₁ * Var.denote ctx v₁) ≤ denote ctx r₂ + (denote ctx m₂ + k₂ * Var.denote ctx v₂)

Tactic:
assumption

Result:
no goals