Average Error: 6.6 → 2.6
Time: 2.0s
Precision: 64
\[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;z \le -3149.6947709486194:\\ \;\;\;\;\frac{\frac{x \cdot \left(-2\right)}{-\left(y - t\right)}}{z}\\ \mathbf{elif}\;z \le -7.1620056551756794 \cdot 10^{-309}:\\ \;\;\;\;\frac{x}{\frac{z \cdot \left(y - t\right)}{2}}\\ \mathbf{elif}\;z \le 2.4161758237400621 \cdot 10^{-244}:\\ \;\;\;\;\frac{\left(x \cdot \left(-2\right)\right) \cdot \frac{-1}{y - t}}{z}\\ \mathbf{elif}\;z \le 2.78048176862088268 \cdot 10^{-47}:\\ \;\;\;\;\frac{x}{\frac{z \cdot \left(y - t\right)}{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x \cdot \left(-2\right)}{-\left(y - t\right)}}{z}\\ \end{array}\]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
\mathbf{if}\;z \le -3149.6947709486194:\\
\;\;\;\;\frac{\frac{x \cdot \left(-2\right)}{-\left(y - t\right)}}{z}\\

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

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

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

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

\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 ((z <= -3149.6947709486194)) {
		VAR = (((x * -2.0) / -(y - t)) / z);
	} else {
		double VAR_1;
		if ((z <= -7.16200565517568e-309)) {
			VAR_1 = (x / ((z * (y - t)) / 2.0));
		} else {
			double VAR_2;
			if ((z <= 2.416175823740062e-244)) {
				VAR_2 = (((x * -2.0) * (-1.0 / (y - t))) / z);
			} else {
				double VAR_3;
				if ((z <= 2.7804817686208827e-47)) {
					VAR_3 = (x / ((z * (y - t)) / 2.0));
				} else {
					VAR_3 = (((x * -2.0) / -(y - t)) / z);
				}
				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.6
Target2.1
Herbie2.6
\[\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 < -3149.6947709486194 or 2.7804817686208827e-47 < z

    1. Initial program 10.0

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

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

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

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

      \[\leadsto x \cdot \frac{2}{\color{blue}{\left(y - t\right) \cdot z}}\]
    8. Applied associate-/r*7.5

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

      \[\leadsto \color{blue}{\frac{x \cdot \frac{2}{y - t}}{z}}\]
    10. Using strategy rm
    11. Applied frac-2neg2.0

      \[\leadsto \frac{x \cdot \color{blue}{\frac{-2}{-\left(y - t\right)}}}{z}\]
    12. Applied associate-*r/2.0

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

    if -3149.6947709486194 < z < -7.16200565517568e-309 or 2.416175823740062e-244 < z < 2.7804817686208827e-47

    1. Initial program 2.0

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

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

    if -7.16200565517568e-309 < z < 2.416175823740062e-244

    1. Initial program 5.6

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

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

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

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

      \[\leadsto x \cdot \frac{2}{\color{blue}{\left(y - t\right) \cdot z}}\]
    8. Applied associate-/r*6.1

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

      \[\leadsto \color{blue}{\frac{x \cdot \frac{2}{y - t}}{z}}\]
    10. Using strategy rm
    11. Applied frac-2neg18.3

      \[\leadsto \frac{x \cdot \color{blue}{\frac{-2}{-\left(y - t\right)}}}{z}\]
    12. Applied associate-*r/18.2

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -3149.6947709486194:\\ \;\;\;\;\frac{\frac{x \cdot \left(-2\right)}{-\left(y - t\right)}}{z}\\ \mathbf{elif}\;z \le -7.1620056551756794 \cdot 10^{-309}:\\ \;\;\;\;\frac{x}{\frac{z \cdot \left(y - t\right)}{2}}\\ \mathbf{elif}\;z \le 2.4161758237400621 \cdot 10^{-244}:\\ \;\;\;\;\frac{\left(x \cdot \left(-2\right)\right) \cdot \frac{-1}{y - t}}{z}\\ \mathbf{elif}\;z \le 2.78048176862088268 \cdot 10^{-47}:\\ \;\;\;\;\frac{x}{\frac{z \cdot \left(y - t\right)}{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x \cdot \left(-2\right)}{-\left(y - t\right)}}{z}\\ \end{array}\]

Reproduce

herbie shell --seed 2020071 +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))))