| Alternative 1 | |
|---|---|
| Accuracy | 83.1% |
| Cost | 16324 |

(FPCore (x y z t a b c i j) :precision binary64 (+ (- (* x (- (* y z) (* t a))) (* b (- (* c z) (* t i)))) (* j (- (* c a) (* y i)))))
(FPCore (x y z t a b c i j)
:precision binary64
(let* ((t_1 (- (* y z) (* t a)))
(t_2 (* j (- (* a c) (* y i))))
(t_3 (- (* t i) (* z c))))
(if (<= (+ t_2 (+ (* x t_1) (* b t_3))) INFINITY)
(fma b t_3 (fma x t_1 t_2))
(- (* z (- (* x y) (* b c))) (* a (- (* x t) (* c j)))))))double code(double x, double y, double z, double t, double a, double b, double c, double i, double j) {
return ((x * ((y * z) - (t * a))) - (b * ((c * z) - (t * i)))) + (j * ((c * a) - (y * i)));
}
double code(double x, double y, double z, double t, double a, double b, double c, double i, double j) {
double t_1 = (y * z) - (t * a);
double t_2 = j * ((a * c) - (y * i));
double t_3 = (t * i) - (z * c);
double tmp;
if ((t_2 + ((x * t_1) + (b * t_3))) <= ((double) INFINITY)) {
tmp = fma(b, t_3, fma(x, t_1, t_2));
} else {
tmp = (z * ((x * y) - (b * c))) - (a * ((x * t) - (c * j)));
}
return tmp;
}
function code(x, y, z, t, a, b, c, i, j) return Float64(Float64(Float64(x * Float64(Float64(y * z) - Float64(t * a))) - Float64(b * Float64(Float64(c * z) - Float64(t * i)))) + Float64(j * Float64(Float64(c * a) - Float64(y * i)))) end
function code(x, y, z, t, a, b, c, i, j) t_1 = Float64(Float64(y * z) - Float64(t * a)) t_2 = Float64(j * Float64(Float64(a * c) - Float64(y * i))) t_3 = Float64(Float64(t * i) - Float64(z * c)) tmp = 0.0 if (Float64(t_2 + Float64(Float64(x * t_1) + Float64(b * t_3))) <= Inf) tmp = fma(b, t_3, fma(x, t_1, t_2)); else tmp = Float64(Float64(z * Float64(Float64(x * y) - Float64(b * c))) - Float64(a * Float64(Float64(x * t) - Float64(c * j)))); end return tmp end
code[x_, y_, z_, t_, a_, b_, c_, i_, j_] := N[(N[(N[(x * N[(N[(y * z), $MachinePrecision] - N[(t * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(b * N[(N[(c * z), $MachinePrecision] - N[(t * i), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(j * N[(N[(c * a), $MachinePrecision] - N[(y * i), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_, c_, i_, j_] := Block[{t$95$1 = N[(N[(y * z), $MachinePrecision] - N[(t * a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(j * N[(N[(a * c), $MachinePrecision] - N[(y * i), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[(t * i), $MachinePrecision] - N[(z * c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$2 + N[(N[(x * t$95$1), $MachinePrecision] + N[(b * t$95$3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(b * t$95$3 + N[(x * t$95$1 + t$95$2), $MachinePrecision]), $MachinePrecision], N[(N[(z * N[(N[(x * y), $MachinePrecision] - N[(b * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(a * N[(N[(x * t), $MachinePrecision] - N[(c * j), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\left(x \cdot \left(y \cdot z - t \cdot a\right) - b \cdot \left(c \cdot z - t \cdot i\right)\right) + j \cdot \left(c \cdot a - y \cdot i\right)
\begin{array}{l}
t_1 := y \cdot z - t \cdot a\\
t_2 := j \cdot \left(a \cdot c - y \cdot i\right)\\
t_3 := t \cdot i - z \cdot c\\
\mathbf{if}\;t_2 + \left(x \cdot t_1 + b \cdot t_3\right) \leq \infty:\\
\;\;\;\;\mathsf{fma}\left(b, t_3, \mathsf{fma}\left(x, t_1, t_2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x \cdot y - b \cdot c\right) - a \cdot \left(x \cdot t - c \cdot j\right)\\
\end{array}
Herbie found 25 alternatives:
| Alternative | Accuracy | Speedup |
|---|
| Original | 73.1% |
|---|---|
| Target | 59.4% |
| Herbie | 83.1% |
if (+.f64 (-.f64 (*.f64 x (-.f64 (*.f64 y z) (*.f64 t a))) (*.f64 b (-.f64 (*.f64 c z) (*.f64 t i)))) (*.f64 j (-.f64 (*.f64 c a) (*.f64 y i)))) < +inf.0Initial program 91.1%
Simplified91.1%
[Start]91.1% | \[ \left(x \cdot \left(y \cdot z - t \cdot a\right) - b \cdot \left(c \cdot z - t \cdot i\right)\right) + j \cdot \left(c \cdot a - y \cdot i\right)
\] |
|---|---|
sub-neg [=>]91.1% | \[ \color{blue}{\left(x \cdot \left(y \cdot z - t \cdot a\right) + \left(-b \cdot \left(c \cdot z - t \cdot i\right)\right)\right)} + j \cdot \left(c \cdot a - y \cdot i\right)
\] |
+-commutative [=>]91.1% | \[ \color{blue}{\left(\left(-b \cdot \left(c \cdot z - t \cdot i\right)\right) + x \cdot \left(y \cdot z - t \cdot a\right)\right)} + j \cdot \left(c \cdot a - y \cdot i\right)
\] |
associate-+l+ [=>]91.1% | \[ \color{blue}{\left(-b \cdot \left(c \cdot z - t \cdot i\right)\right) + \left(x \cdot \left(y \cdot z - t \cdot a\right) + j \cdot \left(c \cdot a - y \cdot i\right)\right)}
\] |
distribute-rgt-neg-in [=>]91.1% | \[ \color{blue}{b \cdot \left(-\left(c \cdot z - t \cdot i\right)\right)} + \left(x \cdot \left(y \cdot z - t \cdot a\right) + j \cdot \left(c \cdot a - y \cdot i\right)\right)
\] |
+-commutative [<=]91.1% | \[ b \cdot \left(-\left(c \cdot z - t \cdot i\right)\right) + \color{blue}{\left(j \cdot \left(c \cdot a - y \cdot i\right) + x \cdot \left(y \cdot z - t \cdot a\right)\right)}
\] |
fma-def [=>]91.1% | \[ \color{blue}{\mathsf{fma}\left(b, -\left(c \cdot z - t \cdot i\right), j \cdot \left(c \cdot a - y \cdot i\right) + x \cdot \left(y \cdot z - t \cdot a\right)\right)}
\] |
sub-neg [=>]91.1% | \[ \mathsf{fma}\left(b, -\color{blue}{\left(c \cdot z + \left(-t \cdot i\right)\right)}, j \cdot \left(c \cdot a - y \cdot i\right) + x \cdot \left(y \cdot z - t \cdot a\right)\right)
\] |
+-commutative [=>]91.1% | \[ \mathsf{fma}\left(b, -\color{blue}{\left(\left(-t \cdot i\right) + c \cdot z\right)}, j \cdot \left(c \cdot a - y \cdot i\right) + x \cdot \left(y \cdot z - t \cdot a\right)\right)
\] |
distribute-neg-in [=>]91.1% | \[ \mathsf{fma}\left(b, \color{blue}{\left(-\left(-t \cdot i\right)\right) + \left(-c \cdot z\right)}, j \cdot \left(c \cdot a - y \cdot i\right) + x \cdot \left(y \cdot z - t \cdot a\right)\right)
\] |
unsub-neg [=>]91.1% | \[ \mathsf{fma}\left(b, \color{blue}{\left(-\left(-t \cdot i\right)\right) - c \cdot z}, j \cdot \left(c \cdot a - y \cdot i\right) + x \cdot \left(y \cdot z - t \cdot a\right)\right)
\] |
remove-double-neg [=>]91.1% | \[ \mathsf{fma}\left(b, \color{blue}{t \cdot i} - c \cdot z, j \cdot \left(c \cdot a - y \cdot i\right) + x \cdot \left(y \cdot z - t \cdot a\right)\right)
\] |
*-commutative [=>]91.1% | \[ \mathsf{fma}\left(b, t \cdot i - \color{blue}{z \cdot c}, j \cdot \left(c \cdot a - y \cdot i\right) + x \cdot \left(y \cdot z - t \cdot a\right)\right)
\] |
if +inf.0 < (+.f64 (-.f64 (*.f64 x (-.f64 (*.f64 y z) (*.f64 t a))) (*.f64 b (-.f64 (*.f64 c z) (*.f64 t i)))) (*.f64 j (-.f64 (*.f64 c a) (*.f64 y i)))) Initial program 0.0%
Simplified17.6%
[Start]0.0% | \[ \left(x \cdot \left(y \cdot z - t \cdot a\right) - b \cdot \left(c \cdot z - t \cdot i\right)\right) + j \cdot \left(c \cdot a - y \cdot i\right)
\] |
|---|---|
sub-neg [=>]0.0% | \[ \color{blue}{\left(x \cdot \left(y \cdot z - t \cdot a\right) + \left(-b \cdot \left(c \cdot z - t \cdot i\right)\right)\right)} + j \cdot \left(c \cdot a - y \cdot i\right)
\] |
+-commutative [=>]0.0% | \[ \color{blue}{\left(\left(-b \cdot \left(c \cdot z - t \cdot i\right)\right) + x \cdot \left(y \cdot z - t \cdot a\right)\right)} + j \cdot \left(c \cdot a - y \cdot i\right)
\] |
associate-+l+ [=>]0.0% | \[ \color{blue}{\left(-b \cdot \left(c \cdot z - t \cdot i\right)\right) + \left(x \cdot \left(y \cdot z - t \cdot a\right) + j \cdot \left(c \cdot a - y \cdot i\right)\right)}
\] |
distribute-rgt-neg-in [=>]0.0% | \[ \color{blue}{b \cdot \left(-\left(c \cdot z - t \cdot i\right)\right)} + \left(x \cdot \left(y \cdot z - t \cdot a\right) + j \cdot \left(c \cdot a - y \cdot i\right)\right)
\] |
+-commutative [<=]0.0% | \[ b \cdot \left(-\left(c \cdot z - t \cdot i\right)\right) + \color{blue}{\left(j \cdot \left(c \cdot a - y \cdot i\right) + x \cdot \left(y \cdot z - t \cdot a\right)\right)}
\] |
fma-def [=>]7.8% | \[ \color{blue}{\mathsf{fma}\left(b, -\left(c \cdot z - t \cdot i\right), j \cdot \left(c \cdot a - y \cdot i\right) + x \cdot \left(y \cdot z - t \cdot a\right)\right)}
\] |
sub-neg [=>]7.8% | \[ \mathsf{fma}\left(b, -\color{blue}{\left(c \cdot z + \left(-t \cdot i\right)\right)}, j \cdot \left(c \cdot a - y \cdot i\right) + x \cdot \left(y \cdot z - t \cdot a\right)\right)
\] |
+-commutative [=>]7.8% | \[ \mathsf{fma}\left(b, -\color{blue}{\left(\left(-t \cdot i\right) + c \cdot z\right)}, j \cdot \left(c \cdot a - y \cdot i\right) + x \cdot \left(y \cdot z - t \cdot a\right)\right)
\] |
distribute-neg-in [=>]7.8% | \[ \mathsf{fma}\left(b, \color{blue}{\left(-\left(-t \cdot i\right)\right) + \left(-c \cdot z\right)}, j \cdot \left(c \cdot a - y \cdot i\right) + x \cdot \left(y \cdot z - t \cdot a\right)\right)
\] |
unsub-neg [=>]7.8% | \[ \mathsf{fma}\left(b, \color{blue}{\left(-\left(-t \cdot i\right)\right) - c \cdot z}, j \cdot \left(c \cdot a - y \cdot i\right) + x \cdot \left(y \cdot z - t \cdot a\right)\right)
\] |
remove-double-neg [=>]7.8% | \[ \mathsf{fma}\left(b, \color{blue}{t \cdot i} - c \cdot z, j \cdot \left(c \cdot a - y \cdot i\right) + x \cdot \left(y \cdot z - t \cdot a\right)\right)
\] |
*-commutative [=>]7.8% | \[ \mathsf{fma}\left(b, t \cdot i - \color{blue}{z \cdot c}, j \cdot \left(c \cdot a - y \cdot i\right) + x \cdot \left(y \cdot z - t \cdot a\right)\right)
\] |
Taylor expanded in a around -inf 25.5%
Simplified31.4%
[Start]25.5% | \[ -1 \cdot \left(a \cdot \left(t \cdot x + -1 \cdot \left(c \cdot j\right)\right)\right) + \left(-1 \cdot \left(y \cdot \left(i \cdot j\right)\right) + \left(y \cdot \left(z \cdot x\right) + \left(i \cdot t - c \cdot z\right) \cdot b\right)\right)
\] |
|---|---|
associate-+r+ [=>]25.5% | \[ -1 \cdot \left(a \cdot \left(t \cdot x + -1 \cdot \left(c \cdot j\right)\right)\right) + \color{blue}{\left(\left(-1 \cdot \left(y \cdot \left(i \cdot j\right)\right) + y \cdot \left(z \cdot x\right)\right) + \left(i \cdot t - c \cdot z\right) \cdot b\right)}
\] |
+-commutative [=>]25.5% | \[ -1 \cdot \left(a \cdot \left(t \cdot x + -1 \cdot \left(c \cdot j\right)\right)\right) + \left(\color{blue}{\left(y \cdot \left(z \cdot x\right) + -1 \cdot \left(y \cdot \left(i \cdot j\right)\right)\right)} + \left(i \cdot t - c \cdot z\right) \cdot b\right)
\] |
associate-+r+ [=>]25.5% | \[ \color{blue}{\left(-1 \cdot \left(a \cdot \left(t \cdot x + -1 \cdot \left(c \cdot j\right)\right)\right) + \left(y \cdot \left(z \cdot x\right) + -1 \cdot \left(y \cdot \left(i \cdot j\right)\right)\right)\right) + \left(i \cdot t - c \cdot z\right) \cdot b}
\] |
Taylor expanded in i around 0 41.4%
Simplified55.2%
[Start]41.4% | \[ \left(-1 \cdot \left(c \cdot \left(z \cdot b\right)\right) + y \cdot \left(z \cdot x\right)\right) - a \cdot \left(t \cdot x - c \cdot j\right)
\] |
|---|---|
sub-neg [=>]41.4% | \[ \color{blue}{\left(-1 \cdot \left(c \cdot \left(z \cdot b\right)\right) + y \cdot \left(z \cdot x\right)\right) + \left(-a \cdot \left(t \cdot x - c \cdot j\right)\right)}
\] |
*-commutative [=>]41.4% | \[ \left(-1 \cdot \left(c \cdot \color{blue}{\left(b \cdot z\right)}\right) + y \cdot \left(z \cdot x\right)\right) + \left(-a \cdot \left(t \cdot x - c \cdot j\right)\right)
\] |
associate-*r* [=>]43.5% | \[ \left(-1 \cdot \color{blue}{\left(\left(c \cdot b\right) \cdot z\right)} + y \cdot \left(z \cdot x\right)\right) + \left(-a \cdot \left(t \cdot x - c \cdot j\right)\right)
\] |
associate-*r* [=>]43.5% | \[ \left(\color{blue}{\left(-1 \cdot \left(c \cdot b\right)\right) \cdot z} + y \cdot \left(z \cdot x\right)\right) + \left(-a \cdot \left(t \cdot x - c \cdot j\right)\right)
\] |
*-commutative [=>]43.5% | \[ \left(\left(-1 \cdot \left(c \cdot b\right)\right) \cdot z + y \cdot \color{blue}{\left(x \cdot z\right)}\right) + \left(-a \cdot \left(t \cdot x - c \cdot j\right)\right)
\] |
associate-*r* [=>]43.5% | \[ \left(\left(-1 \cdot \left(c \cdot b\right)\right) \cdot z + \color{blue}{\left(y \cdot x\right) \cdot z}\right) + \left(-a \cdot \left(t \cdot x - c \cdot j\right)\right)
\] |
distribute-rgt-in [<=]55.2% | \[ \color{blue}{z \cdot \left(-1 \cdot \left(c \cdot b\right) + y \cdot x\right)} + \left(-a \cdot \left(t \cdot x - c \cdot j\right)\right)
\] |
+-commutative [<=]55.2% | \[ z \cdot \color{blue}{\left(y \cdot x + -1 \cdot \left(c \cdot b\right)\right)} + \left(-a \cdot \left(t \cdot x - c \cdot j\right)\right)
\] |
mul-1-neg [=>]55.2% | \[ z \cdot \left(y \cdot x + \color{blue}{\left(-c \cdot b\right)}\right) + \left(-a \cdot \left(t \cdot x - c \cdot j\right)\right)
\] |
unsub-neg [=>]55.2% | \[ z \cdot \color{blue}{\left(y \cdot x - c \cdot b\right)} + \left(-a \cdot \left(t \cdot x - c \cdot j\right)\right)
\] |
distribute-rgt-neg-in [=>]55.2% | \[ z \cdot \left(y \cdot x - c \cdot b\right) + \color{blue}{a \cdot \left(-\left(t \cdot x - c \cdot j\right)\right)}
\] |
neg-sub0 [=>]55.2% | \[ z \cdot \left(y \cdot x - c \cdot b\right) + a \cdot \color{blue}{\left(0 - \left(t \cdot x - c \cdot j\right)\right)}
\] |
associate-+l- [<=]55.2% | \[ z \cdot \left(y \cdot x - c \cdot b\right) + a \cdot \color{blue}{\left(\left(0 - t \cdot x\right) + c \cdot j\right)}
\] |
neg-sub0 [<=]55.2% | \[ z \cdot \left(y \cdot x - c \cdot b\right) + a \cdot \left(\color{blue}{\left(-t \cdot x\right)} + c \cdot j\right)
\] |
neg-mul-1 [=>]55.2% | \[ z \cdot \left(y \cdot x - c \cdot b\right) + a \cdot \left(\color{blue}{-1 \cdot \left(t \cdot x\right)} + c \cdot j\right)
\] |
+-commutative [<=]55.2% | \[ z \cdot \left(y \cdot x - c \cdot b\right) + a \cdot \color{blue}{\left(c \cdot j + -1 \cdot \left(t \cdot x\right)\right)}
\] |
neg-mul-1 [<=]55.2% | \[ z \cdot \left(y \cdot x - c \cdot b\right) + a \cdot \left(c \cdot j + \color{blue}{\left(-t \cdot x\right)}\right)
\] |
sub-neg [<=]55.2% | \[ z \cdot \left(y \cdot x - c \cdot b\right) + a \cdot \color{blue}{\left(c \cdot j - t \cdot x\right)}
\] |
Final simplification83.9%
| Alternative 1 | |
|---|---|
| Accuracy | 83.1% |
| Cost | 16324 |
| Alternative 2 | |
|---|---|
| Accuracy | 83.1% |
| Cost | 3780 |
| Alternative 3 | |
|---|---|
| Accuracy | 65.5% |
| Cost | 2136 |
| Alternative 4 | |
|---|---|
| Accuracy | 63.2% |
| Cost | 2008 |
| Alternative 5 | |
|---|---|
| Accuracy | 54.1% |
| Cost | 1884 |
| Alternative 6 | |
|---|---|
| Accuracy | 52.7% |
| Cost | 1752 |
| Alternative 7 | |
|---|---|
| Accuracy | 66.6% |
| Cost | 1740 |
| Alternative 8 | |
|---|---|
| Accuracy | 59.0% |
| Cost | 1620 |
| Alternative 9 | |
|---|---|
| Accuracy | 66.7% |
| Cost | 1612 |
| Alternative 10 | |
|---|---|
| Accuracy | 66.6% |
| Cost | 1612 |
| Alternative 11 | |
|---|---|
| Accuracy | 49.9% |
| Cost | 1500 |
| Alternative 12 | |
|---|---|
| Accuracy | 43.0% |
| Cost | 1368 |
| Alternative 13 | |
|---|---|
| Accuracy | 51.9% |
| Cost | 1368 |
| Alternative 14 | |
|---|---|
| Accuracy | 60.7% |
| Cost | 1225 |
| Alternative 15 | |
|---|---|
| Accuracy | 42.9% |
| Cost | 1104 |
| Alternative 16 | |
|---|---|
| Accuracy | 51.4% |
| Cost | 1104 |
| Alternative 17 | |
|---|---|
| Accuracy | 51.6% |
| Cost | 1104 |
| Alternative 18 | |
|---|---|
| Accuracy | 52.1% |
| Cost | 972 |
| Alternative 19 | |
|---|---|
| Accuracy | 29.7% |
| Cost | 912 |
| Alternative 20 | |
|---|---|
| Accuracy | 30.5% |
| Cost | 912 |
| Alternative 21 | |
|---|---|
| Accuracy | 30.6% |
| Cost | 912 |
| Alternative 22 | |
|---|---|
| Accuracy | 30.9% |
| Cost | 912 |
| Alternative 23 | |
|---|---|
| Accuracy | 29.5% |
| Cost | 585 |
| Alternative 24 | |
|---|---|
| Accuracy | 29.2% |
| Cost | 584 |
| Alternative 25 | |
|---|---|
| Accuracy | 22.3% |
| Cost | 320 |
herbie shell --seed 2023171
(FPCore (x y z t a b c i j)
:name "Data.Colour.Matrix:determinant from colour-2.3.3, A"
:precision binary64
:herbie-target
(if (< x -1.469694296777705e-64) (+ (- (* x (- (* y z) (* t a))) (/ (* b (- (pow (* c z) 2.0) (pow (* t i) 2.0))) (+ (* c z) (* t i)))) (* j (- (* c a) (* y i)))) (if (< x 3.2113527362226803e-147) (- (* (- (* b i) (* x a)) t) (- (* z (* c b)) (* j (- (* c a) (* y i))))) (+ (- (* x (- (* y z) (* t a))) (/ (* b (- (pow (* c z) 2.0) (pow (* t i) 2.0))) (+ (* c z) (* t i)))) (* j (- (* c a) (* y i))))))
(+ (- (* x (- (* y z) (* t a))) (* b (- (* c z) (* t i)))) (* j (- (* c a) (* y i)))))