Average Error: 7.0 → 1.1
Time: 9.2s
Precision: binary64
Cost: 1736
\[\frac{x \cdot 2}{y \cdot z - t \cdot z} \]
\[\begin{array}{l} t_1 := y \cdot z - z \cdot t\\ t_2 := 2 \cdot \frac{\frac{x}{z}}{y - t}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+238}:\\ \;\;\;\;\frac{2 \cdot x}{t_1}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \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 (* 2.0 (/ (/ x z) (- y t)))))
   (if (<= t_1 (- INFINITY)) t_2 (if (<= t_1 2e+238) (/ (* 2.0 x) t_1) t_2))))
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 = 2.0 * ((x / z) / (y - t));
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = t_2;
	} else if (t_1 <= 2e+238) {
		tmp = (2.0 * x) / t_1;
	} else {
		tmp = t_2;
	}
	return tmp;
}
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 = (y * z) - (z * t);
	double t_2 = 2.0 * ((x / z) / (y - t));
	double tmp;
	if (t_1 <= -Double.POSITIVE_INFINITY) {
		tmp = t_2;
	} else if (t_1 <= 2e+238) {
		tmp = (2.0 * x) / t_1;
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(x, y, z, t):
	return (x * 2.0) / ((y * z) - (t * z))
def code(x, y, z, t):
	t_1 = (y * z) - (z * t)
	t_2 = 2.0 * ((x / z) / (y - t))
	tmp = 0
	if t_1 <= -math.inf:
		tmp = t_2
	elif t_1 <= 2e+238:
		tmp = (2.0 * x) / t_1
	else:
		tmp = t_2
	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(y * z) - Float64(z * t))
	t_2 = Float64(2.0 * Float64(Float64(x / z) / Float64(y - t)))
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = t_2;
	elseif (t_1 <= 2e+238)
		tmp = Float64(Float64(2.0 * x) / t_1);
	else
		tmp = t_2;
	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 = (y * z) - (z * t);
	t_2 = 2.0 * ((x / z) / (y - t));
	tmp = 0.0;
	if (t_1 <= -Inf)
		tmp = t_2;
	elseif (t_1 <= 2e+238)
		tmp = (2.0 * x) / t_1;
	else
		tmp = t_2;
	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[(y * z), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(2.0 * N[(N[(x / z), $MachinePrecision] / N[(y - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], t$95$2, If[LessEqual[t$95$1, 2e+238], N[(N[(2.0 * x), $MachinePrecision] / t$95$1), $MachinePrecision], t$95$2]]]]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
t_1 := y \cdot z - z \cdot t\\
t_2 := 2 \cdot \frac{\frac{x}{z}}{y - t}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_1 \leq 2 \cdot 10^{+238}:\\
\;\;\;\;\frac{2 \cdot x}{t_1}\\

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original7.0
Target2.2
Herbie1.1
\[\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 (*.f64 y z) (*.f64 t z)) < -inf.0 or 2.0000000000000001e238 < (-.f64 (*.f64 y z) (*.f64 t z))

    1. Initial program 20.7

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

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

      \[\leadsto \color{blue}{2 \cdot \frac{\frac{x}{z}}{y - t}} \]
      Proof
      (*.f64 2 (/.f64 (/.f64 x z) (-.f64 y t))): 0 points increase in error, 0 points decrease in error
      (*.f64 2 (Rewrite<= associate-/r*_binary64 (/.f64 x (*.f64 z (-.f64 y t))))): 50 points increase in error, 48 points decrease in error
      (*.f64 2 (/.f64 x (Rewrite<= distribute-rgt-out--_binary64 (-.f64 (*.f64 y z) (*.f64 t z))))): 3 points increase in error, 0 points decrease in error

    if -inf.0 < (-.f64 (*.f64 y z) (*.f64 t z)) < 2.0000000000000001e238

    1. Initial program 1.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot z - z \cdot t \leq -\infty:\\ \;\;\;\;2 \cdot \frac{\frac{x}{z}}{y - t}\\ \mathbf{elif}\;y \cdot z - z \cdot t \leq 2 \cdot 10^{+238}:\\ \;\;\;\;\frac{2 \cdot x}{y \cdot z - z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \frac{\frac{x}{z}}{y - t}\\ \end{array} \]

Alternatives

Alternative 1
Error17.8
Cost1108
\[\begin{array}{l} t_1 := 2 \cdot \frac{\frac{x}{y}}{z}\\ t_2 := \frac{\frac{x \cdot -2}{t}}{z}\\ \mathbf{if}\;y \leq -8.798234999427454 \cdot 10^{-42}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -6.3540774146604435 \cdot 10^{-127}:\\ \;\;\;\;-2 \cdot \frac{\frac{x}{z}}{t}\\ \mathbf{elif}\;y \leq 3.797881000980718 \cdot 10^{-81}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 2912375.234592336:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 8.12048462224306 \cdot 10^{+73}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{2}{y \cdot z}\\ \end{array} \]
Alternative 2
Error17.8
Cost1108
\[\begin{array}{l} t_1 := 2 \cdot \frac{\frac{x}{y}}{z}\\ t_2 := \frac{\frac{x \cdot -2}{t}}{z}\\ \mathbf{if}\;y \leq -8.798234999427454 \cdot 10^{-42}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -6.3540774146604435 \cdot 10^{-127}:\\ \;\;\;\;-2 \cdot \frac{\frac{x}{z}}{t}\\ \mathbf{elif}\;y \leq 3.797881000980718 \cdot 10^{-81}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 2912375.234592336:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 8.12048462224306 \cdot 10^{+73}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot x}{y \cdot z}\\ \end{array} \]
Alternative 3
Error2.2
Cost1096
\[\begin{array}{l} t_1 := \frac{x \cdot \frac{2}{y - t}}{z}\\ \mathbf{if}\;2 \cdot x \leq -2 \cdot 10^{-46}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;2 \cdot x \leq 2000000000:\\ \;\;\;\;2 \cdot \frac{\frac{x}{z}}{y - t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error2.4
Cost1096
\[\begin{array}{l} \mathbf{if}\;2 \cdot x \leq -1 \cdot 10^{-93}:\\ \;\;\;\;\frac{2}{z} \cdot \frac{x}{y - t}\\ \mathbf{elif}\;2 \cdot x \leq 2000000000:\\ \;\;\;\;2 \cdot \frac{\frac{x}{z}}{y - t}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \frac{2}{y - t}}{z}\\ \end{array} \]
Alternative 5
Error18.0
Cost976
\[\begin{array}{l} t_1 := \frac{\frac{x \cdot -2}{t}}{z}\\ t_2 := \frac{2}{z} \cdot \frac{x}{y}\\ \mathbf{if}\;y \leq -8.798234999427454 \cdot 10^{-42}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 3.797881000980718 \cdot 10^{-81}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2912375.234592336:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 8.12048462224306 \cdot 10^{+73}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{2}{y \cdot z}\\ \end{array} \]
Alternative 6
Error18.0
Cost976
\[\begin{array}{l} t_1 := \frac{\frac{x \cdot -2}{t}}{z}\\ t_2 := 2 \cdot \frac{\frac{x}{y}}{z}\\ \mathbf{if}\;y \leq -8.798234999427454 \cdot 10^{-42}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 3.797881000980718 \cdot 10^{-81}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2912375.234592336:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 8.12048462224306 \cdot 10^{+73}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{2}{y \cdot z}\\ \end{array} \]
Alternative 7
Error2.8
Cost840
\[\begin{array}{l} t_1 := 2 \cdot \frac{\frac{x}{z}}{y - t}\\ \mathbf{if}\;z \leq -9.201288146360107 \cdot 10^{-61}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 4.0505795340973147 \cdot 10^{+164}:\\ \;\;\;\;x \cdot \frac{\frac{2}{y - t}}{z}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error6.0
Cost708
\[\begin{array}{l} \mathbf{if}\;t \leq -1.5391949009218926 \cdot 10^{+207}:\\ \;\;\;\;\frac{\frac{x \cdot -2}{t}}{z}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \frac{\frac{x}{z}}{y - t}\\ \end{array} \]
Alternative 9
Error30.9
Cost580
\[\begin{array}{l} \mathbf{if}\;x \leq 4.0733272416195696 \cdot 10^{-69}:\\ \;\;\;\;x \cdot \frac{2}{y \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{z} \cdot \frac{x}{y}\\ \end{array} \]
Alternative 10
Error31.7
Cost448
\[x \cdot \frac{2}{y \cdot z} \]

Error

Reproduce

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