| Alternative 1 | |
|---|---|
| Error | 7.2 |
| Cost | 13964 |
(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 -1.55e+95)
(/ (fma b -0.6666666666666666 (* (/ c (/ b a)) 0.5)) a)
(if (<= b 4.8e-294)
(/ (- (sqrt (+ (* b b) (* c (* a -3.0)))) b) (* a 3.0))
(if (<= b 2.85e+78)
(/ c (- (- b) (sqrt (fma b b (* a (* c -3.0))))))
(* -0.5 (/ c 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) {
double tmp;
if (b <= -1.55e+95) {
tmp = fma(b, -0.6666666666666666, ((c / (b / a)) * 0.5)) / a;
} else if (b <= 4.8e-294) {
tmp = (sqrt(((b * b) + (c * (a * -3.0)))) - b) / (a * 3.0);
} else if (b <= 2.85e+78) {
tmp = c / (-b - sqrt(fma(b, b, (a * (c * -3.0)))));
} else {
tmp = -0.5 * (c / b);
}
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 <= -1.55e+95) tmp = Float64(fma(b, -0.6666666666666666, Float64(Float64(c / Float64(b / a)) * 0.5)) / a); elseif (b <= 4.8e-294) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) + Float64(c * Float64(a * -3.0)))) - b) / Float64(a * 3.0)); elseif (b <= 2.85e+78) tmp = Float64(c / Float64(Float64(-b) - sqrt(fma(b, b, Float64(a * Float64(c * -3.0)))))); else tmp = Float64(-0.5 * Float64(c / b)); 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, -1.55e+95], N[(N[(b * -0.6666666666666666 + N[(N[(c / N[(b / a), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b, 4.8e-294], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(c * N[(a * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.85e+78], N[(c / N[((-b) - N[Sqrt[N[(b * b + N[(a * N[(c * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[(c / b), $MachinePrecision]), $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 -1.55 \cdot 10^{+95}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, -0.6666666666666666, \frac{c}{\frac{b}{a}} \cdot 0.5\right)}{a}\\
\mathbf{elif}\;b \leq 4.8 \cdot 10^{-294}:\\
\;\;\;\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} - b}{a \cdot 3}\\
\mathbf{elif}\;b \leq 2.85 \cdot 10^{+78}:\\
\;\;\;\;\frac{c}{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -3\right)\right)}}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b}\\
\end{array}
if b < -1.5500000000000001e95Initial program 45.9
Simplified45.9
[Start]45.9 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
remove-double-neg [<=]45.9 | \[ \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 [<=]45.9 | \[ \frac{\color{blue}{\left(-b\right) - \left(-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}{3 \cdot a}
\] |
div-sub [=>]45.9 | \[ \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 [=>]45.9 | \[ \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/ [<=]45.9 | \[ \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 [=>]45.9 | \[ \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 [=>]45.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 [<=]45.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 [<=]45.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* [<=]45.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 [<=]45.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 [<=]45.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 [<=]45.9 | \[ \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 [=>]45.9 | \[ \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-rr45.9
Taylor expanded in b around -inf 10.6
Simplified4.3
[Start]10.6 | \[ \frac{0.5 \cdot \frac{c \cdot a}{b} + -0.6666666666666666 \cdot b}{a}
\] |
|---|---|
+-commutative [=>]10.6 | \[ \frac{\color{blue}{-0.6666666666666666 \cdot b + 0.5 \cdot \frac{c \cdot a}{b}}}{a}
\] |
*-commutative [=>]10.6 | \[ \frac{\color{blue}{b \cdot -0.6666666666666666} + 0.5 \cdot \frac{c \cdot a}{b}}{a}
\] |
fma-def [=>]10.6 | \[ \frac{\color{blue}{\mathsf{fma}\left(b, -0.6666666666666666, 0.5 \cdot \frac{c \cdot a}{b}\right)}}{a}
\] |
*-commutative [=>]10.6 | \[ \frac{\mathsf{fma}\left(b, -0.6666666666666666, \color{blue}{\frac{c \cdot a}{b} \cdot 0.5}\right)}{a}
\] |
associate-/l* [=>]4.3 | \[ \frac{\mathsf{fma}\left(b, -0.6666666666666666, \color{blue}{\frac{c}{\frac{b}{a}}} \cdot 0.5\right)}{a}
\] |
if -1.5500000000000001e95 < b < 4.79999999999999994e-294Initial program 10.4
if 4.79999999999999994e-294 < b < 2.84999999999999993e78Initial program 30.9
Simplified31.0
[Start]30.9 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
*-lft-identity [<=]30.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 [<=]30.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 [<=]30.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)}}
\] |
neg-mul-1 [<=]30.9 | \[ \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 [=>]30.9 | \[ \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 [=>]31.0 | \[ \color{blue}{\frac{-1}{3} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-a}}
\] |
*-commutative [=>]31.0 | \[ \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-a} \cdot \frac{-1}{3}}
\] |
Applied egg-rr31.0
Simplified16.7
[Start]31.0 | \[ \frac{\left(-\left(b \cdot b - \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right)\right) \cdot \frac{-0.3333333333333333}{a}}{-\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}
\] |
|---|
Taylor expanded in b around 0 9.0
Applied egg-rr9.0
Taylor expanded in a around 0 9.0
Simplified9.0
[Start]9.0 | \[ \frac{c}{\left(-\sqrt{{b}^{2} + -3 \cdot \left(c \cdot a\right)}\right) - b}
\] |
|---|---|
unpow2 [=>]9.0 | \[ \frac{c}{\left(-\sqrt{\color{blue}{b \cdot b} + -3 \cdot \left(c \cdot a\right)}\right) - b}
\] |
associate-*r* [=>]9.0 | \[ \frac{c}{\left(-\sqrt{b \cdot b + \color{blue}{\left(-3 \cdot c\right) \cdot a}}\right) - b}
\] |
*-commutative [<=]9.0 | \[ \frac{c}{\left(-\sqrt{b \cdot b + \color{blue}{\left(c \cdot -3\right)} \cdot a}\right) - b}
\] |
*-commutative [<=]9.0 | \[ \frac{c}{\left(-\sqrt{b \cdot b + \color{blue}{a \cdot \left(c \cdot -3\right)}}\right) - b}
\] |
fma-udef [<=]9.0 | \[ \frac{c}{\left(-\sqrt{\color{blue}{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -3\right)\right)}}\right) - b}
\] |
if 2.84999999999999993e78 < b Initial program 58.8
Simplified58.8
[Start]58.8 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
remove-double-neg [<=]58.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 [<=]58.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 [=>]59.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 [=>]59.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/ [<=]60.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 [=>]60.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 [=>]62.6 | \[ \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 [<=]62.6 | \[ \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 [<=]62.6 | \[ \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* [<=]62.6 | \[ \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 [<=]62.6 | \[ \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 [<=]62.6 | \[ \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 [<=]60.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 [=>]60.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 3.5
Final simplification7.2
| Alternative 1 | |
|---|---|
| Error | 7.2 |
| Cost | 13964 |
| Alternative 2 | |
|---|---|
| Error | 7.4 |
| Cost | 7692 |
| Alternative 3 | |
|---|---|
| Error | 7.2 |
| Cost | 7692 |
| Alternative 4 | |
|---|---|
| Error | 10.5 |
| Cost | 7560 |
| Alternative 5 | |
|---|---|
| Error | 14.0 |
| Cost | 7368 |
| Alternative 6 | |
|---|---|
| Error | 14.0 |
| Cost | 7368 |
| Alternative 7 | |
|---|---|
| Error | 14.0 |
| Cost | 7304 |
| Alternative 8 | |
|---|---|
| Error | 14.1 |
| Cost | 7304 |
| Alternative 9 | |
|---|---|
| Error | 23.2 |
| Cost | 452 |
| Alternative 10 | |
|---|---|
| Error | 23.1 |
| Cost | 452 |
| Alternative 11 | |
|---|---|
| Error | 23.1 |
| Cost | 452 |
| Alternative 12 | |
|---|---|
| Error | 40.1 |
| Cost | 320 |
herbie shell --seed 2023083
(FPCore (a b c)
:name "Cubic critical"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))