Average Error: 6.8 → 1.2
Time: 14.6s
Precision: 64
\[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;y \cdot z - t \cdot z \le -1.989577839511013605559193707688169001455 \cdot 10^{188}:\\ \;\;\;\;\frac{\frac{2}{z}}{\frac{y - t}{x}}\\ \mathbf{elif}\;y \cdot z - t \cdot z \le 1.05207730988959976736022850622177780129 \cdot 10^{250}:\\ \;\;\;\;\frac{x \cdot 2}{y \cdot z - t \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{2}{z}}{\frac{y - t}{x}}\\ \end{array}\]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
\mathbf{if}\;y \cdot z - t \cdot z \le -1.989577839511013605559193707688169001455 \cdot 10^{188}:\\
\;\;\;\;\frac{\frac{2}{z}}{\frac{y - t}{x}}\\

\mathbf{elif}\;y \cdot z - t \cdot z \le 1.05207730988959976736022850622177780129 \cdot 10^{250}:\\
\;\;\;\;\frac{x \cdot 2}{y \cdot z - t \cdot z}\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r20097685 = x;
        double r20097686 = 2.0;
        double r20097687 = r20097685 * r20097686;
        double r20097688 = y;
        double r20097689 = z;
        double r20097690 = r20097688 * r20097689;
        double r20097691 = t;
        double r20097692 = r20097691 * r20097689;
        double r20097693 = r20097690 - r20097692;
        double r20097694 = r20097687 / r20097693;
        return r20097694;
}

double f(double x, double y, double z, double t) {
        double r20097695 = y;
        double r20097696 = z;
        double r20097697 = r20097695 * r20097696;
        double r20097698 = t;
        double r20097699 = r20097698 * r20097696;
        double r20097700 = r20097697 - r20097699;
        double r20097701 = -1.9895778395110136e+188;
        bool r20097702 = r20097700 <= r20097701;
        double r20097703 = 2.0;
        double r20097704 = r20097703 / r20097696;
        double r20097705 = r20097695 - r20097698;
        double r20097706 = x;
        double r20097707 = r20097705 / r20097706;
        double r20097708 = r20097704 / r20097707;
        double r20097709 = 1.0520773098895998e+250;
        bool r20097710 = r20097700 <= r20097709;
        double r20097711 = r20097706 * r20097703;
        double r20097712 = r20097711 / r20097700;
        double r20097713 = r20097710 ? r20097712 : r20097708;
        double r20097714 = r20097702 ? r20097708 : r20097713;
        return r20097714;
}

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.1
Herbie1.2
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot 2}{y \cdot z - t \cdot z} \lt -2.559141628295061113708240820439530037456 \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.045027827330126029709547581125571222799 \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 2 regimes
  2. if (- (* y z) (* t z)) < -1.9895778395110136e+188 or 1.0520773098895998e+250 < (- (* y z) (* t z))

    1. Initial program 16.1

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

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

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

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

      \[\leadsto \frac{2}{z \cdot \color{blue}{\frac{y - t}{x}}}\]
    7. Using strategy rm
    8. Applied associate-/r*0.4

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

    if -1.9895778395110136e+188 < (- (* y z) (* t z)) < 1.0520773098895998e+250

    1. Initial program 1.7

      \[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification1.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot z - t \cdot z \le -1.989577839511013605559193707688169001455 \cdot 10^{188}:\\ \;\;\;\;\frac{\frac{2}{z}}{\frac{y - t}{x}}\\ \mathbf{elif}\;y \cdot z - t \cdot z \le 1.05207730988959976736022850622177780129 \cdot 10^{250}:\\ \;\;\;\;\frac{x \cdot 2}{y \cdot z - t \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{2}{z}}{\frac{y - t}{x}}\\ \end{array}\]

Reproduce

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

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

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