| Alternative 1 | |
|---|---|
| Accuracy | 83.1% |
| Cost | 13896 |
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))
(FPCore (a b c)
:precision binary64
(if (<= b -540000000.0)
(/ (/ (* b 2.0) a) -3.0)
(if (<= b 4e-163)
(/ (* -0.3333333333333333 (- b (sqrt (fma b b (* -3.0 (* a c)))))) a)
(/ (* c -0.5) b))))double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
}
double code(double a, double b, double c) {
double tmp;
if (b <= -540000000.0) {
tmp = ((b * 2.0) / a) / -3.0;
} else if (b <= 4e-163) {
tmp = (-0.3333333333333333 * (b - sqrt(fma(b, b, (-3.0 * (a * c)))))) / a;
} else {
tmp = (c * -0.5) / b;
}
return tmp;
}
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(3.0 * a) * c)))) / Float64(3.0 * a)) end
function code(a, b, c) tmp = 0.0 if (b <= -540000000.0) tmp = Float64(Float64(Float64(b * 2.0) / a) / -3.0); elseif (b <= 4e-163) tmp = Float64(Float64(-0.3333333333333333 * Float64(b - sqrt(fma(b, b, Float64(-3.0 * Float64(a * c)))))) / a); else tmp = Float64(Float64(c * -0.5) / b); end return tmp end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(3.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_] := If[LessEqual[b, -540000000.0], N[(N[(N[(b * 2.0), $MachinePrecision] / a), $MachinePrecision] / -3.0), $MachinePrecision], If[LessEqual[b, 4e-163], N[(N[(-0.3333333333333333 * N[(b - N[Sqrt[N[(b * b + N[(-3.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[(N[(c * -0.5), $MachinePrecision] / b), $MachinePrecision]]]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \leq -540000000:\\
\;\;\;\;\frac{\frac{b \cdot 2}{a}}{-3}\\
\mathbf{elif}\;b \leq 4 \cdot 10^{-163}:\\
\;\;\;\;\frac{-0.3333333333333333 \cdot \left(b - \sqrt{\mathsf{fma}\left(b, b, -3 \cdot \left(a \cdot c\right)\right)}\right)}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot -0.5}{b}\\
\end{array}
if b < -5.4e8Initial program 68.1%
Simplified68.2%
[Start]68.1 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
/-rgt-identity [<=]68.1 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{\color{blue}{\frac{3 \cdot a}{1}}}
\] |
metadata-eval [<=]68.1 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{\frac{3 \cdot a}{\color{blue}{--1}}}
\] |
associate-/r/ [=>]68.1 | \[ \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \cdot \left(--1\right)}
\] |
metadata-eval [=>]68.1 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \cdot \color{blue}{1}
\] |
metadata-eval [<=]68.1 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \cdot \color{blue}{\frac{-1}{-1}}
\] |
times-frac [<=]68.1 | \[ \color{blue}{\frac{\left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot -1}{\left(3 \cdot a\right) \cdot -1}}
\] |
*-commutative [<=]68.1 | \[ \frac{\left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot -1}{\color{blue}{-1 \cdot \left(3 \cdot a\right)}}
\] |
times-frac [=>]68.1 | \[ \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-1} \cdot \frac{-1}{3 \cdot a}}
\] |
*-commutative [<=]68.1 | \[ \color{blue}{\frac{-1}{3 \cdot a} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-1}}
\] |
associate-/r* [=>]68.1 | \[ \color{blue}{\frac{\frac{-1}{3}}{a}} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-1}
\] |
associate-*l/ [=>]68.2 | \[ \color{blue}{\frac{\frac{-1}{3} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-1}}{a}}
\] |
Applied egg-rr49.4%
[Start]68.2 | \[ \frac{-0.3333333333333333 \cdot \left(b - \sqrt{\mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -3\right)}\right)}{a}
\] |
|---|---|
clear-num [=>]68.1 | \[ \color{blue}{\frac{1}{\frac{a}{-0.3333333333333333 \cdot \left(b - \sqrt{\mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -3\right)}\right)}}}
\] |
inv-pow [=>]68.1 | \[ \color{blue}{{\left(\frac{a}{-0.3333333333333333 \cdot \left(b - \sqrt{\mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -3\right)}\right)}\right)}^{-1}}
\] |
*-un-lft-identity [=>]68.1 | \[ {\left(\frac{\color{blue}{1 \cdot a}}{-0.3333333333333333 \cdot \left(b - \sqrt{\mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -3\right)}\right)}\right)}^{-1}
\] |
times-frac [=>]68.1 | \[ {\color{blue}{\left(\frac{1}{-0.3333333333333333} \cdot \frac{a}{b - \sqrt{\mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -3\right)}}\right)}}^{-1}
\] |
metadata-eval [=>]68.1 | \[ {\left(\color{blue}{-3} \cdot \frac{a}{b - \sqrt{\mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -3\right)}}\right)}^{-1}
\] |
fma-udef [=>]68.1 | \[ {\left(-3 \cdot \frac{a}{b - \sqrt{\color{blue}{b \cdot b + \left(a \cdot c\right) \cdot -3}}}\right)}^{-1}
\] |
add-sqr-sqrt [=>]37.1 | \[ {\left(-3 \cdot \frac{a}{b - \sqrt{b \cdot b + \color{blue}{\sqrt{\left(a \cdot c\right) \cdot -3} \cdot \sqrt{\left(a \cdot c\right) \cdot -3}}}}\right)}^{-1}
\] |
hypot-def [=>]49.4 | \[ {\left(-3 \cdot \frac{a}{b - \color{blue}{\mathsf{hypot}\left(b, \sqrt{\left(a \cdot c\right) \cdot -3}\right)}}\right)}^{-1}
\] |
associate-*l* [=>]49.4 | \[ {\left(-3 \cdot \frac{a}{b - \mathsf{hypot}\left(b, \sqrt{\color{blue}{a \cdot \left(c \cdot -3\right)}}\right)}\right)}^{-1}
\] |
Applied egg-rr49.5%
[Start]49.4 | \[ {\left(-3 \cdot \frac{a}{b - \mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -3\right)}\right)}\right)}^{-1}
\] |
|---|---|
unpow-1 [=>]49.4 | \[ \color{blue}{\frac{1}{-3 \cdot \frac{a}{b - \mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -3\right)}\right)}}}
\] |
*-commutative [=>]49.4 | \[ \frac{1}{\color{blue}{\frac{a}{b - \mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -3\right)}\right)} \cdot -3}}
\] |
associate-/r* [=>]49.4 | \[ \color{blue}{\frac{\frac{1}{\frac{a}{b - \mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -3\right)}\right)}}}{-3}}
\] |
clear-num [<=]49.5 | \[ \frac{\color{blue}{\frac{b - \mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -3\right)}\right)}{a}}}{-3}
\] |
hypot-udef [=>]37.2 | \[ \frac{\frac{b - \color{blue}{\sqrt{b \cdot b + \sqrt{a \cdot \left(c \cdot -3\right)} \cdot \sqrt{a \cdot \left(c \cdot -3\right)}}}}{a}}{-3}
\] |
add-sqr-sqrt [<=]68.2 | \[ \frac{\frac{b - \sqrt{b \cdot b + \color{blue}{a \cdot \left(c \cdot -3\right)}}}{a}}{-3}
\] |
+-commutative [=>]68.2 | \[ \frac{\frac{b - \sqrt{\color{blue}{a \cdot \left(c \cdot -3\right) + b \cdot b}}}{a}}{-3}
\] |
add-sqr-sqrt [=>]37.2 | \[ \frac{\frac{b - \sqrt{\color{blue}{\sqrt{a \cdot \left(c \cdot -3\right)} \cdot \sqrt{a \cdot \left(c \cdot -3\right)}} + b \cdot b}}{a}}{-3}
\] |
hypot-def [=>]49.5 | \[ \frac{\frac{b - \color{blue}{\mathsf{hypot}\left(\sqrt{a \cdot \left(c \cdot -3\right)}, b\right)}}{a}}{-3}
\] |
Taylor expanded in b around -inf 94.4%
Simplified94.4%
[Start]94.4 | \[ \frac{\frac{2 \cdot b}{a}}{-3}
\] |
|---|---|
*-commutative [=>]94.4 | \[ \frac{\frac{\color{blue}{b \cdot 2}}{a}}{-3}
\] |
if -5.4e8 < b < 3.99999999999999969e-163Initial program 76.6%
Simplified76.6%
[Start]76.6 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
/-rgt-identity [<=]76.6 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{\color{blue}{\frac{3 \cdot a}{1}}}
\] |
metadata-eval [<=]76.6 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{\frac{3 \cdot a}{\color{blue}{--1}}}
\] |
associate-/r/ [=>]76.6 | \[ \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \cdot \left(--1\right)}
\] |
metadata-eval [=>]76.6 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \cdot \color{blue}{1}
\] |
metadata-eval [<=]76.6 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \cdot \color{blue}{\frac{-1}{-1}}
\] |
times-frac [<=]76.6 | \[ \color{blue}{\frac{\left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot -1}{\left(3 \cdot a\right) \cdot -1}}
\] |
*-commutative [<=]76.6 | \[ \frac{\left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot -1}{\color{blue}{-1 \cdot \left(3 \cdot a\right)}}
\] |
times-frac [=>]76.5 | \[ \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-1} \cdot \frac{-1}{3 \cdot a}}
\] |
*-commutative [<=]76.5 | \[ \color{blue}{\frac{-1}{3 \cdot a} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-1}}
\] |
associate-/r* [=>]76.4 | \[ \color{blue}{\frac{\frac{-1}{3}}{a}} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-1}
\] |
associate-*l/ [=>]76.5 | \[ \color{blue}{\frac{\frac{-1}{3} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-1}}{a}}
\] |
if 3.99999999999999969e-163 < b Initial program 16.6%
Simplified16.6%
[Start]16.6 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
/-rgt-identity [<=]16.6 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{\color{blue}{\frac{3 \cdot a}{1}}}
\] |
metadata-eval [<=]16.6 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{\frac{3 \cdot a}{\color{blue}{--1}}}
\] |
associate-/r/ [=>]16.6 | \[ \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \cdot \left(--1\right)}
\] |
metadata-eval [=>]16.6 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \cdot \color{blue}{1}
\] |
metadata-eval [<=]16.6 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \cdot \color{blue}{\frac{-1}{-1}}
\] |
times-frac [<=]16.6 | \[ \color{blue}{\frac{\left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot -1}{\left(3 \cdot a\right) \cdot -1}}
\] |
*-commutative [<=]16.6 | \[ \frac{\left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot -1}{\color{blue}{-1 \cdot \left(3 \cdot a\right)}}
\] |
times-frac [=>]16.6 | \[ \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-1} \cdot \frac{-1}{3 \cdot a}}
\] |
*-commutative [<=]16.6 | \[ \color{blue}{\frac{-1}{3 \cdot a} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-1}}
\] |
associate-/r* [=>]16.6 | \[ \color{blue}{\frac{\frac{-1}{3}}{a}} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-1}
\] |
associate-*l/ [=>]16.6 | \[ \color{blue}{\frac{\frac{-1}{3} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-1}}{a}}
\] |
Taylor expanded in b around inf 22.1%
Taylor expanded in b around 0 85.5%
Simplified85.5%
[Start]85.5 | \[ -0.5 \cdot \frac{c}{b}
\] |
|---|---|
*-commutative [=>]85.5 | \[ \color{blue}{\frac{c}{b} \cdot -0.5}
\] |
associate-*l/ [=>]85.5 | \[ \color{blue}{\frac{c \cdot -0.5}{b}}
\] |
Final simplification85.3%
| Alternative 1 | |
|---|---|
| Accuracy | 83.1% |
| Cost | 13896 |
| Alternative 2 | |
|---|---|
| Accuracy | 83.1% |
| Cost | 7624 |
| Alternative 3 | |
|---|---|
| Accuracy | 83.1% |
| Cost | 7624 |
| Alternative 4 | |
|---|---|
| Accuracy | 79.3% |
| Cost | 7368 |
| Alternative 5 | |
|---|---|
| Accuracy | 67.2% |
| Cost | 580 |
| Alternative 6 | |
|---|---|
| Accuracy | 67.2% |
| Cost | 452 |
| Alternative 7 | |
|---|---|
| Accuracy | 67.2% |
| Cost | 452 |
| Alternative 8 | |
|---|---|
| Accuracy | 67.2% |
| Cost | 452 |
| Alternative 9 | |
|---|---|
| Accuracy | 67.3% |
| Cost | 452 |
| Alternative 10 | |
|---|---|
| Accuracy | 34.9% |
| Cost | 320 |
herbie shell --seed 2023160
(FPCore (a b c)
:name "Cubic critical"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))