Average Error: 6.5 → 0.7
Time: 10.4s
Precision: binary64
Cost: 1864
\[x + \frac{\left(y - x\right) \cdot z}{t} \]
\[\begin{array}{l} t_1 := x + \left(y - x\right) \cdot \frac{z}{t}\\ t_2 := x + \frac{\left(y - x\right) \cdot z}{t}\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 2 \cdot 10^{+307}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (+ x (/ (* (- y x) z) t)))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (+ x (* (- y x) (/ z t)))) (t_2 (+ x (/ (* (- y x) z) t))))
   (if (<= t_2 (- INFINITY)) t_1 (if (<= t_2 2e+307) t_2 t_1))))
double code(double x, double y, double z, double t) {
	return x + (((y - x) * z) / t);
}
double code(double x, double y, double z, double t) {
	double t_1 = x + ((y - x) * (z / t));
	double t_2 = x + (((y - x) * z) / t);
	double tmp;
	if (t_2 <= -((double) INFINITY)) {
		tmp = t_1;
	} else if (t_2 <= 2e+307) {
		tmp = t_2;
	} else {
		tmp = t_1;
	}
	return tmp;
}
public static double code(double x, double y, double z, double t) {
	return x + (((y - x) * z) / t);
}
public static double code(double x, double y, double z, double t) {
	double t_1 = x + ((y - x) * (z / t));
	double t_2 = x + (((y - x) * z) / t);
	double tmp;
	if (t_2 <= -Double.POSITIVE_INFINITY) {
		tmp = t_1;
	} else if (t_2 <= 2e+307) {
		tmp = t_2;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z, t):
	return x + (((y - x) * z) / t)
def code(x, y, z, t):
	t_1 = x + ((y - x) * (z / t))
	t_2 = x + (((y - x) * z) / t)
	tmp = 0
	if t_2 <= -math.inf:
		tmp = t_1
	elif t_2 <= 2e+307:
		tmp = t_2
	else:
		tmp = t_1
	return tmp
function code(x, y, z, t)
	return Float64(x + Float64(Float64(Float64(y - x) * z) / t))
end
function code(x, y, z, t)
	t_1 = Float64(x + Float64(Float64(y - x) * Float64(z / t)))
	t_2 = Float64(x + Float64(Float64(Float64(y - x) * z) / t))
	tmp = 0.0
	if (t_2 <= Float64(-Inf))
		tmp = t_1;
	elseif (t_2 <= 2e+307)
		tmp = t_2;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp = code(x, y, z, t)
	tmp = x + (((y - x) * z) / t);
end
function tmp_2 = code(x, y, z, t)
	t_1 = x + ((y - x) * (z / t));
	t_2 = x + (((y - x) * z) / t);
	tmp = 0.0;
	if (t_2 <= -Inf)
		tmp = t_1;
	elseif (t_2 <= 2e+307)
		tmp = t_2;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x + N[(N[(y - x), $MachinePrecision] * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(x + N[(N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, (-Infinity)], t$95$1, If[LessEqual[t$95$2, 2e+307], t$95$2, t$95$1]]]]
x + \frac{\left(y - x\right) \cdot z}{t}
\begin{array}{l}
t_1 := x + \left(y - x\right) \cdot \frac{z}{t}\\
t_2 := x + \frac{\left(y - x\right) \cdot z}{t}\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_2 \leq 2 \cdot 10^{+307}:\\
\;\;\;\;t_2\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original6.5
Target2.1
Herbie0.7
\[\begin{array}{l} \mathbf{if}\;x < -9.025511195533005 \cdot 10^{-135}:\\ \;\;\;\;x - \frac{z}{t} \cdot \left(x - y\right)\\ \mathbf{elif}\;x < 4.275032163700715 \cdot 10^{-250}:\\ \;\;\;\;x + \frac{y - x}{t} \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \end{array} \]

Derivation

  1. Split input into 2 regimes
  2. if (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t)) < -inf.0 or 1.99999999999999997e307 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t))

    1. Initial program 63.6

      \[x + \frac{\left(y - x\right) \cdot z}{t} \]
    2. Simplified0.2

      \[\leadsto \color{blue}{\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)} \]
      Proof
      (fma.f64 (-.f64 y x) (/.f64 z t) x): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (-.f64 y x) (/.f64 z t)) x)): 2 points increase in error, 2 points decrease in error
      (+.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 (-.f64 y x) z) t)) x): 40 points increase in error, 26 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t))): 0 points increase in error, 0 points decrease in error
    3. Applied egg-rr0.2

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

    if -inf.0 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t)) < 1.99999999999999997e307

    1. Initial program 0.8

      \[x + \frac{\left(y - x\right) \cdot z}{t} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.7

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

Alternatives

Alternative 1
Error13.8
Cost1504
\[\begin{array}{l} t_1 := x + \frac{x \cdot z}{-t}\\ t_2 := x + \frac{y \cdot z}{t}\\ \mathbf{if}\;x \leq -8 \cdot 10^{+130}:\\ \;\;\;\;x + z \cdot \frac{y}{t}\\ \mathbf{elif}\;x \leq -7.988716413752078 \cdot 10^{-43}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 6.32613376522273 \cdot 10^{-178}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.7392429621383046 \cdot 10^{-115}:\\ \;\;\;\;z \cdot \frac{y - x}{t}\\ \mathbf{elif}\;x \leq 1.037105644295127 \cdot 10^{-80}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.8440925578088987 \cdot 10^{-49}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 6.904825731231534 \cdot 10^{-27}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 3 \cdot 10^{+226}:\\ \;\;\;\;x - z \cdot \frac{x}{t}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error11.7
Cost1108
\[\begin{array}{l} t_1 := \frac{\left(y - x\right) \cdot z}{t}\\ t_2 := x + z \cdot \frac{y}{t}\\ \mathbf{if}\;t \leq -3.4 \cdot 10^{-67}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -5.5 \cdot 10^{-104}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -1.7 \cdot 10^{-112}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -2.6 \cdot 10^{-249}:\\ \;\;\;\;x + \frac{x \cdot z}{-t}\\ \mathbf{elif}\;t \leq 6.5 \cdot 10^{-68}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error27.1
Cost1044
\[\begin{array}{l} \mathbf{if}\;x \leq -4.697691919899153 \cdot 10^{-108}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.849208373517797 \cdot 10^{-153}:\\ \;\;\;\;\frac{z}{\frac{t}{y}}\\ \mathbf{elif}\;x \leq -7.07815686820283 \cdot 10^{-192}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 4.518794284040882 \cdot 10^{-126}:\\ \;\;\;\;\frac{y \cdot z}{t}\\ \mathbf{elif}\;x \leq 8.153060337899973 \cdot 10^{-57}:\\ \;\;\;\;\frac{x \cdot \left(-z\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error27.1
Cost1044
\[\begin{array}{l} \mathbf{if}\;x \leq -4.697691919899153 \cdot 10^{-108}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.849208373517797 \cdot 10^{-153}:\\ \;\;\;\;\frac{z}{\frac{t}{y}}\\ \mathbf{elif}\;x \leq -7.07815686820283 \cdot 10^{-192}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 4.518794284040882 \cdot 10^{-126}:\\ \;\;\;\;\frac{y \cdot z}{t}\\ \mathbf{elif}\;x \leq 8.153060337899973 \cdot 10^{-57}:\\ \;\;\;\;z \cdot \frac{-x}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error27.1
Cost1044
\[\begin{array}{l} \mathbf{if}\;x \leq -4.697691919899153 \cdot 10^{-108}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.849208373517797 \cdot 10^{-153}:\\ \;\;\;\;\frac{z}{\frac{t}{y}}\\ \mathbf{elif}\;x \leq -7.07815686820283 \cdot 10^{-192}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 4.518794284040882 \cdot 10^{-126}:\\ \;\;\;\;\frac{y \cdot z}{t}\\ \mathbf{elif}\;x \leq 8.153060337899973 \cdot 10^{-57}:\\ \;\;\;\;\frac{z}{\frac{-t}{x}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 6
Error26.3
Cost980
\[\begin{array}{l} \mathbf{if}\;x \leq -4.697691919899153 \cdot 10^{-108}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.849208373517797 \cdot 10^{-153}:\\ \;\;\;\;\frac{z}{\frac{t}{y}}\\ \mathbf{elif}\;x \leq -7.07815686820283 \cdot 10^{-192}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 4.576027900297505 \cdot 10^{-204}:\\ \;\;\;\;\frac{y \cdot z}{t}\\ \mathbf{elif}\;x \leq 8.153060337899973 \cdot 10^{-57}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 7
Error3.6
Cost840
\[\begin{array}{l} t_1 := x + \left(y - x\right) \cdot \frac{z}{t}\\ \mathbf{if}\;y \leq -3.4438556248271856 \cdot 10^{-203}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 4.079802681758391 \cdot 10^{-158}:\\ \;\;\;\;x + \frac{x \cdot z}{-t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error21.9
Cost712
\[\begin{array}{l} \mathbf{if}\;t \leq -3.4 \cdot 10^{+23}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq 4.5 \cdot 10^{-17}:\\ \;\;\;\;\frac{\left(y - x\right) \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Error10.6
Cost712
\[\begin{array}{l} t_1 := x + z \cdot \frac{y}{t}\\ \mathbf{if}\;t \leq -3.4 \cdot 10^{-67}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 6.5 \cdot 10^{-68}:\\ \;\;\;\;\frac{\left(y - x\right) \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Error25.5
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -4.697691919899153 \cdot 10^{-108}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 8.153060337899973 \cdot 10^{-57}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 11
Error25.5
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -4.697691919899153 \cdot 10^{-108}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 8.153060337899973 \cdot 10^{-57}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 12
Error31.6
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2022294 
(FPCore (x y z t)
  :name "Numeric.Histogram:binBounds from Chart-1.5.3"
  :precision binary64

  :herbie-target
  (if (< x -9.025511195533005e-135) (- x (* (/ z t) (- x y))) (if (< x 4.275032163700715e-250) (+ x (* (/ (- y x) t) z)) (+ x (/ (- y x) (/ t z)))))

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