-- WadrayVerification/Aux.lean

import CorelibVerification.Aux.ZMod

import Aegis.Aux.Bool

import Aegis.Aux.ZMod.DivMod

open Sierra

namespace Wad

variable (w w' : Wad)

end Wad

def Ray : Type := UInt128

namespace Ray

def RAY_SCALE : ℕ := 1000000000000000000000000000

variable (r r' : Ray)

protected def toZMod : UInt128 := r

protected def toRat : ℚ := r.toZMod.val / RAY_SCALE

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

end Ray

namespace SignedWad

variable (w w₁ w₂ : SignedWad)

end SignedWad

def SignedRay := UInt128 × (Unit ⊕ Unit)

namespace SignedRay

variable (w w₁ w₂ : SignedRay)

def toRat : ℚ := if SierraBool.toBool w.2 then -(Ray.toRat w.1) else Ray.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 Ray : Type := UInt128

content: def RAY_SCALE : ℕ := 1000000000000000000000000000

content: protected def toZMod : UInt128 := r

content: protected def toRat : ℚ := r.toZMod.val / RAY_SCALE

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

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

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

-- Local lemmas used:
content: theorem RAY_SCALE_pos : 0 < RAY_SCALE

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