| Alternative 1 | |
|---|---|
| Error | 10.7 |
| 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 -9.5e+120)
(/ (/ (* b 2.0) -3.0) a)
(if (<= b 1.25e-75)
(/ (/ (- b (sqrt (+ (* -3.0 (* a c)) (* b b)))) a) -3.0)
(if (<= b 4000.0)
(/
(+ (* b (- b b)) (* c (* a 3.0)))
(/ (+ b (sqrt (fma a (* -3.0 c) (* b b)))) (/ -0.3333333333333333 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 <= -9.5e+120) {
tmp = ((b * 2.0) / -3.0) / a;
} else if (b <= 1.25e-75) {
tmp = ((b - sqrt(((-3.0 * (a * c)) + (b * b)))) / a) / -3.0;
} else if (b <= 4000.0) {
tmp = ((b * (b - b)) + (c * (a * 3.0))) / ((b + sqrt(fma(a, (-3.0 * c), (b * b)))) / (-0.3333333333333333 / 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 <= -9.5e+120) tmp = Float64(Float64(Float64(b * 2.0) / -3.0) / a); elseif (b <= 1.25e-75) tmp = Float64(Float64(Float64(b - sqrt(Float64(Float64(-3.0 * Float64(a * c)) + Float64(b * b)))) / a) / -3.0); elseif (b <= 4000.0) tmp = Float64(Float64(Float64(b * Float64(b - b)) + Float64(c * Float64(a * 3.0))) / Float64(Float64(b + sqrt(fma(a, Float64(-3.0 * c), Float64(b * b)))) / Float64(-0.3333333333333333 / 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, -9.5e+120], N[(N[(N[(b * 2.0), $MachinePrecision] / -3.0), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b, 1.25e-75], N[(N[(N[(b - N[Sqrt[N[(N[(-3.0 * N[(a * c), $MachinePrecision]), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision] / -3.0), $MachinePrecision], If[LessEqual[b, 4000.0], N[(N[(N[(b * N[(b - b), $MachinePrecision]), $MachinePrecision] + N[(c * N[(a * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(b + N[Sqrt[N[(a * N[(-3.0 * c), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(-0.3333333333333333 / a), $MachinePrecision]), $MachinePrecision]), $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 -9.5 \cdot 10^{+120}:\\
\;\;\;\;\frac{\frac{b \cdot 2}{-3}}{a}\\
\mathbf{elif}\;b \leq 1.25 \cdot 10^{-75}:\\
\;\;\;\;\frac{\frac{b - \sqrt{-3 \cdot \left(a \cdot c\right) + b \cdot b}}{a}}{-3}\\
\mathbf{elif}\;b \leq 4000:\\
\;\;\;\;\frac{b \cdot \left(b - b\right) + c \cdot \left(a \cdot 3\right)}{\frac{b + \sqrt{\mathsf{fma}\left(a, -3 \cdot c, b \cdot b\right)}}{\frac{-0.3333333333333333}{a}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot -0.5}{b}\\
\end{array}
if b < -9.5e120Initial program 52.4
Applied egg-rr52.4
Simplified52.4
[Start]52.4 | \[ \frac{b - \sqrt{\mathsf{fma}\left(b, b, -3 \cdot \left(a \cdot c\right)\right)}}{-3} \cdot \frac{1}{a}
\] |
|---|---|
*-commutative [<=]52.4 | \[ \color{blue}{\frac{1}{a} \cdot \frac{b - \sqrt{\mathsf{fma}\left(b, b, -3 \cdot \left(a \cdot c\right)\right)}}{-3}}
\] |
associate-*l/ [=>]52.4 | \[ \color{blue}{\frac{1 \cdot \frac{b - \sqrt{\mathsf{fma}\left(b, b, -3 \cdot \left(a \cdot c\right)\right)}}{-3}}{a}}
\] |
*-lft-identity [=>]52.4 | \[ \frac{\color{blue}{\frac{b - \sqrt{\mathsf{fma}\left(b, b, -3 \cdot \left(a \cdot c\right)\right)}}{-3}}}{a}
\] |
fma-def [<=]52.4 | \[ \frac{\frac{b - \sqrt{\color{blue}{b \cdot b + -3 \cdot \left(a \cdot c\right)}}}{-3}}{a}
\] |
+-commutative [=>]52.4 | \[ \frac{\frac{b - \sqrt{\color{blue}{-3 \cdot \left(a \cdot c\right) + b \cdot b}}}{-3}}{a}
\] |
fma-def [=>]52.4 | \[ \frac{\frac{b - \sqrt{\color{blue}{\mathsf{fma}\left(-3, a \cdot c, b \cdot b\right)}}}{-3}}{a}
\] |
*-commutative [=>]52.4 | \[ \frac{\frac{b - \sqrt{\mathsf{fma}\left(-3, \color{blue}{c \cdot a}, b \cdot b\right)}}{-3}}{a}
\] |
Taylor expanded in b around -inf 3.8
Simplified3.8
[Start]3.8 | \[ \frac{\frac{2 \cdot b}{-3}}{a}
\] |
|---|---|
*-commutative [=>]3.8 | \[ \frac{\frac{\color{blue}{b \cdot 2}}{-3}}{a}
\] |
if -9.5e120 < b < 1.24999999999999995e-75Initial program 12.9
Simplified13.1
[Start]12.9 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
remove-double-neg [<=]12.9 | \[ \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 [<=]12.9 | \[ \frac{\color{blue}{\left(-b\right) - \left(-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}{3 \cdot a}
\] |
div-sub [=>]12.9 | \[ \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 [=>]12.9 | \[ \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/ [<=]12.9 | \[ \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 [=>]12.9 | \[ \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 [=>]12.9 | \[ \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 [<=]12.9 | \[ \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 [<=]12.9 | \[ \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* [<=]12.9 | \[ \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 [<=]12.9 | \[ \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 [<=]12.9 | \[ \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 [<=]12.9 | \[ \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 [=>]12.9 | \[ \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}}
\] |
Applied egg-rr13.0
Applied egg-rr13.0
if 1.24999999999999995e-75 < b < 4e3Initial program 39.3
Simplified39.4
[Start]39.3 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
*-lft-identity [<=]39.3 | \[ \color{blue}{1 \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}}
\] |
metadata-eval [<=]39.3 | \[ \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 [<=]39.3 | \[ \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 [<=]39.3 | \[ \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 [=>]39.3 | \[ \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 [=>]39.4 | \[ \color{blue}{\frac{-1}{3} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-a}}
\] |
*-commutative [=>]39.4 | \[ \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-a} \cdot \frac{-1}{3}}
\] |
Applied egg-rr42.8
Simplified20.5
[Start]42.8 | \[ \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)}
\] |
|---|---|
associate-/r* [=>]39.4 | \[ \color{blue}{\frac{\frac{\left(b \cdot b - \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right) \cdot -0.3333333333333333}{a}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}
\] |
associate-*r/ [<=]39.4 | \[ \frac{\color{blue}{\left(b \cdot b - \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right) \cdot \frac{-0.3333333333333333}{a}}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
associate-/l* [=>]42.8 | \[ \color{blue}{\frac{b \cdot b - \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{\frac{-0.3333333333333333}{a}}}}
\] |
fma-udef [=>]42.8 | \[ \frac{b \cdot b - \color{blue}{\left(a \cdot \left(c \cdot -3\right) + b \cdot b\right)}}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{\frac{-0.3333333333333333}{a}}}
\] |
associate-*l* [<=]42.8 | \[ \frac{b \cdot b - \left(\color{blue}{\left(a \cdot c\right) \cdot -3} + b \cdot b\right)}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{\frac{-0.3333333333333333}{a}}}
\] |
+-commutative [=>]42.8 | \[ \frac{b \cdot b - \color{blue}{\left(b \cdot b + \left(a \cdot c\right) \cdot -3\right)}}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{\frac{-0.3333333333333333}{a}}}
\] |
associate--r+ [=>]20.5 | \[ \frac{\color{blue}{\left(b \cdot b - b \cdot b\right) - \left(a \cdot c\right) \cdot -3}}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{\frac{-0.3333333333333333}{a}}}
\] |
distribute-lft-out-- [=>]20.5 | \[ \frac{\color{blue}{b \cdot \left(b - b\right)} - \left(a \cdot c\right) \cdot -3}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{\frac{-0.3333333333333333}{a}}}
\] |
associate-*l* [=>]20.5 | \[ \frac{b \cdot \left(b - b\right) - \color{blue}{a \cdot \left(c \cdot -3\right)}}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{\frac{-0.3333333333333333}{a}}}
\] |
*-commutative [=>]20.5 | \[ \frac{b \cdot \left(b - b\right) - \color{blue}{\left(c \cdot -3\right) \cdot a}}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{\frac{-0.3333333333333333}{a}}}
\] |
associate-*l* [=>]20.5 | \[ \frac{b \cdot \left(b - b\right) - \color{blue}{c \cdot \left(-3 \cdot a\right)}}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{\frac{-0.3333333333333333}{a}}}
\] |
if 4e3 < b Initial program 56.3
Simplified56.3
[Start]56.3 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
remove-double-neg [<=]56.3 | \[ \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 [<=]56.3 | \[ \frac{\color{blue}{\left(-b\right) - \left(-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}{3 \cdot a}
\] |
div-sub [=>]57.0 | \[ \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 [=>]57.0 | \[ \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/ [<=]57.8 | \[ \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 [=>]57.8 | \[ \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 [=>]60.6 | \[ \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 [<=]60.6 | \[ \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 [<=]60.6 | \[ \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* [<=]60.6 | \[ \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 [<=]60.6 | \[ \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 [<=]60.6 | \[ \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 [<=]57.8 | \[ \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 [=>]57.8 | \[ \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 5.2
Applied egg-rr5.2
Final simplification9.6
| Alternative 1 | |
|---|---|
| Error | 10.7 |
| Cost | 7624 |
| Alternative 2 | |
|---|---|
| Error | 10.7 |
| Cost | 7624 |
| Alternative 3 | |
|---|---|
| Error | 14.2 |
| Cost | 7368 |
| Alternative 4 | |
|---|---|
| Error | 14.2 |
| Cost | 7368 |
| Alternative 5 | |
|---|---|
| Error | 14.2 |
| Cost | 7368 |
| Alternative 6 | |
|---|---|
| Error | 14.2 |
| Cost | 7368 |
| Alternative 7 | |
|---|---|
| Error | 22.9 |
| Cost | 580 |
| Alternative 8 | |
|---|---|
| Error | 22.9 |
| Cost | 452 |
| Alternative 9 | |
|---|---|
| Error | 22.9 |
| Cost | 452 |
| Alternative 10 | |
|---|---|
| Error | 22.9 |
| Cost | 452 |
| Alternative 11 | |
|---|---|
| Error | 22.9 |
| Cost | 452 |
| Alternative 12 | |
|---|---|
| Error | 39.2 |
| Cost | 320 |
herbie shell --seed 2023039
(FPCore (a b c)
:name "Cubic critical"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))