Average Error: 7.3 → 2.5
Time: 3.7s
Precision: binary64
\[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;z \le -3.7870085792068665 \cdot 10^{29}:\\ \;\;\;\;\frac{x \cdot \frac{2}{y - t}}{z}\\ \mathbf{elif}\;z \le 2.1693266226356799 \cdot 10^{65}:\\ \;\;\;\;x \cdot \frac{\frac{2}{y - t}}{z}\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot \frac{2}{y - t}\right) \cdot \frac{1}{z}\\ \end{array}\]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
\mathbf{if}\;z \le -3.7870085792068665 \cdot 10^{29}:\\
\;\;\;\;\frac{x \cdot \frac{2}{y - t}}{z}\\

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

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

\end{array}
double code(double x, double y, double z, double t) {
	return (((double) (x * 2.0)) / ((double) (((double) (y * z)) - ((double) (t * z)))));
}
double code(double x, double y, double z, double t) {
	double VAR;
	if ((z <= -3.7870085792068665e+29)) {
		VAR = (((double) (x * (2.0 / ((double) (y - t))))) / z);
	} else {
		double VAR_1;
		if ((z <= 2.16932662263568e+65)) {
			VAR_1 = ((double) (x * ((2.0 / ((double) (y - t))) / z)));
		} else {
			VAR_1 = ((double) (((double) (x * (2.0 / ((double) (y - t))))) * (1.0 / z)));
		}
		VAR = VAR_1;
	}
	return VAR;
}

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

Original7.3
Target2.2
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 < -3.7870085792068665e29

    1. Initial program 12.2

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

      \[\leadsto \color{blue}{x \cdot \frac{2}{z \cdot \left(y - t\right)}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt10.8

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

      \[\leadsto x \cdot \color{blue}{\left(\frac{\sqrt{2}}{z} \cdot \frac{\sqrt{2}}{y - t}\right)}\]
    6. Using strategy rm
    7. Applied associate-*l/9.8

      \[\leadsto x \cdot \color{blue}{\frac{\sqrt{2} \cdot \frac{\sqrt{2}}{y - t}}{z}}\]
    8. Applied associate-*r/2.5

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

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

    if -3.7870085792068665e29 < z < 2.1693266226356799e65

    1. Initial program 2.4

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

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

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

      \[\leadsto x \cdot \color{blue}{\left(\frac{\sqrt{2}}{z} \cdot \frac{\sqrt{2}}{y - t}\right)}\]
    6. Using strategy rm
    7. Applied associate-*l/2.9

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

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

    if 2.1693266226356799e65 < z

    1. Initial program 13.7

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

      \[\leadsto \color{blue}{x \cdot \frac{2}{z \cdot \left(y - t\right)}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt11.6

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

      \[\leadsto x \cdot \color{blue}{\left(\frac{\sqrt{2}}{z} \cdot \frac{\sqrt{2}}{y - t}\right)}\]
    6. Using strategy rm
    7. Applied associate-*l/10.6

      \[\leadsto x \cdot \color{blue}{\frac{\sqrt{2} \cdot \frac{\sqrt{2}}{y - t}}{z}}\]
    8. Simplified10.4

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

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

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

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

Reproduce

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

  :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.0450278273301259e-269) (/ (* (/ x z) 2.0) (- y t)) (* (/ x (* (- y t) z)) 2.0)))

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