| Alternative 1 | |
|---|---|
| Error | 10.6 |
| 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 -1e+125)
(/ b (* a -1.5))
(if (<= b 2.15e-26)
(/ (- (sqrt (- (* b b) (* (* a 3.0) c))) b) (* a 3.0))
(* (/ c b) (+ -0.5 (* (/ c (/ b a)) (/ -0.375 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 <= -1e+125) {
tmp = b / (a * -1.5);
} else if (b <= 2.15e-26) {
tmp = (sqrt(((b * b) - ((a * 3.0) * c))) - b) / (a * 3.0);
} else {
tmp = (c / b) * (-0.5 + ((c / (b / a)) * (-0.375 / 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 <= (-1d+125)) then
tmp = b / (a * (-1.5d0))
else if (b <= 2.15d-26) then
tmp = (sqrt(((b * b) - ((a * 3.0d0) * c))) - b) / (a * 3.0d0)
else
tmp = (c / b) * ((-0.5d0) + ((c / (b / a)) * ((-0.375d0) / 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 <= -1e+125) {
tmp = b / (a * -1.5);
} else if (b <= 2.15e-26) {
tmp = (Math.sqrt(((b * b) - ((a * 3.0) * c))) - b) / (a * 3.0);
} else {
tmp = (c / b) * (-0.5 + ((c / (b / a)) * (-0.375 / 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 <= -1e+125: tmp = b / (a * -1.5) elif b <= 2.15e-26: tmp = (math.sqrt(((b * b) - ((a * 3.0) * c))) - b) / (a * 3.0) else: tmp = (c / b) * (-0.5 + ((c / (b / a)) * (-0.375 / 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 <= -1e+125) tmp = Float64(b / Float64(a * -1.5)); elseif (b <= 2.15e-26) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(a * 3.0) * c))) - b) / Float64(a * 3.0)); else tmp = Float64(Float64(c / b) * Float64(-0.5 + Float64(Float64(c / Float64(b / a)) * Float64(-0.375 / 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 <= -1e+125) tmp = b / (a * -1.5); elseif (b <= 2.15e-26) tmp = (sqrt(((b * b) - ((a * 3.0) * c))) - b) / (a * 3.0); else tmp = (c / b) * (-0.5 + ((c / (b / a)) * (-0.375 / 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, -1e+125], N[(b / N[(a * -1.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.15e-26], 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[(N[(c / b), $MachinePrecision] * N[(-0.5 + N[(N[(c / N[(b / a), $MachinePrecision]), $MachinePrecision] * N[(-0.375 / b), $MachinePrecision]), $MachinePrecision]), $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 \cdot 10^{+125}:\\
\;\;\;\;\frac{b}{a \cdot -1.5}\\
\mathbf{elif}\;b \leq 2.15 \cdot 10^{-26}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 3\right) \cdot c} - b}{a \cdot 3}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} \cdot \left(-0.5 + \frac{c}{\frac{b}{a}} \cdot \frac{-0.375}{b}\right)\\
\end{array}
Results
if b < -9.9999999999999992e124Initial program 54.1
Simplified54.2
[Start]54.1 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
remove-double-neg [<=]54.1 | \[ \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 [<=]54.1 | \[ \frac{\color{blue}{\left(-b\right) - \left(-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}{3 \cdot a}
\] |
div-sub [=>]54.1 | \[ \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 [=>]54.1 | \[ \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.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 [=>]54.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 [=>]54.1 | \[ \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 [<=]54.1 | \[ \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 [<=]54.1 | \[ \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* [<=]54.1 | \[ \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 [<=]54.1 | \[ \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 [<=]54.1 | \[ \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.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 [=>]54.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}}
\] |
Taylor expanded in b around -inf 3.7
Simplified3.7
[Start]3.7 | \[ -0.6666666666666666 \cdot \frac{b}{a}
\] |
|---|---|
*-commutative [=>]3.7 | \[ \color{blue}{\frac{b}{a} \cdot -0.6666666666666666}
\] |
Taylor expanded in b around 0 3.7
Simplified3.6
[Start]3.7 | \[ -0.6666666666666666 \cdot \frac{b}{a}
\] |
|---|---|
*-commutative [<=]3.7 | \[ \color{blue}{\frac{b}{a} \cdot -0.6666666666666666}
\] |
/-rgt-identity [<=]3.7 | \[ \color{blue}{\frac{\frac{b}{a} \cdot -0.6666666666666666}{1}}
\] |
associate-/l* [=>]3.6 | \[ \color{blue}{\frac{\frac{b}{a}}{\frac{1}{-0.6666666666666666}}}
\] |
associate-/r* [<=]3.6 | \[ \color{blue}{\frac{b}{a \cdot \frac{1}{-0.6666666666666666}}}
\] |
metadata-eval [=>]3.6 | \[ \frac{b}{a \cdot \color{blue}{-1.5}}
\] |
if -9.9999999999999992e124 < b < 2.14999999999999994e-26Initial program 15.0
if 2.14999999999999994e-26 < b Initial program 55.1
Simplified55.1
[Start]55.1 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
*-lft-identity [<=]55.1 | \[ \color{blue}{1 \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}}
\] |
metadata-eval [<=]55.1 | \[ \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 [<=]55.1 | \[ \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 [<=]55.1 | \[ \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 [=>]55.1 | \[ \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/ [=>]55.1 | \[ \color{blue}{\frac{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-1} \cdot -1}{3 \cdot a}}
\] |
Taylor expanded in b around inf 19.0
Simplified15.0
[Start]19.0 | \[ -0.5 \cdot \frac{c}{b} + -0.375 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}}
\] |
|---|---|
fma-def [=>]19.0 | \[ \color{blue}{\mathsf{fma}\left(-0.5, \frac{c}{b}, -0.375 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}}\right)}
\] |
associate-*r/ [=>]19.0 | \[ \mathsf{fma}\left(-0.5, \frac{c}{b}, \color{blue}{\frac{-0.375 \cdot \left({c}^{2} \cdot a\right)}{{b}^{3}}}\right)
\] |
associate-/l* [=>]19.0 | \[ \mathsf{fma}\left(-0.5, \frac{c}{b}, \color{blue}{\frac{-0.375}{\frac{{b}^{3}}{{c}^{2} \cdot a}}}\right)
\] |
unpow2 [=>]19.0 | \[ \mathsf{fma}\left(-0.5, \frac{c}{b}, \frac{-0.375}{\frac{{b}^{3}}{\color{blue}{\left(c \cdot c\right)} \cdot a}}\right)
\] |
associate-*l* [=>]15.0 | \[ \mathsf{fma}\left(-0.5, \frac{c}{b}, \frac{-0.375}{\frac{{b}^{3}}{\color{blue}{c \cdot \left(c \cdot a\right)}}}\right)
\] |
Taylor expanded in c around 0 19.0
Simplified7.2
[Start]19.0 | \[ -0.5 \cdot \frac{c}{b} + -0.375 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}}
\] |
|---|---|
*-commutative [=>]19.0 | \[ \color{blue}{\frac{c}{b} \cdot -0.5} + -0.375 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}}
\] |
associate-*r/ [=>]19.0 | \[ \frac{c}{b} \cdot -0.5 + \color{blue}{\frac{-0.375 \cdot \left({c}^{2} \cdot a\right)}{{b}^{3}}}
\] |
unpow2 [=>]19.0 | \[ \frac{c}{b} \cdot -0.5 + \frac{-0.375 \cdot \left(\color{blue}{\left(c \cdot c\right)} \cdot a\right)}{{b}^{3}}
\] |
associate-*r* [<=]15.0 | \[ \frac{c}{b} \cdot -0.5 + \frac{-0.375 \cdot \color{blue}{\left(c \cdot \left(c \cdot a\right)\right)}}{{b}^{3}}
\] |
*-commutative [=>]15.0 | \[ \frac{c}{b} \cdot -0.5 + \frac{\color{blue}{\left(c \cdot \left(c \cdot a\right)\right) \cdot -0.375}}{{b}^{3}}
\] |
unpow3 [=>]15.0 | \[ \frac{c}{b} \cdot -0.5 + \frac{\left(c \cdot \left(c \cdot a\right)\right) \cdot -0.375}{\color{blue}{\left(b \cdot b\right) \cdot b}}
\] |
times-frac [=>]15.0 | \[ \frac{c}{b} \cdot -0.5 + \color{blue}{\frac{c \cdot \left(c \cdot a\right)}{b \cdot b} \cdot \frac{-0.375}{b}}
\] |
times-frac [=>]9.7 | \[ \frac{c}{b} \cdot -0.5 + \color{blue}{\left(\frac{c}{b} \cdot \frac{c \cdot a}{b}\right)} \cdot \frac{-0.375}{b}
\] |
associate-*l* [=>]9.7 | \[ \frac{c}{b} \cdot -0.5 + \color{blue}{\frac{c}{b} \cdot \left(\frac{c \cdot a}{b} \cdot \frac{-0.375}{b}\right)}
\] |
distribute-lft-out [=>]9.7 | \[ \color{blue}{\frac{c}{b} \cdot \left(-0.5 + \frac{c \cdot a}{b} \cdot \frac{-0.375}{b}\right)}
\] |
associate-/l* [=>]7.2 | \[ \frac{c}{b} \cdot \left(-0.5 + \color{blue}{\frac{c}{\frac{b}{a}}} \cdot \frac{-0.375}{b}\right)
\] |
Final simplification10.6
| Alternative 1 | |
|---|---|
| Error | 10.6 |
| Cost | 7624 |
| Alternative 2 | |
|---|---|
| Error | 14.2 |
| Cost | 7368 |
| Alternative 3 | |
|---|---|
| Error | 14.2 |
| Cost | 7368 |
| Alternative 4 | |
|---|---|
| Error | 23.1 |
| Cost | 1092 |
| Alternative 5 | |
|---|---|
| Error | 39.4 |
| Cost | 452 |
| Alternative 6 | |
|---|---|
| Error | 39.5 |
| Cost | 452 |
| Alternative 7 | |
|---|---|
| Error | 23.1 |
| Cost | 452 |
| Alternative 8 | |
|---|---|
| Error | 23.0 |
| Cost | 452 |
| Alternative 9 | |
|---|---|
| Error | 22.7 |
| Cost | 452 |
| Alternative 10 | |
|---|---|
| Error | 56.1 |
| Cost | 64 |
herbie shell --seed 2023045
(FPCore (a b c)
:name "Cubic critical"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))