| Alternative 1 | |
|---|---|
| Error | 3.9 |
| Cost | 5320 |
(FPCore (x y z t a b c i j k) :precision binary64 (- (- (+ (- (* (* (* (* x 18.0) y) z) t) (* (* a 4.0) t)) (* b c)) (* (* x 4.0) i)) (* (* j 27.0) k)))
(FPCore (x y z t a b c i j k)
:precision binary64
(let* ((t_1 (+ (* x (* i -4.0)) (* j (* k -27.0)))))
(if (<= t -1.85e-125)
(+ (+ (* b c) (* t (+ (* (* x 18.0) (* y z)) (* a -4.0)))) t_1)
(if (<= t 2.25e-66)
(+ (+ (* b c) (* 18.0 (* x (* z (* y t))))) t_1)
(+
(* k (* j -27.0))
(+
(+ (* b c) (+ (* (* z (* x y)) (* 18.0 t)) (* t (* a -4.0))))
(* i (* x -4.0))))))))double code(double x, double y, double z, double t, double a, double b, double c, double i, double j, double k) {
return (((((((x * 18.0) * y) * z) * t) - ((a * 4.0) * t)) + (b * c)) - ((x * 4.0) * i)) - ((j * 27.0) * k);
}
double code(double x, double y, double z, double t, double a, double b, double c, double i, double j, double k) {
double t_1 = (x * (i * -4.0)) + (j * (k * -27.0));
double tmp;
if (t <= -1.85e-125) {
tmp = ((b * c) + (t * (((x * 18.0) * (y * z)) + (a * -4.0)))) + t_1;
} else if (t <= 2.25e-66) {
tmp = ((b * c) + (18.0 * (x * (z * (y * t))))) + t_1;
} else {
tmp = (k * (j * -27.0)) + (((b * c) + (((z * (x * y)) * (18.0 * t)) + (t * (a * -4.0)))) + (i * (x * -4.0)));
}
return tmp;
}
real(8) function code(x, y, z, t, a, b, c, i, j, k)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: i
real(8), intent (in) :: j
real(8), intent (in) :: k
code = (((((((x * 18.0d0) * y) * z) * t) - ((a * 4.0d0) * t)) + (b * c)) - ((x * 4.0d0) * i)) - ((j * 27.0d0) * k)
end function
real(8) function code(x, y, z, t, a, b, c, i, j, k)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: i
real(8), intent (in) :: j
real(8), intent (in) :: k
real(8) :: t_1
real(8) :: tmp
t_1 = (x * (i * (-4.0d0))) + (j * (k * (-27.0d0)))
if (t <= (-1.85d-125)) then
tmp = ((b * c) + (t * (((x * 18.0d0) * (y * z)) + (a * (-4.0d0))))) + t_1
else if (t <= 2.25d-66) then
tmp = ((b * c) + (18.0d0 * (x * (z * (y * t))))) + t_1
else
tmp = (k * (j * (-27.0d0))) + (((b * c) + (((z * (x * y)) * (18.0d0 * t)) + (t * (a * (-4.0d0))))) + (i * (x * (-4.0d0))))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b, double c, double i, double j, double k) {
return (((((((x * 18.0) * y) * z) * t) - ((a * 4.0) * t)) + (b * c)) - ((x * 4.0) * i)) - ((j * 27.0) * k);
}
public static double code(double x, double y, double z, double t, double a, double b, double c, double i, double j, double k) {
double t_1 = (x * (i * -4.0)) + (j * (k * -27.0));
double tmp;
if (t <= -1.85e-125) {
tmp = ((b * c) + (t * (((x * 18.0) * (y * z)) + (a * -4.0)))) + t_1;
} else if (t <= 2.25e-66) {
tmp = ((b * c) + (18.0 * (x * (z * (y * t))))) + t_1;
} else {
tmp = (k * (j * -27.0)) + (((b * c) + (((z * (x * y)) * (18.0 * t)) + (t * (a * -4.0)))) + (i * (x * -4.0)));
}
return tmp;
}
def code(x, y, z, t, a, b, c, i, j, k): return (((((((x * 18.0) * y) * z) * t) - ((a * 4.0) * t)) + (b * c)) - ((x * 4.0) * i)) - ((j * 27.0) * k)
def code(x, y, z, t, a, b, c, i, j, k): t_1 = (x * (i * -4.0)) + (j * (k * -27.0)) tmp = 0 if t <= -1.85e-125: tmp = ((b * c) + (t * (((x * 18.0) * (y * z)) + (a * -4.0)))) + t_1 elif t <= 2.25e-66: tmp = ((b * c) + (18.0 * (x * (z * (y * t))))) + t_1 else: tmp = (k * (j * -27.0)) + (((b * c) + (((z * (x * y)) * (18.0 * t)) + (t * (a * -4.0)))) + (i * (x * -4.0))) return tmp
function code(x, y, z, t, a, b, c, i, j, k) return Float64(Float64(Float64(Float64(Float64(Float64(Float64(Float64(x * 18.0) * y) * z) * t) - Float64(Float64(a * 4.0) * t)) + Float64(b * c)) - Float64(Float64(x * 4.0) * i)) - Float64(Float64(j * 27.0) * k)) end
function code(x, y, z, t, a, b, c, i, j, k) t_1 = Float64(Float64(x * Float64(i * -4.0)) + Float64(j * Float64(k * -27.0))) tmp = 0.0 if (t <= -1.85e-125) tmp = Float64(Float64(Float64(b * c) + Float64(t * Float64(Float64(Float64(x * 18.0) * Float64(y * z)) + Float64(a * -4.0)))) + t_1); elseif (t <= 2.25e-66) tmp = Float64(Float64(Float64(b * c) + Float64(18.0 * Float64(x * Float64(z * Float64(y * t))))) + t_1); else tmp = Float64(Float64(k * Float64(j * -27.0)) + Float64(Float64(Float64(b * c) + Float64(Float64(Float64(z * Float64(x * y)) * Float64(18.0 * t)) + Float64(t * Float64(a * -4.0)))) + Float64(i * Float64(x * -4.0)))); end return tmp end
function tmp = code(x, y, z, t, a, b, c, i, j, k) tmp = (((((((x * 18.0) * y) * z) * t) - ((a * 4.0) * t)) + (b * c)) - ((x * 4.0) * i)) - ((j * 27.0) * k); end
function tmp_2 = code(x, y, z, t, a, b, c, i, j, k) t_1 = (x * (i * -4.0)) + (j * (k * -27.0)); tmp = 0.0; if (t <= -1.85e-125) tmp = ((b * c) + (t * (((x * 18.0) * (y * z)) + (a * -4.0)))) + t_1; elseif (t <= 2.25e-66) tmp = ((b * c) + (18.0 * (x * (z * (y * t))))) + t_1; else tmp = (k * (j * -27.0)) + (((b * c) + (((z * (x * y)) * (18.0 * t)) + (t * (a * -4.0)))) + (i * (x * -4.0))); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_, c_, i_, j_, k_] := N[(N[(N[(N[(N[(N[(N[(N[(x * 18.0), $MachinePrecision] * y), $MachinePrecision] * z), $MachinePrecision] * t), $MachinePrecision] - N[(N[(a * 4.0), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision] + N[(b * c), $MachinePrecision]), $MachinePrecision] - N[(N[(x * 4.0), $MachinePrecision] * i), $MachinePrecision]), $MachinePrecision] - N[(N[(j * 27.0), $MachinePrecision] * k), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_, c_, i_, j_, k_] := Block[{t$95$1 = N[(N[(x * N[(i * -4.0), $MachinePrecision]), $MachinePrecision] + N[(j * N[(k * -27.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t, -1.85e-125], N[(N[(N[(b * c), $MachinePrecision] + N[(t * N[(N[(N[(x * 18.0), $MachinePrecision] * N[(y * z), $MachinePrecision]), $MachinePrecision] + N[(a * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision], If[LessEqual[t, 2.25e-66], N[(N[(N[(b * c), $MachinePrecision] + N[(18.0 * N[(x * N[(z * N[(y * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision], N[(N[(k * N[(j * -27.0), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(b * c), $MachinePrecision] + N[(N[(N[(z * N[(x * y), $MachinePrecision]), $MachinePrecision] * N[(18.0 * t), $MachinePrecision]), $MachinePrecision] + N[(t * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(i * N[(x * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\left(\left(\left(\left(\left(\left(x \cdot 18\right) \cdot y\right) \cdot z\right) \cdot t - \left(a \cdot 4\right) \cdot t\right) + b \cdot c\right) - \left(x \cdot 4\right) \cdot i\right) - \left(j \cdot 27\right) \cdot k
\begin{array}{l}
t_1 := x \cdot \left(i \cdot -4\right) + j \cdot \left(k \cdot -27\right)\\
\mathbf{if}\;t \leq -1.85 \cdot 10^{-125}:\\
\;\;\;\;\left(b \cdot c + t \cdot \left(\left(x \cdot 18\right) \cdot \left(y \cdot z\right) + a \cdot -4\right)\right) + t_1\\
\mathbf{elif}\;t \leq 2.25 \cdot 10^{-66}:\\
\;\;\;\;\left(b \cdot c + 18 \cdot \left(x \cdot \left(z \cdot \left(y \cdot t\right)\right)\right)\right) + t_1\\
\mathbf{else}:\\
\;\;\;\;k \cdot \left(j \cdot -27\right) + \left(\left(b \cdot c + \left(\left(z \cdot \left(x \cdot y\right)\right) \cdot \left(18 \cdot t\right) + t \cdot \left(a \cdot -4\right)\right)\right) + i \cdot \left(x \cdot -4\right)\right)\\
\end{array}
Results
| Original | 5.2 |
|---|---|
| Target | 1.6 |
| Herbie | 4.4 |
if t < -1.85e-125Initial program 3.0
Simplified3.7
[Start]3.0 | \[ \left(\left(\left(\left(\left(\left(x \cdot 18\right) \cdot y\right) \cdot z\right) \cdot t - \left(a \cdot 4\right) \cdot t\right) + b \cdot c\right) - \left(x \cdot 4\right) \cdot i\right) - \left(j \cdot 27\right) \cdot k
\] |
|---|---|
associate--l- [=>]3.0 | \[ \color{blue}{\left(\left(\left(\left(\left(x \cdot 18\right) \cdot y\right) \cdot z\right) \cdot t - \left(a \cdot 4\right) \cdot t\right) + b \cdot c\right) - \left(\left(x \cdot 4\right) \cdot i + \left(j \cdot 27\right) \cdot k\right)}
\] |
associate-+l- [=>]3.0 | \[ \color{blue}{\left(\left(\left(\left(x \cdot 18\right) \cdot y\right) \cdot z\right) \cdot t - \left(\left(a \cdot 4\right) \cdot t - b \cdot c\right)\right)} - \left(\left(x \cdot 4\right) \cdot i + \left(j \cdot 27\right) \cdot k\right)
\] |
associate-+l- [<=]3.0 | \[ \color{blue}{\left(\left(\left(\left(\left(x \cdot 18\right) \cdot y\right) \cdot z\right) \cdot t - \left(a \cdot 4\right) \cdot t\right) + b \cdot c\right)} - \left(\left(x \cdot 4\right) \cdot i + \left(j \cdot 27\right) \cdot k\right)
\] |
distribute-rgt-out-- [=>]3.0 | \[ \left(\color{blue}{t \cdot \left(\left(\left(x \cdot 18\right) \cdot y\right) \cdot z - a \cdot 4\right)} + b \cdot c\right) - \left(\left(x \cdot 4\right) \cdot i + \left(j \cdot 27\right) \cdot k\right)
\] |
associate-*l* [=>]3.6 | \[ \left(t \cdot \left(\color{blue}{\left(x \cdot 18\right) \cdot \left(y \cdot z\right)} - a \cdot 4\right) + b \cdot c\right) - \left(\left(x \cdot 4\right) \cdot i + \left(j \cdot 27\right) \cdot k\right)
\] |
associate-*l* [=>]3.6 | \[ \left(t \cdot \left(\left(x \cdot 18\right) \cdot \left(y \cdot z\right) - a \cdot 4\right) + b \cdot c\right) - \left(\color{blue}{x \cdot \left(4 \cdot i\right)} + \left(j \cdot 27\right) \cdot k\right)
\] |
associate-*l* [=>]3.7 | \[ \left(t \cdot \left(\left(x \cdot 18\right) \cdot \left(y \cdot z\right) - a \cdot 4\right) + b \cdot c\right) - \left(x \cdot \left(4 \cdot i\right) + \color{blue}{j \cdot \left(27 \cdot k\right)}\right)
\] |
if -1.85e-125 < t < 2.2499999999999999e-66Initial program 8.1
Simplified9.3
[Start]8.1 | \[ \left(\left(\left(\left(\left(\left(x \cdot 18\right) \cdot y\right) \cdot z\right) \cdot t - \left(a \cdot 4\right) \cdot t\right) + b \cdot c\right) - \left(x \cdot 4\right) \cdot i\right) - \left(j \cdot 27\right) \cdot k
\] |
|---|---|
associate--l- [=>]8.1 | \[ \color{blue}{\left(\left(\left(\left(\left(x \cdot 18\right) \cdot y\right) \cdot z\right) \cdot t - \left(a \cdot 4\right) \cdot t\right) + b \cdot c\right) - \left(\left(x \cdot 4\right) \cdot i + \left(j \cdot 27\right) \cdot k\right)}
\] |
associate-+l- [=>]8.1 | \[ \color{blue}{\left(\left(\left(\left(x \cdot 18\right) \cdot y\right) \cdot z\right) \cdot t - \left(\left(a \cdot 4\right) \cdot t - b \cdot c\right)\right)} - \left(\left(x \cdot 4\right) \cdot i + \left(j \cdot 27\right) \cdot k\right)
\] |
associate-+l- [<=]8.1 | \[ \color{blue}{\left(\left(\left(\left(\left(x \cdot 18\right) \cdot y\right) \cdot z\right) \cdot t - \left(a \cdot 4\right) \cdot t\right) + b \cdot c\right)} - \left(\left(x \cdot 4\right) \cdot i + \left(j \cdot 27\right) \cdot k\right)
\] |
distribute-rgt-out-- [=>]8.1 | \[ \left(\color{blue}{t \cdot \left(\left(\left(x \cdot 18\right) \cdot y\right) \cdot z - a \cdot 4\right)} + b \cdot c\right) - \left(\left(x \cdot 4\right) \cdot i + \left(j \cdot 27\right) \cdot k\right)
\] |
associate-*l* [=>]9.3 | \[ \left(t \cdot \left(\color{blue}{\left(x \cdot 18\right) \cdot \left(y \cdot z\right)} - a \cdot 4\right) + b \cdot c\right) - \left(\left(x \cdot 4\right) \cdot i + \left(j \cdot 27\right) \cdot k\right)
\] |
associate-*l* [=>]9.3 | \[ \left(t \cdot \left(\left(x \cdot 18\right) \cdot \left(y \cdot z\right) - a \cdot 4\right) + b \cdot c\right) - \left(\color{blue}{x \cdot \left(4 \cdot i\right)} + \left(j \cdot 27\right) \cdot k\right)
\] |
associate-*l* [=>]9.3 | \[ \left(t \cdot \left(\left(x \cdot 18\right) \cdot \left(y \cdot z\right) - a \cdot 4\right) + b \cdot c\right) - \left(x \cdot \left(4 \cdot i\right) + \color{blue}{j \cdot \left(27 \cdot k\right)}\right)
\] |
Taylor expanded in x around inf 9.6
Simplified5.8
[Start]9.6 | \[ \left(18 \cdot \left(y \cdot \left(t \cdot \left(z \cdot x\right)\right)\right) + b \cdot c\right) - \left(x \cdot \left(4 \cdot i\right) + j \cdot \left(27 \cdot k\right)\right)
\] |
|---|---|
associate-*r* [=>]9.5 | \[ \left(18 \cdot \color{blue}{\left(\left(y \cdot t\right) \cdot \left(z \cdot x\right)\right)} + b \cdot c\right) - \left(x \cdot \left(4 \cdot i\right) + j \cdot \left(27 \cdot k\right)\right)
\] |
associate-*r* [=>]5.8 | \[ \left(18 \cdot \color{blue}{\left(\left(\left(y \cdot t\right) \cdot z\right) \cdot x\right)} + b \cdot c\right) - \left(x \cdot \left(4 \cdot i\right) + j \cdot \left(27 \cdot k\right)\right)
\] |
*-commutative [=>]5.8 | \[ \left(18 \cdot \left(\left(\color{blue}{\left(t \cdot y\right)} \cdot z\right) \cdot x\right) + b \cdot c\right) - \left(x \cdot \left(4 \cdot i\right) + j \cdot \left(27 \cdot k\right)\right)
\] |
if 2.2499999999999999e-66 < t Initial program 2.6
Taylor expanded in x around 0 5.0
Simplified2.5
[Start]5.0 | \[ \left(\left(\left(18 \cdot \left(y \cdot \left(t \cdot \left(z \cdot x\right)\right)\right) - \left(a \cdot 4\right) \cdot t\right) + b \cdot c\right) - \left(x \cdot 4\right) \cdot i\right) - \left(j \cdot 27\right) \cdot k
\] |
|---|---|
*-commutative [=>]5.0 | \[ \left(\left(\left(18 \cdot \left(y \cdot \color{blue}{\left(\left(z \cdot x\right) \cdot t\right)}\right) - \left(a \cdot 4\right) \cdot t\right) + b \cdot c\right) - \left(x \cdot 4\right) \cdot i\right) - \left(j \cdot 27\right) \cdot k
\] |
associate-*r* [=>]2.4 | \[ \left(\left(\left(18 \cdot \color{blue}{\left(\left(y \cdot \left(z \cdot x\right)\right) \cdot t\right)} - \left(a \cdot 4\right) \cdot t\right) + b \cdot c\right) - \left(x \cdot 4\right) \cdot i\right) - \left(j \cdot 27\right) \cdot k
\] |
associate-*l* [<=]2.4 | \[ \left(\left(\left(\color{blue}{\left(18 \cdot \left(y \cdot \left(z \cdot x\right)\right)\right) \cdot t} - \left(a \cdot 4\right) \cdot t\right) + b \cdot c\right) - \left(x \cdot 4\right) \cdot i\right) - \left(j \cdot 27\right) \cdot k
\] |
*-commutative [=>]2.4 | \[ \left(\left(\left(\color{blue}{\left(\left(y \cdot \left(z \cdot x\right)\right) \cdot 18\right)} \cdot t - \left(a \cdot 4\right) \cdot t\right) + b \cdot c\right) - \left(x \cdot 4\right) \cdot i\right) - \left(j \cdot 27\right) \cdot k
\] |
associate-*l* [=>]2.4 | \[ \left(\left(\left(\color{blue}{\left(y \cdot \left(z \cdot x\right)\right) \cdot \left(18 \cdot t\right)} - \left(a \cdot 4\right) \cdot t\right) + b \cdot c\right) - \left(x \cdot 4\right) \cdot i\right) - \left(j \cdot 27\right) \cdot k
\] |
*-commutative [=>]2.4 | \[ \left(\left(\left(\color{blue}{\left(\left(z \cdot x\right) \cdot y\right)} \cdot \left(18 \cdot t\right) - \left(a \cdot 4\right) \cdot t\right) + b \cdot c\right) - \left(x \cdot 4\right) \cdot i\right) - \left(j \cdot 27\right) \cdot k
\] |
associate-*l* [=>]2.5 | \[ \left(\left(\left(\color{blue}{\left(z \cdot \left(x \cdot y\right)\right)} \cdot \left(18 \cdot t\right) - \left(a \cdot 4\right) \cdot t\right) + b \cdot c\right) - \left(x \cdot 4\right) \cdot i\right) - \left(j \cdot 27\right) \cdot k
\] |
*-commutative [<=]2.5 | \[ \left(\left(\left(\left(z \cdot \color{blue}{\left(y \cdot x\right)}\right) \cdot \left(18 \cdot t\right) - \left(a \cdot 4\right) \cdot t\right) + b \cdot c\right) - \left(x \cdot 4\right) \cdot i\right) - \left(j \cdot 27\right) \cdot k
\] |
Final simplification4.4
| Alternative 1 | |
|---|---|
| Error | 3.9 |
| Cost | 5320 |
| Alternative 2 | |
|---|---|
| Error | 37.2 |
| Cost | 2552 |
| Alternative 3 | |
|---|---|
| Error | 36.3 |
| Cost | 2412 |
| Alternative 4 | |
|---|---|
| Error | 21.2 |
| Cost | 2412 |
| Alternative 5 | |
|---|---|
| Error | 36.2 |
| Cost | 2285 |
| Alternative 6 | |
|---|---|
| Error | 11.4 |
| Cost | 2265 |
| Alternative 7 | |
|---|---|
| Error | 36.6 |
| Cost | 2152 |
| Alternative 8 | |
|---|---|
| Error | 5.0 |
| Cost | 2121 |
| Alternative 9 | |
|---|---|
| Error | 44.9 |
| Cost | 2028 |
| Alternative 10 | |
|---|---|
| Error | 23.8 |
| Cost | 2016 |
| Alternative 11 | |
|---|---|
| Error | 9.0 |
| Cost | 1996 |
| Alternative 12 | |
|---|---|
| Error | 10.7 |
| Cost | 1872 |
| Alternative 13 | |
|---|---|
| Error | 19.5 |
| Cost | 1752 |
| Alternative 14 | |
|---|---|
| Error | 19.7 |
| Cost | 1752 |
| Alternative 15 | |
|---|---|
| Error | 10.3 |
| Cost | 1608 |
| Alternative 16 | |
|---|---|
| Error | 45.1 |
| Cost | 1508 |
| Alternative 17 | |
|---|---|
| Error | 44.7 |
| Cost | 1508 |
| Alternative 18 | |
|---|---|
| Error | 44.6 |
| Cost | 1508 |
| Alternative 19 | |
|---|---|
| Error | 30.8 |
| Cost | 1365 |
| Alternative 20 | |
|---|---|
| Error | 30.6 |
| Cost | 1364 |
| Alternative 21 | |
|---|---|
| Error | 33.8 |
| Cost | 1104 |
| Alternative 22 | |
|---|---|
| Error | 43.4 |
| Cost | 584 |
| Alternative 23 | |
|---|---|
| Error | 48.0 |
| Cost | 192 |
herbie shell --seed 2022356
(FPCore (x y z t a b c i j k)
:name "Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, E"
:precision binary64
:herbie-target
(if (< t -1.6210815397541398e-69) (- (- (* (* 18.0 t) (* (* x y) z)) (* (+ (* a t) (* i x)) 4.0)) (- (* (* k j) 27.0) (* c b))) (if (< t 165.68027943805222) (+ (- (* (* 18.0 y) (* x (* z t))) (* (+ (* a t) (* i x)) 4.0)) (- (* c b) (* 27.0 (* k j)))) (- (- (* (* 18.0 t) (* (* x y) z)) (* (+ (* a t) (* i x)) 4.0)) (- (* (* k j) 27.0) (* c b)))))
(- (- (+ (- (* (* (* (* x 18.0) y) z) t) (* (* a 4.0) t)) (* b c)) (* (* x 4.0) i)) (* (* j 27.0) k)))