Average Error: 6.9 → 1.7
Time: 6.0s
Precision: 64
\[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot 2}{y \cdot z - t \cdot z} \le -2.14107292843783933 \cdot 10^{-275}:\\ \;\;\;\;\frac{x \cdot 2}{y \cdot z - t \cdot z}\\ \mathbf{elif}\;\frac{x \cdot 2}{y \cdot z - t \cdot z} \le 2.22545972557674268 \cdot 10^{45}:\\ \;\;\;\;\frac{\frac{x}{z}}{\frac{y - t}{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{z \cdot \frac{\frac{y - t}{2}}{x}}\\ \end{array}\]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
\mathbf{if}\;\frac{x \cdot 2}{y \cdot z - t \cdot z} \le -2.14107292843783933 \cdot 10^{-275}:\\
\;\;\;\;\frac{x \cdot 2}{y \cdot z - t \cdot z}\\

\mathbf{elif}\;\frac{x \cdot 2}{y \cdot z - t \cdot z} \le 2.22545972557674268 \cdot 10^{45}:\\
\;\;\;\;\frac{\frac{x}{z}}{\frac{y - t}{2}}\\

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

\end{array}
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 VAR;
	if ((((x * 2.0) / ((y * z) - (t * z))) <= -2.1410729284378393e-275)) {
		VAR = ((x * 2.0) / ((y * z) - (t * z)));
	} else {
		double VAR_1;
		if ((((x * 2.0) / ((y * z) - (t * z))) <= 2.2254597255767427e+45)) {
			VAR_1 = ((x / z) / ((y - t) / 2.0));
		} else {
			VAR_1 = (1.0 / (z * (((y - t) / 2.0) / x)));
		}
		VAR = VAR_1;
	}
	return VAR;
}

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.7
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot 2}{y \cdot z - t \cdot z} \lt -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} \lt 1.04502782733012586 \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 (/ (* x 2.0) (- (* y z) (* t z))) < -2.1410729284378393e-275

    1. Initial program 1.5

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

    if -2.1410729284378393e-275 < (/ (* x 2.0) (- (* y z) (* t z))) < 2.2254597255767427e+45

    1. Initial program 7.9

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

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

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

      \[\leadsto \frac{x}{\color{blue}{\frac{z}{1} \cdot \frac{y - t}{2}}}\]
    6. Applied associate-/r*1.3

      \[\leadsto \color{blue}{\frac{\frac{x}{\frac{z}{1}}}{\frac{y - t}{2}}}\]
    7. Simplified1.3

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

    if 2.2254597255767427e+45 < (/ (* x 2.0) (- (* y z) (* t z)))

    1. Initial program 14.1

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

      \[\leadsto \color{blue}{\frac{x}{\frac{z \cdot \left(y - t\right)}{2}}}\]
    3. Using strategy rm
    4. Applied *-un-lft-identity6.0

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

      \[\leadsto \frac{x}{\color{blue}{\frac{z}{1} \cdot \frac{y - t}{2}}}\]
    6. Applied *-un-lft-identity6.0

      \[\leadsto \frac{\color{blue}{1 \cdot x}}{\frac{z}{1} \cdot \frac{y - t}{2}}\]
    7. Applied times-frac3.4

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{x}{\frac{y - t}{2}}}}{z}\]
    12. Using strategy rm
    13. Applied clear-num3.4

      \[\leadsto \frac{\color{blue}{\frac{1}{\frac{\frac{y - t}{2}}{x}}}}{z}\]
    14. Using strategy rm
    15. Applied associate-/l/3.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot 2}{y \cdot z - t \cdot z} \le -2.14107292843783933 \cdot 10^{-275}:\\ \;\;\;\;\frac{x \cdot 2}{y \cdot z - t \cdot z}\\ \mathbf{elif}\;\frac{x \cdot 2}{y \cdot z - t \cdot z} \le 2.22545972557674268 \cdot 10^{45}:\\ \;\;\;\;\frac{\frac{x}{z}}{\frac{y - t}{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{z \cdot \frac{\frac{y - t}{2}}{x}}\\ \end{array}\]

Reproduce

herbie shell --seed 2020102 +o rules:numerics
(FPCore (x y z t)
  :name "Linear.Projection:infinitePerspective from linear-1.19.1.3, A"
  :precision binary64

  :herbie-target
  (if (< (/ (* x 2) (- (* y z) (* t z))) -2.559141628295061e-13) (* (/ x (* (- y t) z)) 2) (if (< (/ (* x 2) (- (* y z) (* t z))) 1.0450278273301259e-269) (/ (* (/ x z) 2) (- y t)) (* (/ x (* (- y t) z)) 2)))

  (/ (* x 2) (- (* y z) (* t z))))