File: .lake/packages/batteries/Batteries/Data/Rat/Basic.lean

full_name: Rat.num
code: /--
Rational numbers, implemented as a pair of integers `num / den` such that the
denominator is positive and the numerator and denominator are coprime.
-/
-- `Rat` is not tagged with the `ext` attribute, since this is more often than not undesirable
structure Rat where
  /-- Constructs a rational number from components.
  We rename the constructor to `mk'` to avoid a clash with the smart constructor. -/
  mk' ::
  /-- The numerator of the rational number is an integer. -/
  num : Int
  /-- The denominator of the rational number is a natural number. -/
  den : Nat := 1
  /-- The denominator is nonzero. -/
  den_nz : den ≠ 0 := by decide
  /-- The numerator and denominator are coprime: it is in "reduced form". -/
  reduced : num.natAbs.Coprime den := by decide
  deriving DecidableEq
goal: Int

full_name: Rat.den_nz
code: /--
Rational numbers, implemented as a pair of integers `num / den` such that the
denominator is positive and the numerator and denominator are coprime.
-/
-- `Rat` is not tagged with the `ext` attribute, since this is more often than not undesirable
structure Rat where
  /-- Constructs a rational number from components.
  We rename the constructor to `mk'` to avoid a clash with the smart constructor. -/
  mk' ::
  /-- The numerator of the rational number is an integer. -/
  num : Int
  /-- The denominator of the rational number is a natural number. -/
  den : Nat := 1
  /-- The denominator is nonzero. -/
  den_nz : den ≠ 0 := by decide
  /-- The numerator and denominator are coprime: it is in "reduced form". -/
  reduced : num.natAbs.Coprime den := by decide
  deriving DecidableEq
goal: self.den ≠ 0

full_name: Rat.mk'
code: /--
Rational numbers, implemented as a pair of integers `num / den` such that the
denominator is positive and the numerator and denominator are coprime.
-/
-- `Rat` is not tagged with the `ext` attribute, since this is more often than not undesirable
structure Rat where
  /-- Constructs a rational number from components.
  We rename the constructor to `mk'` to avoid a clash with the smart constructor. -/
  mk' ::
  /-- The numerator of the rational number is an integer. -/
  num : Int
  /-- The denominator of the rational number is a natural number. -/
  den : Nat := 1
  /-- The denominator is nonzero. -/
  den_nz : den ≠ 0 := by decide
  /-- The numerator and denominator are coprime: it is in "reduced form". -/
  reduced : num.natAbs.Coprime den := by decide
  deriving DecidableEq
goal: Rat

full_name: Rat.reduced
code: /--
Rational numbers, implemented as a pair of integers `num / den` such that the
denominator is positive and the numerator and denominator are coprime.
-/
-- `Rat` is not tagged with the `ext` attribute, since this is more often than not undesirable
structure Rat where
  /-- Constructs a rational number from components.
  We rename the constructor to `mk'` to avoid a clash with the smart constructor. -/
  mk' ::
  /-- The numerator of the rational number is an integer. -/
  num : Int
  /-- The denominator of the rational number is a natural number. -/
  den : Nat := 1
  /-- The denominator is nonzero. -/
  den_nz : den ≠ 0 := by decide
  /-- The numerator and denominator are coprime: it is in "reduced form". -/
  reduced : num.natAbs.Coprime den := by decide
  deriving DecidableEq
goal: self.num.natAbs.Coprime self.den

full_name: Rat.den
code: /--
Rational numbers, implemented as a pair of integers `num / den` such that the
denominator is positive and the numerator and denominator are coprime.
-/
-- `Rat` is not tagged with the `ext` attribute, since this is more often than not undesirable
structure Rat where
  /-- Constructs a rational number from components.
  We rename the constructor to `mk'` to avoid a clash with the smart constructor. -/
  mk' ::
  /-- The numerator of the rational number is an integer. -/
  num : Int
  /-- The denominator of the rational number is a natural number. -/
  den : Nat := 1
  /-- The denominator is nonzero. -/
  den_nz : den ≠ 0 := by decide
  /-- The numerator and denominator are coprime: it is in "reduced form". -/
  reduced : num.natAbs.Coprime den := by decide
  deriving DecidableEq
goal: Nat

full_name: Rat
code: /--
Rational numbers, implemented as a pair of integers `num / den` such that the
denominator is positive and the numerator and denominator are coprime.
-/
-- `Rat` is not tagged with the `ext` attribute, since this is more often than not undesirable
structure Rat where
  /-- Constructs a rational number from components.
  We rename the constructor to `mk'` to avoid a clash with the smart constructor. -/
  mk' ::
  /-- The numerator of the rational number is an integer. -/
  num : Int
  /-- The denominator of the rational number is a natural number. -/
  den : Nat := 1
  /-- The denominator is nonzero. -/
  den_nz : den ≠ 0 := by decide
  /-- The numerator and denominator are coprime: it is in "reduced form". -/
  reduced : num.natAbs.Coprime den := by decide
  deriving DecidableEq
goal: Type

full_name: instInhabitedRat
code: instance : Inhabited Rat 
goal: Inhabited Rat

full_name: instToStringRat
code: instance : ToString Rat 
goal: ToString Rat

full_name: instReprRat
code: instance : Repr Rat 
goal: Repr Rat

full_name: Rat.den_pos
code: theorem Rat.den_pos (self : Rat) : 0 < self.den 
goal: 0 < self.den

full_name: Rat.maybeNormalize
code: /--
Auxiliary definition for `Rat.normalize`. Constructs `num / den` as a rational number,
dividing both `num` and `den` by `g` (which is the gcd of the two) if it is not 1.
-/
@[inline] def Rat.maybeNormalize (num : Int) (den g : Nat)
    (den_nz : den / g ≠ 0) (reduced : (num.div g).natAbs.Coprime (den / g)) : Rat 
goal: Rat

full_name: Rat.normalize.den_nz
code: theorem Rat.normalize.den_nz {num : Int} {den g : Nat} (den_nz : den ≠ 0)
    (e : g = num.natAbs.gcd den) : den / g ≠ 0 
goal: den / g ≠ 0

full_name: Rat.normalize.reduced
code: theorem Rat.normalize.reduced {num : Int} {den g : Nat} (den_nz : den ≠ 0)
    (e : g = num.natAbs.gcd den) : (num.div g).natAbs.Coprime (den / g) 
goal: (num.div ↑g).natAbs.Coprime (den / g)

full_name: Rat.normalize
code: /--
Construct a normalized `Rat` from a numerator and nonzero denominator.
This is a "smart constructor" that divides the numerator and denominator by
the gcd to ensure that the resulting rational number is normalized.
-/
@[inline] def Rat.normalize (num : Int) (den : Nat := 1) (den_nz : den ≠ 0 := by decide) : Rat 
goal: Rat

full_name: mkRat
code: /--
Construct a rational number from a numerator and denominator.
This is a "smart constructor" that divides the numerator and denominator by
the gcd to ensure that the resulting rational number is normalized, and returns
zero if `den` is zero.
-/
def mkRat (num : Int) (den : Nat) : Rat 
goal: Rat

full_name: Rat.ofInt
code: /-- Embedding of `Int` in the rational numbers. -/
def ofInt (num : Int) : Rat 
goal: Rat

full_name: Rat.instNatCast
code: instance : NatCast Rat 
goal: NatCast Rat

full_name: Rat.instIntCast
code: instance : IntCast Rat 
goal: IntCast Rat

full_name: Rat.instOfNat
code: instance : OfNat Rat n 
goal: OfNat Rat n

full_name: Rat.isInt
code: /-- Is this rational number integral? -/
@[inline] protected def isInt (a : Rat) : Bool 
goal: Bool

full_name: Rat.divInt
code: /-- Form the quotient `n / d` where `n d : Int`. -/
def divInt : Int → Int → Rat
  
goal: Int → Int → Rat

full_name: Rat.«_aux_.lake_packages_batteries_Batteries_Data_Rat_Basic___unexpand_Rat_divInt_1»
code: @[inherit_doc] scoped infixl:70 " /. " => Rat.divInt
goal: Lean.PrettyPrinter.Unexpander

full_name: Rat.«_aux_.lake_packages_batteries_Batteries_Data_Rat_Basic___macroRules_Rat_term_/.__1»
code: @[inherit_doc] scoped infixl:70 " /. " => Rat.divInt
goal: Lean.Macro

full_name: Rat.ofScientific
code: /-- Implements "scientific notation" `123.4e-5` for rational numbers. (This definition is
`@[irreducible]` because you don't want to unfold it. Use `Rat.ofScientific_def`,
`Rat.ofScientific_true_def`, or `Rat.ofScientific_false_def` instead.) -/
@[irreducible] protected def ofScientific (m : Nat) (s : Bool) (e : Nat) : Rat 
goal: Rat

full_name: Rat.instOfScientific
code: instance : OfScientific Rat 
goal: OfScientific Rat

full_name: Rat.blt
code: /-- Rational number strictly less than relation, as a `Bool`. -/
protected def blt (a b : Rat) : Bool 
goal: Bool

full_name: Rat.instLT
code: instance : LT Rat 
goal: LT Rat

full_name: Rat.instDecidableLt
code: instance (a b : Rat) : Decidable (a < b) 
goal: Decidable (a < b)

full_name: Rat.instLE
code: instance : LE Rat 
goal: LE Rat

full_name: Rat.instDecidableLe
code: instance (a b : Rat) : Decidable (a ≤ b) 
goal: Decidable (a ≤ b)

full_name: Rat.mul
code: /-- Multiplication of rational numbers. (This definition is `@[irreducible]` because you don't
want to unfold it. Use `Rat.mul_def` instead.) -/
@[irreducible] protected def mul (a b : Rat) : Rat 
goal: Rat

full_name: Rat.instMul
code: instance : Mul Rat 
goal: Mul Rat

full_name: Rat.inv
code: /--
The inverse of a rational number. Note: `inv 0 = 0`. (This definition is `@[irreducible]`
because you don't want to unfold it. Use `Rat.inv_def` instead.)
-/
@[irreducible] protected def inv (a : Rat) : Rat 
goal: Rat

full_name: Rat.div
code: /-- Division of rational numbers. Note: `div a 0 = 0`. -/
protected def div : Rat → Rat → Rat 
goal: Rat → Rat → Rat

full_name: Rat.instDiv
code: /-- Division of rational numbers. Note: `div a 0 = 0`.  Written with a separate function `Rat.div`
as a wrapper so that the definition is not unfolded at `.instance` transparency. -/
instance : Div Rat 
goal: Div Rat

full_name: Rat.add.aux
code: theorem add.aux (a b : Rat) {g ad bd} (hg : g = a.den.gcd b.den)
    (had : ad = a.den / g) (hbd : bd = b.den / g) :
    let den := ad * b.den; let num := a.num * bd + b.num * ad
    num.natAbs.gcd g = num.natAbs.gcd den 
goal: let den := ad * b.den;
let num := a.num * ↑bd + b.num * ↑ad;
num.natAbs.gcd g = num.natAbs.gcd den

full_name: Rat.add
code: /--
Addition of rational numbers. (This definition is `@[irreducible]` because you don't want to
unfold it. Use `Rat.add_def` instead.)
-/
@[irreducible] protected def add (a b : Rat) : Rat 
goal: Rat

full_name: Rat.instAdd
code: instance : Add Rat 
goal: Add Rat

full_name: Rat.neg
code: /-- Negation of rational numbers. -/
protected def neg (a : Rat) : Rat 
goal: Rat

full_name: Rat.instNeg
code: instance : Neg Rat 
goal: Neg Rat

full_name: Rat.sub.aux
code: theorem sub.aux (a b : Rat) {g ad bd} (hg : g = a.den.gcd b.den)
    (had : ad = a.den / g) (hbd : bd = b.den / g) :
    let den := ad * b.den; let num := a.num * bd - b.num * ad
    num.natAbs.gcd g = num.natAbs.gcd den 
goal: let den := ad * b.den;
let num := a.num * ↑bd - b.num * ↑ad;
num.natAbs.gcd g = num.natAbs.gcd den

full_name: Rat.sub
code: /-- Subtraction of rational numbers. (This definition is `@[irreducible]` because you don't want to
unfold it. Use `Rat.sub_def` instead.)
-/
@[irreducible] protected def sub (a b : Rat) : Rat 
goal: Rat

full_name: Rat.instSub
code: instance : Sub Rat 
goal: Sub Rat

full_name: Rat.floor
code: /-- The floor of a rational number `a` is the largest integer less than or equal to `a`. -/
protected def floor (a : Rat) : Int 
goal: Int

full_name: Rat.ceil
code: /-- The ceiling of a rational number `a` is the smallest integer greater than or equal to `a`. -/
protected def ceil (a : Rat) : Int 
goal: Int

full_name: Rat.toFloat
code: /-- Convert this rational number to a `Float` value. -/
protected def toFloat (a : Rat) : Float 
goal: Float

full_name: Float.toRat?
code: /-- Convert this floating point number to a rational value. -/
protected def _root_.Float.toRat? (a : Float) : Option Rat 
goal: Option Rat

full_name: Float.toRat0
code: /--
Convert this floating point number to a rational value,
mapping non-finite values (`inf`, `-inf`, `nan`) to 0.
-/
protected def _root_.Float.toRat0 (a : Float) : Rat 
goal: Rat

full_name: Rat.instCoeFloat
code: instance : Coe Rat Float 
goal: Coe Rat Float