Average Error: 6.8 → 2.4
Time: 6.8s
Precision: binary64
\[\frac{x \cdot 2}{y \cdot z - t \cdot z} \]
\[\begin{array}{l} t_1 := \frac{\frac{x \cdot 2}{y - t}}{z}\\ \mathbf{if}\;x \cdot 2 \leq -2.127933069782768 \cdot 10^{-92}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot 2 \leq 8.706980749572951 \cdot 10^{-32}:\\ \;\;\;\;\frac{x \cdot 2}{\left(y - t\right) \cdot z}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
t_1 := \frac{\frac{x \cdot 2}{y - t}}{z}\\
\mathbf{if}\;x \cdot 2 \leq -2.127933069782768 \cdot 10^{-92}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \cdot 2 \leq 8.706980749572951 \cdot 10^{-32}:\\
\;\;\;\;\frac{x \cdot 2}{\left(y - t\right) \cdot z}\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
(FPCore (x y z t) :precision binary64 (/ (* x 2.0) (- (* y z) (* t z))))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (/ (/ (* x 2.0) (- y t)) z)))
   (if (<= (* x 2.0) -2.127933069782768e-92)
     t_1
     (if (<= (* x 2.0) 8.706980749572951e-32)
       (/ (* x 2.0) (* (- y t) z))
       t_1))))
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 t_1 = ((x * 2.0) / (y - t)) / z;
	double tmp;
	if ((x * 2.0) <= -2.127933069782768e-92) {
		tmp = t_1;
	} else if ((x * 2.0) <= 8.706980749572951e-32) {
		tmp = (x * 2.0) / ((y - t) * z);
	} else {
		tmp = t_1;
	}
	return tmp;
}

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
Herbie2.4
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot 2}{y \cdot z - t \cdot z} < -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} < 1.045027827330126 \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 2 regimes
  2. if (*.f64 x 2) < -2.1279330697827681e-92 or 8.7069807495729508e-32 < (*.f64 x 2)

    1. Initial program 9.4

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

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

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

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

    if -2.1279330697827681e-92 < (*.f64 x 2) < 8.7069807495729508e-32

    1. Initial program 3.4

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot 2 \leq -2.127933069782768 \cdot 10^{-92}:\\ \;\;\;\;\frac{\frac{x \cdot 2}{y - t}}{z}\\ \mathbf{elif}\;x \cdot 2 \leq 8.706980749572951 \cdot 10^{-32}:\\ \;\;\;\;\frac{x \cdot 2}{\left(y - t\right) \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x \cdot 2}{y - t}}{z}\\ \end{array} \]

Reproduce

herbie shell --seed 2022077 
(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.045027827330126e-269) (/ (* (/ x z) 2.0) (- y t)) (* (/ x (* (- y t) z)) 2.0)))

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