Average Error: 6.7 → 2.8
Time: 5.4s
Precision: binary64
\[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;z \le -4.19232077706326539 \cdot 10^{94}:\\ \;\;\;\;\frac{\frac{x}{z}}{\frac{y - t}{2}}\\ \mathbf{elif}\;z \le 5.5114979619320889 \cdot 10^{-97}:\\ \;\;\;\;x \cdot \frac{2}{z \cdot \left(y - t\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{2}{y - t} \cdot x}{z}\\ \end{array}\]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
\mathbf{if}\;z \le -4.19232077706326539 \cdot 10^{94}:\\
\;\;\;\;\frac{\frac{x}{z}}{\frac{y - t}{2}}\\

\mathbf{elif}\;z \le 5.5114979619320889 \cdot 10^{-97}:\\
\;\;\;\;x \cdot \frac{2}{z \cdot \left(y - t\right)}\\

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

\end{array}
double code(double x, double y, double z, double t) {
	return ((double) (((double) (x * 2.0)) / ((double) (((double) (y * z)) - ((double) (t * z))))));
}
double code(double x, double y, double z, double t) {
	double VAR;
	if ((z <= -4.1923207770632654e+94)) {
		VAR = ((double) (((double) (x / z)) / ((double) (((double) (y - t)) / 2.0))));
	} else {
		double VAR_1;
		if ((z <= 5.511497961932089e-97)) {
			VAR_1 = ((double) (x * ((double) (2.0 / ((double) (z * ((double) (y - t))))))));
		} else {
			VAR_1 = ((double) (((double) (((double) (2.0 / ((double) (y - t)))) * x)) / z));
		}
		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.7
Target2.1
Herbie2.8
\[\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 z < -4.19232077706326539e94

    1. Initial program 13.0

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

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

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

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

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

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

    if -4.19232077706326539e94 < z < 5.5114979619320889e-97

    1. Initial program 2.9

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

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

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

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

    if 5.5114979619320889e-97 < z

    1. Initial program 8.3

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -4.19232077706326539 \cdot 10^{94}:\\ \;\;\;\;\frac{\frac{x}{z}}{\frac{y - t}{2}}\\ \mathbf{elif}\;z \le 5.5114979619320889 \cdot 10^{-97}:\\ \;\;\;\;x \cdot \frac{2}{z \cdot \left(y - t\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{2}{y - t} \cdot x}{z}\\ \end{array}\]

Reproduce

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