Average Error: 6.8 → 2.7
Time: 5.6s
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 r635493 = x;
        double r635494 = 2.0;
        double r635495 = r635493 * r635494;
        double r635496 = y;
        double r635497 = z;
        double r635498 = r635496 * r635497;
        double r635499 = t;
        double r635500 = r635499 * r635497;
        double r635501 = r635498 - r635500;
        double r635502 = r635495 / r635501;
        return r635502;
}

double f(double x, double y, double z, double t) {
        double r635503 = z;
        double r635504 = -6.93799498024277e-128;
        bool r635505 = r635503 <= r635504;
        double r635506 = x;
        double r635507 = 2.0;
        double r635508 = y;
        double r635509 = t;
        double r635510 = r635508 - r635509;
        double r635511 = r635507 / r635510;
        double r635512 = r635506 * r635511;
        double r635513 = r635512 / r635503;
        double r635514 = 4.536023366252226e-37;
        bool r635515 = r635503 <= r635514;
        double r635516 = r635506 * r635507;
        double r635517 = r635503 * r635510;
        double r635518 = r635516 / r635517;
        double r635519 = r635516 / r635503;
        double r635520 = r635519 / r635510;
        double r635521 = r635515 ? r635518 : r635520;
        double r635522 = r635505 ? r635513 : r635521;
        return r635522;
}

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 associate-/r*11.9

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

      \[\leadsto \frac{\color{blue}{\left(x \cdot 2\right) \cdot \frac{1}{z}}}{y - t}\]
    7. Applied associate-/l*3.6

      \[\leadsto \color{blue}{\frac{x \cdot 2}{\frac{y - t}{\frac{1}{z}}}}\]
    8. Simplified3.5

      \[\leadsto \frac{x \cdot 2}{\color{blue}{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))))