| Alternative 1 | |
|---|---|
| Error | 99.3% |
| Cost | 13824.00 |
\[\frac{c}{a} \cdot \frac{-a}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\]
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))
(FPCore (a b c) :precision binary64 (/ (/ (* c (- a)) (+ b (sqrt (fma a (* c -3.0) (* b b))))) a))
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 * -a) / (b + sqrt(fma(a, (c * -3.0), (b * b))))) / a;
}
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(Float64(c * Float64(-a)) / Float64(b + sqrt(fma(a, Float64(c * -3.0), Float64(b * b))))) / a) 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[(N[(N[(c * (-a)), $MachinePrecision] / N[(b + N[Sqrt[N[(a * N[(c * -3.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\frac{\frac{c \cdot \left(-a\right)}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}{a}
Initial program 55.7
Simplified55.7
[Start]55.7 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
*-lft-identity [<=]55.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 [<=]55.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 [<=]55.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 [<=]55.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 [=>]55.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 [=>]55.7 | \[ \color{blue}{\frac{-1}{3} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-a}}
\] |
*-commutative [=>]55.7 | \[ \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-a} \cdot \frac{-1}{3}}
\] |
Applied egg-rr57.1
Simplified57.1
[Start]57.1 | \[ \frac{\left(b \cdot b - \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right) \cdot \frac{1}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}{a} \cdot -0.3333333333333333
\] |
|---|---|
associate-*r/ [=>]57.1 | \[ \frac{\color{blue}{\frac{\left(b \cdot b - \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right) \cdot 1}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}}{a} \cdot -0.3333333333333333
\] |
*-rgt-identity [=>]57.1 | \[ \frac{\frac{\color{blue}{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)}}}{a} \cdot -0.3333333333333333
\] |
Taylor expanded in b around 0 99.1
Applied egg-rr61.8
Simplified99.3
[Start]61.8 | \[ e^{\mathsf{log1p}\left(\frac{-1 \cdot \frac{c \cdot a}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}{a}\right)} - 1
\] |
|---|---|
expm1-def [=>]85.0 | \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1 \cdot \frac{c \cdot a}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}{a}\right)\right)}
\] |
expm1-log1p [=>]99.3 | \[ \color{blue}{\frac{-1 \cdot \frac{c \cdot a}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}{a}}
\] |
associate-*r/ [=>]99.3 | \[ \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}
\] |
neg-mul-1 [<=]99.3 | \[ \frac{\frac{\color{blue}{-c \cdot a}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}{a}
\] |
distribute-rgt-neg-in [=>]99.3 | \[ \frac{\frac{\color{blue}{c \cdot \left(-a\right)}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}{a}
\] |
Final simplification99.3
| Alternative 1 | |
|---|---|
| Error | 99.3% |
| Cost | 13824.00 |
| Alternative 2 | |
|---|---|
| Error | 85.3% |
| Cost | 13764.00 |
| Alternative 3 | |
|---|---|
| Error | 85.3% |
| Cost | 13764.00 |
| Alternative 4 | |
|---|---|
| Error | 85.3% |
| Cost | 13764.00 |
| Alternative 5 | |
|---|---|
| Error | 85.3% |
| Cost | 7492.00 |
| Alternative 6 | |
|---|---|
| Error | 85.3% |
| Cost | 7492.00 |
| Alternative 7 | |
|---|---|
| Error | 82.0% |
| Cost | 832.00 |
| Alternative 8 | |
|---|---|
| Error | 64.2% |
| Cost | 320.00 |
herbie shell --seed 2023093
(FPCore (a b c)
:name "Cubic critical, narrow range"
:precision binary64
:pre (and (and (and (< 1.0536712127723509e-8 a) (< a 94906265.62425156)) (and (< 1.0536712127723509e-8 b) (< b 94906265.62425156))) (and (< 1.0536712127723509e-8 c) (< c 94906265.62425156)))
(/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))