Average Error: 6.8 → 2.7
Time: 6.8s
Precision: 64
\[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;z \le -6.9379949802427703 \cdot 10^{-128}:\\ \;\;\;\;\frac{x \cdot \frac{2}{y - t}}{z}\\ \mathbf{elif}\;z \le 4.5360233662522261 \cdot 10^{-37}:\\ \;\;\;\;\frac{x \cdot 2}{z \cdot \left(y - t\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x \cdot 2}{z}}{y - t}\\ \end{array}\]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
\mathbf{if}\;z \le -6.9379949802427703 \cdot 10^{-128}:\\
\;\;\;\;\frac{x \cdot \frac{2}{y - t}}{z}\\

\mathbf{elif}\;z \le 4.5360233662522261 \cdot 10^{-37}:\\
\;\;\;\;\frac{x \cdot 2}{z \cdot \left(y - t\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{x \cdot 2}{z}}{y - t}\\

\end{array}
double f(double x, double y, double z, double t) {
        double r470794 = x;
        double r470795 = 2.0;
        double r470796 = r470794 * r470795;
        double r470797 = y;
        double r470798 = z;
        double r470799 = r470797 * r470798;
        double r470800 = t;
        double r470801 = r470800 * r470798;
        double r470802 = r470799 - r470801;
        double r470803 = r470796 / r470802;
        return r470803;
}

double f(double x, double y, double z, double t) {
        double r470804 = z;
        double r470805 = -6.93799498024277e-128;
        bool r470806 = r470804 <= r470805;
        double r470807 = x;
        double r470808 = 2.0;
        double r470809 = y;
        double r470810 = t;
        double r470811 = r470809 - r470810;
        double r470812 = r470808 / r470811;
        double r470813 = r470807 * r470812;
        double r470814 = r470813 / r470804;
        double r470815 = 4.536023366252226e-37;
        bool r470816 = r470804 <= r470815;
        double r470817 = r470807 * r470808;
        double r470818 = r470804 * r470811;
        double r470819 = r470817 / r470818;
        double r470820 = r470817 / r470804;
        double r470821 = r470820 / r470811;
        double r470822 = r470816 ? r470819 : r470821;
        double r470823 = r470806 ? r470814 : r470822;
        return r470823;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original6.8
Target2.2
Herbie2.7
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot 2}{y \cdot z - t \cdot z} \lt -2.559141628295061 \cdot 10^{-13}:\\ \;\;\;\;\frac{x}{\left(y - t\right) \cdot z} \cdot 2\\ \mathbf{elif}\;\frac{x \cdot 2}{y \cdot z - t \cdot z} \lt 1.04502782733012586 \cdot 10^{-269}:\\ \;\;\;\;\frac{\frac{x}{z} \cdot 2}{y - t}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\left(y - t\right) \cdot z} \cdot 2\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if z < -6.93799498024277e-128

    1. Initial program 7.5

      \[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
    2. Simplified6.2

      \[\leadsto \color{blue}{\frac{x \cdot 2}{z \cdot \left(y - t\right)}}\]
    3. Using strategy rm
    4. Applied times-frac2.5

      \[\leadsto \color{blue}{\frac{x}{z} \cdot \frac{2}{y - t}}\]
    5. Using strategy rm
    6. Applied associate-*l/3.0

      \[\leadsto \color{blue}{\frac{x \cdot \frac{2}{y - t}}{z}}\]

    if -6.93799498024277e-128 < z < 4.536023366252226e-37

    1. Initial program 3.5

      \[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
    2. Simplified3.5

      \[\leadsto \color{blue}{\frac{x \cdot 2}{z \cdot \left(y - t\right)}}\]
    3. Using strategy rm
    4. Applied times-frac11.9

      \[\leadsto \color{blue}{\frac{x}{z} \cdot \frac{2}{y - t}}\]
    5. Using strategy rm
    6. Applied frac-times3.5

      \[\leadsto \color{blue}{\frac{x \cdot 2}{z \cdot \left(y - t\right)}}\]

    if 4.536023366252226e-37 < z

    1. Initial program 9.5

      \[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
    2. Simplified7.5

      \[\leadsto \color{blue}{\frac{x \cdot 2}{z \cdot \left(y - t\right)}}\]
    3. Using strategy rm
    4. Applied associate-/r*1.6

      \[\leadsto \color{blue}{\frac{\frac{x \cdot 2}{z}}{y - t}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification2.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -6.9379949802427703 \cdot 10^{-128}:\\ \;\;\;\;\frac{x \cdot \frac{2}{y - t}}{z}\\ \mathbf{elif}\;z \le 4.5360233662522261 \cdot 10^{-37}:\\ \;\;\;\;\frac{x \cdot 2}{z \cdot \left(y - t\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x \cdot 2}{z}}{y - t}\\ \end{array}\]

Reproduce

herbie shell --seed 2020047 +o rules:numerics
(FPCore (x y z t)
  :name "Linear.Projection:infinitePerspective from linear-1.19.1.3, A"
  :precision binary64

  :herbie-target
  (if (< (/ (* x 2) (- (* y z) (* t z))) -2.559141628295061e-13) (* (/ x (* (- y t) z)) 2) (if (< (/ (* x 2) (- (* y z) (* t z))) 1.0450278273301259e-269) (/ (* (/ x z) 2) (- y t)) (* (/ x (* (- y t) z)) 2)))

  (/ (* x 2) (- (* y z) (* t z))))