| Alternative 1 | |
|---|---|
| Error | 5.9 |
| Cost | 896 |
\[\frac{-c}{-1.5 \cdot \frac{c \cdot a}{b} + b \cdot 2}
\]
(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 43.5
Simplified43.5
[Start]43.5 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
remove-double-neg [<=]43.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 [<=]43.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 [=>]43.8 | \[ \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 [=>]43.8 | \[ \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/ [<=]43.6 | \[ \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 [=>]43.6 | \[ \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 [=>]42.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 [<=]42.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 [<=]42.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* [<=]42.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 [<=]42.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 [<=]42.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 [<=]43.6 | \[ \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 [=>]43.6 | \[ \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-rr42.9
Simplified42.9
[Start]42.9 | \[ \frac{\frac{\frac{-0.3333333333333333}{a} \cdot \left(b \cdot b - \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right)}{\sqrt{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}}{\sqrt{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}
\] |
|---|---|
associate-/l/ [=>]42.9 | \[ \color{blue}{\frac{\frac{-0.3333333333333333}{a} \cdot \left(b \cdot b - \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right)}{\sqrt{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}} \cdot \sqrt{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}}
\] |
*-commutative [=>]42.9 | \[ \frac{\color{blue}{\left(b \cdot b - \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right) \cdot \frac{-0.3333333333333333}{a}}}{\sqrt{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}} \cdot \sqrt{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}
\] |
Taylor expanded in b around 0 0.5
Simplified0.5
[Start]0.5 | \[ \frac{-1 \cdot c}{\sqrt{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}} \cdot \sqrt{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}
\] |
|---|---|
mul-1-neg [=>]0.5 | \[ \frac{\color{blue}{-c}}{\sqrt{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}} \cdot \sqrt{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}
\] |
Applied egg-rr0.2
Final simplification0.2
| Alternative 1 | |
|---|---|
| Error | 5.9 |
| Cost | 896 |
| Alternative 2 | |
|---|---|
| Error | 12.3 |
| Cost | 320 |
herbie shell --seed 2023073
(FPCore (a b c)
:name "Cubic critical, medium range"
:precision binary64
:pre (and (and (and (< 1.1102230246251565e-16 a) (< a 9007199254740992.0)) (and (< 1.1102230246251565e-16 b) (< b 9007199254740992.0))) (and (< 1.1102230246251565e-16 c) (< c 9007199254740992.0)))
(/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))