| Alternative 1 | |
|---|---|
| Error | 99.4% |
| Cost | 7744.00 |
(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 32.3
Simplified32.3
[Start]32.3 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
remove-double-neg [<=]32.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 [<=]32.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 [=>]31.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 [=>]31.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/ [<=]32.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 [=>]32.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 [=>]33.5 | \[ \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 [<=]33.5 | \[ \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 [<=]33.5 | \[ \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* [<=]33.5 | \[ \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 [<=]33.5 | \[ \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 [<=]33.5 | \[ \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 [<=]32.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 [=>]32.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}}
\] |
Applied egg-rr33.2
Taylor expanded in b around 0 99.1
Simplified99.3
[Start]99.1 | \[ \frac{3 \cdot \left(c \cdot a\right)}{\frac{a \cdot -3}{\frac{1}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}}
\] |
|---|---|
*-commutative [=>]99.1 | \[ \frac{\color{blue}{\left(c \cdot a\right) \cdot 3}}{\frac{a \cdot -3}{\frac{1}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}}
\] |
associate-*l* [=>]99.3 | \[ \frac{\color{blue}{c \cdot \left(a \cdot 3\right)}}{\frac{a \cdot -3}{\frac{1}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}}
\] |
*-commutative [=>]99.3 | \[ \frac{c \cdot \color{blue}{\left(3 \cdot a\right)}}{\frac{a \cdot -3}{\frac{1}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}}
\] |
Applied egg-rr99.4
Applied egg-rr52.2
Simplified99.7
[Start]52.2 | \[ -\left(e^{\mathsf{log1p}\left(\left(\frac{c}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}} \cdot \left(3 \cdot a\right)\right) \cdot \frac{0.3333333333333333}{a}\right)} - 1\right)
\] |
|---|---|
expm1-def [=>]98.9 | \[ -\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(\frac{c}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}} \cdot \left(3 \cdot a\right)\right) \cdot \frac{0.3333333333333333}{a}\right)\right)}
\] |
expm1-log1p [=>]99.2 | \[ -\color{blue}{\left(\frac{c}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}} \cdot \left(3 \cdot a\right)\right) \cdot \frac{0.3333333333333333}{a}}
\] |
associate-*l* [=>]99.1 | \[ -\color{blue}{\frac{c}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}} \cdot \left(\left(3 \cdot a\right) \cdot \frac{0.3333333333333333}{a}\right)}
\] |
*-commutative [<=]99.1 | \[ -\frac{c}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}} \cdot \color{blue}{\left(\frac{0.3333333333333333}{a} \cdot \left(3 \cdot a\right)\right)}
\] |
associate-*l/ [=>]99.1 | \[ -\color{blue}{\frac{c \cdot \left(\frac{0.3333333333333333}{a} \cdot \left(3 \cdot a\right)\right)}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}
\] |
associate-*l/ [=>]99.3 | \[ -\frac{c \cdot \color{blue}{\frac{0.3333333333333333 \cdot \left(3 \cdot a\right)}{a}}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
associate-*r/ [=>]99.3 | \[ -\frac{\color{blue}{\frac{c \cdot \left(0.3333333333333333 \cdot \left(3 \cdot a\right)\right)}{a}}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
associate-*l* [<=]99.2 | \[ -\frac{\frac{\color{blue}{\left(c \cdot 0.3333333333333333\right) \cdot \left(3 \cdot a\right)}}{a}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
associate-/l/ [=>]99.1 | \[ -\color{blue}{\frac{\left(c \cdot 0.3333333333333333\right) \cdot \left(3 \cdot a\right)}{\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right) \cdot a}}
\] |
times-frac [=>]99.1 | \[ -\color{blue}{\frac{c \cdot 0.3333333333333333}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}} \cdot \frac{3 \cdot a}{a}}
\] |
associate-*l/ [=>]99.2 | \[ -\color{blue}{\frac{\left(c \cdot 0.3333333333333333\right) \cdot \frac{3 \cdot a}{a}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}
\] |
associate-/l* [=>]99.4 | \[ -\frac{\left(c \cdot 0.3333333333333333\right) \cdot \color{blue}{\frac{3}{\frac{a}{a}}}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
*-inverses [=>]99.4 | \[ -\frac{\left(c \cdot 0.3333333333333333\right) \cdot \frac{3}{\color{blue}{1}}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
metadata-eval [=>]99.4 | \[ -\frac{\left(c \cdot 0.3333333333333333\right) \cdot \color{blue}{3}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
associate-*l* [=>]99.7 | \[ -\frac{\color{blue}{c \cdot \left(0.3333333333333333 \cdot 3\right)}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
metadata-eval [=>]99.7 | \[ -\frac{c \cdot \color{blue}{1}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
*-rgt-identity [=>]99.7 | \[ -\frac{\color{blue}{c}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
remove-double-neg [<=]99.7 | \[ -\frac{\color{blue}{-\left(-c\right)}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
Final simplification99.7
| Alternative 1 | |
|---|---|
| Error | 99.4% |
| Cost | 7744.00 |
| Alternative 2 | |
|---|---|
| Error | 90.3% |
| Cost | 1088.00 |
| Alternative 3 | |
|---|---|
| Error | 90.2% |
| Cost | 960.00 |
| Alternative 4 | |
|---|---|
| Error | 90.2% |
| Cost | 960.00 |
| Alternative 5 | |
|---|---|
| Error | 80.6% |
| Cost | 320.00 |
herbie shell --seed 2023098
(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)))