| Alternative 1 | |
|---|---|
| Error | 17.53% |
| Cost | 4824 |
(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 (* c (* b i))) (t_2 (+ a (* b c))) (t_3 (* (* c t_2) i)))
(if (<= t_3 (- INFINITY))
(*
2.0
(+
(* y x)
(+
(/ (* c (- (* (* a i) (* a i)) (* t_1 t_1))) (- t_1 (* a i)))
(* t z))))
(if (<= t_3 2e+252)
(* 2.0 (fma z t (- (* y x) (* i (* c (fma c b a))))))
(* 2.0 (+ (* y x) (- (* t z) (* (* c i) t_2))))))))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 = c * (b * i);
double t_2 = a + (b * c);
double t_3 = (c * t_2) * i;
double tmp;
if (t_3 <= -((double) INFINITY)) {
tmp = 2.0 * ((y * x) + (((c * (((a * i) * (a * i)) - (t_1 * t_1))) / (t_1 - (a * i))) + (t * z)));
} else if (t_3 <= 2e+252) {
tmp = 2.0 * fma(z, t, ((y * x) - (i * (c * fma(c, b, a)))));
} else {
tmp = 2.0 * ((y * x) + ((t * z) - ((c * i) * t_2)));
}
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(c * Float64(b * i)) t_2 = Float64(a + Float64(b * c)) t_3 = Float64(Float64(c * t_2) * i) tmp = 0.0 if (t_3 <= Float64(-Inf)) tmp = Float64(2.0 * Float64(Float64(y * x) + Float64(Float64(Float64(c * Float64(Float64(Float64(a * i) * Float64(a * i)) - Float64(t_1 * t_1))) / Float64(t_1 - Float64(a * i))) + Float64(t * z)))); elseif (t_3 <= 2e+252) tmp = Float64(2.0 * fma(z, t, Float64(Float64(y * x) - Float64(i * Float64(c * fma(c, b, a)))))); else tmp = Float64(2.0 * Float64(Float64(y * x) + Float64(Float64(t * z) - Float64(Float64(c * i) * t_2)))); 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[(c * N[(b * i), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(a + N[(b * c), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[(c * t$95$2), $MachinePrecision] * i), $MachinePrecision]}, If[LessEqual[t$95$3, (-Infinity)], N[(2.0 * N[(N[(y * x), $MachinePrecision] + N[(N[(N[(c * N[(N[(N[(a * i), $MachinePrecision] * N[(a * i), $MachinePrecision]), $MachinePrecision] - N[(t$95$1 * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(t$95$1 - N[(a * i), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(t * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 2e+252], N[(2.0 * N[(z * t + N[(N[(y * x), $MachinePrecision] - N[(i * N[(c * N[(c * b + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 * N[(N[(y * x), $MachinePrecision] + N[(N[(t * z), $MachinePrecision] - N[(N[(c * i), $MachinePrecision] * t$95$2), $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 := c \cdot \left(b \cdot i\right)\\
t_2 := a + b \cdot c\\
t_3 := \left(c \cdot t_2\right) \cdot i\\
\mathbf{if}\;t_3 \leq -\infty:\\
\;\;\;\;2 \cdot \left(y \cdot x + \left(\frac{c \cdot \left(\left(a \cdot i\right) \cdot \left(a \cdot i\right) - t_1 \cdot t_1\right)}{t_1 - a \cdot i} + t \cdot z\right)\right)\\
\mathbf{elif}\;t_3 \leq 2 \cdot 10^{+252}:\\
\;\;\;\;2 \cdot \mathsf{fma}\left(z, t, y \cdot x - i \cdot \left(c \cdot \mathsf{fma}\left(c, b, a\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(y \cdot x + \left(t \cdot z - \left(c \cdot i\right) \cdot t_2\right)\right)\\
\end{array}
| Original | 9.49% |
|---|---|
| Target | 2.92% |
| Herbie | 3.08% |
if (*.f64 (*.f64 (+.f64 a (*.f64 b c)) c) i) < -inf.0Initial program 100
Taylor expanded in i around inf 18.79
Applied egg-rr39.46
if -inf.0 < (*.f64 (*.f64 (+.f64 a (*.f64 b c)) c) i) < 2.0000000000000002e252Initial program 0.42
Taylor expanded in x around 0 6.54
Simplified0.41
[Start]6.54 | \[ 2 \cdot \left(\left(y \cdot x + t \cdot z\right) - c \cdot \left(i \cdot \left(c \cdot b + a\right)\right)\right)
\] |
|---|---|
cancel-sign-sub-inv [=>]6.54 | \[ 2 \cdot \color{blue}{\left(\left(y \cdot x + t \cdot z\right) + \left(-c\right) \cdot \left(i \cdot \left(c \cdot b + a\right)\right)\right)}
\] |
+-commutative [=>]6.54 | \[ 2 \cdot \left(\color{blue}{\left(t \cdot z + y \cdot x\right)} + \left(-c\right) \cdot \left(i \cdot \left(c \cdot b + a\right)\right)\right)
\] |
*-commutative [<=]6.54 | \[ 2 \cdot \left(\left(\color{blue}{z \cdot t} + y \cdot x\right) + \left(-c\right) \cdot \left(i \cdot \left(c \cdot b + a\right)\right)\right)
\] |
*-commutative [=>]6.54 | \[ 2 \cdot \left(\left(z \cdot t + \color{blue}{x \cdot y}\right) + \left(-c\right) \cdot \left(i \cdot \left(c \cdot b + a\right)\right)\right)
\] |
*-commutative [=>]6.54 | \[ 2 \cdot \left(\left(z \cdot t + x \cdot y\right) + \left(-c\right) \cdot \color{blue}{\left(\left(c \cdot b + a\right) \cdot i\right)}\right)
\] |
*-commutative [<=]6.54 | \[ 2 \cdot \left(\left(z \cdot t + x \cdot y\right) + \left(-c\right) \cdot \left(\left(\color{blue}{b \cdot c} + a\right) \cdot i\right)\right)
\] |
fma-udef [<=]6.54 | \[ 2 \cdot \left(\left(z \cdot t + x \cdot y\right) + \left(-c\right) \cdot \left(\color{blue}{\mathsf{fma}\left(b, c, a\right)} \cdot i\right)\right)
\] |
associate-+r+ [<=]6.54 | \[ 2 \cdot \color{blue}{\left(z \cdot t + \left(x \cdot y + \left(-c\right) \cdot \left(\mathsf{fma}\left(b, c, a\right) \cdot i\right)\right)\right)}
\] |
cancel-sign-sub-inv [<=]6.54 | \[ 2 \cdot \left(z \cdot t + \color{blue}{\left(x \cdot y - c \cdot \left(\mathsf{fma}\left(b, c, a\right) \cdot i\right)\right)}\right)
\] |
fma-def [=>]6.53 | \[ 2 \cdot \color{blue}{\mathsf{fma}\left(z, t, x \cdot y - c \cdot \left(\mathsf{fma}\left(b, c, a\right) \cdot i\right)\right)}
\] |
*-commutative [<=]6.53 | \[ 2 \cdot \mathsf{fma}\left(z, t, \color{blue}{y \cdot x} - c \cdot \left(\mathsf{fma}\left(b, c, a\right) \cdot i\right)\right)
\] |
associate-*r* [=>]0.41 | \[ 2 \cdot \mathsf{fma}\left(z, t, y \cdot x - \color{blue}{\left(c \cdot \mathsf{fma}\left(b, c, a\right)\right) \cdot i}\right)
\] |
*-commutative [=>]0.41 | \[ 2 \cdot \mathsf{fma}\left(z, t, y \cdot x - \color{blue}{i \cdot \left(c \cdot \mathsf{fma}\left(b, c, a\right)\right)}\right)
\] |
fma-udef [=>]0.41 | \[ 2 \cdot \mathsf{fma}\left(z, t, y \cdot x - i \cdot \left(c \cdot \color{blue}{\left(b \cdot c + a\right)}\right)\right)
\] |
*-commutative [=>]0.41 | \[ 2 \cdot \mathsf{fma}\left(z, t, y \cdot x - i \cdot \left(c \cdot \left(\color{blue}{c \cdot b} + a\right)\right)\right)
\] |
fma-def [=>]0.41 | \[ 2 \cdot \mathsf{fma}\left(z, t, y \cdot x - i \cdot \left(c \cdot \color{blue}{\mathsf{fma}\left(c, b, a\right)}\right)\right)
\] |
if 2.0000000000000002e252 < (*.f64 (*.f64 (+.f64 a (*.f64 b c)) c) i) Initial program 65.44
Taylor expanded in x around 0 24.59
Simplified65.44
[Start]24.59 | \[ 2 \cdot \left(\left(y \cdot x + t \cdot z\right) - c \cdot \left(i \cdot \left(c \cdot b + a\right)\right)\right)
\] |
|---|---|
cancel-sign-sub-inv [=>]24.59 | \[ 2 \cdot \color{blue}{\left(\left(y \cdot x + t \cdot z\right) + \left(-c\right) \cdot \left(i \cdot \left(c \cdot b + a\right)\right)\right)}
\] |
+-commutative [=>]24.59 | \[ 2 \cdot \left(\color{blue}{\left(t \cdot z + y \cdot x\right)} + \left(-c\right) \cdot \left(i \cdot \left(c \cdot b + a\right)\right)\right)
\] |
*-commutative [<=]24.59 | \[ 2 \cdot \left(\left(\color{blue}{z \cdot t} + y \cdot x\right) + \left(-c\right) \cdot \left(i \cdot \left(c \cdot b + a\right)\right)\right)
\] |
*-commutative [=>]24.59 | \[ 2 \cdot \left(\left(z \cdot t + \color{blue}{x \cdot y}\right) + \left(-c\right) \cdot \left(i \cdot \left(c \cdot b + a\right)\right)\right)
\] |
*-commutative [=>]24.59 | \[ 2 \cdot \left(\left(z \cdot t + x \cdot y\right) + \left(-c\right) \cdot \color{blue}{\left(\left(c \cdot b + a\right) \cdot i\right)}\right)
\] |
*-commutative [<=]24.59 | \[ 2 \cdot \left(\left(z \cdot t + x \cdot y\right) + \left(-c\right) \cdot \left(\left(\color{blue}{b \cdot c} + a\right) \cdot i\right)\right)
\] |
fma-udef [<=]24.58 | \[ 2 \cdot \left(\left(z \cdot t + x \cdot y\right) + \left(-c\right) \cdot \left(\color{blue}{\mathsf{fma}\left(b, c, a\right)} \cdot i\right)\right)
\] |
associate-+r+ [<=]24.58 | \[ 2 \cdot \color{blue}{\left(z \cdot t + \left(x \cdot y + \left(-c\right) \cdot \left(\mathsf{fma}\left(b, c, a\right) \cdot i\right)\right)\right)}
\] |
cancel-sign-sub-inv [<=]24.58 | \[ 2 \cdot \left(z \cdot t + \color{blue}{\left(x \cdot y - c \cdot \left(\mathsf{fma}\left(b, c, a\right) \cdot i\right)\right)}\right)
\] |
fma-def [=>]24.58 | \[ 2 \cdot \color{blue}{\mathsf{fma}\left(z, t, x \cdot y - c \cdot \left(\mathsf{fma}\left(b, c, a\right) \cdot i\right)\right)}
\] |
*-commutative [<=]24.58 | \[ 2 \cdot \mathsf{fma}\left(z, t, \color{blue}{y \cdot x} - c \cdot \left(\mathsf{fma}\left(b, c, a\right) \cdot i\right)\right)
\] |
associate-*r* [=>]65.44 | \[ 2 \cdot \mathsf{fma}\left(z, t, y \cdot x - \color{blue}{\left(c \cdot \mathsf{fma}\left(b, c, a\right)\right) \cdot i}\right)
\] |
*-commutative [=>]65.44 | \[ 2 \cdot \mathsf{fma}\left(z, t, y \cdot x - \color{blue}{i \cdot \left(c \cdot \mathsf{fma}\left(b, c, a\right)\right)}\right)
\] |
fma-udef [=>]65.44 | \[ 2 \cdot \mathsf{fma}\left(z, t, y \cdot x - i \cdot \left(c \cdot \color{blue}{\left(b \cdot c + a\right)}\right)\right)
\] |
*-commutative [=>]65.44 | \[ 2 \cdot \mathsf{fma}\left(z, t, y \cdot x - i \cdot \left(c \cdot \left(\color{blue}{c \cdot b} + a\right)\right)\right)
\] |
fma-def [=>]65.44 | \[ 2 \cdot \mathsf{fma}\left(z, t, y \cdot x - i \cdot \left(c \cdot \color{blue}{\mathsf{fma}\left(c, b, a\right)}\right)\right)
\] |
Applied egg-rr12.68
Applied egg-rr12.68
Final simplification3.08
| Alternative 1 | |
|---|---|
| Error | 17.53% |
| Cost | 4824 |
| Alternative 2 | |
|---|---|
| Error | 17.11% |
| Cost | 3536 |
| Alternative 3 | |
|---|---|
| Error | 12.32% |
| Cost | 3536 |
| Alternative 4 | |
|---|---|
| Error | 3.09% |
| Cost | 3268 |
| Alternative 5 | |
|---|---|
| Error | 4.44% |
| Cost | 2504 |
| Alternative 6 | |
|---|---|
| Error | 39.26% |
| Cost | 2024 |
| Alternative 7 | |
|---|---|
| Error | 34.97% |
| Cost | 2004 |
| Alternative 8 | |
|---|---|
| Error | 38.09% |
| Cost | 1764 |
| Alternative 9 | |
|---|---|
| Error | 39.05% |
| Cost | 1761 |
| Alternative 10 | |
|---|---|
| Error | 31.84% |
| Cost | 1744 |
| Alternative 11 | |
|---|---|
| Error | 34.56% |
| Cost | 1496 |
| Alternative 12 | |
|---|---|
| Error | 2.92% |
| Cost | 1216 |
| Alternative 13 | |
|---|---|
| Error | 35.69% |
| Cost | 1106 |
| Alternative 14 | |
|---|---|
| Error | 58.34% |
| Cost | 848 |
| Alternative 15 | |
|---|---|
| Error | 57.28% |
| Cost | 585 |
| Alternative 16 | |
|---|---|
| Error | 66.78% |
| Cost | 320 |
| Alternative 17 | |
|---|---|
| Error | 97.31% |
| Cost | 64 |
herbie shell --seed 2023121
(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))))