Average Error: 6.8 → 3.3
Time: 4.4s
Precision: 64
\[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;z \le -5.69801363483779798 \cdot 10^{44}:\\ \;\;\;\;\frac{1}{z} \cdot \frac{x}{\frac{y - t}{2}}\\ \mathbf{elif}\;z \le 1.26255554836431083 \cdot 10^{-207}:\\ \;\;\;\;\frac{x}{\frac{y - t}{2} \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}\;z \le -5.69801363483779798 \cdot 10^{44}:\\
\;\;\;\;\frac{1}{z} \cdot \frac{x}{\frac{y - t}{2}}\\

\mathbf{elif}\;z \le 1.26255554836431083 \cdot 10^{-207}:\\
\;\;\;\;\frac{x}{\frac{y - t}{2} \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 ((x * 2.0) / ((y * z) - (t * z)));
}
double code(double x, double y, double z, double t) {
	double temp;
	if ((z <= -5.698013634837798e+44)) {
		temp = ((1.0 / z) * (x / ((y - t) / 2.0)));
	} else {
		double temp_1;
		if ((z <= 1.2625555483643108e-207)) {
			temp_1 = (x / (((y - t) / 2.0) * z));
		} else {
			temp_1 = ((x / z) / ((y - t) / 2.0));
		}
		temp = temp_1;
	}
	return temp;
}

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.2
Herbie3.3
\[\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 < -5.698013634837798e+44

    1. Initial program 12.4

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

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

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

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

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

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

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

    if -5.698013634837798e+44 < z < 1.2625555483643108e-207

    1. Initial program 3.0

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{x}{z}}}{\frac{y - t}{2}}\]
    8. Using strategy rm
    9. Applied div-inv11.1

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

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

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

    if 1.2625555483643108e-207 < z

    1. Initial program 6.7

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -5.69801363483779798 \cdot 10^{44}:\\ \;\;\;\;\frac{1}{z} \cdot \frac{x}{\frac{y - t}{2}}\\ \mathbf{elif}\;z \le 1.26255554836431083 \cdot 10^{-207}:\\ \;\;\;\;\frac{x}{\frac{y - t}{2} \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{z}}{\frac{y - t}{2}}\\ \end{array}\]

Reproduce

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