TorchLean API

NN.Floats.NeuralFloat.Format.Generic

Generic Format Properties #

Elementary closure properties of the Flocq-style generic format. These lemmas are independent of the standard FIX, FLX, and FLT families.

@[simp]

Magnitude is invariant under negation.

@[simp]
theorem TorchLean.Floats.neuralCexp_neg {β : NeuralRadix} {fexp : } [NeuralValidExp fexp] (x : ) :
neuralCexp β fexp (-x) = neuralCexp β fexp x

The canonical exponent is invariant under negation.

@[simp]

Negation negates the canonical scaled mantissa.

@[simp]

Zero belongs to every valid generic format.

theorem TorchLean.Floats.neural_generic_format_neg {β : NeuralRadix} {fexp : } [NeuralValidExp fexp] (x : ) (hx : neuralGenericFormat β fexp x) :

Generic formats are closed under negation.

@[simp]

A value is representable exactly when its negation is representable.

A value is representable exactly when its absolute value is representable.

theorem TorchLean.Floats.neural_generic_format_bpow {β : NeuralRadix} {fexp : } [NeuralValidExp fexp] (e : ) (h : fexp (e + 1) e) :

A radix power is representable whenever its canonical exponent is no larger than its exponent.

A mantissa/exponent representation is generic when its stored exponent is at least the canonical exponent selected for its value.

theorem TorchLean.Floats.neuralCexp_lt_magnitude_of_pos_generic {β : NeuralRadix} {fexp : } [NeuralValidExp fexp] {x : } (hx : 0 < x) (hfmt : neuralGenericFormat β fexp x) :

A positive representable value uses a canonical exponent strictly below its magnitude.

theorem TorchLean.Floats.neural_fexp_succ_le_of_generic_bpow {β : NeuralRadix} {fexp : } [NeuralValidExp fexp] (e : ) (hfmt : neuralGenericFormat β fexp (neuralBpow β e)) :
fexp (e + 1) e

Representability of a radix power forces its canonical exponent below that power.

theorem TorchLean.Floats.neural_fexp_le_of_generic_bpow {β : NeuralRadix} {fexp : } [NeuralValidExp fexp] (e : ) (hfmt : neuralGenericFormat β fexp (neuralBpow β e)) :
fexp e e

If β^e is representable, the exponent selected for the bin below it is at most e.

theorem TorchLean.Floats.neural_generic_inclusion_mag {β : NeuralRadix} {fexp₁ fexp₂ : } [NeuralValidExp fexp₁] [NeuralValidExp fexp₂] {x : } (hexp : x 0fexp₂ (neuralMagnitude β x) fexp₁ (neuralMagnitude β x)) (hx : neuralGenericFormat β fexp₁ x) :
neuralGenericFormat β fexp₂ x

A value representable with fexp₁ remains representable with fexp₂ when the second canonical exponent is no larger at that value's magnitude. The condition is local because representability of x only depends on the exponent selected at magnitude x.

theorem TorchLean.Floats.neural_generic_inclusion {β : NeuralRadix} {fexp₁ fexp₂ : } [NeuralValidExp fexp₁] [NeuralValidExp fexp₂] (hexp : ∀ (e : ), fexp₂ e fexp₁ e) {x : } (hx : neuralGenericFormat β fexp₁ x) :
neuralGenericFormat β fexp₂ x

Pointwise-smaller exponent selection defines a containing generic format.

theorem TorchLean.Floats.neural_generic_format_discrete {β : NeuralRadix} {fexp : } [NeuralValidExp fexp] (x : ) (m : ) (hlower : m * neuralBpow β (neuralCexp β fexp x) < x) (hupper : x < ↑(m + 1) * neuralBpow β (neuralCexp β fexp x)) :

No generic-format value lies strictly between consecutive points on its canonical grid.

theorem TorchLean.Floats.neural_canonical_exists_of_generic {β : NeuralRadix} {fexp : } [NeuralValidExp fexp] {x : } (hx : neuralGenericFormat β fexp x) :
∃ (f : NeuralFloat β), x = neuralToReal f NeuralCanonical β fexp f

Every generic-format value has a canonical mantissa/exponent representation.

The real value of a canonical representation belongs to its generic format.

theorem TorchLean.Floats.neural_canonical_unique {β : NeuralRadix} {fexp : } [NeuralValidExp fexp] {f g : NeuralFloat β} (hf : NeuralCanonical β fexp f) (hg : NeuralCanonical β fexp g) (hval : neuralToReal f = neuralToReal g) :
f = g

Canonical representations of the same real value are equal.