Average Error: 6.7 → 1.2
Time: 4.9s
Precision: binary64
\[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;y \cdot z - z \cdot t \leq -8.092130891572425 \cdot 10^{+289}:\\ \;\;\;\;\frac{x}{z} \cdot \frac{2}{y - t}\\ \mathbf{elif}\;y \cdot z - z \cdot t \leq 6.123476084055259 \cdot 10^{+242}:\\ \;\;\;\;\frac{x \cdot 2}{y \cdot z - z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{z} \cdot 2}{y - t}\\ \end{array}\]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
\mathbf{if}\;y \cdot z - z \cdot t \leq -8.092130891572425 \cdot 10^{+289}:\\
\;\;\;\;\frac{x}{z} \cdot \frac{2}{y - t}\\

\mathbf{elif}\;y \cdot z - z \cdot t \leq 6.123476084055259 \cdot 10^{+242}:\\
\;\;\;\;\frac{x \cdot 2}{y \cdot z - z \cdot t}\\

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

\end{array}
(FPCore (x y z t) :precision binary64 (/ (* x 2.0) (- (* y z) (* t z))))
(FPCore (x y z t)
 :precision binary64
 (if (<= (- (* y z) (* z t)) -8.092130891572425e+289)
   (* (/ x z) (/ 2.0 (- y t)))
   (if (<= (- (* y z) (* z t)) 6.123476084055259e+242)
     (/ (* x 2.0) (- (* y z) (* z t)))
     (/ (* (/ x z) 2.0) (- y t)))))
double code(double x, double y, double z, double t) {
	return (x * 2.0) / ((y * z) - (t * z));
}
double code(double x, double y, double z, double t) {
	double tmp;
	if (((y * z) - (z * t)) <= -8.092130891572425e+289) {
		tmp = (x / z) * (2.0 / (y - t));
	} else if (((y * z) - (z * t)) <= 6.123476084055259e+242) {
		tmp = (x * 2.0) / ((y * z) - (z * t));
	} else {
		tmp = ((x / z) * 2.0) / (y - t);
	}
	return tmp;
}

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.7
Target2.2
Herbie1.2
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot 2}{y \cdot z - t \cdot z} < -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} < 1.0450278273301259 \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 (-.f64 (*.f64 y z) (*.f64 t z)) < -8.09213089157242499e289

    1. Initial program 18.2

      \[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
    2. Using strategy rm
    3. Applied distribute-rgt-out--_binary64_744718.2

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

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

    if -8.09213089157242499e289 < (-.f64 (*.f64 y z) (*.f64 t z)) < 6.12347608405525864e242

    1. Initial program 1.6

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

    if 6.12347608405525864e242 < (-.f64 (*.f64 y z) (*.f64 t z))

    1. Initial program 21.1

      \[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
    2. Using strategy rm
    3. Applied distribute-rgt-out--_binary64_744714.9

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot z - z \cdot t \leq -8.092130891572425 \cdot 10^{+289}:\\ \;\;\;\;\frac{x}{z} \cdot \frac{2}{y - t}\\ \mathbf{elif}\;y \cdot z - z \cdot t \leq 6.123476084055259 \cdot 10^{+242}:\\ \;\;\;\;\frac{x \cdot 2}{y \cdot z - z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{z} \cdot 2}{y - t}\\ \end{array}\]

Reproduce

herbie shell --seed 2020281 
(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))))