-- WadrayVerification/Aux.lean

import CorelibVerification.Aux.ZMod

import Aegis.Aux.Bool

import Aegis.Aux.ZMod.DivMod

open Sierra

def Wad : Type := UInt128

namespace Wad

def WAD_SCALE : ℕ := 1000000000000000000

variable (w w' : Wad)

protected def toZMod : UInt128 := w

protected def toRat : ℚ := w.toZMod.val / WAD_SCALE

end Wad

def Ray : Type := UInt128

namespace Ray

variable (r r' : Ray)

protected def toZMod : UInt128 := r

protected def add : Ray := r.toZMod + r'.toZMod

end Ray

def SignedWad := UInt128 × (Unit ⊕ Unit)

namespace SignedWad

variable (w w₁ w₂ : SignedWad)

def toRat : ℚ := if w.2 then -(Wad.toRat w.1) else Wad.toRat w.1

-- Repository definitions used:
content: ...

-- Repository lemmas used:
content: theorem List.getElem_append_left{α : Type u_1} {l₁ l₂ : List α} {i : Nat} (hn : i < l₁.length) :\n(l₁ ++ l₂)[i] = l₁[i]

-- Local definitions used:
content: def Wad : Type := UInt128

content: def WAD_SCALE : ℕ := 1000000000000000000

content: protected def toZMod : UInt128 := w

content: protected def toRat : ℚ := w.toZMod.val / WAD_SCALE

content: def Ray : Type := UInt128

content: protected def toZMod : UInt128 := r

content: protected def add : Ray := r.toZMod + r'.toZMod

content: def SignedWad := UInt128 × (Unit ⊕ Unit)

content: def toRat : ℚ := if w.2 then -(Wad.toRat w.1) else Wad.toRat w.1

-- Local lemmas used:
content: theorem WAD_SCALE_pos : 0 < WAD_SCALE

-- Target theorem and proof:
theorem toRat_eq_zero_iff : w.toRat = 0 ↔ w.1 = 0
:= by
  have := Wad.WAD_SCALE_pos
  rcases w with ⟨w, (s|s)⟩ <;> cases s
  <;> simp only [SignedWad.toRat, Wad.toRat, Wad.toZMod]
  <;> aesop (add simp ZMod.cast_rat_eq_zero_iff)