Average Error: 7.0 → 1.1
Time: 9.2s
Precision: binary64
\[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;y \cdot z - z \cdot t \leq -3.2664811044545367 \cdot 10^{+243}:\\ \;\;\;\;\frac{x \cdot \frac{2}{z}}{y - t}\\ \mathbf{elif}\;y \cdot z - z \cdot t \leq -2.2702182992859946 \cdot 10^{-82}:\\ \;\;\;\;\frac{x \cdot 2}{z \cdot \left(y - t\right)}\\ \mathbf{elif}\;y \cdot z - z \cdot t \leq 4.1364563040059193 \cdot 10^{-187}:\\ \;\;\;\;\frac{2}{z} \cdot \frac{x}{y - t}\\ \mathbf{elif}\;y \cdot z - z \cdot t \leq 7.838488152591629 \cdot 10^{+126}:\\ \;\;\;\;\frac{x \cdot 2}{z \cdot \left(y - t\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x \cdot 2}{z}}{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 -3.2664811044545367 \cdot 10^{+243}:\\
\;\;\;\;\frac{x \cdot \frac{2}{z}}{y - t}\\

\mathbf{elif}\;y \cdot z - z \cdot t \leq -2.2702182992859946 \cdot 10^{-82}:\\
\;\;\;\;\frac{x \cdot 2}{z \cdot \left(y - t\right)}\\

\mathbf{elif}\;y \cdot z - z \cdot t \leq 4.1364563040059193 \cdot 10^{-187}:\\
\;\;\;\;\frac{2}{z} \cdot \frac{x}{y - t}\\

\mathbf{elif}\;y \cdot z - z \cdot t \leq 7.838488152591629 \cdot 10^{+126}:\\
\;\;\;\;\frac{x \cdot 2}{z \cdot \left(y - t\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{x \cdot 2}{z}}{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)) -3.2664811044545367e+243)
   (/ (* x (/ 2.0 z)) (- y t))
   (if (<= (- (* y z) (* z t)) -2.2702182992859946e-82)
     (/ (* x 2.0) (* z (- y t)))
     (if (<= (- (* y z) (* z t)) 4.1364563040059193e-187)
       (* (/ 2.0 z) (/ x (- y t)))
       (if (<= (- (* y z) (* z t)) 7.838488152591629e+126)
         (/ (* x 2.0) (* z (- y t)))
         (/ (/ (* x 2.0) z) (- 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)) <= -3.2664811044545367e+243) {
		tmp = (x * (2.0 / z)) / (y - t);
	} else if (((y * z) - (z * t)) <= -2.2702182992859946e-82) {
		tmp = (x * 2.0) / (z * (y - t));
	} else if (((y * z) - (z * t)) <= 4.1364563040059193e-187) {
		tmp = (2.0 / z) * (x / (y - t));
	} else if (((y * z) - (z * t)) <= 7.838488152591629e+126) {
		tmp = (x * 2.0) / (z * (y - t));
	} else {
		tmp = ((x * 2.0) / z) / (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

Original7.0
Target2.2
Herbie1.1
\[\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 4 regimes
  2. if (-.f64 (*.f64 y z) (*.f64 t z)) < -3.2664811044545367e243

    1. Initial program 14.2

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

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

    if -3.2664811044545367e243 < (-.f64 (*.f64 y z) (*.f64 t z)) < -2.2702182992859946e-82 or 4.13645630400591931e-187 < (-.f64 (*.f64 y z) (*.f64 t z)) < 7.83848815259162875e126

    1. Initial program 0.3

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

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

    if -2.2702182992859946e-82 < (-.f64 (*.f64 y z) (*.f64 t z)) < 4.13645630400591931e-187

    1. Initial program 9.6

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

      \[\leadsto \color{blue}{\frac{x \cdot \frac{2}{z}}{y - t}}\]
    3. Taylor expanded around 0 9.6

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

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

    if 7.83848815259162875e126 < (-.f64 (*.f64 y z) (*.f64 t z))

    1. Initial program 13.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot z - z \cdot t \leq -3.2664811044545367 \cdot 10^{+243}:\\ \;\;\;\;\frac{x \cdot \frac{2}{z}}{y - t}\\ \mathbf{elif}\;y \cdot z - z \cdot t \leq -2.2702182992859946 \cdot 10^{-82}:\\ \;\;\;\;\frac{x \cdot 2}{z \cdot \left(y - t\right)}\\ \mathbf{elif}\;y \cdot z - z \cdot t \leq 4.1364563040059193 \cdot 10^{-187}:\\ \;\;\;\;\frac{2}{z} \cdot \frac{x}{y - t}\\ \mathbf{elif}\;y \cdot z - z \cdot t \leq 7.838488152591629 \cdot 10^{+126}:\\ \;\;\;\;\frac{x \cdot 2}{z \cdot \left(y - t\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x \cdot 2}{z}}{y - t}\\ \end{array}\]

Reproduce

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