Average Error: 6.8 → 0.2
Time: 5.6s
Precision: binary64
\[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;y \cdot z - t \cdot z \le -2.5496593359406929 \cdot 10^{290}:\\ \;\;\;\;\frac{\frac{x}{z}}{\frac{y - t}{2}}\\ \mathbf{elif}\;y \cdot z - t \cdot z \le -6.1429186476606086 \cdot 10^{-306}:\\ \;\;\;\;\frac{x \cdot 2}{y \cdot z - t \cdot z}\\ \mathbf{elif}\;y \cdot z - t \cdot z \le 2.57530990086597633 \cdot 10^{-293}:\\ \;\;\;\;\frac{\frac{1}{\frac{\frac{y - t}{2}}{x}}}{z}\\ \mathbf{elif}\;y \cdot z - t \cdot z \le 1.80640514384054668 \cdot 10^{282}:\\ \;\;\;\;\frac{x \cdot 2}{y \cdot z - t \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{z}}{\frac{y - t}{2}}\\ \end{array}\]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
\mathbf{if}\;y \cdot z - t \cdot z \le -2.5496593359406929 \cdot 10^{290}:\\
\;\;\;\;\frac{\frac{x}{z}}{\frac{y - t}{2}}\\

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

\mathbf{elif}\;y \cdot z - t \cdot z \le 2.57530990086597633 \cdot 10^{-293}:\\
\;\;\;\;\frac{\frac{1}{\frac{\frac{y - t}{2}}{x}}}{z}\\

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

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

\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 ((((double) (((double) (y * z)) - ((double) (t * z)))) <= -2.549659335940693e+290)) {
		VAR = ((double) (((double) (x / z)) / ((double) (((double) (y - t)) / 2.0))));
	} else {
		double VAR_1;
		if ((((double) (((double) (y * z)) - ((double) (t * z)))) <= -6.142918647660609e-306)) {
			VAR_1 = ((double) (((double) (x * 2.0)) / ((double) (((double) (y * z)) - ((double) (t * z))))));
		} else {
			double VAR_2;
			if ((((double) (((double) (y * z)) - ((double) (t * z)))) <= 2.5753099008659763e-293)) {
				VAR_2 = ((double) (((double) (1.0 / ((double) (((double) (((double) (y - t)) / 2.0)) / x)))) / z));
			} else {
				double VAR_3;
				if ((((double) (((double) (y * z)) - ((double) (t * z)))) <= 1.8064051438405467e+282)) {
					VAR_3 = ((double) (((double) (x * 2.0)) / ((double) (((double) (y * z)) - ((double) (t * z))))));
				} else {
					VAR_3 = ((double) (((double) (x / z)) / ((double) (((double) (y - t)) / 2.0))));
				}
				VAR_2 = VAR_3;
			}
			VAR_1 = VAR_2;
		}
		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.8
Target2.0
Herbie0.2
\[\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 (- (* y z) (* t z)) < -2.5496593359406929e290 or 1.80640514384054668e282 < (- (* y z) (* t z))

    1. Initial program 22.3

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

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

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

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

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

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

    if -2.5496593359406929e290 < (- (* y z) (* t z)) < -6.1429186476606086e-306 or 2.57530990086597633e-293 < (- (* y z) (* t z)) < 1.80640514384054668e282

    1. Initial program 0.2

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

    if -6.1429186476606086e-306 < (- (* y z) (* t z)) < 2.57530990086597633e-293

    1. Initial program 51.7

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot z - t \cdot z \le -2.5496593359406929 \cdot 10^{290}:\\ \;\;\;\;\frac{\frac{x}{z}}{\frac{y - t}{2}}\\ \mathbf{elif}\;y \cdot z - t \cdot z \le -6.1429186476606086 \cdot 10^{-306}:\\ \;\;\;\;\frac{x \cdot 2}{y \cdot z - t \cdot z}\\ \mathbf{elif}\;y \cdot z - t \cdot z \le 2.57530990086597633 \cdot 10^{-293}:\\ \;\;\;\;\frac{\frac{1}{\frac{\frac{y - t}{2}}{x}}}{z}\\ \mathbf{elif}\;y \cdot z - t \cdot z \le 1.80640514384054668 \cdot 10^{282}:\\ \;\;\;\;\frac{x \cdot 2}{y \cdot z - t \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{z}}{\frac{y - t}{2}}\\ \end{array}\]

Reproduce

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