Average Error: 6.9 → 1.3
Time: 9.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 -7.627969348684387 \cdot 10^{+165}:\\ \;\;\;\;\frac{x \cdot 2}{y - t} \cdot \frac{1}{z}\\ \mathbf{elif}\;y \cdot z - z \cdot t \leq 1.3655434386994245 \cdot 10^{+301}:\\ \;\;\;\;\frac{x \cdot 2}{y \cdot z - z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{z} \cdot \left(x \cdot \frac{2}{y - t}\right)\\ \end{array}\]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
\mathbf{if}\;y \cdot z - z \cdot t \leq -7.627969348684387 \cdot 10^{+165}:\\
\;\;\;\;\frac{x \cdot 2}{y - t} \cdot \frac{1}{z}\\

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

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

\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)) -7.627969348684387e+165)
   (* (/ (* x 2.0) (- y t)) (/ 1.0 z))
   (if (<= (- (* y z) (* z t)) 1.3655434386994245e+301)
     (/ (* x 2.0) (- (* y z) (* z t)))
     (* (/ 1.0 z) (* x (/ 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)) <= -7.627969348684387e+165) {
		tmp = ((x * 2.0) / (y - t)) * (1.0 / z);
	} else if (((y * z) - (z * t)) <= 1.3655434386994245e+301) {
		tmp = (x * 2.0) / ((y * z) - (z * t));
	} else {
		tmp = (1.0 / z) * (x * (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.9
Target2.0
Herbie1.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 3 regimes
  2. if (-.f64 (*.f64 y z) (*.f64 t z)) < -7.6279693486843872e165

    1. Initial program 10.6

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

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

      \[\leadsto x \cdot \frac{\frac{2}{y - t}}{\color{blue}{1 \cdot z}}\]
    5. Applied *-un-lft-identity_binary64_137189.9

      \[\leadsto x \cdot \frac{\frac{2}{\color{blue}{1 \cdot \left(y - t\right)}}}{1 \cdot z}\]
    6. Applied add-sqr-sqrt_binary64_1374010.2

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

      \[\leadsto x \cdot \frac{\color{blue}{\frac{\sqrt{2}}{1} \cdot \frac{\sqrt{2}}{y - t}}}{1 \cdot z}\]
    8. Applied times-frac_binary64_1372410.1

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

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

      \[\leadsto \color{blue}{\left(x \cdot \sqrt{2}\right)} \cdot \frac{\frac{\sqrt{2}}{y - t}}{z}\]
    11. Using strategy rm
    12. Applied div-inv_binary64_1371510.1

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

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

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

    if -7.6279693486843872e165 < (-.f64 (*.f64 y z) (*.f64 t z)) < 1.36554343869942453e301

    1. Initial program 1.7

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

    if 1.36554343869942453e301 < (-.f64 (*.f64 y z) (*.f64 t z))

    1. Initial program 27.8

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot z - z \cdot t \leq -7.627969348684387 \cdot 10^{+165}:\\ \;\;\;\;\frac{x \cdot 2}{y - t} \cdot \frac{1}{z}\\ \mathbf{elif}\;y \cdot z - z \cdot t \leq 1.3655434386994245 \cdot 10^{+301}:\\ \;\;\;\;\frac{x \cdot 2}{y \cdot z - z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{z} \cdot \left(x \cdot \frac{2}{y - t}\right)\\ \end{array}\]

Reproduce

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