-- 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

-- 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

-- Local lemmas used:
content: theorem ZMod.cast_rat_nonneg [NeZero n] (a : ZMod n) : 0 ≤ (a.cast : ℚ)

content: theorem RAY_SCALE_rat_pos : 0 < (RAY_SCALE : ℚ)

-- Target theorem and proof:
theorem toRat_nonneg : 0 ≤ r.toRat
:= by
  simp [Ray.toRat]
  rw [le_div_iff RAY_SCALE_rat_pos, zero_mul]
  exact ZMod.cast_rat_nonneg (Ray.toZMod r)