Average Error: 7.0 → 3.6
Time: 3.6s
Precision: binary64
\[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;z \leq -2.4796712913962077 \cdot 10^{+133}:\\ \;\;\;\;\frac{\frac{x \cdot 2}{y - t}}{z}\\ \mathbf{elif}\;z \leq 1.00293945317054 \cdot 10^{-310}:\\ \;\;\;\;x \cdot \frac{\frac{2}{y - t}}{z}\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot \frac{2}{\sqrt{z}}\right) \cdot \frac{\frac{1}{y - t}}{\sqrt{z}}\\ \end{array}\]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
\mathbf{if}\;z \leq -2.4796712913962077 \cdot 10^{+133}:\\
\;\;\;\;\frac{\frac{x \cdot 2}{y - t}}{z}\\

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

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

\end{array}
(FPCore (x y z t) :precision binary64 (/ (* x 2.0) (- (* y z) (* t z))))
(FPCore (x y z t)
 :precision binary64
 (if (<= z -2.4796712913962077e+133)
   (/ (/ (* x 2.0) (- y t)) z)
   (if (<= z 1.00293945317054e-310)
     (* x (/ (/ 2.0 (- y t)) z))
     (* (* x (/ 2.0 (sqrt z))) (/ (/ 1.0 (- y t)) (sqrt z))))))
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 (z <= -2.4796712913962077e+133) {
		tmp = ((x * 2.0) / (y - t)) / z;
	} else if (z <= 1.00293945317054e-310) {
		tmp = x * ((2.0 / (y - t)) / z);
	} else {
		tmp = (x * (2.0 / sqrt(z))) * ((1.0 / (y - t)) / sqrt(z));
	}
	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.1
Herbie3.6
\[\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 z < -2.4796712913962077e133

    1. Initial program 15.7

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

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

      \[\leadsto x \cdot \frac{\frac{2}{y - t}}{\color{blue}{1 \cdot z}}\]
    5. Applied add-cube-cbrt_binary6411.8

      \[\leadsto x \cdot \frac{\frac{2}{\color{blue}{\left(\sqrt[3]{y - t} \cdot \sqrt[3]{y - t}\right) \cdot \sqrt[3]{y - t}}}}{1 \cdot z}\]
    6. Applied *-un-lft-identity_binary6411.8

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

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

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

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

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

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

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

    if -2.4796712913962077e133 < z < 1.00293945317054e-310

    1. Initial program 3.7

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

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

    if 1.00293945317054e-310 < z

    1. Initial program 6.6

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

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

      \[\leadsto x \cdot \frac{\frac{2}{y - t}}{\color{blue}{\sqrt{z} \cdot \sqrt{z}}}\]
    5. Applied div-inv_binary645.6

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -2.4796712913962077 \cdot 10^{+133}:\\ \;\;\;\;\frac{\frac{x \cdot 2}{y - t}}{z}\\ \mathbf{elif}\;z \leq 1.00293945317054 \cdot 10^{-310}:\\ \;\;\;\;x \cdot \frac{\frac{2}{y - t}}{z}\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot \frac{2}{\sqrt{z}}\right) \cdot \frac{\frac{1}{y - t}}{\sqrt{z}}\\ \end{array}\]

Reproduce

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