Average Error: 6.6 → 2.9
Time: 5.9s
Precision: 64
\[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.014343242050049761157872931103442569929 \cdot 10^{-140} \lor \neg \left(x \le 4.682548860145129920579692546790894336778 \cdot 10^{-88}\right):\\ \;\;\;\;\frac{1}{z} \cdot \frac{x}{\frac{y - t}{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{z}}{\frac{y - t}{2}}\\ \end{array}\]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
\mathbf{if}\;x \le -2.014343242050049761157872931103442569929 \cdot 10^{-140} \lor \neg \left(x \le 4.682548860145129920579692546790894336778 \cdot 10^{-88}\right):\\
\;\;\;\;\frac{1}{z} \cdot \frac{x}{\frac{y - t}{2}}\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r541117 = x;
        double r541118 = 2.0;
        double r541119 = r541117 * r541118;
        double r541120 = y;
        double r541121 = z;
        double r541122 = r541120 * r541121;
        double r541123 = t;
        double r541124 = r541123 * r541121;
        double r541125 = r541122 - r541124;
        double r541126 = r541119 / r541125;
        return r541126;
}

double f(double x, double y, double z, double t) {
        double r541127 = x;
        double r541128 = -2.0143432420500498e-140;
        bool r541129 = r541127 <= r541128;
        double r541130 = 4.68254886014513e-88;
        bool r541131 = r541127 <= r541130;
        double r541132 = !r541131;
        bool r541133 = r541129 || r541132;
        double r541134 = 1.0;
        double r541135 = z;
        double r541136 = r541134 / r541135;
        double r541137 = y;
        double r541138 = t;
        double r541139 = r541137 - r541138;
        double r541140 = 2.0;
        double r541141 = r541139 / r541140;
        double r541142 = r541127 / r541141;
        double r541143 = r541136 * r541142;
        double r541144 = r541127 / r541135;
        double r541145 = r541144 / r541141;
        double r541146 = r541133 ? r541143 : r541145;
        return r541146;
}

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.6
Target2.0
Herbie2.9
\[\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.045027827330125861587720199944080049996 \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 x < -2.0143432420500498e-140 or 4.68254886014513e-88 < x

    1. Initial program 8.3

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

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

      \[\leadsto \frac{x}{\frac{z \cdot \left(y - t\right)}{\color{blue}{1 \cdot 2}}}\]
    5. Applied times-frac7.4

      \[\leadsto \frac{x}{\color{blue}{\frac{z}{1} \cdot \frac{y - t}{2}}}\]
    6. Applied *-un-lft-identity7.4

      \[\leadsto \frac{\color{blue}{1 \cdot x}}{\frac{z}{1} \cdot \frac{y - t}{2}}\]
    7. Applied times-frac3.3

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

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

    if -2.0143432420500498e-140 < x < 4.68254886014513e-88

    1. Initial program 3.4

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

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

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

      \[\leadsto \frac{x}{\color{blue}{\frac{z}{1} \cdot \frac{y - t}{2}}}\]
    6. Applied associate-/r*2.2

      \[\leadsto \color{blue}{\frac{\frac{x}{\frac{z}{1}}}{\frac{y - t}{2}}}\]
    7. Simplified2.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.014343242050049761157872931103442569929 \cdot 10^{-140} \lor \neg \left(x \le 4.682548860145129920579692546790894336778 \cdot 10^{-88}\right):\\ \;\;\;\;\frac{1}{z} \cdot \frac{x}{\frac{y - t}{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{z}}{\frac{y - t}{2}}\\ \end{array}\]

Reproduce

herbie shell --seed 2020001 +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))))