Average Error: 6.5 → 0.6
Time: 10.2s
Precision: binary64
Cost: 3152
\[x + \frac{\left(y - x\right) \cdot z}{t} \]
\[\begin{array}{l} t_1 := x + z \cdot \frac{y - x}{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^{-80}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_2 \leq 2 \cdot 10^{-180}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 10^{+305}:\\ \;\;\;\;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 (* z (/ (- y x) t)))) (t_2 (+ x (/ (* (- y x) z) t))))
   (if (<= t_2 (- INFINITY))
     t_1
     (if (<= t_2 -2e-80)
       t_2
       (if (<= t_2 2e-180) t_1 (if (<= t_2 1e+305) 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 + (z * ((y - x) / t));
	double t_2 = x + (((y - x) * z) / t);
	double tmp;
	if (t_2 <= -((double) INFINITY)) {
		tmp = t_1;
	} else if (t_2 <= -2e-80) {
		tmp = t_2;
	} else if (t_2 <= 2e-180) {
		tmp = t_1;
	} else if (t_2 <= 1e+305) {
		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 + (z * ((y - x) / 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-80) {
		tmp = t_2;
	} else if (t_2 <= 2e-180) {
		tmp = t_1;
	} else if (t_2 <= 1e+305) {
		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 + (z * ((y - x) / t))
	t_2 = x + (((y - x) * z) / t)
	tmp = 0
	if t_2 <= -math.inf:
		tmp = t_1
	elif t_2 <= -2e-80:
		tmp = t_2
	elif t_2 <= 2e-180:
		tmp = t_1
	elif t_2 <= 1e+305:
		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(z * Float64(Float64(y - x) / 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-80)
		tmp = t_2;
	elseif (t_2 <= 2e-180)
		tmp = t_1;
	elseif (t_2 <= 1e+305)
		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 + (z * ((y - x) / t));
	t_2 = x + (((y - x) * z) / t);
	tmp = 0.0;
	if (t_2 <= -Inf)
		tmp = t_1;
	elseif (t_2 <= -2e-80)
		tmp = t_2;
	elseif (t_2 <= 2e-180)
		tmp = t_1;
	elseif (t_2 <= 1e+305)
		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[(z * N[(N[(y - x), $MachinePrecision] / 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-80], t$95$2, If[LessEqual[t$95$2, 2e-180], t$95$1, If[LessEqual[t$95$2, 1e+305], t$95$2, t$95$1]]]]]]
x + \frac{\left(y - x\right) \cdot z}{t}
\begin{array}{l}
t_1 := x + z \cdot \frac{y - x}{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^{-80}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_2 \leq 2 \cdot 10^{-180}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_2 \leq 10^{+305}:\\
\;\;\;\;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.0
Herbie0.6
\[\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.99999999999999992e-80 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t)) < 2e-180 or 9.9999999999999994e304 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t))

    1. Initial program 27.4

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

      \[\leadsto \color{blue}{x + \frac{y - x}{t} \cdot z} \]
      Proof
      (+.f64 x (*.f64 (/.f64 (-.f64 y x) t) z)): 0 points increase in error, 0 points decrease in error
      (+.f64 x (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 (-.f64 y x) z) t))): 38 points increase in error, 40 points decrease in error

    if -inf.0 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t)) < -1.99999999999999992e-80 or 2e-180 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t)) < 9.9999999999999994e304

    1. Initial program 0.3

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

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

Alternatives

Alternative 1
Error2.3
Cost6980
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{+41}:\\ \;\;\;\;\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\ \mathbf{elif}\;x \leq -3.3 \cdot 10^{-278}:\\ \;\;\;\;x + z \cdot \frac{y - x}{t}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \end{array} \]
Alternative 2
Error11.9
Cost1636
\[\begin{array}{l} t_1 := x + \frac{y}{\frac{t}{z}}\\ t_2 := z \cdot \frac{y - x}{t}\\ t_3 := x - x \cdot \frac{z}{t}\\ \mathbf{if}\;x \leq -4.3 \cdot 10^{+88}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -1.1 \cdot 10^{-36}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -5.6 \cdot 10^{-90}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -1.4 \cdot 10^{-131}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -4.4 \cdot 10^{-140}:\\ \;\;\;\;x - z \cdot \frac{x}{t}\\ \mathbf{elif}\;x \leq -6.8 \cdot 10^{-159}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.7 \cdot 10^{-12}:\\ \;\;\;\;x + \frac{z}{\frac{t}{y}}\\ \mathbf{elif}\;x \leq 3.2 \cdot 10^{+20}:\\ \;\;\;\;\left(y - x\right) \cdot \frac{z}{t}\\ \mathbf{elif}\;x \leq 10^{+50}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 3
Error12.3
Cost1636
\[\begin{array}{l} t_1 := x + \frac{y}{\frac{t}{z}}\\ t_2 := \frac{\left(y - x\right) \cdot z}{t}\\ t_3 := x - x \cdot \frac{z}{t}\\ t_4 := x + \frac{z}{\frac{t}{y}}\\ \mathbf{if}\;x \leq -4.5 \cdot 10^{+88}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -1.1 \cdot 10^{-36}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -8.8 \cdot 10^{-110}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -1.4 \cdot 10^{-131}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;x \leq -3.4 \cdot 10^{-140}:\\ \;\;\;\;x - z \cdot \frac{x}{t}\\ \mathbf{elif}\;x \leq -6.8 \cdot 10^{-159}:\\ \;\;\;\;z \cdot \frac{y - x}{t}\\ \mathbf{elif}\;x \leq 6.5 \cdot 10^{-10}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;x \leq 3.3 \cdot 10^{+25}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 8.5 \cdot 10^{+50}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 4
Error27.6
Cost1244
\[\begin{array}{l} t_1 := z \cdot \frac{x}{-t}\\ t_2 := z \cdot \frac{y}{t}\\ \mathbf{if}\;x \leq -1.1 \cdot 10^{-36}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -6.5 \cdot 10^{-87}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.4 \cdot 10^{-131}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \mathbf{elif}\;x \leq -6.8 \cdot 10^{-159}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.3 \cdot 10^{-227}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -6 \cdot 10^{-257}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.45 \cdot 10^{-128}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error27.7
Cost1244
\[\begin{array}{l} t_1 := z \cdot \frac{y}{t}\\ \mathbf{if}\;x \leq -1.8 \cdot 10^{-36}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -3.4 \cdot 10^{-89}:\\ \;\;\;\;z \cdot \frac{x}{-t}\\ \mathbf{elif}\;x \leq -1.45 \cdot 10^{-131}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \mathbf{elif}\;x \leq -5.2 \cdot 10^{-159}:\\ \;\;\;\;\frac{x \cdot \left(-z\right)}{t}\\ \mathbf{elif}\;x \leq -4 \cdot 10^{-227}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -3.5 \cdot 10^{-257}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 6.5 \cdot 10^{-125}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 6
Error12.4
Cost1240
\[\begin{array}{l} t_1 := x + \frac{y}{\frac{t}{z}}\\ t_2 := x - x \cdot \frac{z}{t}\\ \mathbf{if}\;x \leq -4.3 \cdot 10^{+88}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -1.1 \cdot 10^{-36}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -6.8 \cdot 10^{-159}:\\ \;\;\;\;z \cdot \frac{y - x}{t}\\ \mathbf{elif}\;x \leq 3.9 \cdot 10^{-10}:\\ \;\;\;\;x + \frac{z}{\frac{t}{y}}\\ \mathbf{elif}\;x \leq 3.2 \cdot 10^{+20}:\\ \;\;\;\;\left(y - x\right) \cdot \frac{z}{t}\\ \mathbf{elif}\;x \leq 1.05 \cdot 10^{+50}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 7
Error22.3
Cost976
\[\begin{array}{l} t_1 := z \cdot \frac{y - x}{t}\\ \mathbf{if}\;z \leq -3.1 \cdot 10^{-38}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -5.6 \cdot 10^{-116}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -3.15 \cdot 10^{-140}:\\ \;\;\;\;\left(y - x\right) \cdot \frac{z}{t}\\ \mathbf{elif}\;z \leq 270000:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error4.5
Cost840
\[\begin{array}{l} t_1 := x - x \cdot \frac{z}{t}\\ \mathbf{if}\;x \leq -1.75 \cdot 10^{+89}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3 \cdot 10^{+107}:\\ \;\;\;\;x + z \cdot \frac{y - x}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error2.2
Cost840
\[\begin{array}{l} t_1 := x + \frac{y - x}{\frac{t}{z}}\\ \mathbf{if}\;x \leq -1.55 \cdot 10^{+16}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.4 \cdot 10^{-276}:\\ \;\;\;\;x + z \cdot \frac{y - x}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Error21.9
Cost712
\[\begin{array}{l} t_1 := z \cdot \frac{y - x}{t}\\ \mathbf{if}\;z \leq -1.42 \cdot 10^{-36}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 19500:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 11
Error10.8
Cost712
\[\begin{array}{l} t_1 := x + \frac{y}{\frac{t}{z}}\\ \mathbf{if}\;t \leq -5 \cdot 10^{-112}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.1 \cdot 10^{-147}:\\ \;\;\;\;\left(y - x\right) \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 12
Error11.0
Cost712
\[\begin{array}{l} t_1 := x + \frac{z}{\frac{t}{y}}\\ \mathbf{if}\;t \leq -3.2 \cdot 10^{-112}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 3.8 \cdot 10^{-126}:\\ \;\;\;\;\left(y - x\right) \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 13
Error28.6
Cost584
\[\begin{array}{l} t_1 := y \cdot \frac{z}{t}\\ \mathbf{if}\;z \leq -4.8 \cdot 10^{-35}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 8.5 \cdot 10^{+27}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 14
Error28.4
Cost584
\[\begin{array}{l} t_1 := z \cdot \frac{y}{t}\\ \mathbf{if}\;z \leq -5.4 \cdot 10^{-35}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 9 \cdot 10^{+27}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 15
Error28.4
Cost584
\[\begin{array}{l} \mathbf{if}\;z \leq -2.4 \cdot 10^{-35}:\\ \;\;\;\;z \cdot \frac{y}{t}\\ \mathbf{elif}\;z \leq 1.4 \cdot 10^{+28}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \end{array} \]
Alternative 16
Error31.0
Cost64
\[x \]

Error

Reproduce

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