Average Error: 6.9 → 2.5
Time: 3.1s
Precision: 64
\[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;z \le -5.1635111201463088 \cdot 10^{-59}:\\ \;\;\;\;\frac{\frac{x}{z}}{\frac{y - t}{2}}\\ \mathbf{elif}\;z \le 1.9443547244995207 \cdot 10^{78}:\\ \;\;\;\;\frac{x}{z \cdot \left(y - t\right)} \cdot 2\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y - t} \cdot \left(\frac{1}{z} \cdot 2\right)\\ \end{array}\]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
\mathbf{if}\;z \le -5.1635111201463088 \cdot 10^{-59}:\\
\;\;\;\;\frac{\frac{x}{z}}{\frac{y - t}{2}}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{x}{y - t} \cdot \left(\frac{1}{z} \cdot 2\right)\\

\end{array}
double f(double x, double y, double z, double t) {
        double r640794 = x;
        double r640795 = 2.0;
        double r640796 = r640794 * r640795;
        double r640797 = y;
        double r640798 = z;
        double r640799 = r640797 * r640798;
        double r640800 = t;
        double r640801 = r640800 * r640798;
        double r640802 = r640799 - r640801;
        double r640803 = r640796 / r640802;
        return r640803;
}

double f(double x, double y, double z, double t) {
        double r640804 = z;
        double r640805 = -5.163511120146309e-59;
        bool r640806 = r640804 <= r640805;
        double r640807 = x;
        double r640808 = r640807 / r640804;
        double r640809 = y;
        double r640810 = t;
        double r640811 = r640809 - r640810;
        double r640812 = 2.0;
        double r640813 = r640811 / r640812;
        double r640814 = r640808 / r640813;
        double r640815 = 1.9443547244995207e+78;
        bool r640816 = r640804 <= r640815;
        double r640817 = r640804 * r640811;
        double r640818 = r640807 / r640817;
        double r640819 = r640818 * r640812;
        double r640820 = r640807 / r640811;
        double r640821 = 1.0;
        double r640822 = r640821 / r640804;
        double r640823 = r640822 * r640812;
        double r640824 = r640820 * r640823;
        double r640825 = r640816 ? r640819 : r640824;
        double r640826 = r640806 ? r640814 : r640825;
        return r640826;
}

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.9
Target2.1
Herbie2.5
\[\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 < -5.163511120146309e-59

    1. Initial program 9.2

      \[\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 associate-/r*2.3

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

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

    if -5.163511120146309e-59 < z < 1.9443547244995207e+78

    1. Initial program 2.5

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

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

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

    if 1.9443547244995207e+78 < z

    1. Initial program 13.8

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{x}{z}}}{\frac{y - t}{2}}\]
    8. Using strategy rm
    9. Applied div-inv2.4

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

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

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

      \[\leadsto \frac{x}{y - t} \cdot \color{blue}{\left(\frac{1}{z} \cdot 2\right)}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification2.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -5.1635111201463088 \cdot 10^{-59}:\\ \;\;\;\;\frac{\frac{x}{z}}{\frac{y - t}{2}}\\ \mathbf{elif}\;z \le 1.9443547244995207 \cdot 10^{78}:\\ \;\;\;\;\frac{x}{z \cdot \left(y - t\right)} \cdot 2\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y - t} \cdot \left(\frac{1}{z} \cdot 2\right)\\ \end{array}\]

Reproduce

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