| Alternative 1 | |
|---|---|
| Error | 2.1 |
| 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 (* i (* c t_1))))
(if (<= t_2 (- INFINITY))
(* (* c (* t_1 i)) -2.0)
(if (<= t_2 4e+296)
(* 2.0 (- (+ (* z t) (* x y)) t_2))
(* 2.0 (- (fma x y (* z t)) (* 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 = i * (c * t_1);
double tmp;
if (t_2 <= -((double) INFINITY)) {
tmp = (c * (t_1 * i)) * -2.0;
} else if (t_2 <= 4e+296) {
tmp = 2.0 * (((z * t) + (x * y)) - t_2);
} else {
tmp = 2.0 * (fma(x, y, (z * t)) - (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(i * 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 <= 4e+296) tmp = Float64(2.0 * Float64(Float64(Float64(z * t) + Float64(x * y)) - t_2)); else tmp = Float64(2.0 * Float64(fma(x, y, Float64(z * t)) - Float64(c * Float64(c * Float64(b * i))))); end return 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[(i * N[(c * t$95$1), $MachinePrecision]), $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, 4e+296], N[(2.0 * N[(N[(N[(z * t), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision] - t$95$2), $MachinePrecision]), $MachinePrecision], N[(2.0 * N[(N[(x * y + N[(z * t), $MachinePrecision]), $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 := i \cdot \left(c \cdot t_1\right)\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;\left(c \cdot \left(t_1 \cdot i\right)\right) \cdot -2\\
\mathbf{elif}\;t_2 \leq 4 \cdot 10^{+296}:\\
\;\;\;\;2 \cdot \left(\left(z \cdot t + x \cdot y\right) - t_2\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - c \cdot \left(c \cdot \left(b \cdot i\right)\right)\right)\\
\end{array}
| Original | 6.5 |
|---|---|
| Target | 2.1 |
| Herbie | 2.6 |
if (*.f64 (*.f64 (+.f64 a (*.f64 b c)) c) i) < -inf.0Initial program 64.0
Taylor expanded in i around inf 25.2
if -inf.0 < (*.f64 (*.f64 (+.f64 a (*.f64 b c)) c) i) < 3.99999999999999993e296Initial program 0.3
if 3.99999999999999993e296 < (*.f64 (*.f64 (+.f64 a (*.f64 b c)) c) i) Initial program 60.2
Simplified13.3
[Start]60.2 | \[ 2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \left(\left(a + b \cdot c\right) \cdot c\right) \cdot i\right)
\] |
|---|---|
*-commutative [=>]60.2 | \[ 2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \color{blue}{\left(c \cdot \left(a + b \cdot c\right)\right)} \cdot i\right)
\] |
associate-*l* [=>]13.3 | \[ 2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \color{blue}{c \cdot \left(\left(a + b \cdot c\right) \cdot i\right)}\right)
\] |
cancel-sign-sub-inv [=>]13.3 | \[ 2 \cdot \color{blue}{\left(\left(x \cdot y + z \cdot t\right) + \left(-c\right) \cdot \left(\left(a + b \cdot c\right) \cdot i\right)\right)}
\] |
cancel-sign-sub [<=]13.3 | \[ 2 \cdot \color{blue}{\left(\left(x \cdot y + z \cdot t\right) - \left(-\left(-c\right)\right) \cdot \left(\left(a + b \cdot c\right) \cdot i\right)\right)}
\] |
fma-def [=>]13.3 | \[ 2 \cdot \left(\color{blue}{\mathsf{fma}\left(x, y, z \cdot t\right)} - \left(-\left(-c\right)\right) \cdot \left(\left(a + b \cdot c\right) \cdot i\right)\right)
\] |
remove-double-neg [=>]13.3 | \[ 2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - \color{blue}{c} \cdot \left(\left(a + b \cdot c\right) \cdot i\right)\right)
\] |
+-commutative [=>]13.3 | \[ 2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - c \cdot \left(\color{blue}{\left(b \cdot c + a\right)} \cdot i\right)\right)
\] |
fma-def [=>]13.3 | \[ 2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - c \cdot \left(\color{blue}{\mathsf{fma}\left(b, c, a\right)} \cdot i\right)\right)
\] |
Taylor expanded in b around inf 20.5
Final simplification2.6
| Alternative 1 | |
|---|---|
| Error | 2.1 |
| Cost | 7488 |
| Alternative 2 | |
|---|---|
| Error | 10.5 |
| Cost | 3536 |
| Alternative 3 | |
|---|---|
| Error | 9.9 |
| Cost | 2892 |
| Alternative 4 | |
|---|---|
| Error | 2.4 |
| Cost | 2504 |
| Alternative 5 | |
|---|---|
| Error | 27.0 |
| Cost | 2153 |
| Alternative 6 | |
|---|---|
| Error | 27.4 |
| Cost | 2024 |
| Alternative 7 | |
|---|---|
| Error | 9.1 |
| Cost | 1609 |
| Alternative 8 | |
|---|---|
| Error | 22.5 |
| Cost | 969 |
| Alternative 9 | |
|---|---|
| Error | 20.0 |
| Cost | 969 |
| Alternative 10 | |
|---|---|
| Error | 36.5 |
| Cost | 850 |
| Alternative 11 | |
|---|---|
| Error | 22.7 |
| Cost | 841 |
| Alternative 12 | |
|---|---|
| Error | 22.4 |
| Cost | 841 |
| Alternative 13 | |
|---|---|
| Error | 22.9 |
| Cost | 840 |
| Alternative 14 | |
|---|---|
| Error | 22.7 |
| Cost | 840 |
| Alternative 15 | |
|---|---|
| Error | 42.6 |
| Cost | 320 |
| Alternative 16 | |
|---|---|
| Error | 62.2 |
| Cost | 64 |
herbie shell --seed 2023060
(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))))