| Alternative 1 | |
|---|---|
| Error | 15.2 |
| Cost | 7368 |
(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.1e+154)
(/ (* b -0.6666666666666666) a)
(if (<= b 9.5e-167)
(/ (- (sqrt (- (* b b) (* (* a 3.0) c))) b) (* a 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.1e+154) {
tmp = (b * -0.6666666666666666) / a;
} else if (b <= 9.5e-167) {
tmp = (sqrt(((b * b) - ((a * 3.0) * c))) - b) / (a * 3.0);
} else {
tmp = -0.5 * (c / b);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b + sqrt(((b * b) - ((3.0d0 * a) * c)))) / (3.0d0 * a)
end function
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-1.1d+154)) then
tmp = (b * (-0.6666666666666666d0)) / a
else if (b <= 9.5d-167) then
tmp = (sqrt(((b * b) - ((a * 3.0d0) * c))) - b) / (a * 3.0d0)
else
tmp = (-0.5d0) * (c / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
}
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.1e+154) {
tmp = (b * -0.6666666666666666) / a;
} else if (b <= 9.5e-167) {
tmp = (Math.sqrt(((b * b) - ((a * 3.0) * c))) - b) / (a * 3.0);
} else {
tmp = -0.5 * (c / b);
}
return tmp;
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a)
def code(a, b, c): tmp = 0 if b <= -1.1e+154: tmp = (b * -0.6666666666666666) / a elif b <= 9.5e-167: tmp = (math.sqrt(((b * b) - ((a * 3.0) * c))) - b) / (a * 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.1e+154) tmp = Float64(Float64(b * -0.6666666666666666) / a); elseif (b <= 9.5e-167) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(a * 3.0) * c))) - b) / Float64(a * 3.0)); else tmp = Float64(-0.5 * Float64(c / b)); end return tmp end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a); end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.1e+154) tmp = (b * -0.6666666666666666) / a; elseif (b <= 9.5e-167) tmp = (sqrt(((b * b) - ((a * 3.0) * c))) - b) / (a * 3.0); else tmp = -0.5 * (c / b); end tmp_2 = 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.1e+154], N[(N[(b * -0.6666666666666666), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b, 9.5e-167], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(a * 3.0), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $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.1 \cdot 10^{+154}:\\
\;\;\;\;\frac{b \cdot -0.6666666666666666}{a}\\
\mathbf{elif}\;b \leq 9.5 \cdot 10^{-167}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 3\right) \cdot c} - b}{a \cdot 3}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b}\\
\end{array}
Results
if b < -1.1000000000000001e154Initial program 64.0
Simplified64.0
[Start]64.0 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
remove-double-neg [<=]64.0 | \[ \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 [<=]64.0 | \[ \frac{\color{blue}{\left(-b\right) - \left(-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}{3 \cdot a}
\] |
div-sub [=>]64.0 | \[ \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 [=>]64.0 | \[ \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/ [<=]64.0 | \[ \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 [=>]64.0 | \[ \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 [=>]64.0 | \[ \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 [<=]64.0 | \[ \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 [<=]64.0 | \[ \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* [<=]64.0 | \[ \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 [<=]64.0 | \[ \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 [<=]64.0 | \[ \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 [<=]64.0 | \[ \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 [=>]64.0 | \[ \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}}
\] |
associate-*r/ [=>]64.0 | \[ \frac{-1}{3 \cdot a} \cdot \frac{-b}{-1} - \color{blue}{\frac{-1 \cdot \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}}
\] |
associate-*l/ [<=]64.0 | \[ \frac{-1}{3 \cdot a} \cdot \frac{-b}{-1} - \color{blue}{\frac{-1}{3 \cdot a} \cdot \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}
\] |
distribute-lft-out-- [=>]64.0 | \[ \color{blue}{\frac{-1}{3 \cdot a} \cdot \left(\frac{-b}{-1} - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}
\] |
*-commutative [=>]64.0 | \[ \color{blue}{\left(\frac{-b}{-1} - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot \frac{-1}{3 \cdot a}}
\] |
neg-mul-1 [=>]64.0 | \[ \left(\frac{\color{blue}{-1 \cdot b}}{-1} - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot \frac{-1}{3 \cdot a}
\] |
*-commutative [=>]64.0 | \[ \left(\frac{\color{blue}{b \cdot -1}}{-1} - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot \frac{-1}{3 \cdot a}
\] |
associate-/l* [=>]64.0 | \[ \left(\color{blue}{\frac{b}{\frac{-1}{-1}}} - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot \frac{-1}{3 \cdot a}
\] |
metadata-eval [=>]64.0 | \[ \left(\frac{b}{\color{blue}{1}} - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot \frac{-1}{3 \cdot a}
\] |
/-rgt-identity [=>]64.0 | \[ \left(\color{blue}{b} - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot \frac{-1}{3 \cdot a}
\] |
cancel-sign-sub-inv [=>]64.0 | \[ \left(b - \sqrt{\color{blue}{b \cdot b + \left(-3 \cdot a\right) \cdot c}}\right) \cdot \frac{-1}{3 \cdot a}
\] |
+-commutative [=>]64.0 | \[ \left(b - \sqrt{\color{blue}{\left(-3 \cdot a\right) \cdot c + b \cdot b}}\right) \cdot \frac{-1}{3 \cdot a}
\] |
*-commutative [=>]64.0 | \[ \left(b - \sqrt{\color{blue}{c \cdot \left(-3 \cdot a\right)} + b \cdot b}\right) \cdot \frac{-1}{3 \cdot a}
\] |
distribute-lft-neg-in [=>]64.0 | \[ \left(b - \sqrt{c \cdot \color{blue}{\left(\left(-3\right) \cdot a\right)} + b \cdot b}\right) \cdot \frac{-1}{3 \cdot a}
\] |
associate-*r* [=>]64.0 | \[ \left(b - \sqrt{\color{blue}{\left(c \cdot \left(-3\right)\right) \cdot a} + b \cdot b}\right) \cdot \frac{-1}{3 \cdot a}
\] |
*-commutative [=>]64.0 | \[ \left(b - \sqrt{\color{blue}{a \cdot \left(c \cdot \left(-3\right)\right)} + b \cdot b}\right) \cdot \frac{-1}{3 \cdot a}
\] |
fma-def [=>]64.0 | \[ \left(b - \sqrt{\color{blue}{\mathsf{fma}\left(a, c \cdot \left(-3\right), b \cdot b\right)}}\right) \cdot \frac{-1}{3 \cdot a}
\] |
metadata-eval [=>]64.0 | \[ \left(b - \sqrt{\mathsf{fma}\left(a, c \cdot \color{blue}{-3}, b \cdot b\right)}\right) \cdot \frac{-1}{3 \cdot a}
\] |
associate-/r* [=>]64.0 | \[ \left(b - \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right) \cdot \color{blue}{\frac{\frac{-1}{3}}{a}}
\] |
metadata-eval [=>]64.0 | \[ \left(b - \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right) \cdot \frac{\color{blue}{-0.3333333333333333}}{a}
\] |
Taylor expanded in b around -inf 3.0
Simplified3.0
[Start]3.0 | \[ -0.6666666666666666 \cdot \frac{b}{a}
\] |
|---|---|
associate-*r/ [=>]3.0 | \[ \color{blue}{\frac{-0.6666666666666666 \cdot b}{a}}
\] |
*-commutative [=>]3.0 | \[ \frac{\color{blue}{b \cdot -0.6666666666666666}}{a}
\] |
if -1.1000000000000001e154 < b < 9.49999999999999955e-167Initial program 10.7
if 9.49999999999999955e-167 < b Initial program 48.4
Simplified48.4
[Start]48.4 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
remove-double-neg [<=]48.4 | \[ \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 [<=]48.4 | \[ \frac{\color{blue}{\left(-b\right) - \left(-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}{3 \cdot a}
\] |
div-sub [=>]49.0 | \[ \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 [=>]49.0 | \[ \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/ [<=]49.7 | \[ \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 [=>]49.7 | \[ \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 [=>]51.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 [<=]51.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 [<=]51.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* [<=]51.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 [<=]51.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 [<=]51.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 [<=]49.7 | \[ \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 [=>]49.7 | \[ \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}}
\] |
associate-*r/ [=>]49.7 | \[ \frac{-1}{3 \cdot a} \cdot \frac{-b}{-1} - \color{blue}{\frac{-1 \cdot \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}}
\] |
associate-*l/ [<=]49.0 | \[ \frac{-1}{3 \cdot a} \cdot \frac{-b}{-1} - \color{blue}{\frac{-1}{3 \cdot a} \cdot \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}
\] |
distribute-lft-out-- [=>]48.4 | \[ \color{blue}{\frac{-1}{3 \cdot a} \cdot \left(\frac{-b}{-1} - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}
\] |
*-commutative [=>]48.4 | \[ \color{blue}{\left(\frac{-b}{-1} - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot \frac{-1}{3 \cdot a}}
\] |
neg-mul-1 [=>]48.4 | \[ \left(\frac{\color{blue}{-1 \cdot b}}{-1} - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot \frac{-1}{3 \cdot a}
\] |
*-commutative [=>]48.4 | \[ \left(\frac{\color{blue}{b \cdot -1}}{-1} - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot \frac{-1}{3 \cdot a}
\] |
associate-/l* [=>]48.4 | \[ \left(\color{blue}{\frac{b}{\frac{-1}{-1}}} - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot \frac{-1}{3 \cdot a}
\] |
metadata-eval [=>]48.4 | \[ \left(\frac{b}{\color{blue}{1}} - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot \frac{-1}{3 \cdot a}
\] |
/-rgt-identity [=>]48.4 | \[ \left(\color{blue}{b} - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot \frac{-1}{3 \cdot a}
\] |
cancel-sign-sub-inv [=>]48.4 | \[ \left(b - \sqrt{\color{blue}{b \cdot b + \left(-3 \cdot a\right) \cdot c}}\right) \cdot \frac{-1}{3 \cdot a}
\] |
+-commutative [=>]48.4 | \[ \left(b - \sqrt{\color{blue}{\left(-3 \cdot a\right) \cdot c + b \cdot b}}\right) \cdot \frac{-1}{3 \cdot a}
\] |
*-commutative [=>]48.4 | \[ \left(b - \sqrt{\color{blue}{c \cdot \left(-3 \cdot a\right)} + b \cdot b}\right) \cdot \frac{-1}{3 \cdot a}
\] |
distribute-lft-neg-in [=>]48.4 | \[ \left(b - \sqrt{c \cdot \color{blue}{\left(\left(-3\right) \cdot a\right)} + b \cdot b}\right) \cdot \frac{-1}{3 \cdot a}
\] |
associate-*r* [=>]48.4 | \[ \left(b - \sqrt{\color{blue}{\left(c \cdot \left(-3\right)\right) \cdot a} + b \cdot b}\right) \cdot \frac{-1}{3 \cdot a}
\] |
*-commutative [=>]48.4 | \[ \left(b - \sqrt{\color{blue}{a \cdot \left(c \cdot \left(-3\right)\right)} + b \cdot b}\right) \cdot \frac{-1}{3 \cdot a}
\] |
fma-def [=>]48.4 | \[ \left(b - \sqrt{\color{blue}{\mathsf{fma}\left(a, c \cdot \left(-3\right), b \cdot b\right)}}\right) \cdot \frac{-1}{3 \cdot a}
\] |
metadata-eval [=>]48.4 | \[ \left(b - \sqrt{\mathsf{fma}\left(a, c \cdot \color{blue}{-3}, b \cdot b\right)}\right) \cdot \frac{-1}{3 \cdot a}
\] |
associate-/r* [=>]48.4 | \[ \left(b - \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right) \cdot \color{blue}{\frac{\frac{-1}{3}}{a}}
\] |
metadata-eval [=>]48.4 | \[ \left(b - \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right) \cdot \frac{\color{blue}{-0.3333333333333333}}{a}
\] |
Taylor expanded in b around inf 14.6
Final simplification11.6
| Alternative 1 | |
|---|---|
| Error | 15.2 |
| Cost | 7368 |
| Alternative 2 | |
|---|---|
| Error | 37.2 |
| Cost | 452 |
| Alternative 3 | |
|---|---|
| Error | 23.1 |
| Cost | 452 |
| Alternative 4 | |
|---|---|
| Error | 23.1 |
| Cost | 452 |
| Alternative 5 | |
|---|---|
| Error | 23.0 |
| Cost | 452 |
| Alternative 6 | |
|---|---|
| Error | 40.4 |
| Cost | 320 |
herbie shell --seed 2022356
(FPCore (a b c)
:name "Cubic critical"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))