Documentation

Hale.Scientific.Data.Scientific

A number in scientific notation: $c \times 10^{e}$.

  • coefficient — the significand $c$ (arbitrary-precision integer)
  • base10Exponent — the exponent $e$ (arbitrary-precision integer)

Two Scientific values are logically equal when they represent the same real number; structural equality after normalize is canonical.

  • coefficient : Int

    The significand $c$.

  • base10Exponent : Int

    The base-10 exponent $e$.

Instances For
    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      @[inline]

      Smart constructor: $\text{scientific}(c, e) = c \times 10^{e}$.

      Equations
      Instances For
        @[inline]

        Create a Scientific from an integer: $n \mapsto n \times 10^{0}$.

        Equations
        Instances For

          Remove trailing zeros from the coefficient, adjusting the exponent.

          $$\text{normalize}(c \times 10^{e}) = (c / 10^{k}) \times 10^{e+k}$$

          where $k$ is the number of trailing zeros in $c$. The result is canonical: the coefficient has no trailing zeros (or is zero).

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            @[inline]

            Is the number zero? $$\text{isZero}(s) \iff c = 0$$

            Equations
            Instances For

              Is the number an integer? True when the exponent is non-negative (after normalization).

              Equations
              Instances For
                @[inline]

                Is the number negative zero? Always false since Int has no negative zero.

                Equations
                Instances For

                  Convert to Float (may lose precision for large or very precise values).

                  $$\text{toRealFloat}(c \times 10^{e}) = \text{Float.ofInt}(c) \times 10^{e}$$

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For

                    Convert a Float to Scientific by decomposing it into decimal digits.

                    Note: this performs a best-effort conversion through the string representation, similar to Haskell's fromFloatDigits.

                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For

                      Convert to a bounded integer, returning none if the number is fractional or outside the representable range of a 64-bit signed integer.

                      Range: $[-2^{63}, 2^{63} - 1]$.

                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For

                        Decompose into a list of mantissa digits and a base-10 exponent.

                        Returns (digits, exp) such that: $$\text{value} = 0.\text{digits} \times 10^{\text{exp}}$$

                        For example, $123.45$ yields ([1,2,3,4,5], 3). The digit list has no trailing zeros. For zero, returns ([0], 1).

                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For
                          @[implicit_reducible]
                          Equations
                          @[implicit_reducible]
                          Equations
                          @[implicit_reducible]
                          Equations
                          @[implicit_reducible]
                          Equations
                          @[implicit_reducible]
                          Equations
                          • One or more equations did not get rendered due to their size.
                          @[implicit_reducible]
                          Equations
                          • One or more equations did not get rendered due to their size.
                          @[implicit_reducible]
                          Equations
                          @[implicit_reducible]
                          Equations
                          @[implicit_reducible]
                          Equations
                          • One or more equations did not get rendered due to their size.
                          @[implicit_reducible]

                          Format a Scientific as a plain decimal string.

                          • $1.23 \times 10^{5}$ → "123000.0"
                          • $1.23 \times 10^{-2}$ → "0.0123"
                          • $-42 \times 10^{0}$ → "-42.0"
                          Equations
                          • One or more equations did not get rendered due to their size.

                          isZero is true if and only if the coefficient is zero. $$\text{isZero}(s) = \text{true} \iff s.\text{coefficient} = 0$$

                          fromInt 0 produces a zero scientific. $$\text{isZero}(\text{fromInt}(0)) = \text{true}$$

                          theorem Data.Scientific.normalize_zero (e : Int) :
                          { coefficient := 0, base10Exponent := e }.normalize = { coefficient := 0, base10Exponent := 0 }

                          Normalizing zero yields the canonical zero ⟨0, 0⟩. $$\text{normalize}(0 \times 10^{e}) = 0 \times 10^{0}$$

                          Negation is self-inverse. $$-(-s) = s$$

                          fromInt preserves zero under BEq. $$(\text{fromInt}(0) == 0) = \text{true}$$