Average Error: 7.0 → 2.3
Time: 3.7s
Precision: binary64
\[\frac{x \cdot 2}{y \cdot z - t \cdot z} \]
\[\begin{array}{l} t_1 := \frac{x \cdot 2}{y \cdot z - z \cdot t}\\ \mathbf{if}\;t_1 \leq -5 \cdot 10^{+95}:\\ \;\;\;\;\frac{-2}{z} \cdot \frac{x}{t - y}\\ \mathbf{elif}\;t_1 \leq 0:\\ \;\;\;\;2 \cdot \frac{\frac{x}{z}}{y - t}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot -2}{z \cdot \left(t - y\right)}\\ \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 z) (* z t)))))
   (if (<= t_1 -5e+95)
     (* (/ -2.0 z) (/ x (- t y)))
     (if (<= t_1 0.0)
       (* 2.0 (/ (/ x z) (- y t)))
       (/ (* x -2.0) (* z (- t y)))))))
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 * z) - (z * t));
	double tmp;
	if (t_1 <= -5e+95) {
		tmp = (-2.0 / z) * (x / (t - y));
	} else if (t_1 <= 0.0) {
		tmp = 2.0 * ((x / z) / (y - t));
	} else {
		tmp = (x * -2.0) / (z * (t - y));
	}
	return tmp;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = (x * 2.0d0) / ((y * z) - (t * z))
end function
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: t_1
    real(8) :: tmp
    t_1 = (x * 2.0d0) / ((y * z) - (z * t))
    if (t_1 <= (-5d+95)) then
        tmp = ((-2.0d0) / z) * (x / (t - y))
    else if (t_1 <= 0.0d0) then
        tmp = 2.0d0 * ((x / z) / (y - t))
    else
        tmp = (x * (-2.0d0)) / (z * (t - y))
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	return (x * 2.0) / ((y * z) - (t * z));
}
public static double code(double x, double y, double z, double t) {
	double t_1 = (x * 2.0) / ((y * z) - (z * t));
	double tmp;
	if (t_1 <= -5e+95) {
		tmp = (-2.0 / z) * (x / (t - y));
	} else if (t_1 <= 0.0) {
		tmp = 2.0 * ((x / z) / (y - t));
	} else {
		tmp = (x * -2.0) / (z * (t - y));
	}
	return tmp;
}
def code(x, y, z, t):
	return (x * 2.0) / ((y * z) - (t * z))
def code(x, y, z, t):
	t_1 = (x * 2.0) / ((y * z) - (z * t))
	tmp = 0
	if t_1 <= -5e+95:
		tmp = (-2.0 / z) * (x / (t - y))
	elif t_1 <= 0.0:
		tmp = 2.0 * ((x / z) / (y - t))
	else:
		tmp = (x * -2.0) / (z * (t - y))
	return tmp
function code(x, y, z, t)
	return Float64(Float64(x * 2.0) / Float64(Float64(y * z) - Float64(t * z)))
end
function code(x, y, z, t)
	t_1 = Float64(Float64(x * 2.0) / Float64(Float64(y * z) - Float64(z * t)))
	tmp = 0.0
	if (t_1 <= -5e+95)
		tmp = Float64(Float64(-2.0 / z) * Float64(x / Float64(t - y)));
	elseif (t_1 <= 0.0)
		tmp = Float64(2.0 * Float64(Float64(x / z) / Float64(y - t)));
	else
		tmp = Float64(Float64(x * -2.0) / Float64(z * Float64(t - y)));
	end
	return tmp
end
function tmp = code(x, y, z, t)
	tmp = (x * 2.0) / ((y * z) - (t * z));
end
function tmp_2 = code(x, y, z, t)
	t_1 = (x * 2.0) / ((y * z) - (z * t));
	tmp = 0.0;
	if (t_1 <= -5e+95)
		tmp = (-2.0 / z) * (x / (t - y));
	elseif (t_1 <= 0.0)
		tmp = 2.0 * ((x / z) / (y - t));
	else
		tmp = (x * -2.0) / (z * (t - y));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := N[(N[(x * 2.0), $MachinePrecision] / N[(N[(y * z), $MachinePrecision] - N[(t * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(x * 2.0), $MachinePrecision] / N[(N[(y * z), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -5e+95], N[(N[(-2.0 / z), $MachinePrecision] * N[(x / N[(t - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 0.0], N[(2.0 * N[(N[(x / z), $MachinePrecision] / N[(y - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * -2.0), $MachinePrecision] / N[(z * N[(t - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
t_1 := \frac{x \cdot 2}{y \cdot z - z \cdot t}\\
\mathbf{if}\;t_1 \leq -5 \cdot 10^{+95}:\\
\;\;\;\;\frac{-2}{z} \cdot \frac{x}{t - y}\\

\mathbf{elif}\;t_1 \leq 0:\\
\;\;\;\;2 \cdot \frac{\frac{x}{z}}{y - t}\\

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


\end{array}

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

Original7.0
Target2.1
Herbie2.3
\[\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 3 regimes
  2. if (/.f64 (*.f64 x 2) (-.f64 (*.f64 y z) (*.f64 t z))) < -5.00000000000000025e95

    1. Initial program 5.0

      \[\frac{x \cdot 2}{y \cdot z - t \cdot z} \]
    2. Taylor expanded in z around -inf 4.9

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

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

    if -5.00000000000000025e95 < (/.f64 (*.f64 x 2) (-.f64 (*.f64 y z) (*.f64 t z))) < -0.0

    1. Initial program 8.2

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

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

    if -0.0 < (/.f64 (*.f64 x 2) (-.f64 (*.f64 y z) (*.f64 t z)))

    1. Initial program 5.7

      \[\frac{x \cdot 2}{y \cdot z - t \cdot z} \]
    2. Applied egg-rr8.7

      \[\leadsto \color{blue}{{\left(\frac{z}{x} \cdot \frac{y - t}{2}\right)}^{-1}} \]
    3. Taylor expanded in x around -inf 5.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot 2}{y \cdot z - z \cdot t} \leq -5 \cdot 10^{+95}:\\ \;\;\;\;\frac{-2}{z} \cdot \frac{x}{t - y}\\ \mathbf{elif}\;\frac{x \cdot 2}{y \cdot z - z \cdot t} \leq 0:\\ \;\;\;\;2 \cdot \frac{\frac{x}{z}}{y - t}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot -2}{z \cdot \left(t - y\right)}\\ \end{array} \]

Reproduce

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