\[\left(x \cdot \left(y \cdot z - t \cdot a\right) - b \cdot \left(c \cdot z - i \cdot a\right)\right) + j \cdot \left(c \cdot t - i \cdot y\right)
\]
↓
\[\begin{array}{l}
t_1 := \left(x \cdot \left(y \cdot z - t \cdot a\right) + b \cdot \left(a \cdot i - z \cdot c\right)\right) + j \cdot \left(t \cdot c - y \cdot i\right)\\
\mathbf{if}\;t_1 \leq \infty:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot z - i \cdot j\right) - c \cdot \left(z \cdot b\right)\\
\end{array}
\]
(FPCore (x y z t a b c i j)
:precision binary64
(+
(- (* x (- (* y z) (* t a))) (* b (- (* c z) (* i a))))
(* j (- (* c t) (* i y)))))
↓
(FPCore (x y z t a b c i j)
:precision binary64
(let* ((t_1
(+
(+ (* x (- (* y z) (* t a))) (* b (- (* a i) (* z c))))
(* j (- (* t c) (* y i))))))
(if (<= t_1 INFINITY) t_1 (- (* y (- (* x z) (* i j))) (* c (* z b))))))
The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.
Herbie found 23 alternatives:
Alternative
Accuracy
Speedup
Accuracy vs Speed
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.
if (+.f64 (-.f64 (*.f64 x (-.f64 (*.f64 y z) (*.f64 t a))) (*.f64 b (-.f64 (*.f64 c z) (*.f64 i a)))) (*.f64 j (-.f64 (*.f64 c t) (*.f64 i y)))) < +inf.0
Initial program 88.1%
\[\left(x \cdot \left(y \cdot z - t \cdot a\right) - b \cdot \left(c \cdot z - i \cdot a\right)\right) + j \cdot \left(c \cdot t - i \cdot y\right)
\]
if +inf.0 < (+.f64 (-.f64 (*.f64 x (-.f64 (*.f64 y z) (*.f64 t a))) (*.f64 b (-.f64 (*.f64 c z) (*.f64 i a)))) (*.f64 j (-.f64 (*.f64 c t) (*.f64 i y))))
Initial program 0.0%
\[\left(x \cdot \left(y \cdot z - t \cdot a\right) - b \cdot \left(c \cdot z - i \cdot a\right)\right) + j \cdot \left(c \cdot t - i \cdot y\right)
\]
Simplified0.0%
\[\leadsto \color{blue}{\left(x \cdot \left(y \cdot z - t \cdot a\right) - b \cdot \left(z \cdot c - a \cdot i\right)\right) + j \cdot \left(t \cdot c - y \cdot i\right)}
\]
Step-by-step derivation
[Start]0.0%
\[ \left(x \cdot \left(y \cdot z - t \cdot a\right) - b \cdot \left(c \cdot z - i \cdot a\right)\right) + j \cdot \left(c \cdot t - i \cdot y\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 - i \cdot a\right)\right) - \left(-j\right) \cdot \left(c \cdot t - i \cdot y\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 - i \cdot a\right)\right) + \left(-\left(-j\right)\right) \cdot \left(c \cdot t - i \cdot y\right)}
\]
*-commutative [=>]0.0%
\[ \left(x \cdot \left(y \cdot z - t \cdot a\right) - b \cdot \left(c \cdot z - \color{blue}{a \cdot i}\right)\right) + \left(-\left(-j\right)\right) \cdot \left(c \cdot t - i \cdot y\right)
\]
*-commutative [=>]0.0%
\[ \left(x \cdot \left(y \cdot z - t \cdot a\right) - b \cdot \left(\color{blue}{z \cdot c} - a \cdot i\right)\right) + \left(-\left(-j\right)\right) \cdot \left(c \cdot t - i \cdot y\right)
\]
remove-double-neg [=>]0.0%
\[ \left(x \cdot \left(y \cdot z - t \cdot a\right) - b \cdot \left(z \cdot c - a \cdot i\right)\right) + \color{blue}{j} \cdot \left(c \cdot t - i \cdot y\right)
\]
*-commutative [=>]0.0%
\[ \left(x \cdot \left(y \cdot z - t \cdot a\right) - b \cdot \left(z \cdot c - a \cdot i\right)\right) + j \cdot \left(\color{blue}{t \cdot c} - i \cdot y\right)
\]
*-commutative [=>]0.0%
\[ \left(x \cdot \left(y \cdot z - t \cdot a\right) - b \cdot \left(z \cdot c - a \cdot i\right)\right) + j \cdot \left(t \cdot c - \color{blue}{y \cdot i}\right)
\]
Taylor expanded in i around -inf 21.4%
\[\leadsto \color{blue}{\left(-1 \cdot \left(i \cdot \left(y \cdot j - a \cdot b\right)\right) + \left(\left(y \cdot z - a \cdot t\right) \cdot x + c \cdot \left(t \cdot j\right)\right)\right) - c \cdot \left(b \cdot z\right)}
\]
Taylor expanded in y around inf 57.8%
\[\leadsto \color{blue}{y \cdot \left(-1 \cdot \left(i \cdot j\right) + z \cdot x\right)} - c \cdot \left(b \cdot z\right)
\]
Simplified57.8%
\[\leadsto \color{blue}{y \cdot \left(x \cdot z - i \cdot j\right)} - c \cdot \left(b \cdot z\right)
\]
Step-by-step derivation
[Start]57.8%
\[ y \cdot \left(-1 \cdot \left(i \cdot j\right) + z \cdot x\right) - c \cdot \left(b \cdot z\right)
\]
+-commutative [=>]57.8%
\[ y \cdot \color{blue}{\left(z \cdot x + -1 \cdot \left(i \cdot j\right)\right)} - c \cdot \left(b \cdot z\right)
\]
mul-1-neg [=>]57.8%
\[ y \cdot \left(z \cdot x + \color{blue}{\left(-i \cdot j\right)}\right) - c \cdot \left(b \cdot z\right)
\]
unsub-neg [=>]57.8%
\[ y \cdot \color{blue}{\left(z \cdot x - i \cdot j\right)} - c \cdot \left(b \cdot z\right)
\]
*-commutative [=>]57.8%
\[ y \cdot \left(\color{blue}{x \cdot z} - i \cdot j\right) - c \cdot \left(b \cdot z\right)
\]
Recombined 2 regimes into one program.
Final simplification81.5%
\[\leadsto \begin{array}{l}
\mathbf{if}\;\left(x \cdot \left(y \cdot z - t \cdot a\right) + b \cdot \left(a \cdot i - z \cdot c\right)\right) + j \cdot \left(t \cdot c - y \cdot i\right) \leq \infty:\\
\;\;\;\;\left(x \cdot \left(y \cdot z - t \cdot a\right) + b \cdot \left(a \cdot i - z \cdot c\right)\right) + j \cdot \left(t \cdot c - y \cdot i\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot z - i \cdot j\right) - c \cdot \left(z \cdot b\right)\\
\end{array}
\]
Alternatives
Alternative 1
Accuracy
82.4%
Cost
3780
\[\begin{array}{l}
t_1 := \left(x \cdot \left(y \cdot z - t \cdot a\right) + b \cdot \left(a \cdot i - z \cdot c\right)\right) + j \cdot \left(t \cdot c - y \cdot i\right)\\
\mathbf{if}\;t_1 \leq \infty:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot z - i \cdot j\right) - c \cdot \left(z \cdot b\right)\\
\end{array}
\]
Alternative 2
Accuracy
65.6%
Cost
2005
\[\begin{array}{l}
t_1 := x \cdot \left(y \cdot z - t \cdot a\right)\\
t_2 := t_1 + \left(a \cdot \left(b \cdot i\right) - y \cdot \left(i \cdot j\right)\right)\\
\mathbf{if}\;j \leq -6 \cdot 10^{+84}:\\
\;\;\;\;j \cdot \left(t \cdot c - y \cdot i\right) - c \cdot \left(z \cdot b\right)\\
\mathbf{elif}\;j \leq -2.05 \cdot 10^{-16}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;j \leq 7.2 \cdot 10^{-68}:\\
\;\;\;\;t_1 + b \cdot \left(a \cdot i - z \cdot c\right)\\
\mathbf{elif}\;j \leq 10600000 \lor \neg \left(j \leq 1.15 \cdot 10^{+115}\right):\\
\;\;\;\;c \cdot \left(t \cdot j - z \cdot b\right) - i \cdot \left(y \cdot j\right)\\
\mathbf{else}:\\
\;\;\;\;t_2\\
\end{array}
\]
herbie shell --seed 2023272
(FPCore (x y z t a b c i j)
:name "Linear.Matrix:det33 from linear-1.19.1.3"
:precision binary64
:herbie-target
(if (< t -8.120978919195912e-33) (- (* x (- (* z y) (* a t))) (- (* b (- (* z c) (* a i))) (* (- (* c t) (* y i)) j))) (if (< t -4.712553818218485e-169) (+ (- (* x (- (* y z) (* t a))) (* b (- (* c z) (* i a)))) (/ (* j (- (pow (* c t) 2.0) (pow (* i y) 2.0))) (+ (* c t) (* i y)))) (if (< t -7.633533346031584e-308) (- (* x (- (* z y) (* a t))) (- (* b (- (* z c) (* a i))) (* (- (* c t) (* y i)) j))) (if (< t 1.0535888557455487e-139) (+ (- (* x (- (* y z) (* t a))) (* b (- (* c z) (* i a)))) (/ (* j (- (pow (* c t) 2.0) (pow (* i y) 2.0))) (+ (* c t) (* i y)))) (- (* x (- (* z y) (* a t))) (- (* b (- (* z c) (* a i))) (* (- (* c t) (* y i)) j)))))))
(+ (- (* x (- (* y z) (* t a))) (* b (- (* c z) (* i a)))) (* j (- (* c t) (* i y)))))