| Alternative 1 | |
|---|---|
| Error | 10.3 |
| Cost | 7624 |
(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 -2e+154)
(/ (fma 1.5 (* (/ c b) a) (* b -2.0)) (* a 3.0))
(if (<= b -1.7e-283)
(/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) (* a 3.0))
(if (<= b 1e+88)
(/ (/ c (/ a (- a))) (+ b (sqrt (+ (* b b) (* (* c a) -3.0)))))
(* (/ c b) -0.5)))))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 <= -2e+154) {
tmp = fma(1.5, ((c / b) * a), (b * -2.0)) / (a * 3.0);
} else if (b <= -1.7e-283) {
tmp = (sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0);
} else if (b <= 1e+88) {
tmp = (c / (a / -a)) / (b + sqrt(((b * b) + ((c * a) * -3.0))));
} else {
tmp = (c / b) * -0.5;
}
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 <= -2e+154) tmp = Float64(fma(1.5, Float64(Float64(c / b) * a), Float64(b * -2.0)) / Float64(a * 3.0)); elseif (b <= -1.7e-283) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 3.0)))) - b) / Float64(a * 3.0)); elseif (b <= 1e+88) tmp = Float64(Float64(c / Float64(a / Float64(-a))) / Float64(b + sqrt(Float64(Float64(b * b) + Float64(Float64(c * a) * -3.0))))); else tmp = Float64(Float64(c / b) * -0.5); 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, -2e+154], N[(N[(1.5 * N[(N[(c / b), $MachinePrecision] * a), $MachinePrecision] + N[(b * -2.0), $MachinePrecision]), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, -1.7e-283], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1e+88], N[(N[(c / N[(a / (-a)), $MachinePrecision]), $MachinePrecision] / N[(b + N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(N[(c * a), $MachinePrecision] * -3.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] * -0.5), $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 -2 \cdot 10^{+154}:\\
\;\;\;\;\frac{\mathsf{fma}\left(1.5, \frac{c}{b} \cdot a, b \cdot -2\right)}{a \cdot 3}\\
\mathbf{elif}\;b \leq -1.7 \cdot 10^{-283}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3}\\
\mathbf{elif}\;b \leq 10^{+88}:\\
\;\;\;\;\frac{\frac{c}{\frac{a}{-a}}}{b + \sqrt{b \cdot b + \left(c \cdot a\right) \cdot -3}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} \cdot -0.5\\
\end{array}
if b < -2.00000000000000007e154Initial program 64.0
Taylor expanded in b around -inf 12.9
Simplified3.6
[Start]12.9 | \[ \frac{1.5 \cdot \frac{c \cdot a}{b} + -2 \cdot b}{3 \cdot a}
\] |
|---|---|
fma-def [=>]12.9 | \[ \frac{\color{blue}{\mathsf{fma}\left(1.5, \frac{c \cdot a}{b}, -2 \cdot b\right)}}{3 \cdot a}
\] |
associate-/l* [=>]3.6 | \[ \frac{\mathsf{fma}\left(1.5, \color{blue}{\frac{c}{\frac{b}{a}}}, -2 \cdot b\right)}{3 \cdot a}
\] |
associate-/r/ [=>]3.6 | \[ \frac{\mathsf{fma}\left(1.5, \color{blue}{\frac{c}{b} \cdot a}, -2 \cdot b\right)}{3 \cdot a}
\] |
*-commutative [=>]3.6 | \[ \frac{\mathsf{fma}\left(1.5, \frac{c}{b} \cdot a, \color{blue}{b \cdot -2}\right)}{3 \cdot a}
\] |
if -2.00000000000000007e154 < b < -1.6999999999999999e-283Initial program 8.1
if -1.6999999999999999e-283 < b < 9.99999999999999959e87Initial program 31.7
Simplified31.8
[Start]31.7 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
*-lft-identity [<=]31.7 | \[ \color{blue}{1 \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}}
\] |
metadata-eval [<=]31.7 | \[ \color{blue}{\frac{-1}{-1}} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
times-frac [<=]31.7 | \[ \color{blue}{\frac{-1 \cdot \left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}{-1 \cdot \left(3 \cdot a\right)}}
\] |
neg-mul-1 [<=]31.7 | \[ \frac{-1 \cdot \left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}{\color{blue}{-3 \cdot a}}
\] |
distribute-rgt-neg-in [=>]31.7 | \[ \frac{-1 \cdot \left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}{\color{blue}{3 \cdot \left(-a\right)}}
\] |
times-frac [=>]31.8 | \[ \color{blue}{\frac{-1}{3} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-a}}
\] |
*-commutative [=>]31.8 | \[ \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-a} \cdot \frac{-1}{3}}
\] |
Applied egg-rr36.3
Simplified17.2
[Start]36.3 | \[ \frac{\left(b \cdot b - \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right) \cdot -0.3333333333333333}{a \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}
\] |
|---|---|
*-commutative [=>]36.3 | \[ \frac{\color{blue}{-0.3333333333333333 \cdot \left(b \cdot b - \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right)}}{a \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}
\] |
times-frac [=>]31.8 | \[ \color{blue}{\frac{-0.3333333333333333}{a} \cdot \frac{b \cdot b - \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}
\] |
fma-udef [=>]31.8 | \[ \frac{-0.3333333333333333}{a} \cdot \frac{b \cdot b - \color{blue}{\left(a \cdot \left(c \cdot -3\right) + b \cdot b\right)}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
associate-*l* [<=]31.8 | \[ \frac{-0.3333333333333333}{a} \cdot \frac{b \cdot b - \left(\color{blue}{\left(a \cdot c\right) \cdot -3} + b \cdot b\right)}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
+-commutative [=>]31.8 | \[ \frac{-0.3333333333333333}{a} \cdot \frac{b \cdot b - \color{blue}{\left(b \cdot b + \left(a \cdot c\right) \cdot -3\right)}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
associate--r+ [=>]17.2 | \[ \frac{-0.3333333333333333}{a} \cdot \frac{\color{blue}{\left(b \cdot b - b \cdot b\right) - \left(a \cdot c\right) \cdot -3}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
distribute-lft-out-- [=>]17.2 | \[ \frac{-0.3333333333333333}{a} \cdot \frac{\color{blue}{b \cdot \left(b - b\right)} - \left(a \cdot c\right) \cdot -3}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
*-commutative [<=]17.2 | \[ \frac{-0.3333333333333333}{a} \cdot \frac{b \cdot \left(b - b\right) - \color{blue}{\left(c \cdot a\right)} \cdot -3}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
associate-*l* [=>]17.2 | \[ \frac{-0.3333333333333333}{a} \cdot \frac{b \cdot \left(b - b\right) - \color{blue}{c \cdot \left(a \cdot -3\right)}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
Applied egg-rr17.2
Simplified17.2
[Start]17.2 | \[ \frac{-0.3333333333333333}{a} \cdot \left(\frac{b \cdot \left(b - b\right) - c \cdot \left(a \cdot -3\right)}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}} + \frac{0}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}\right)
\] |
|---|---|
div0 [=>]17.2 | \[ \frac{-0.3333333333333333}{a} \cdot \left(\frac{b \cdot \left(b - b\right) - c \cdot \left(a \cdot -3\right)}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}} + \color{blue}{0}\right)
\] |
+-rgt-identity [=>]17.2 | \[ \frac{-0.3333333333333333}{a} \cdot \color{blue}{\frac{b \cdot \left(b - b\right) - c \cdot \left(a \cdot -3\right)}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}
\] |
+-inverses [=>]17.2 | \[ \frac{-0.3333333333333333}{a} \cdot \frac{b \cdot \color{blue}{0} - c \cdot \left(a \cdot -3\right)}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
mul0-rgt [=>]17.2 | \[ \frac{-0.3333333333333333}{a} \cdot \frac{\color{blue}{0} - c \cdot \left(a \cdot -3\right)}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
neg-sub0 [<=]17.2 | \[ \frac{-0.3333333333333333}{a} \cdot \frac{\color{blue}{-c \cdot \left(a \cdot -3\right)}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
associate-*r* [=>]17.2 | \[ \frac{-0.3333333333333333}{a} \cdot \frac{-\color{blue}{\left(c \cdot a\right) \cdot -3}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
distribute-rgt-neg-in [=>]17.2 | \[ \frac{-0.3333333333333333}{a} \cdot \frac{\color{blue}{\left(c \cdot a\right) \cdot \left(--3\right)}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
metadata-eval [=>]17.2 | \[ \frac{-0.3333333333333333}{a} \cdot \frac{\left(c \cdot a\right) \cdot \color{blue}{3}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
Applied egg-rr50.4
Simplified9.5
[Start]50.4 | \[ e^{\mathsf{log1p}\left(\frac{-0.3333333333333333}{a} \cdot \frac{\left(c \cdot a\right) \cdot 3}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}\right)} - 1
\] |
|---|---|
expm1-def [=>]28.5 | \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-0.3333333333333333}{a} \cdot \frac{\left(c \cdot a\right) \cdot 3}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}\right)\right)}
\] |
expm1-log1p [=>]17.2 | \[ \color{blue}{\frac{-0.3333333333333333}{a} \cdot \frac{\left(c \cdot a\right) \cdot 3}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}
\] |
associate-*l/ [=>]17.2 | \[ \color{blue}{\frac{-0.3333333333333333 \cdot \frac{\left(c \cdot a\right) \cdot 3}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}{a}}
\] |
*-commutative [=>]17.2 | \[ \frac{-0.3333333333333333 \cdot \frac{\color{blue}{3 \cdot \left(c \cdot a\right)}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}{a}
\] |
associate-/l* [=>]17.4 | \[ \frac{-0.3333333333333333 \cdot \color{blue}{\frac{3}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{c \cdot a}}}}{a}
\] |
associate-*r/ [=>]17.3 | \[ \frac{\color{blue}{\frac{-0.3333333333333333 \cdot 3}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{c \cdot a}}}}{a}
\] |
metadata-eval [=>]17.3 | \[ \frac{\frac{\color{blue}{-1}}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{c \cdot a}}}{a}
\] |
associate-/l* [<=]17.1 | \[ \frac{\color{blue}{\frac{-1 \cdot \left(c \cdot a\right)}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}}{a}
\] |
associate-/r* [<=]21.8 | \[ \color{blue}{\frac{-1 \cdot \left(c \cdot a\right)}{\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right) \cdot a}}
\] |
associate-/l/ [<=]16.4 | \[ \color{blue}{\frac{\frac{-1 \cdot \left(c \cdot a\right)}{a}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}
\] |
mul-1-neg [=>]16.4 | \[ \frac{\frac{\color{blue}{-c \cdot a}}{a}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
distribute-rgt-neg-in [=>]16.4 | \[ \frac{\frac{\color{blue}{c \cdot \left(-a\right)}}{a}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
associate-/l* [=>]9.5 | \[ \frac{\color{blue}{\frac{c}{\frac{a}{-a}}}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
Applied egg-rr9.5
if 9.99999999999999959e87 < b Initial program 58.5
Simplified58.5
[Start]58.5 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
remove-double-neg [<=]58.5 | \[ \frac{\left(-b\right) + \color{blue}{\left(-\left(-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)\right)}}{3 \cdot a}
\] |
sub-neg [<=]58.5 | \[ \frac{\color{blue}{\left(-b\right) - \left(-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}{3 \cdot a}
\] |
div-sub [=>]59.2 | \[ \color{blue}{\frac{-b}{3 \cdot a} - \frac{-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}}
\] |
neg-mul-1 [=>]59.2 | \[ \frac{\color{blue}{-1 \cdot b}}{3 \cdot a} - \frac{-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
associate-*l/ [<=]60.1 | \[ \color{blue}{\frac{-1}{3 \cdot a} \cdot b} - \frac{-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
distribute-frac-neg [=>]60.1 | \[ \frac{-1}{3 \cdot a} \cdot b - \color{blue}{\left(-\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\right)}
\] |
fma-neg [=>]62.7 | \[ \color{blue}{\mathsf{fma}\left(\frac{-1}{3 \cdot a}, b, -\left(-\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\right)\right)}
\] |
/-rgt-identity [<=]62.7 | \[ \mathsf{fma}\left(\frac{-1}{3 \cdot a}, \color{blue}{\frac{b}{1}}, -\left(-\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\right)\right)
\] |
metadata-eval [<=]62.7 | \[ \mathsf{fma}\left(\frac{-1}{3 \cdot a}, \frac{b}{\color{blue}{\frac{-1}{-1}}}, -\left(-\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\right)\right)
\] |
associate-/l* [<=]62.7 | \[ \mathsf{fma}\left(\frac{-1}{3 \cdot a}, \color{blue}{\frac{b \cdot -1}{-1}}, -\left(-\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\right)\right)
\] |
*-commutative [<=]62.7 | \[ \mathsf{fma}\left(\frac{-1}{3 \cdot a}, \frac{\color{blue}{-1 \cdot b}}{-1}, -\left(-\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\right)\right)
\] |
neg-mul-1 [<=]62.7 | \[ \mathsf{fma}\left(\frac{-1}{3 \cdot a}, \frac{\color{blue}{-b}}{-1}, -\left(-\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\right)\right)
\] |
fma-neg [<=]60.1 | \[ \color{blue}{\frac{-1}{3 \cdot a} \cdot \frac{-b}{-1} - \left(-\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\right)}
\] |
neg-mul-1 [=>]60.1 | \[ \frac{-1}{3 \cdot a} \cdot \frac{-b}{-1} - \color{blue}{-1 \cdot \frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}}
\] |
Taylor expanded in b around inf 3.1
Final simplification6.7
| Alternative 1 | |
|---|---|
| Error | 10.3 |
| Cost | 7624 |
| Alternative 2 | |
|---|---|
| Error | 10.2 |
| Cost | 7624 |
| Alternative 3 | |
|---|---|
| Error | 14.2 |
| Cost | 7368 |
| Alternative 4 | |
|---|---|
| Error | 14.1 |
| Cost | 7368 |
| Alternative 5 | |
|---|---|
| Error | 14.1 |
| Cost | 7368 |
| Alternative 6 | |
|---|---|
| Error | 14.1 |
| Cost | 7368 |
| Alternative 7 | |
|---|---|
| Error | 14.1 |
| Cost | 7368 |
| Alternative 8 | |
|---|---|
| Error | 22.6 |
| Cost | 580 |
| Alternative 9 | |
|---|---|
| Error | 22.6 |
| Cost | 452 |
| Alternative 10 | |
|---|---|
| Error | 39.9 |
| Cost | 320 |
herbie shell --seed 2023187
(FPCore (a b c)
:name "Cubic critical"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))