| Alternative 1 | |
|---|---|
| Error | 10.0 |
| 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 -7.2e+114)
(* (+ (* -1.5 (/ c b)) (* 2.0 (/ b a))) -0.3333333333333333)
(if (<= b 3.3e-74)
(/
(+
(sqrt (* 0.1111111111111111 (fma b b (* c (* a -3.0)))))
(* b -0.3333333333333333))
a)
(* (/ c b) -0.5))))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 <= -7.2e+114) {
tmp = ((-1.5 * (c / b)) + (2.0 * (b / a))) * -0.3333333333333333;
} else if (b <= 3.3e-74) {
tmp = (sqrt((0.1111111111111111 * fma(b, b, (c * (a * -3.0))))) + (b * -0.3333333333333333)) / a;
} else {
tmp = (c / b) * -0.5;
}
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 <= -7.2e+114) tmp = Float64(Float64(Float64(-1.5 * Float64(c / b)) + Float64(2.0 * Float64(b / a))) * -0.3333333333333333); elseif (b <= 3.3e-74) tmp = Float64(Float64(sqrt(Float64(0.1111111111111111 * fma(b, b, Float64(c * Float64(a * -3.0))))) + Float64(b * -0.3333333333333333)) / a); else tmp = Float64(Float64(c / b) * -0.5); 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, -7.2e+114], N[(N[(N[(-1.5 * N[(c / b), $MachinePrecision]), $MachinePrecision] + N[(2.0 * N[(b / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -0.3333333333333333), $MachinePrecision], If[LessEqual[b, 3.3e-74], N[(N[(N[Sqrt[N[(0.1111111111111111 * N[(b * b + N[(c * N[(a * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + N[(b * -0.3333333333333333), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[(N[(c / b), $MachinePrecision] * -0.5), $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 -7.2 \cdot 10^{+114}:\\
\;\;\;\;\left(-1.5 \cdot \frac{c}{b} + 2 \cdot \frac{b}{a}\right) \cdot -0.3333333333333333\\
\mathbf{elif}\;b \leq 3.3 \cdot 10^{-74}:\\
\;\;\;\;\frac{\sqrt{0.1111111111111111 \cdot \mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)} + b \cdot -0.3333333333333333}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} \cdot -0.5\\
\end{array}
if b < -7.2000000000000001e114Initial program 50.4
Simplified50.5
[Start]50.4 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
*-lft-identity [<=]50.4 | \[ \color{blue}{1 \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}}
\] |
metadata-eval [<=]50.4 | \[ \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 [<=]50.4 | \[ \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 [<=]50.4 | \[ \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 [=>]50.4 | \[ \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 [=>]50.5 | \[ \color{blue}{\frac{-1}{3} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-a}}
\] |
*-commutative [=>]50.5 | \[ \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-a} \cdot \frac{-1}{3}}
\] |
Taylor expanded in b around -inf 3.2
if -7.2000000000000001e114 < b < 3.29999999999999996e-74Initial program 12.9
Simplified13.0
[Start]12.9 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
*-lft-identity [<=]12.9 | \[ \color{blue}{1 \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}}
\] |
metadata-eval [<=]12.9 | \[ \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 [<=]12.9 | \[ \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)}}
\] |
*-commutative [<=]12.9 | \[ \frac{\color{blue}{\left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot -1}}{-1 \cdot \left(3 \cdot a\right)}
\] |
times-frac [=>]13.0 | \[ \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-1} \cdot \frac{-1}{3 \cdot a}}
\] |
associate-*r/ [=>]12.9 | \[ \color{blue}{\frac{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-1} \cdot -1}{3 \cdot a}}
\] |
Applied egg-rr37.4
Simplified19.0
[Start]37.4 | \[ \frac{\left(e^{\mathsf{log1p}\left(\mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -3\right)}\right)\right)} - 1\right) - b}{3 \cdot a}
\] |
|---|---|
expm1-def [=>]20.6 | \[ \frac{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -3\right)}\right)\right)\right)} - b}{3 \cdot a}
\] |
expm1-log1p [=>]19.1 | \[ \frac{\color{blue}{\mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -3\right)}\right)} - b}{3 \cdot a}
\] |
associate-*r* [=>]19.1 | \[ \frac{\mathsf{hypot}\left(b, \sqrt{\color{blue}{\left(a \cdot c\right) \cdot -3}}\right) - b}{3 \cdot a}
\] |
*-commutative [=>]19.1 | \[ \frac{\mathsf{hypot}\left(b, \sqrt{\color{blue}{\left(c \cdot a\right)} \cdot -3}\right) - b}{3 \cdot a}
\] |
associate-*l* [=>]19.0 | \[ \frac{\mathsf{hypot}\left(b, \sqrt{\color{blue}{c \cdot \left(a \cdot -3\right)}}\right) - b}{3 \cdot a}
\] |
Applied egg-rr19.3
Simplified19.1
[Start]19.3 | \[ \frac{\sqrt{\mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -3\right)}\right) - b}}{a} \cdot \frac{\sqrt{\mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -3\right)}\right) - b}}{3}
\] |
|---|---|
associate-*l/ [=>]19.3 | \[ \color{blue}{\frac{\sqrt{\mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -3\right)}\right) - b} \cdot \frac{\sqrt{\mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -3\right)}\right) - b}}{3}}{a}}
\] |
associate-*r/ [=>]19.3 | \[ \frac{\color{blue}{\frac{\sqrt{\mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -3\right)}\right) - b} \cdot \sqrt{\mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -3\right)}\right) - b}}{3}}}{a}
\] |
rem-square-sqrt [=>]19.1 | \[ \frac{\frac{\color{blue}{\mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -3\right)}\right) - b}}{3}}{a}
\] |
Applied egg-rr19.1
Applied egg-rr13.0
if 3.29999999999999996e-74 < b Initial program 52.7
Simplified52.8
[Start]52.7 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
remove-double-neg [<=]52.7 | \[ \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.7 | \[ \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.5 | \[ \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.5 | \[ \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/ [<=]54.2 | \[ \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 [=>]54.2 | \[ \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 [=>]56.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 [<=]56.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 [<=]56.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* [<=]56.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 [<=]56.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 [<=]56.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 [<=]54.2 | \[ \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 [=>]54.2 | \[ \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 8.9
Final simplification10.0
| Alternative 1 | |
|---|---|
| Error | 10.0 |
| Cost | 7624 |
| Alternative 2 | |
|---|---|
| Error | 10.0 |
| Cost | 7624 |
| Alternative 3 | |
|---|---|
| Error | 13.2 |
| Cost | 7368 |
| Alternative 4 | |
|---|---|
| Error | 13.2 |
| Cost | 7368 |
| Alternative 5 | |
|---|---|
| Error | 22.4 |
| Cost | 964 |
| Alternative 6 | |
|---|---|
| Error | 22.3 |
| Cost | 836 |
| Alternative 7 | |
|---|---|
| Error | 22.4 |
| Cost | 580 |
| Alternative 8 | |
|---|---|
| Error | 36.2 |
| Cost | 452 |
| Alternative 9 | |
|---|---|
| Error | 22.4 |
| Cost | 452 |
| Alternative 10 | |
|---|---|
| Error | 22.4 |
| Cost | 452 |
| Alternative 11 | |
|---|---|
| Error | 39.4 |
| Cost | 320 |
herbie shell --seed 2023034
(FPCore (a b c)
:name "Cubic critical"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))