Average Error: 6.9 → 0.4
Time: 6.4s
Precision: binary64
\[\frac{x \cdot 2}{y \cdot z - t \cdot z} \]
\[\begin{array}{l} t_1 := y \cdot z - z \cdot t\\ t_2 := \frac{x \cdot 2}{z \cdot \left(y - t\right)}\\ \mathbf{if}\;t_1 \leq -7.346581112776964 \cdot 10^{+246}:\\ \;\;\;\;\frac{x}{y - t} \cdot \frac{2}{z}\\ \mathbf{elif}\;t_1 \leq -4.510519146821146 \cdot 10^{-157}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 0:\\ \;\;\;\;\frac{2}{y - t} \cdot \left(x \cdot \frac{1}{z}\right)\\ \mathbf{elif}\;t_1 \leq 3.3690673652284793 \cdot 10^{+210}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot \frac{1}{z}}{\frac{y - t}{x}}\\ \end{array} \]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
t_1 := y \cdot z - z \cdot t\\
t_2 := \frac{x \cdot 2}{z \cdot \left(y - t\right)}\\
\mathbf{if}\;t_1 \leq -7.346581112776964 \cdot 10^{+246}:\\
\;\;\;\;\frac{x}{y - t} \cdot \frac{2}{z}\\

\mathbf{elif}\;t_1 \leq -4.510519146821146 \cdot 10^{-157}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_1 \leq 0:\\
\;\;\;\;\frac{2}{y - t} \cdot \left(x \cdot \frac{1}{z}\right)\\

\mathbf{elif}\;t_1 \leq 3.3690673652284793 \cdot 10^{+210}:\\
\;\;\;\;t_2\\

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


\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 (- (* y z) (* z t))) (t_2 (/ (* x 2.0) (* z (- y t)))))
   (if (<= t_1 -7.346581112776964e+246)
     (* (/ x (- y t)) (/ 2.0 z))
     (if (<= t_1 -4.510519146821146e-157)
       t_2
       (if (<= t_1 0.0)
         (* (/ 2.0 (- y t)) (* x (/ 1.0 z)))
         (if (<= t_1 3.3690673652284793e+210)
           t_2
           (/ (* 2.0 (/ 1.0 z)) (/ (- y t) x))))))))
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 = (y * z) - (z * t);
	double t_2 = (x * 2.0) / (z * (y - t));
	double tmp;
	if (t_1 <= -7.346581112776964e+246) {
		tmp = (x / (y - t)) * (2.0 / z);
	} else if (t_1 <= -4.510519146821146e-157) {
		tmp = t_2;
	} else if (t_1 <= 0.0) {
		tmp = (2.0 / (y - t)) * (x * (1.0 / z));
	} else if (t_1 <= 3.3690673652284793e+210) {
		tmp = t_2;
	} else {
		tmp = (2.0 * (1.0 / z)) / ((y - t) / x);
	}
	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.9
Target2.1
Herbie0.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 4 regimes
  2. if (-.f64 (*.f64 y z) (*.f64 t z)) < -7.346581112776964e246

    1. Initial program 14.5

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

      \[\leadsto \color{blue}{x \cdot \frac{\frac{2}{y - t}}{z}} \]
    3. Applied egg-rr0.2

      \[\leadsto \color{blue}{\frac{x \cdot \frac{2}{y - t}}{z}} \]
    4. Taylor expanded in x around 0 0.2

      \[\leadsto \frac{\color{blue}{2 \cdot \frac{x}{y - t}}}{z} \]
    5. Applied egg-rr0.2

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

    if -7.346581112776964e246 < (-.f64 (*.f64 y z) (*.f64 t z)) < -4.5105191468211463e-157 or 0.0 < (-.f64 (*.f64 y z) (*.f64 t z)) < 3.36906736522847935e210

    1. Initial program 0.3

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

      \[\leadsto \color{blue}{x \cdot \frac{\frac{2}{y - t}}{z}} \]
    3. Applied egg-rr0.3

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

    if -4.5105191468211463e-157 < (-.f64 (*.f64 y z) (*.f64 t z)) < 0.0

    1. Initial program 19.0

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

      \[\leadsto \color{blue}{x \cdot \frac{\frac{2}{y - t}}{z}} \]
    3. Applied egg-rr2.6

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

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

    if 3.36906736522847935e210 < (-.f64 (*.f64 y z) (*.f64 t z))

    1. Initial program 18.6

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

      \[\leadsto \color{blue}{x \cdot \frac{\frac{2}{y - t}}{z}} \]
    3. Applied egg-rr0.2

      \[\leadsto \color{blue}{\frac{x \cdot \frac{2}{y - t}}{z}} \]
    4. Taylor expanded in x around 0 0.2

      \[\leadsto \frac{\color{blue}{2 \cdot \frac{x}{y - t}}}{z} \]
    5. Applied egg-rr0.9

      \[\leadsto \color{blue}{2 \cdot \frac{1}{z \cdot \frac{y - t}{x}}} \]
    6. Applied egg-rr0.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot z - z \cdot t \leq -7.346581112776964 \cdot 10^{+246}:\\ \;\;\;\;\frac{x}{y - t} \cdot \frac{2}{z}\\ \mathbf{elif}\;y \cdot z - z \cdot t \leq -4.510519146821146 \cdot 10^{-157}:\\ \;\;\;\;\frac{x \cdot 2}{z \cdot \left(y - t\right)}\\ \mathbf{elif}\;y \cdot z - z \cdot t \leq 0:\\ \;\;\;\;\frac{2}{y - t} \cdot \left(x \cdot \frac{1}{z}\right)\\ \mathbf{elif}\;y \cdot z - z \cdot t \leq 3.3690673652284793 \cdot 10^{+210}:\\ \;\;\;\;\frac{x \cdot 2}{z \cdot \left(y - t\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot \frac{1}{z}}{\frac{y - t}{x}}\\ \end{array} \]

Reproduce

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