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

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: 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_rat_pos : 0 < (WAD_SCALE : ℚ)

content: theorem toRat_lt_toRat_of_val_lt_val (h : @ZMod.val U128_MOD w < @ZMod.val U128_MOD w') :
    w.toRat < w'.toRat

content: theorem toRat_injective : Function.Injective Wad.toRat

content: @[simp]
theorem toRat_zero : (0 : Wad).toRat = 0

-- Target theorem and proof:
theorem val_eq_zero_of_toRat_neg' (x : Wad) (p q : Unit)
  (h : SignedWad.toRat ((x, .inr p) : SignedWad) = SignedWad.toRat ((x, .inl q) : SignedWad)) :
    x = 0
:= by
  simp only [toRat, SierraBool_toBool_inr, ite_true, SierraBool_toBool_inl, ite_false,
    neg_eq_self_iff] at h
  rw [← Wad.toRat_zero] at h
  exact Wad.toRat_injective h