Average Error: 12.5 → 9.7
Time: 3.0m
Precision: 64
Internal Precision: 384
\[\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}
\mathbf{if}\;x \le -4.335731413434198 \cdot 10^{-76}:\\
\;\;\;\;\left(x \cdot \left(y \cdot z - t \cdot a\right) - \left(b \cdot \left(\sqrt[3]{c \cdot z - t \cdot i} \cdot \sqrt[3]{c \cdot z - t \cdot i}\right)\right) \cdot \sqrt[3]{c \cdot z - t \cdot i}\right) + j \cdot \left(c \cdot a - y \cdot i\right)\\
\mathbf{if}\;x \le 6.915320746710514 \cdot 10^{-242}:\\
\;\;\;\;\left(b \cdot i - x \cdot a\right) \cdot t - \left(\left(b \cdot c\right) \cdot z - j \cdot \left(c \cdot a - y \cdot i\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot \left(y \cdot z - t \cdot a\right) - b \cdot \left(c \cdot z - t \cdot i\right)\right) + \left(\sqrt[3]{j \cdot \left(c \cdot a - y \cdot i\right)} \cdot \sqrt[3]{j \cdot \left(c \cdot a - y \cdot i\right)}\right) \cdot \sqrt[3]{j \cdot \left(c \cdot a - y \cdot i\right)}\\
\end{array}\]
Target
| Original | 12.5 |
|---|
| Target | 17.8 |
|---|
| Herbie | 9.7 |
|---|
\[\begin{array}{l}
\mathbf{if}\;x \lt -1.469694296777705 \cdot 10^{-64}:\\
\;\;\;\;\left(x \cdot \left(y \cdot z - t \cdot a\right) - \frac{b \cdot \left({\left(c \cdot z\right)}^{2} - {\left(t \cdot i\right)}^{2}\right)}{c \cdot z + t \cdot i}\right) + j \cdot \left(c \cdot a - y \cdot i\right)\\
\mathbf{if}\;x \lt 3.2113527362226803 \cdot 10^{-147}:\\
\;\;\;\;\left(b \cdot i - x \cdot a\right) \cdot t - \left(z \cdot \left(c \cdot b\right) - j \cdot \left(c \cdot a - y \cdot i\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot \left(y \cdot z - t \cdot a\right) - \frac{b \cdot \left({\left(c \cdot z\right)}^{2} - {\left(t \cdot i\right)}^{2}\right)}{c \cdot z + t \cdot i}\right) + j \cdot \left(c \cdot a - y \cdot i\right)\\
\end{array}\]
Derivation
- Split input into 3 regimes
if x < -4.335731413434198e-76
Initial program 7.8
\[\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)\]
- Using strategy
rm Applied add-cube-cbrt8.0
\[\leadsto \left(x \cdot \left(y \cdot z - t \cdot a\right) - b \cdot \color{blue}{\left(\left(\sqrt[3]{c \cdot z - t \cdot i} \cdot \sqrt[3]{c \cdot z - t \cdot i}\right) \cdot \sqrt[3]{c \cdot z - t \cdot i}\right)}\right) + j \cdot \left(c \cdot a - y \cdot i\right)\]
Applied associate-*r*8.0
\[\leadsto \left(x \cdot \left(y \cdot z - t \cdot a\right) - \color{blue}{\left(b \cdot \left(\sqrt[3]{c \cdot z - t \cdot i} \cdot \sqrt[3]{c \cdot z - t \cdot i}\right)\right) \cdot \sqrt[3]{c \cdot z - t \cdot i}}\right) + j \cdot \left(c \cdot a - y \cdot i\right)\]
if -4.335731413434198e-76 < x < 6.915320746710514e-242
Initial program 18.6
\[\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)\]
Taylor expanded around inf 9.4
\[\leadsto \color{blue}{\left(b \cdot \left(t \cdot i\right) - \left(a \cdot \left(t \cdot x\right) + z \cdot \left(b \cdot c\right)\right)\right)} + j \cdot \left(c \cdot a - y \cdot i\right)\]
Applied simplify9.0
\[\leadsto \color{blue}{\left(b \cdot i - x \cdot a\right) \cdot t - \left(\left(b \cdot c\right) \cdot z - j \cdot \left(c \cdot a - y \cdot i\right)\right)}\]
if 6.915320746710514e-242 < x
Initial program 10.9
\[\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)\]
- Using strategy
rm Applied add-cube-cbrt11.1
\[\leadsto \left(x \cdot \left(y \cdot z - t \cdot a\right) - b \cdot \left(c \cdot z - t \cdot i\right)\right) + \color{blue}{\left(\sqrt[3]{j \cdot \left(c \cdot a - y \cdot i\right)} \cdot \sqrt[3]{j \cdot \left(c \cdot a - y \cdot i\right)}\right) \cdot \sqrt[3]{j \cdot \left(c \cdot a - y \cdot i\right)}}\]
- Recombined 3 regimes into one program.
- Removed slow
pow expressions.
Runtime
herbie shell --seed '#(1567391828 2030694642 2833800258 828025724 3004380912 3532991858)' +o setup:early-exit
(FPCore (x y z t a b c i j)
:name "Data.Colour.Matrix:determinant from colour-2.3.3, A"
:herbie-target
(if (< x -1.469694296777705e-64) (+ (- (* x (- (* y z) (* t a))) (/ (* b (- (pow (* c z) 2) (pow (* t i) 2))) (+ (* 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) (pow (* t i) 2))) (+ (* c z) (* t i)))) (* j (- (* c a) (* y i))))))
(+ (- (* x (- (* y z) (* t a))) (* b (- (* c z) (* t i)))) (* j (- (* c a) (* y i)))))