| Alternative 1 | |
|---|---|
| Error | 0.5 |
| Cost | 8256 |
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))
(FPCore (a b c) :precision binary64 (/ (- c) (+ b (sqrt (fma a (* c -3.0) (* b 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) {
return -c / (b + sqrt(fma(a, (c * -3.0), (b * b))));
}
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) return Float64(Float64(-c) / Float64(b + sqrt(fma(a, Float64(c * -3.0), Float64(b * b))))) 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_] := N[((-c) / N[(b + N[Sqrt[N[(a * N[(c * -3.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\frac{-c}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
Initial program 52.8
Simplified52.8
[Start]52.8 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
remove-double-neg [<=]52.8 | \[ \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 [<=]52.8 | \[ \frac{\color{blue}{\left(-b\right) - \left(-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}{3 \cdot a}
\] |
div-sub [=>]53.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 [=>]53.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/ [<=]52.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 [=>]52.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 [=>]52.0 | \[ \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 [<=]52.0 | \[ \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 [<=]52.0 | \[ \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* [<=]52.0 | \[ \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 [<=]52.0 | \[ \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 [<=]52.0 | \[ \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 [<=]52.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 [=>]52.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}}
\] |
Applied egg-rr52.5
Applied egg-rr0.5
Applied egg-rr51.4
Simplified0.4
[Start]51.4 | \[ e^{\mathsf{log1p}\left(\frac{\left(-a \cdot \left(c \cdot -3\right)\right) + \left(\left(-b \cdot b\right) + b \cdot b\right)}{\left(a \cdot -3\right) \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}\right)} - 1
\] |
|---|---|
expm1-def [=>]10.7 | \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\left(-a \cdot \left(c \cdot -3\right)\right) + \left(\left(-b \cdot b\right) + b \cdot b\right)}{\left(a \cdot -3\right) \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}\right)\right)}
\] |
expm1-log1p [=>]0.5 | \[ \color{blue}{\frac{\left(-a \cdot \left(c \cdot -3\right)\right) + \left(\left(-b \cdot b\right) + b \cdot b\right)}{\left(a \cdot -3\right) \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}}
\] |
rem-3cbrt-lft [<=]1.4 | \[ \frac{\color{blue}{\left(\sqrt[3]{\left(-a \cdot \left(c \cdot -3\right)\right) + \left(\left(-b \cdot b\right) + b \cdot b\right)} \cdot \sqrt[3]{\left(-a \cdot \left(c \cdot -3\right)\right) + \left(\left(-b \cdot b\right) + b \cdot b\right)}\right) \cdot \sqrt[3]{\left(-a \cdot \left(c \cdot -3\right)\right) + \left(\left(-b \cdot b\right) + b \cdot b\right)}}}{\left(a \cdot -3\right) \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}
\] |
unpow2 [<=]1.4 | \[ \frac{\color{blue}{{\left(\sqrt[3]{\left(-a \cdot \left(c \cdot -3\right)\right) + \left(\left(-b \cdot b\right) + b \cdot b\right)}\right)}^{2}} \cdot \sqrt[3]{\left(-a \cdot \left(c \cdot -3\right)\right) + \left(\left(-b \cdot b\right) + b \cdot b\right)}}{\left(a \cdot -3\right) \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}
\] |
associate-/r* [=>]1.4 | \[ \color{blue}{\frac{\frac{{\left(\sqrt[3]{\left(-a \cdot \left(c \cdot -3\right)\right) + \left(\left(-b \cdot b\right) + b \cdot b\right)}\right)}^{2} \cdot \sqrt[3]{\left(-a \cdot \left(c \cdot -3\right)\right) + \left(\left(-b \cdot b\right) + b \cdot b\right)}}{a \cdot -3}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}
\] |
Taylor expanded in a around 0 0.1
Simplified0.1
[Start]0.1 | \[ \frac{-1 \cdot c + -0.3333333333333333 \cdot \frac{-1 \cdot {b}^{2} + {b}^{2}}{a}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
|---|---|
distribute-lft1-in [=>]0.1 | \[ \frac{-1 \cdot c + -0.3333333333333333 \cdot \frac{\color{blue}{\left(-1 + 1\right) \cdot {b}^{2}}}{a}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
metadata-eval [=>]0.1 | \[ \frac{-1 \cdot c + -0.3333333333333333 \cdot \frac{\color{blue}{0} \cdot {b}^{2}}{a}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
associate-*r/ [<=]0.1 | \[ \frac{-1 \cdot c + -0.3333333333333333 \cdot \color{blue}{\left(0 \cdot \frac{{b}^{2}}{a}\right)}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
mul0-lft [=>]0.1 | \[ \frac{-1 \cdot c + -0.3333333333333333 \cdot \color{blue}{0}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
metadata-eval [=>]0.1 | \[ \frac{-1 \cdot c + \color{blue}{0}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
+-commutative [=>]0.1 | \[ \frac{\color{blue}{0 + -1 \cdot c}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
mul-1-neg [=>]0.1 | \[ \frac{0 + \color{blue}{\left(-c\right)}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
unsub-neg [=>]0.1 | \[ \frac{\color{blue}{0 - c}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
neg-sub0 [<=]0.1 | \[ \frac{\color{blue}{-c}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
Final simplification0.1
| Alternative 1 | |
|---|---|
| Error | 0.5 |
| Cost | 8256 |
| Alternative 2 | |
|---|---|
| Error | 0.4 |
| Cost | 8256 |
| Alternative 3 | |
|---|---|
| Error | 3.0 |
| Cost | 960 |
| Alternative 4 | |
|---|---|
| Error | 3.0 |
| Cost | 960 |
| Alternative 5 | |
|---|---|
| Error | 3.0 |
| Cost | 960 |
| Alternative 6 | |
|---|---|
| Error | 6.2 |
| Cost | 320 |
| Alternative 7 | |
|---|---|
| Error | 6.0 |
| Cost | 320 |
herbie shell --seed 2023187
(FPCore (a b c)
:name "Cubic critical, wide range"
:precision binary64
:pre (and (and (and (< 4.930380657631324e-32 a) (< a 2.028240960365167e+31)) (and (< 4.930380657631324e-32 b) (< b 2.028240960365167e+31))) (and (< 4.930380657631324e-32 c) (< c 2.028240960365167e+31)))
(/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))