| Alternative 1 | |
|---|---|
| Error | 16.67% |
| 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 -2.4e+131)
(/ b (* a -1.5))
(if (<= b 3e-135)
(/ (- (sqrt (- (* b b) (* (* a 3.0) c))) b) (* a 3.0))
(/ (* c -0.5) 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 <= -2.4e+131) {
tmp = b / (a * -1.5);
} else if (b <= 3e-135) {
tmp = (sqrt(((b * b) - ((a * 3.0) * c))) - b) / (a * 3.0);
} else {
tmp = (c * -0.5) / 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 <= (-2.4d+131)) then
tmp = b / (a * (-1.5d0))
else if (b <= 3d-135) then
tmp = (sqrt(((b * b) - ((a * 3.0d0) * c))) - b) / (a * 3.0d0)
else
tmp = (c * (-0.5d0)) / 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 <= -2.4e+131) {
tmp = b / (a * -1.5);
} else if (b <= 3e-135) {
tmp = (Math.sqrt(((b * b) - ((a * 3.0) * c))) - b) / (a * 3.0);
} else {
tmp = (c * -0.5) / 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 <= -2.4e+131: tmp = b / (a * -1.5) elif b <= 3e-135: tmp = (math.sqrt(((b * b) - ((a * 3.0) * c))) - b) / (a * 3.0) else: tmp = (c * -0.5) / 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 <= -2.4e+131) tmp = Float64(b / Float64(a * -1.5)); elseif (b <= 3e-135) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(a * 3.0) * c))) - b) / Float64(a * 3.0)); else tmp = Float64(Float64(c * -0.5) / 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 <= -2.4e+131) tmp = b / (a * -1.5); elseif (b <= 3e-135) tmp = (sqrt(((b * b) - ((a * 3.0) * c))) - b) / (a * 3.0); else tmp = (c * -0.5) / 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, -2.4e+131], N[(b / N[(a * -1.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3e-135], 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 * -0.5), $MachinePrecision] / b), $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 -2.4 \cdot 10^{+131}:\\
\;\;\;\;\frac{b}{a \cdot -1.5}\\
\mathbf{elif}\;b \leq 3 \cdot 10^{-135}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 3\right) \cdot c} - b}{a \cdot 3}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot -0.5}{b}\\
\end{array}
Results
if b < -2.3999999999999999e131Initial program 88.68
Simplified88.69
[Start]88.68 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
remove-double-neg [<=]88.68 | \[ \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 [<=]88.68 | \[ \frac{\color{blue}{\left(-b\right) - \left(-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}{3 \cdot a}
\] |
div-sub [=>]88.68 | \[ \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 [=>]88.68 | \[ \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/ [<=]88.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 [=>]88.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 [=>]88.68 | \[ \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 [<=]88.68 | \[ \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 [<=]88.68 | \[ \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* [<=]88.68 | \[ \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 [<=]88.68 | \[ \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 [<=]88.68 | \[ \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 [<=]88.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 [=>]88.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}}
\] |
Taylor expanded in b around -inf 17.58
Taylor expanded in c around 0 5.06
Simplified5.07
[Start]5.06 | \[ -0.6666666666666666 \cdot \frac{b}{a}
\] |
|---|---|
associate-*r/ [=>]5 | \[ \color{blue}{\frac{-0.6666666666666666 \cdot b}{a}}
\] |
metadata-eval [<=]5 | \[ \frac{\color{blue}{\left(-0.3333333333333333 \cdot 2\right)} \cdot b}{a}
\] |
associate-*r* [<=]5 | \[ \frac{\color{blue}{-0.3333333333333333 \cdot \left(2 \cdot b\right)}}{a}
\] |
*-commutative [<=]5 | \[ \frac{-0.3333333333333333 \cdot \color{blue}{\left(b \cdot 2\right)}}{a}
\] |
associate-*l/ [<=]5.07 | \[ \color{blue}{\frac{-0.3333333333333333}{a} \cdot \left(b \cdot 2\right)}
\] |
*-commutative [<=]5.07 | \[ \color{blue}{\left(b \cdot 2\right) \cdot \frac{-0.3333333333333333}{a}}
\] |
associate-*l* [=>]5.07 | \[ \color{blue}{b \cdot \left(2 \cdot \frac{-0.3333333333333333}{a}\right)}
\] |
associate-*r/ [=>]5.07 | \[ b \cdot \color{blue}{\frac{2 \cdot -0.3333333333333333}{a}}
\] |
metadata-eval [=>]5.07 | \[ b \cdot \frac{\color{blue}{-0.6666666666666666}}{a}
\] |
Applied egg-rr4.89
if -2.3999999999999999e131 < b < 3.00000000000000012e-135Initial program 17.37
if 3.00000000000000012e-135 < b Initial program 79.18
Simplified79.23
[Start]79.18 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
*-lft-identity [<=]79.18 | \[ \color{blue}{1 \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}}
\] |
metadata-eval [<=]79.18 | \[ \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 [<=]79.18 | \[ \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 [<=]79.18 | \[ \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 [=>]79.19 | \[ \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/ [=>]79.18 | \[ \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-rr72.05
Taylor expanded in b around inf 100
Simplified19.2
[Start]100 | \[ 0.16666666666666666 \cdot \frac{c \cdot {\left(\sqrt{-3}\right)}^{2}}{b}
\] |
|---|---|
associate-*r/ [=>]100 | \[ \color{blue}{\frac{0.16666666666666666 \cdot \left(c \cdot {\left(\sqrt{-3}\right)}^{2}\right)}{b}}
\] |
*-commutative [=>]100 | \[ \frac{0.16666666666666666 \cdot \color{blue}{\left({\left(\sqrt{-3}\right)}^{2} \cdot c\right)}}{b}
\] |
associate-*r* [=>]100 | \[ \frac{\color{blue}{\left(0.16666666666666666 \cdot {\left(\sqrt{-3}\right)}^{2}\right) \cdot c}}{b}
\] |
unpow2 [=>]100 | \[ \frac{\left(0.16666666666666666 \cdot \color{blue}{\left(\sqrt{-3} \cdot \sqrt{-3}\right)}\right) \cdot c}{b}
\] |
rem-square-sqrt [=>]19.2 | \[ \frac{\left(0.16666666666666666 \cdot \color{blue}{-3}\right) \cdot c}{b}
\] |
metadata-eval [=>]19.2 | \[ \frac{\color{blue}{-0.5} \cdot c}{b}
\] |
Final simplification16.61
| Alternative 1 | |
|---|---|
| Error | 16.67% |
| Cost | 7624 |
| Alternative 2 | |
|---|---|
| Error | 21.96% |
| Cost | 7368 |
| Alternative 3 | |
|---|---|
| Error | 21.98% |
| Cost | 7368 |
| Alternative 4 | |
|---|---|
| Error | 21.96% |
| Cost | 7368 |
| Alternative 5 | |
|---|---|
| Error | 21.92% |
| Cost | 7368 |
| Alternative 6 | |
|---|---|
| Error | 35.71% |
| Cost | 452 |
| Alternative 7 | |
|---|---|
| Error | 35.71% |
| Cost | 452 |
| Alternative 8 | |
|---|---|
| Error | 35.65% |
| Cost | 452 |
| Alternative 9 | |
|---|---|
| Error | 35.65% |
| Cost | 452 |
| Alternative 10 | |
|---|---|
| Error | 61.75% |
| Cost | 320 |
| Alternative 11 | |
|---|---|
| Error | 87.84% |
| Cost | 64 |
herbie shell --seed 2023121
(FPCore (a b c)
:name "Cubic critical"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))