Average Error: 7.0 → 0.3
Time: 9.2s
Precision: binary64
Cost: 2768
\[\frac{x \cdot 2}{y \cdot z - t \cdot z} \]
\[\begin{array}{l} t_1 := \frac{2}{y - t}\\ t_2 := y \cdot z - z \cdot t\\ t_3 := \frac{2 \cdot x}{t_2}\\ \mathbf{if}\;t_2 \leq -2 \cdot 10^{+231}:\\ \;\;\;\;\frac{t_1}{\frac{z}{x}}\\ \mathbf{elif}\;t_2 \leq -1 \cdot 10^{-220}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t_2 \leq 4 \cdot 10^{-317}:\\ \;\;\;\;\frac{2}{z} \cdot \frac{x}{y - t}\\ \mathbf{elif}\;t_2 \leq 5 \cdot 10^{+215}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_1 \cdot \frac{x}{z}\\ \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 (/ 2.0 (- y t)))
        (t_2 (- (* y z) (* z t)))
        (t_3 (/ (* 2.0 x) t_2)))
   (if (<= t_2 -2e+231)
     (/ t_1 (/ z x))
     (if (<= t_2 -1e-220)
       t_3
       (if (<= t_2 4e-317)
         (* (/ 2.0 z) (/ x (- y t)))
         (if (<= t_2 5e+215) t_3 (* t_1 (/ x z))))))))
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 = 2.0 / (y - t);
	double t_2 = (y * z) - (z * t);
	double t_3 = (2.0 * x) / t_2;
	double tmp;
	if (t_2 <= -2e+231) {
		tmp = t_1 / (z / x);
	} else if (t_2 <= -1e-220) {
		tmp = t_3;
	} else if (t_2 <= 4e-317) {
		tmp = (2.0 / z) * (x / (y - t));
	} else if (t_2 <= 5e+215) {
		tmp = t_3;
	} else {
		tmp = t_1 * (x / z);
	}
	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) :: t_2
    real(8) :: t_3
    real(8) :: tmp
    t_1 = 2.0d0 / (y - t)
    t_2 = (y * z) - (z * t)
    t_3 = (2.0d0 * x) / t_2
    if (t_2 <= (-2d+231)) then
        tmp = t_1 / (z / x)
    else if (t_2 <= (-1d-220)) then
        tmp = t_3
    else if (t_2 <= 4d-317) then
        tmp = (2.0d0 / z) * (x / (y - t))
    else if (t_2 <= 5d+215) then
        tmp = t_3
    else
        tmp = t_1 * (x / z)
    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 = 2.0 / (y - t);
	double t_2 = (y * z) - (z * t);
	double t_3 = (2.0 * x) / t_2;
	double tmp;
	if (t_2 <= -2e+231) {
		tmp = t_1 / (z / x);
	} else if (t_2 <= -1e-220) {
		tmp = t_3;
	} else if (t_2 <= 4e-317) {
		tmp = (2.0 / z) * (x / (y - t));
	} else if (t_2 <= 5e+215) {
		tmp = t_3;
	} else {
		tmp = t_1 * (x / z);
	}
	return tmp;
}
def code(x, y, z, t):
	return (x * 2.0) / ((y * z) - (t * z))
def code(x, y, z, t):
	t_1 = 2.0 / (y - t)
	t_2 = (y * z) - (z * t)
	t_3 = (2.0 * x) / t_2
	tmp = 0
	if t_2 <= -2e+231:
		tmp = t_1 / (z / x)
	elif t_2 <= -1e-220:
		tmp = t_3
	elif t_2 <= 4e-317:
		tmp = (2.0 / z) * (x / (y - t))
	elif t_2 <= 5e+215:
		tmp = t_3
	else:
		tmp = t_1 * (x / z)
	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(2.0 / Float64(y - t))
	t_2 = Float64(Float64(y * z) - Float64(z * t))
	t_3 = Float64(Float64(2.0 * x) / t_2)
	tmp = 0.0
	if (t_2 <= -2e+231)
		tmp = Float64(t_1 / Float64(z / x));
	elseif (t_2 <= -1e-220)
		tmp = t_3;
	elseif (t_2 <= 4e-317)
		tmp = Float64(Float64(2.0 / z) * Float64(x / Float64(y - t)));
	elseif (t_2 <= 5e+215)
		tmp = t_3;
	else
		tmp = Float64(t_1 * Float64(x / z));
	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 = 2.0 / (y - t);
	t_2 = (y * z) - (z * t);
	t_3 = (2.0 * x) / t_2;
	tmp = 0.0;
	if (t_2 <= -2e+231)
		tmp = t_1 / (z / x);
	elseif (t_2 <= -1e-220)
		tmp = t_3;
	elseif (t_2 <= 4e-317)
		tmp = (2.0 / z) * (x / (y - t));
	elseif (t_2 <= 5e+215)
		tmp = t_3;
	else
		tmp = t_1 * (x / z);
	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[(2.0 / N[(y - t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(y * z), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[(2.0 * x), $MachinePrecision] / t$95$2), $MachinePrecision]}, If[LessEqual[t$95$2, -2e+231], N[(t$95$1 / N[(z / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, -1e-220], t$95$3, If[LessEqual[t$95$2, 4e-317], N[(N[(2.0 / z), $MachinePrecision] * N[(x / N[(y - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 5e+215], t$95$3, N[(t$95$1 * N[(x / z), $MachinePrecision]), $MachinePrecision]]]]]]]]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
t_1 := \frac{2}{y - t}\\
t_2 := y \cdot z - z \cdot t\\
t_3 := \frac{2 \cdot x}{t_2}\\
\mathbf{if}\;t_2 \leq -2 \cdot 10^{+231}:\\
\;\;\;\;\frac{t_1}{\frac{z}{x}}\\

\mathbf{elif}\;t_2 \leq -1 \cdot 10^{-220}:\\
\;\;\;\;t_3\\

\mathbf{elif}\;t_2 \leq 4 \cdot 10^{-317}:\\
\;\;\;\;\frac{2}{z} \cdot \frac{x}{y - t}\\

\mathbf{elif}\;t_2 \leq 5 \cdot 10^{+215}:\\
\;\;\;\;t_3\\

\mathbf{else}:\\
\;\;\;\;t_1 \cdot \frac{x}{z}\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original7.0
Target2.3
Herbie0.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 4 regimes
  2. if (-.f64 (*.f64 y z) (*.f64 t z)) < -2.0000000000000001e231

    1. Initial program 12.8

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

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

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

    if -2.0000000000000001e231 < (-.f64 (*.f64 y z) (*.f64 t z)) < -9.99999999999999992e-221 or 3.99999993e-317 < (-.f64 (*.f64 y z) (*.f64 t z)) < 5.0000000000000001e215

    1. Initial program 0.3

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

    if -9.99999999999999992e-221 < (-.f64 (*.f64 y z) (*.f64 t z)) < 3.99999993e-317

    1. Initial program 33.3

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

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

    if 5.0000000000000001e215 < (-.f64 (*.f64 y z) (*.f64 t z))

    1. Initial program 19.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot z - z \cdot t \leq -2 \cdot 10^{+231}:\\ \;\;\;\;\frac{\frac{2}{y - t}}{\frac{z}{x}}\\ \mathbf{elif}\;y \cdot z - z \cdot t \leq -1 \cdot 10^{-220}:\\ \;\;\;\;\frac{2 \cdot x}{y \cdot z - z \cdot t}\\ \mathbf{elif}\;y \cdot z - z \cdot t \leq 4 \cdot 10^{-317}:\\ \;\;\;\;\frac{2}{z} \cdot \frac{x}{y - t}\\ \mathbf{elif}\;y \cdot z - z \cdot t \leq 5 \cdot 10^{+215}:\\ \;\;\;\;\frac{2 \cdot x}{y \cdot z - z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{y - t} \cdot \frac{x}{z}\\ \end{array} \]

Alternatives

Alternative 1
Error2.3
Cost1096
\[\begin{array}{l} t_1 := \frac{2}{z} \cdot \frac{x}{y - t}\\ \mathbf{if}\;2 \cdot x \leq -2 \cdot 10^{+53}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;2 \cdot x \leq 5 \cdot 10^{-70}:\\ \;\;\;\;\frac{\frac{2}{y - t}}{\frac{z}{x}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error2.5
Cost840
\[\begin{array}{l} t_1 := \frac{\frac{2}{y - t}}{\frac{z}{x}}\\ \mathbf{if}\;z \leq -5.132137125337712 \cdot 10^{-66}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 630371.9469137819:\\ \;\;\;\;x \cdot \frac{\frac{2}{z}}{y - t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error17.8
Cost712
\[\begin{array}{l} t_1 := \frac{\frac{-2}{t}}{\frac{z}{x}}\\ \mathbf{if}\;t \leq -228646487.55492747:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 9.360912568277212 \cdot 10^{+37}:\\ \;\;\;\;\frac{2}{\frac{y \cdot z}{x}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error17.1
Cost712
\[\begin{array}{l} t_1 := \frac{\frac{-2}{t}}{\frac{z}{x}}\\ \mathbf{if}\;t \leq -228646487.55492747:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 9.360912568277212 \cdot 10^{+37}:\\ \;\;\;\;\frac{\frac{2 \cdot x}{z}}{y}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error17.0
Cost712
\[\begin{array}{l} t_1 := \frac{\frac{-2}{t}}{\frac{z}{x}}\\ \mathbf{if}\;t \leq -228646487.55492747:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 9.360912568277212 \cdot 10^{+37}:\\ \;\;\;\;\frac{\frac{2}{y}}{\frac{z}{x}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error17.0
Cost712
\[\begin{array}{l} \mathbf{if}\;t \leq -228646487.55492747:\\ \;\;\;\;\frac{\frac{-2}{t}}{\frac{z}{x}}\\ \mathbf{elif}\;t \leq 45179880918.50214:\\ \;\;\;\;\frac{\frac{2}{y}}{\frac{z}{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z \cdot t}{-2}}\\ \end{array} \]
Alternative 7
Error5.3
Cost576
\[\frac{\frac{2}{y - t}}{\frac{z}{x}} \]
Alternative 8
Error29.1
Cost448
\[\frac{\frac{-2}{t}}{\frac{z}{x}} \]

Error

Reproduce

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