Average Error: 6.8 → 2.3
Time: 3.0s
Precision: binary64
\[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \cdot 2 \leq -1.1749622850726272 \cdot 10^{-27} \lor \neg \left(x \cdot 2 \leq 3737.5144130491194\right):\\ \;\;\;\;\frac{x \cdot 2}{y - t} \cdot \frac{1}{z}\\ \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}\;x \cdot 2 \leq -1.1749622850726272 \cdot 10^{-27} \lor \neg \left(x \cdot 2 \leq 3737.5144130491194\right):\\
\;\;\;\;\frac{x \cdot 2}{y - t} \cdot \frac{1}{z}\\

\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 (or (<= (* x 2.0) -1.1749622850726272e-27)
         (not (<= (* x 2.0) 3737.5144130491194)))
   (* (/ (* x 2.0) (- y t)) (/ 1.0 z))
   (/ (/ (* 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 (((x * 2.0) <= -1.1749622850726272e-27) || !((x * 2.0) <= 3737.5144130491194)) {
		tmp = ((x * 2.0) / (y - t)) * (1.0 / z);
	} 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

Original6.8
Target2.2
Herbie2.3
\[\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 2 regimes
  2. if (*.f64 x 2) < -1.1749622850726272e-27 or 3737.51441304911941 < (*.f64 x 2)

    1. Initial program 10.5

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

      \[\leadsto \color{blue}{x \cdot \frac{\frac{2}{y - t}}{z}}\]
    3. Using strategy rm
    4. Applied associate-*r/_binary642.7

      \[\leadsto \color{blue}{\frac{x \cdot \frac{2}{y - t}}{z}}\]
    5. Using strategy rm
    6. Applied associate-*r/_binary642.6

      \[\leadsto \frac{\color{blue}{\frac{x \cdot 2}{y - t}}}{z}\]
    7. Using strategy rm
    8. Applied div-inv_binary642.7

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

    if -1.1749622850726272e-27 < (*.f64 x 2) < 3737.51441304911941

    1. Initial program 3.4

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

      \[\leadsto \color{blue}{x \cdot \frac{\frac{2}{y - t}}{z}}\]
    3. Using strategy rm
    4. Applied associate-*r/_binary648.3

      \[\leadsto \color{blue}{\frac{x \cdot \frac{2}{y - t}}{z}}\]
    5. Using strategy rm
    6. Applied associate-*r/_binary648.2

      \[\leadsto \frac{\color{blue}{\frac{x \cdot 2}{y - t}}}{z}\]
    7. Using strategy rm
    8. Applied div-inv_binary648.3

      \[\leadsto \color{blue}{\frac{x \cdot 2}{y - t} \cdot \frac{1}{z}}\]
    9. Using strategy rm
    10. Applied associate-*l/_binary641.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot 2 \leq -1.1749622850726272 \cdot 10^{-27} \lor \neg \left(x \cdot 2 \leq 3737.5144130491194\right):\\ \;\;\;\;\frac{x \cdot 2}{y - t} \cdot \frac{1}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x \cdot 2}{z}}{y - t}\\ \end{array}\]

Reproduce

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