Theorem: PNat.gcd_props
File: Mathlib/Data/PNat/Xgcd.lean

tactic: intros d w x y z a' b'
state_before: a b : ℕ+
⊢ let d := gcdD a b;
  let w := gcdW a b;
  let x := gcdX a b;
  let y := gcdY a b;
  let z := gcdZ a b;
  let a' := gcdA' a b;
  let b' := gcdB' a b;
  w * z = succPNat (x * y) ∧
    a = a' * d ∧
      b = b' * d ∧
        z * a' = succPNat (x * ↑b') ∧ w * b' = succPNat (y * ↑a') ∧ ↑z * ↑a = x * ↑b + ↑d ∧ ↑w * ↑b = y * ↑a + ↑d

tactic: let u := XgcdType.start a b
state_before: a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
⊢ w * z = succPNat (x * y) ∧
    a = a' * d ∧
      b = b' * d ∧
        z * a' = succPNat (x * ↑b') ∧ w * b' = succPNat (y * ↑a') ∧ ↑z * ↑a = x * ↑b + ↑d ∧ ↑w * ↑b = y * ↑a + ↑d

tactic: let ur := u.reduce
state_before: a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
⊢ w * z = succPNat (x * y) ∧
    a = a' * d ∧
      b = b' * d ∧
        z * a' = succPNat (x * ↑b') ∧ w * b' = succPNat (y * ↑a') ∧ ↑z * ↑a = x * ↑b + ↑d ∧ ↑w * ↑b = y * ↑a + ↑d

tactic: have _ : d = ur.a := rfl
state_before: a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
⊢ w * z = succPNat (x * y) ∧
    a = a' * d ∧
      b = b' * d ∧
        z * a' = succPNat (x * ↑b') ∧ w * b' = succPNat (y * ↑a') ∧ ↑z * ↑a = x * ↑b + ↑d ∧ ↑w * ↑b = y * ↑a + ↑d

tactic: have hb : d = ur.b := u.reduce_isReduced'
state_before: a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝ : d = XgcdType.a ur
⊢ w * z = succPNat (x * y) ∧
    a = a' * d ∧
      b = b' * d ∧
        z * a' = succPNat (x * ↑b') ∧ w * b' = succPNat (y * ↑a') ∧ ↑z * ↑a = x * ↑b + ↑d ∧ ↑w * ↑b = y * ↑a + ↑d

tactic: have ha' : (a' : ℕ) = w + x := gcdA'_coe a b
state_before: a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝ : d = XgcdType.a ur
hb : d = XgcdType.b ur
⊢ w * z = succPNat (x * y) ∧
    a = a' * d ∧
      b = b' * d ∧
        z * a' = succPNat (x * ↑b') ∧ w * b' = succPNat (y * ↑a') ∧ ↑z * ↑a = x * ↑b + ↑d ∧ ↑w * ↑b = y * ↑a + ↑d

tactic: have hb' : (b' : ℕ) = y + z := gcdB'_coe a b
state_before: a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝ : d = XgcdType.a ur
hb : d = XgcdType.b ur
ha' : ↑a' = ↑w + x
⊢ w * z = succPNat (x * y) ∧
    a = a' * d ∧
      b = b' * d ∧
        z * a' = succPNat (x * ↑b') ∧ w * b' = succPNat (y * ↑a') ∧ ↑z * ↑a = x * ↑b + ↑d ∧ ↑w * ↑b = y * ↑a + ↑d

tactic: have hdet : w * z = succPNat (x * y) := u.reduce_isSpecial' rfl
state_before: a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝ : d = XgcdType.a ur
hb : d = XgcdType.b ur
ha' : ↑a' = ↑w + x
hb' : ↑b' = y + ↑z
⊢ w * z = succPNat (x * y) ∧
    a = a' * d ∧
      b = b' * d ∧
        z * a' = succPNat (x * ↑b') ∧ w * b' = succPNat (y * ↑a') ∧ ↑z * ↑a = x * ↑b + ↑d ∧ ↑w * ↑b = y * ↑a + ↑d

tactic: constructor
state_before: a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝ : d = XgcdType.a ur
hb : d = XgcdType.b ur
ha' : ↑a' = ↑w + x
hb' : ↑b' = y + ↑z
hdet : w * z = succPNat (x * y)
⊢ w * z = succPNat (x * y) ∧
    a = a' * d ∧
      b = b' * d ∧
        z * a' = succPNat (x * ↑b') ∧ w * b' = succPNat (y * ↑a') ∧ ↑z * ↑a = x * ↑b + ↑d ∧ ↑w * ↑b = y * ↑a + ↑d

tactic: exact hdet
state_before: case left
a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝ : d = XgcdType.a ur
hb : d = XgcdType.b ur
ha' : ↑a' = ↑w + x
hb' : ↑b' = y + ↑z
hdet : w * z = succPNat (x * y)
⊢ w * z = succPNat (x * y)

case right
a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝ : d = XgcdType.a ur
hb : d = XgcdType.b ur
ha' : ↑a' = ↑w + x
hb' : ↑b' = y + ↑z
hdet : w * z = succPNat (x * y)
⊢ a = a' * d ∧
    b = b' * d ∧
      z * a' = succPNat (x * ↑b') ∧ w * b' = succPNat (y * ↑a') ∧ ↑z * ↑a = x * ↑b + ↑d ∧ ↑w * ↑b = y * ↑a + ↑d

tactic: have hdet' : (w * z : ℕ) = x * y + 1 := by rw [← mul_coe, hdet, succPNat_coe]
state_before: case right
a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝ : d = XgcdType.a ur
hb : d = XgcdType.b ur
ha' : ↑a' = ↑w + x
hb' : ↑b' = y + ↑z
hdet : w * z = succPNat (x * y)
⊢ a = a' * d ∧
    b = b' * d ∧
      z * a' = succPNat (x * ↑b') ∧ w * b' = succPNat (y * ↑a') ∧ ↑z * ↑a = x * ↑b + ↑d ∧ ↑w * ↑b = y * ↑a + ↑d

tactic: have _ : u.v = ⟨a, b⟩ := XgcdType.start_v a b
state_before: case right
a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝ : d = XgcdType.a ur
hb : d = XgcdType.b ur
ha' : ↑a' = ↑w + x
hb' : ↑b' = y + ↑z
hdet : w * z = succPNat (x * y)
hdet' : ↑w * ↑z = x * y + 1
⊢ a = a' * d ∧
    b = b' * d ∧
      z * a' = succPNat (x * ↑b') ∧ w * b' = succPNat (y * ↑a') ∧ ↑z * ↑a = x * ↑b + ↑d ∧ ↑w * ↑b = y * ↑a + ↑d

tactic: let hv : Prod.mk (w * d + x * ur.b : ℕ) (y * d + z * ur.b : ℕ) = ⟨a, b⟩ :=
  u.reduce_v.trans (XgcdType.start_v a b)
state_before: case right
a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝¹ : d = XgcdType.a ur
hb : d = XgcdType.b ur
ha' : ↑a' = ↑w + x
hb' : ↑b' = y + ↑z
hdet : w * z = succPNat (x * y)
hdet' : ↑w * ↑z = x * y + 1
x✝ : XgcdType.v u = (↑a, ↑b)
⊢ a = a' * d ∧
    b = b' * d ∧
      z * a' = succPNat (x * ↑b') ∧ w * b' = succPNat (y * ↑a') ∧ ↑z * ↑a = x * ↑b + ↑d ∧ ↑w * ↑b = y * ↑a + ↑d

tactic: rw [← hb, ← add_mul, ← add_mul, ← ha', ← hb'] at hv
state_before: case right
a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝¹ : d = XgcdType.a ur
hb : d = XgcdType.b ur
ha' : ↑a' = ↑w + x
hb' : ↑b' = y + ↑z
hdet : w * z = succPNat (x * y)
hdet' : ↑w * ↑z = x * y + 1
x✝ : XgcdType.v u = (↑a, ↑b)
hv : (↑w * ↑d + x * ↑(XgcdType.b ur), y * ↑d + ↑z * ↑(XgcdType.b ur)) = (↑a, ↑b) :=
  Eq.trans (XgcdType.reduce_v u) (XgcdType.start_v a b)
⊢ a = a' * d ∧
    b = b' * d ∧
      z * a' = succPNat (x * ↑b') ∧ w * b' = succPNat (y * ↑a') ∧ ↑z * ↑a = x * ↑b + ↑d ∧ ↑w * ↑b = y * ↑a + ↑d

tactic: have ha'' : (a : ℕ) = a' * d := (congr_arg Prod.fst hv).symm
state_before: case right
a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝¹ : d = XgcdType.a ur
hb : d = XgcdType.b ur
ha' : ↑a' = ↑w + x
hb' : ↑b' = y + ↑z
hdet : w * z = succPNat (x * y)
hdet' : ↑w * ↑z = x * y + 1
x✝ : XgcdType.v u = (↑a, ↑b)
hv : (↑a' * ↑d, ↑b' * ↑d) = (↑a, ↑b)
⊢ a = a' * d ∧
    b = b' * d ∧
      z * a' = succPNat (x * ↑b') ∧ w * b' = succPNat (y * ↑a') ∧ ↑z * ↑a = x * ↑b + ↑d ∧ ↑w * ↑b = y * ↑a + ↑d

tactic: have hb'' : (b : ℕ) = b' * d := (congr_arg Prod.snd hv).symm
state_before: case right
a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝¹ : d = XgcdType.a ur
hb : d = XgcdType.b ur
ha' : ↑a' = ↑w + x
hb' : ↑b' = y + ↑z
hdet : w * z = succPNat (x * y)
hdet' : ↑w * ↑z = x * y + 1
x✝ : XgcdType.v u = (↑a, ↑b)
hv : (↑a' * ↑d, ↑b' * ↑d) = (↑a, ↑b)
ha'' : ↑a = ↑a' * ↑d
⊢ a = a' * d ∧
    b = b' * d ∧
      z * a' = succPNat (x * ↑b') ∧ w * b' = succPNat (y * ↑a') ∧ ↑z * ↑a = x * ↑b + ↑d ∧ ↑w * ↑b = y * ↑a + ↑d

tactic: constructor
state_before: case right
a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝¹ : d = XgcdType.a ur
hb : d = XgcdType.b ur
ha' : ↑a' = ↑w + x
hb' : ↑b' = y + ↑z
hdet : w * z = succPNat (x * y)
hdet' : ↑w * ↑z = x * y + 1
x✝ : XgcdType.v u = (↑a, ↑b)
hv : (↑a' * ↑d, ↑b' * ↑d) = (↑a, ↑b)
ha'' : ↑a = ↑a' * ↑d
hb'' : ↑b = ↑b' * ↑d
⊢ a = a' * d ∧
    b = b' * d ∧
      z * a' = succPNat (x * ↑b') ∧ w * b' = succPNat (y * ↑a') ∧ ↑z * ↑a = x * ↑b + ↑d ∧ ↑w * ↑b = y * ↑a + ↑d

tactic: exact eq ha''
state_before: case right.left
a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝¹ : d = XgcdType.a ur
hb : d = XgcdType.b ur
ha' : ↑a' = ↑w + x
hb' : ↑b' = y + ↑z
hdet : w * z = succPNat (x * y)
hdet' : ↑w * ↑z = x * y + 1
x✝ : XgcdType.v u = (↑a, ↑b)
hv : (↑a' * ↑d, ↑b' * ↑d) = (↑a, ↑b)
ha'' : ↑a = ↑a' * ↑d
hb'' : ↑b = ↑b' * ↑d
⊢ a = a' * d

case right.right
a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝¹ : d = XgcdType.a ur
hb : d = XgcdType.b ur
ha' : ↑a' = ↑w + x
hb' : ↑b' = y + ↑z
hdet : w * z = succPNat (x * y)
hdet' : ↑w * ↑z = x * y + 1
x✝ : XgcdType.v u = (↑a, ↑b)
hv : (↑a' * ↑d, ↑b' * ↑d) = (↑a, ↑b)
ha'' : ↑a = ↑a' * ↑d
hb'' : ↑b = ↑b' * ↑d
⊢ b = b' * d ∧ z * a' = succPNat (x * ↑b') ∧ w * b' = succPNat (y * ↑a') ∧ ↑z * ↑a = x * ↑b + ↑d ∧ ↑w * ↑b = y * ↑a + ↑d

tactic: constructor
state_before: case right.right
a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝¹ : d = XgcdType.a ur
hb : d = XgcdType.b ur
ha' : ↑a' = ↑w + x
hb' : ↑b' = y + ↑z
hdet : w * z = succPNat (x * y)
hdet' : ↑w * ↑z = x * y + 1
x✝ : XgcdType.v u = (↑a, ↑b)
hv : (↑a' * ↑d, ↑b' * ↑d) = (↑a, ↑b)
ha'' : ↑a = ↑a' * ↑d
hb'' : ↑b = ↑b' * ↑d
⊢ b = b' * d ∧ z * a' = succPNat (x * ↑b') ∧ w * b' = succPNat (y * ↑a') ∧ ↑z * ↑a = x * ↑b + ↑d ∧ ↑w * ↑b = y * ↑a + ↑d

tactic: exact eq hb''
state_before: case right.right.left
a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝¹ : d = XgcdType.a ur
hb : d = XgcdType.b ur
ha' : ↑a' = ↑w + x
hb' : ↑b' = y + ↑z
hdet : w * z = succPNat (x * y)
hdet' : ↑w * ↑z = x * y + 1
x✝ : XgcdType.v u = (↑a, ↑b)
hv : (↑a' * ↑d, ↑b' * ↑d) = (↑a, ↑b)
ha'' : ↑a = ↑a' * ↑d
hb'' : ↑b = ↑b' * ↑d
⊢ b = b' * d

case right.right.right
a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝¹ : d = XgcdType.a ur
hb : d = XgcdType.b ur
ha' : ↑a' = ↑w + x
hb' : ↑b' = y + ↑z
hdet : w * z = succPNat (x * y)
hdet' : ↑w * ↑z = x * y + 1
x✝ : XgcdType.v u = (↑a, ↑b)
hv : (↑a' * ↑d, ↑b' * ↑d) = (↑a, ↑b)
ha'' : ↑a = ↑a' * ↑d
hb'' : ↑b = ↑b' * ↑d
⊢ z * a' = succPNat (x * ↑b') ∧ w * b' = succPNat (y * ↑a') ∧ ↑z * ↑a = x * ↑b + ↑d ∧ ↑w * ↑b = y * ↑a + ↑d

tactic: have hza' : (z * a' : ℕ) = x * b' + 1 := by
  rw [ha', hb', mul_add, mul_add, mul_comm (z : ℕ), hdet']
  ring
state_before: case right.right.right
a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝¹ : d = XgcdType.a ur
hb : d = XgcdType.b ur
ha' : ↑a' = ↑w + x
hb' : ↑b' = y + ↑z
hdet : w * z = succPNat (x * y)
hdet' : ↑w * ↑z = x * y + 1
x✝ : XgcdType.v u = (↑a, ↑b)
hv : (↑a' * ↑d, ↑b' * ↑d) = (↑a, ↑b)
ha'' : ↑a = ↑a' * ↑d
hb'' : ↑b = ↑b' * ↑d
⊢ z * a' = succPNat (x * ↑b') ∧ w * b' = succPNat (y * ↑a') ∧ ↑z * ↑a = x * ↑b + ↑d ∧ ↑w * ↑b = y * ↑a + ↑d

tactic: have hwb' : (w * b' : ℕ) = y * a' + 1 := by
  rw [ha', hb', mul_add, mul_add, hdet']
  ring
state_before: case right.right.right
a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝¹ : d = XgcdType.a ur
hb : d = XgcdType.b ur
ha' : ↑a' = ↑w + x
hb' : ↑b' = y + ↑z
hdet : w * z = succPNat (x * y)
hdet' : ↑w * ↑z = x * y + 1
x✝ : XgcdType.v u = (↑a, ↑b)
hv : (↑a' * ↑d, ↑b' * ↑d) = (↑a, ↑b)
ha'' : ↑a = ↑a' * ↑d
hb'' : ↑b = ↑b' * ↑d
hza' : ↑z * ↑a' = x * ↑b' + 1
⊢ z * a' = succPNat (x * ↑b') ∧ w * b' = succPNat (y * ↑a') ∧ ↑z * ↑a = x * ↑b + ↑d ∧ ↑w * ↑b = y * ↑a + ↑d

tactic: constructor
state_before: case right.right.right
a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝¹ : d = XgcdType.a ur
hb : d = XgcdType.b ur
ha' : ↑a' = ↑w + x
hb' : ↑b' = y + ↑z
hdet : w * z = succPNat (x * y)
hdet' : ↑w * ↑z = x * y + 1
x✝ : XgcdType.v u = (↑a, ↑b)
hv : (↑a' * ↑d, ↑b' * ↑d) = (↑a, ↑b)
ha'' : ↑a = ↑a' * ↑d
hb'' : ↑b = ↑b' * ↑d
hza' : ↑z * ↑a' = x * ↑b' + 1
hwb' : ↑w * ↑b' = y * ↑a' + 1
⊢ z * a' = succPNat (x * ↑b') ∧ w * b' = succPNat (y * ↑a') ∧ ↑z * ↑a = x * ↑b + ↑d ∧ ↑w * ↑b = y * ↑a + ↑d

tactic: constructor
state_before: case right.right.right.right
a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝¹ : d = XgcdType.a ur
hb : d = XgcdType.b ur
ha' : ↑a' = ↑w + x
hb' : ↑b' = y + ↑z
hdet : w * z = succPNat (x * y)
hdet' : ↑w * ↑z = x * y + 1
x✝ : XgcdType.v u = (↑a, ↑b)
hv : (↑a' * ↑d, ↑b' * ↑d) = (↑a, ↑b)
ha'' : ↑a = ↑a' * ↑d
hb'' : ↑b = ↑b' * ↑d
hza' : ↑z * ↑a' = x * ↑b' + 1
hwb' : ↑w * ↑b' = y * ↑a' + 1
⊢ w * b' = succPNat (y * ↑a') ∧ ↑z * ↑a = x * ↑b + ↑d ∧ ↑w * ↑b = y * ↑a + ↑d

tactic: rw [ha'', hb'']
state_before: case right.right.right.right.right
a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝¹ : d = XgcdType.a ur
hb : d = XgcdType.b ur
ha' : ↑a' = ↑w + x
hb' : ↑b' = y + ↑z
hdet : w * z = succPNat (x * y)
hdet' : ↑w * ↑z = x * y + 1
x✝ : XgcdType.v u = (↑a, ↑b)
hv : (↑a' * ↑d, ↑b' * ↑d) = (↑a, ↑b)
ha'' : ↑a = ↑a' * ↑d
hb'' : ↑b = ↑b' * ↑d
hza' : ↑z * ↑a' = x * ↑b' + 1
hwb' : ↑w * ↑b' = y * ↑a' + 1
⊢ ↑z * ↑a = x * ↑b + ↑d ∧ ↑w * ↑b = y * ↑a + ↑d

tactic: repeat' rw [← @mul_assoc]
state_before: case right.right.right.right.right
a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝¹ : d = XgcdType.a ur
hb : d = XgcdType.b ur
ha' : ↑a' = ↑w + x
hb' : ↑b' = y + ↑z
hdet : w * z = succPNat (x * y)
hdet' : ↑w * ↑z = x * y + 1
x✝ : XgcdType.v u = (↑a, ↑b)
hv : (↑a' * ↑d, ↑b' * ↑d) = (↑a, ↑b)
ha'' : ↑a = ↑a' * ↑d
hb'' : ↑b = ↑b' * ↑d
hza' : ↑z * ↑a' = x * ↑b' + 1
hwb' : ↑w * ↑b' = y * ↑a' + 1
⊢ ↑z * (↑a' * ↑d) = x * (↑b' * ↑d) + ↑d ∧ ↑w * (↑b' * ↑d) = y * (↑a' * ↑d) + ↑d

tactic: rw [hza', hwb']
state_before: case right.right.right.right.right
a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝¹ : d = XgcdType.a ur
hb : d = XgcdType.b ur
ha' : ↑a' = ↑w + x
hb' : ↑b' = y + ↑z
hdet : w * z = succPNat (x * y)
hdet' : ↑w * ↑z = x * y + 1
x✝ : XgcdType.v u = (↑a, ↑b)
hv : (↑a' * ↑d, ↑b' * ↑d) = (↑a, ↑b)
ha'' : ↑a = ↑a' * ↑d
hb'' : ↑b = ↑b' * ↑d
hza' : ↑z * ↑a' = x * ↑b' + 1
hwb' : ↑w * ↑b' = y * ↑a' + 1
⊢ ↑z * ↑a' * ↑d = x * ↑b' * ↑d + ↑d ∧ ↑w * ↑b' * ↑d = y * ↑a' * ↑d + ↑d

tactic: constructor <;> ring
state_before: case right.right.right.right.right
a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝¹ : d = XgcdType.a ur
hb : d = XgcdType.b ur
ha' : ↑a' = ↑w + x
hb' : ↑b' = y + ↑z
hdet : w * z = succPNat (x * y)
hdet' : ↑w * ↑z = x * y + 1
x✝ : XgcdType.v u = (↑a, ↑b)
hv : (↑a' * ↑d, ↑b' * ↑d) = (↑a, ↑b)
ha'' : ↑a = ↑a' * ↑d
hb'' : ↑b = ↑b' * ↑d
hza' : ↑z * ↑a' = x * ↑b' + 1
hwb' : ↑w * ↑b' = y * ↑a' + 1
⊢ (x * ↑b' + 1) * ↑d = x * ↑b' * ↑d + ↑d ∧ (y * ↑a' + 1) * ↑d = y * ↑a' * ↑d + ↑d

tactic: rw [← mul_coe, hdet, succPNat_coe]
state_before: a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝ : d = XgcdType.a ur
hb : d = XgcdType.b ur
ha' : ↑a' = ↑w + x
hb' : ↑b' = y + ↑z
hdet : w * z = succPNat (x * y)
⊢ ↑w * ↑z = x * y + 1

tactic: rw [ha', hb', mul_add, mul_add, mul_comm (z : ℕ), hdet']
state_before: a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝¹ : d = XgcdType.a ur
hb : d = XgcdType.b ur
ha' : ↑a' = ↑w + x
hb' : ↑b' = y + ↑z
hdet : w * z = succPNat (x * y)
hdet' : ↑w * ↑z = x * y + 1
x✝ : XgcdType.v u = (↑a, ↑b)
hv : (↑a' * ↑d, ↑b' * ↑d) = (↑a, ↑b)
ha'' : ↑a = ↑a' * ↑d
hb'' : ↑b = ↑b' * ↑d
⊢ ↑z * ↑a' = x * ↑b' + 1

tactic: ring
state_before: a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝¹ : d = XgcdType.a ur
hb : d = XgcdType.b ur
ha' : ↑a' = ↑w + x
hb' : ↑b' = y + ↑z
hdet : w * z = succPNat (x * y)
hdet' : ↑w * ↑z = x * y + 1
x✝ : XgcdType.v u = (↑a, ↑b)
hv : (↑a' * ↑d, ↑b' * ↑d) = (↑a, ↑b)
ha'' : ↑a = ↑a' * ↑d
hb'' : ↑b = ↑b' * ↑d
⊢ x * y + 1 + ↑z * x = x * y + x * ↑z + 1

tactic: rw [ha', hb', mul_add, mul_add, hdet']
state_before: a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝¹ : d = XgcdType.a ur
hb : d = XgcdType.b ur
ha' : ↑a' = ↑w + x
hb' : ↑b' = y + ↑z
hdet : w * z = succPNat (x * y)
hdet' : ↑w * ↑z = x * y + 1
x✝ : XgcdType.v u = (↑a, ↑b)
hv : (↑a' * ↑d, ↑b' * ↑d) = (↑a, ↑b)
ha'' : ↑a = ↑a' * ↑d
hb'' : ↑b = ↑b' * ↑d
hza' : ↑z * ↑a' = x * ↑b' + 1
⊢ ↑w * ↑b' = y * ↑a' + 1

tactic: ring
state_before: a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝¹ : d = XgcdType.a ur
hb : d = XgcdType.b ur
ha' : ↑a' = ↑w + x
hb' : ↑b' = y + ↑z
hdet : w * z = succPNat (x * y)
hdet' : ↑w * ↑z = x * y + 1
x✝ : XgcdType.v u = (↑a, ↑b)
hv : (↑a' * ↑d, ↑b' * ↑d) = (↑a, ↑b)
ha'' : ↑a = ↑a' * ↑d
hb'' : ↑b = ↑b' * ↑d
hza' : ↑z * ↑a' = x * ↑b' + 1
⊢ ↑w * y + (x * y + 1) = y * ↑w + y * x + 1

tactic: apply eq
state_before: case right.right.right.left
a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝¹ : d = XgcdType.a ur
hb : d = XgcdType.b ur
ha' : ↑a' = ↑w + x
hb' : ↑b' = y + ↑z
hdet : w * z = succPNat (x * y)
hdet' : ↑w * ↑z = x * y + 1
x✝ : XgcdType.v u = (↑a, ↑b)
hv : (↑a' * ↑d, ↑b' * ↑d) = (↑a, ↑b)
ha'' : ↑a = ↑a' * ↑d
hb'' : ↑b = ↑b' * ↑d
hza' : ↑z * ↑a' = x * ↑b' + 1
hwb' : ↑w * ↑b' = y * ↑a' + 1
⊢ z * a' = succPNat (x * ↑b')

tactic: rw [succPNat_coe, Nat.succ_eq_add_one, mul_coe, hza']
state_before: case right.right.right.left.a
a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝¹ : d = XgcdType.a ur
hb : d = XgcdType.b ur
ha' : ↑a' = ↑w + x
hb' : ↑b' = y + ↑z
hdet : w * z = succPNat (x * y)
hdet' : ↑w * ↑z = x * y + 1
x✝ : XgcdType.v u = (↑a, ↑b)
hv : (↑a' * ↑d, ↑b' * ↑d) = (↑a, ↑b)
ha'' : ↑a = ↑a' * ↑d
hb'' : ↑b = ↑b' * ↑d
hza' : ↑z * ↑a' = x * ↑b' + 1
hwb' : ↑w * ↑b' = y * ↑a' + 1
⊢ ↑(z * a') = ↑(succPNat (x * ↑b'))

tactic: apply eq
state_before: case right.right.right.right.left
a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝¹ : d = XgcdType.a ur
hb : d = XgcdType.b ur
ha' : ↑a' = ↑w + x
hb' : ↑b' = y + ↑z
hdet : w * z = succPNat (x * y)
hdet' : ↑w * ↑z = x * y + 1
x✝ : XgcdType.v u = (↑a, ↑b)
hv : (↑a' * ↑d, ↑b' * ↑d) = (↑a, ↑b)
ha'' : ↑a = ↑a' * ↑d
hb'' : ↑b = ↑b' * ↑d
hza' : ↑z * ↑a' = x * ↑b' + 1
hwb' : ↑w * ↑b' = y * ↑a' + 1
⊢ w * b' = succPNat (y * ↑a')

tactic: rw [succPNat_coe, Nat.succ_eq_add_one, mul_coe, hwb']
state_before: case right.right.right.right.left.a
a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝¹ : d = XgcdType.a ur
hb : d = XgcdType.b ur
ha' : ↑a' = ↑w + x
hb' : ↑b' = y + ↑z
hdet : w * z = succPNat (x * y)
hdet' : ↑w * ↑z = x * y + 1
x✝ : XgcdType.v u = (↑a, ↑b)
hv : (↑a' * ↑d, ↑b' * ↑d) = (↑a, ↑b)
ha'' : ↑a = ↑a' * ↑d
hb'' : ↑b = ↑b' * ↑d
hza' : ↑z * ↑a' = x * ↑b' + 1
hwb' : ↑w * ↑b' = y * ↑a' + 1
⊢ ↑(w * b') = ↑(succPNat (y * ↑a'))

tactic: rw [← @mul_assoc]
state_before: case right.right.right.right.right
a b : ℕ+
d : ℕ+ := gcdD a b
w : ℕ+ := gcdW a b
x : ℕ := gcdX a b
y : ℕ := gcdY a b
z : ℕ+ := gcdZ a b
a' : ℕ+ := gcdA' a b
b' : ℕ+ := gcdB' a b
u : XgcdType := XgcdType.start a b
ur : XgcdType := XgcdType.reduce u
x✝¹ : d = XgcdType.a ur
hb : d = XgcdType.b ur
ha' : ↑a' = ↑w + x
hb' : ↑b' = y + ↑z
hdet : w * z = succPNat (x * y)
hdet' : ↑w * ↑z = x * y + 1
x✝ : XgcdType.v u = (↑a, ↑b)
hv : (↑a' * ↑d, ↑b' * ↑d) = (↑a, ↑b)
ha'' : ↑a = ↑a' * ↑d
hb'' : ↑b = ↑b' * ↑d
hza' : ↑z * ↑a' = x * ↑b' + 1
hwb' : ↑w * ↑b' = y * ↑a' + 1
⊢ ↑z * ↑a' * ↑d = x * ↑b' * ↑d + ↑d ∧ ↑w * ↑b' * ↑d = y * ↑a' * ↑d + ↑d