| Alternative 1 | |
|---|---|
| Error | 2.0 |
| Cost | 7488 |
\[2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - \left(a + b \cdot c\right) \cdot \left(c \cdot i\right)\right)
\]
(FPCore (x y z t a b c i) :precision binary64 (* 2.0 (- (+ (* x y) (* z t)) (* (* (+ a (* b c)) c) i))))
(FPCore (x y z t a b c i)
:precision binary64
(let* ((t_1 (+ a (* b c))) (t_2 (* c t_1)))
(if (<= t_2 (- INFINITY))
(* (* c (* t_1 i)) -2.0)
(if (<= t_2 1e+297)
(* 2.0 (- (+ (* x y) (* z t)) (* i t_2)))
(* 2.0 (- (* x y) (* c (* c (* b i)))))))))double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return 2.0 * (((x * y) + (z * t)) - (((a + (b * c)) * c) * i));
}
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
double t_1 = a + (b * c);
double t_2 = c * t_1;
double tmp;
if (t_2 <= -((double) INFINITY)) {
tmp = (c * (t_1 * i)) * -2.0;
} else if (t_2 <= 1e+297) {
tmp = 2.0 * (((x * y) + (z * t)) - (i * t_2));
} else {
tmp = 2.0 * ((x * y) - (c * (c * (b * i))));
}
return tmp;
}
public static double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return 2.0 * (((x * y) + (z * t)) - (((a + (b * c)) * c) * i));
}
public static double code(double x, double y, double z, double t, double a, double b, double c, double i) {
double t_1 = a + (b * c);
double t_2 = c * t_1;
double tmp;
if (t_2 <= -Double.POSITIVE_INFINITY) {
tmp = (c * (t_1 * i)) * -2.0;
} else if (t_2 <= 1e+297) {
tmp = 2.0 * (((x * y) + (z * t)) - (i * t_2));
} else {
tmp = 2.0 * ((x * y) - (c * (c * (b * i))));
}
return tmp;
}
def code(x, y, z, t, a, b, c, i): return 2.0 * (((x * y) + (z * t)) - (((a + (b * c)) * c) * i))
def code(x, y, z, t, a, b, c, i): t_1 = a + (b * c) t_2 = c * t_1 tmp = 0 if t_2 <= -math.inf: tmp = (c * (t_1 * i)) * -2.0 elif t_2 <= 1e+297: tmp = 2.0 * (((x * y) + (z * t)) - (i * t_2)) else: tmp = 2.0 * ((x * y) - (c * (c * (b * i)))) return tmp
function code(x, y, z, t, a, b, c, i) return Float64(2.0 * Float64(Float64(Float64(x * y) + Float64(z * t)) - Float64(Float64(Float64(a + Float64(b * c)) * c) * i))) end
function code(x, y, z, t, a, b, c, i) t_1 = Float64(a + Float64(b * c)) t_2 = Float64(c * t_1) tmp = 0.0 if (t_2 <= Float64(-Inf)) tmp = Float64(Float64(c * Float64(t_1 * i)) * -2.0); elseif (t_2 <= 1e+297) tmp = Float64(2.0 * Float64(Float64(Float64(x * y) + Float64(z * t)) - Float64(i * t_2))); else tmp = Float64(2.0 * Float64(Float64(x * y) - Float64(c * Float64(c * Float64(b * i))))); end return tmp end
function tmp = code(x, y, z, t, a, b, c, i) tmp = 2.0 * (((x * y) + (z * t)) - (((a + (b * c)) * c) * i)); end
function tmp_2 = code(x, y, z, t, a, b, c, i) t_1 = a + (b * c); t_2 = c * t_1; tmp = 0.0; if (t_2 <= -Inf) tmp = (c * (t_1 * i)) * -2.0; elseif (t_2 <= 1e+297) tmp = 2.0 * (((x * y) + (z * t)) - (i * t_2)); else tmp = 2.0 * ((x * y) - (c * (c * (b * i)))); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_, c_, i_] := N[(2.0 * N[(N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision] - N[(N[(N[(a + N[(b * c), $MachinePrecision]), $MachinePrecision] * c), $MachinePrecision] * i), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_, c_, i_] := Block[{t$95$1 = N[(a + N[(b * c), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(c * t$95$1), $MachinePrecision]}, If[LessEqual[t$95$2, (-Infinity)], N[(N[(c * N[(t$95$1 * i), $MachinePrecision]), $MachinePrecision] * -2.0), $MachinePrecision], If[LessEqual[t$95$2, 1e+297], N[(2.0 * N[(N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision] - N[(i * t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 * N[(N[(x * y), $MachinePrecision] - N[(c * N[(c * N[(b * i), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \left(\left(a + b \cdot c\right) \cdot c\right) \cdot i\right)
\begin{array}{l}
t_1 := a + b \cdot c\\
t_2 := c \cdot t_1\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;\left(c \cdot \left(t_1 \cdot i\right)\right) \cdot -2\\
\mathbf{elif}\;t_2 \leq 10^{+297}:\\
\;\;\;\;2 \cdot \left(\left(x \cdot y + z \cdot t\right) - i \cdot t_2\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(x \cdot y - c \cdot \left(c \cdot \left(b \cdot i\right)\right)\right)\\
\end{array}
Results
| Original | 6.3 |
|---|---|
| Target | 2.0 |
| Herbie | 2.8 |
if (*.f64 (+.f64 a (*.f64 b c)) c) < -inf.0Initial program 64.0
Taylor expanded in i around inf 24.1
if -inf.0 < (*.f64 (+.f64 a (*.f64 b c)) c) < 1e297Initial program 0.4
if 1e297 < (*.f64 (+.f64 a (*.f64 b c)) c) Initial program 58.6
Taylor expanded in x around inf 59.5
Taylor expanded in a around 0 44.8
Simplified25.8
[Start]44.8 | \[ 2 \cdot \left(y \cdot x - {c}^{2} \cdot \left(i \cdot b\right)\right)
\] |
|---|---|
unpow2 [=>]44.8 | \[ 2 \cdot \left(y \cdot x - \color{blue}{\left(c \cdot c\right)} \cdot \left(i \cdot b\right)\right)
\] |
associate-*l* [=>]25.8 | \[ 2 \cdot \left(y \cdot x - \color{blue}{c \cdot \left(c \cdot \left(i \cdot b\right)\right)}\right)
\] |
Final simplification2.8
| Alternative 1 | |
|---|---|
| Error | 2.0 |
| Cost | 7488 |
| Alternative 2 | |
|---|---|
| Error | 12.3 |
| Cost | 2893 |
| Alternative 3 | |
|---|---|
| Error | 9.6 |
| Cost | 2893 |
| Alternative 4 | |
|---|---|
| Error | 10.5 |
| Cost | 2248 |
| Alternative 5 | |
|---|---|
| Error | 9.9 |
| Cost | 2248 |
| Alternative 6 | |
|---|---|
| Error | 22.9 |
| Cost | 1756 |
| Alternative 7 | |
|---|---|
| Error | 21.8 |
| Cost | 1234 |
| Alternative 8 | |
|---|---|
| Error | 22.2 |
| Cost | 1233 |
| Alternative 9 | |
|---|---|
| Error | 2.0 |
| Cost | 1216 |
| Alternative 10 | |
|---|---|
| Error | 37.0 |
| Cost | 1114 |
| Alternative 11 | |
|---|---|
| Error | 36.4 |
| Cost | 850 |
| Alternative 12 | |
|---|---|
| Error | 23.7 |
| Cost | 841 |
| Alternative 13 | |
|---|---|
| Error | 42.6 |
| Cost | 320 |
herbie shell --seed 2023046
(FPCore (x y z t a b c i)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, A"
:precision binary64
:herbie-target
(* 2.0 (- (+ (* x y) (* z t)) (* (+ a (* b c)) (* c i))))
(* 2.0 (- (+ (* x y) (* z t)) (* (* (+ a (* b c)) c) i))))