| Alternative 1 | |
|---|---|
| Accuracy | 83.2% |
| Cost | 21700 |

(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 (+ (* x (- (* y z) (* t a))) (* b (- (* t i) (* z c)))))
(t_2 (- (* a c) (* y i))))
(if (<= (+ t_1 (* j t_2)) INFINITY)
(fma j t_2 t_1)
(* y (cbrt (pow (fma z x (* i (- j))) 3.0))))))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 = (x * ((y * z) - (t * a))) + (b * ((t * i) - (z * c)));
double t_2 = (a * c) - (y * i);
double tmp;
if ((t_1 + (j * t_2)) <= ((double) INFINITY)) {
tmp = fma(j, t_2, t_1);
} else {
tmp = y * cbrt(pow(fma(z, x, (i * -j)), 3.0));
}
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(x * Float64(Float64(y * z) - Float64(t * a))) + Float64(b * Float64(Float64(t * i) - Float64(z * c)))) t_2 = Float64(Float64(a * c) - Float64(y * i)) tmp = 0.0 if (Float64(t_1 + Float64(j * t_2)) <= Inf) tmp = fma(j, t_2, t_1); else tmp = Float64(y * cbrt((fma(z, x, Float64(i * Float64(-j))) ^ 3.0))); 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[(x * N[(N[(y * z), $MachinePrecision] - N[(t * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(b * N[(N[(t * i), $MachinePrecision] - N[(z * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(a * c), $MachinePrecision] - N[(y * i), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$1 + N[(j * t$95$2), $MachinePrecision]), $MachinePrecision], Infinity], N[(j * t$95$2 + t$95$1), $MachinePrecision], N[(y * N[Power[N[Power[N[(z * x + N[(i * (-j)), $MachinePrecision]), $MachinePrecision], 3.0], $MachinePrecision], 1/3], $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 := x \cdot \left(y \cdot z - t \cdot a\right) + b \cdot \left(t \cdot i - z \cdot c\right)\\
t_2 := a \cdot c - y \cdot i\\
\mathbf{if}\;t_1 + j \cdot t_2 \leq \infty:\\
\;\;\;\;\mathsf{fma}\left(j, t_2, t_1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \sqrt[3]{{\left(\mathsf{fma}\left(z, x, i \cdot \left(-j\right)\right)\right)}^{3}}\\
\end{array}
Herbie found 25 alternatives:
| Alternative | Accuracy | Speedup |
|---|
| Original | 72.6% |
|---|---|
| Target | 59.2% |
| Herbie | 83.2% |
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 92.2%
Simplified92.2%
[Start]92.2% | \[ \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)
\] |
|---|---|
+-commutative [=>]92.2% | \[ \color{blue}{j \cdot \left(c \cdot a - y \cdot i\right) + \left(x \cdot \left(y \cdot z - t \cdot a\right) - b \cdot \left(c \cdot z - t \cdot i\right)\right)}
\] |
fma-def [=>]92.2% | \[ \color{blue}{\mathsf{fma}\left(j, c \cdot a - y \cdot i, x \cdot \left(y \cdot z - t \cdot a\right) - b \cdot \left(c \cdot z - t \cdot i\right)\right)}
\] |
*-commutative [=>]92.2% | \[ \mathsf{fma}\left(j, \color{blue}{a \cdot c} - y \cdot i, x \cdot \left(y \cdot z - t \cdot a\right) - b \cdot \left(c \cdot z - t \cdot i\right)\right)
\] |
*-commutative [=>]92.2% | \[ \mathsf{fma}\left(j, a \cdot c - y \cdot i, x \cdot \left(y \cdot z - t \cdot a\right) - b \cdot \left(\color{blue}{z \cdot c} - t \cdot i\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%
Simplified0.0%
[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)
\] |
|---|---|
cancel-sign-sub [<=]0.0% | \[ \color{blue}{\left(x \cdot \left(y \cdot z - t \cdot a\right) - b \cdot \left(c \cdot z - t \cdot i\right)\right) - \left(-j\right) \cdot \left(c \cdot a - y \cdot i\right)}
\] |
cancel-sign-sub-inv [=>]0.0% | \[ \color{blue}{\left(x \cdot \left(y \cdot z - t \cdot a\right) - b \cdot \left(c \cdot z - t \cdot i\right)\right) + \left(-\left(-j\right)\right) \cdot \left(c \cdot a - y \cdot i\right)}
\] |
*-commutative [=>]0.0% | \[ \left(x \cdot \left(y \cdot z - t \cdot a\right) - b \cdot \left(\color{blue}{z \cdot c} - t \cdot i\right)\right) + \left(-\left(-j\right)\right) \cdot \left(c \cdot a - y \cdot i\right)
\] |
remove-double-neg [=>]0.0% | \[ \left(x \cdot \left(y \cdot z - t \cdot a\right) - b \cdot \left(z \cdot c - t \cdot i\right)\right) + \color{blue}{j} \cdot \left(c \cdot a - y \cdot i\right)
\] |
*-commutative [=>]0.0% | \[ \left(x \cdot \left(y \cdot z - t \cdot a\right) - b \cdot \left(z \cdot c - t \cdot i\right)\right) + j \cdot \left(\color{blue}{a \cdot c} - y \cdot i\right)
\] |
Taylor expanded in y around inf 45.4%
Simplified45.4%
[Start]45.4% | \[ \left(z \cdot x + -1 \cdot \left(i \cdot j\right)\right) \cdot y
\] |
|---|---|
*-commutative [=>]45.4% | \[ \color{blue}{y \cdot \left(z \cdot x + -1 \cdot \left(i \cdot j\right)\right)}
\] |
mul-1-neg [=>]45.4% | \[ y \cdot \left(z \cdot x + \color{blue}{\left(-i \cdot j\right)}\right)
\] |
unsub-neg [=>]45.4% | \[ y \cdot \color{blue}{\left(z \cdot x - i \cdot j\right)}
\] |
Applied egg-rr55.5%
[Start]45.4% | \[ y \cdot \left(z \cdot x - i \cdot j\right)
\] |
|---|---|
add-cbrt-cube [=>]55.5% | \[ y \cdot \color{blue}{\sqrt[3]{\left(\left(z \cdot x - i \cdot j\right) \cdot \left(z \cdot x - i \cdot j\right)\right) \cdot \left(z \cdot x - i \cdot j\right)}}
\] |
fma-neg [=>]55.5% | \[ y \cdot \sqrt[3]{\left(\color{blue}{\mathsf{fma}\left(z, x, -i \cdot j\right)} \cdot \left(z \cdot x - i \cdot j\right)\right) \cdot \left(z \cdot x - i \cdot j\right)}
\] |
*-commutative [=>]55.5% | \[ y \cdot \sqrt[3]{\left(\mathsf{fma}\left(z, x, -\color{blue}{j \cdot i}\right) \cdot \left(z \cdot x - i \cdot j\right)\right) \cdot \left(z \cdot x - i \cdot j\right)}
\] |
fma-neg [=>]55.5% | \[ y \cdot \sqrt[3]{\left(\mathsf{fma}\left(z, x, -j \cdot i\right) \cdot \color{blue}{\mathsf{fma}\left(z, x, -i \cdot j\right)}\right) \cdot \left(z \cdot x - i \cdot j\right)}
\] |
*-commutative [=>]55.5% | \[ y \cdot \sqrt[3]{\left(\mathsf{fma}\left(z, x, -j \cdot i\right) \cdot \mathsf{fma}\left(z, x, -\color{blue}{j \cdot i}\right)\right) \cdot \left(z \cdot x - i \cdot j\right)}
\] |
fma-neg [=>]55.5% | \[ y \cdot \sqrt[3]{\left(\mathsf{fma}\left(z, x, -j \cdot i\right) \cdot \mathsf{fma}\left(z, x, -j \cdot i\right)\right) \cdot \color{blue}{\mathsf{fma}\left(z, x, -i \cdot j\right)}}
\] |
*-commutative [=>]55.5% | \[ y \cdot \sqrt[3]{\left(\mathsf{fma}\left(z, x, -j \cdot i\right) \cdot \mathsf{fma}\left(z, x, -j \cdot i\right)\right) \cdot \mathsf{fma}\left(z, x, -\color{blue}{j \cdot i}\right)}
\] |
Simplified55.5%
[Start]55.5% | \[ y \cdot \sqrt[3]{\left(\mathsf{fma}\left(z, x, -j \cdot i\right) \cdot \mathsf{fma}\left(z, x, -j \cdot i\right)\right) \cdot \mathsf{fma}\left(z, x, -j \cdot i\right)}
\] |
|---|---|
unpow3 [<=]55.5% | \[ y \cdot \sqrt[3]{\color{blue}{{\left(\mathsf{fma}\left(z, x, -j \cdot i\right)\right)}^{3}}}
\] |
distribute-rgt-neg-in [=>]55.5% | \[ y \cdot \sqrt[3]{{\left(\mathsf{fma}\left(z, x, \color{blue}{j \cdot \left(-i\right)}\right)\right)}^{3}}
\] |
*-commutative [<=]55.5% | \[ y \cdot \sqrt[3]{{\left(\mathsf{fma}\left(z, x, \color{blue}{\left(-i\right) \cdot j}\right)\right)}^{3}}
\] |
distribute-lft-neg-out [=>]55.5% | \[ y \cdot \sqrt[3]{{\left(\mathsf{fma}\left(z, x, \color{blue}{-i \cdot j}\right)\right)}^{3}}
\] |
distribute-rgt-neg-in [=>]55.5% | \[ y \cdot \sqrt[3]{{\left(\mathsf{fma}\left(z, x, \color{blue}{i \cdot \left(-j\right)}\right)\right)}^{3}}
\] |
Final simplification85.4%
| Alternative 1 | |
|---|---|
| Accuracy | 83.2% |
| Cost | 21700 |
| Alternative 2 | |
|---|---|
| Accuracy | 81.2% |
| Cost | 10052 |
| Alternative 3 | |
|---|---|
| Accuracy | 81.2% |
| Cost | 3780 |
| Alternative 4 | |
|---|---|
| Accuracy | 64.9% |
| Cost | 1744 |
| Alternative 5 | |
|---|---|
| Accuracy | 28.4% |
| Cost | 1705 |
| Alternative 6 | |
|---|---|
| Accuracy | 49.0% |
| Cost | 1632 |
| Alternative 7 | |
|---|---|
| Accuracy | 48.7% |
| Cost | 1632 |
| Alternative 8 | |
|---|---|
| Accuracy | 48.7% |
| Cost | 1632 |
| Alternative 9 | |
|---|---|
| Accuracy | 48.4% |
| Cost | 1632 |
| Alternative 10 | |
|---|---|
| Accuracy | 56.4% |
| Cost | 1488 |
| Alternative 11 | |
|---|---|
| Accuracy | 28.4% |
| Cost | 1441 |
| Alternative 12 | |
|---|---|
| Accuracy | 29.1% |
| Cost | 1440 |
| Alternative 13 | |
|---|---|
| Accuracy | 30.4% |
| Cost | 1308 |
| Alternative 14 | |
|---|---|
| Accuracy | 29.0% |
| Cost | 1176 |
| Alternative 15 | |
|---|---|
| Accuracy | 51.4% |
| Cost | 1104 |
| Alternative 16 | |
|---|---|
| Accuracy | 29.6% |
| Cost | 980 |
| Alternative 17 | |
|---|---|
| Accuracy | 28.3% |
| Cost | 980 |
| Alternative 18 | |
|---|---|
| Accuracy | 28.5% |
| Cost | 980 |
| Alternative 19 | |
|---|---|
| Accuracy | 52.3% |
| Cost | 841 |
| Alternative 20 | |
|---|---|
| Accuracy | 41.8% |
| Cost | 840 |
| Alternative 21 | |
|---|---|
| Accuracy | 29.4% |
| Cost | 716 |
| Alternative 22 | |
|---|---|
| Accuracy | 30.0% |
| Cost | 585 |
| Alternative 23 | |
|---|---|
| Accuracy | 29.7% |
| Cost | 585 |
| Alternative 24 | |
|---|---|
| Accuracy | 29.5% |
| Cost | 584 |
| Alternative 25 | |
|---|---|
| Accuracy | 22.5% |
| Cost | 320 |
herbie shell --seed 2023165
(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)))))