| Alternative 1 | |
|---|---|
| Accuracy | 83.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
(let* ((t_0 (/ (- (sqrt (+ (* b b) (* c (* a -3.0)))) b) (* a 3.0))))
(if (<= b -1.4e+146)
(/ (/ (* b 2.0) a) -3.0)
(if (<= b -1.6e-143)
t_0
(if (<= b -1.1e-181)
(* 0.3333333333333333 (/ (- (hypot b (sqrt (* a (* -3.0 c)))) b) a))
(if (<= b 4.5e-14) t_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 t_0 = (sqrt(((b * b) + (c * (a * -3.0)))) - b) / (a * 3.0);
double tmp;
if (b <= -1.4e+146) {
tmp = ((b * 2.0) / a) / -3.0;
} else if (b <= -1.6e-143) {
tmp = t_0;
} else if (b <= -1.1e-181) {
tmp = 0.3333333333333333 * ((hypot(b, sqrt((a * (-3.0 * c)))) - b) / a);
} else if (b <= 4.5e-14) {
tmp = t_0;
} else {
tmp = (c * -0.5) / b;
}
return tmp;
}
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 t_0 = (Math.sqrt(((b * b) + (c * (a * -3.0)))) - b) / (a * 3.0);
double tmp;
if (b <= -1.4e+146) {
tmp = ((b * 2.0) / a) / -3.0;
} else if (b <= -1.6e-143) {
tmp = t_0;
} else if (b <= -1.1e-181) {
tmp = 0.3333333333333333 * ((Math.hypot(b, Math.sqrt((a * (-3.0 * c)))) - b) / a);
} else if (b <= 4.5e-14) {
tmp = t_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): t_0 = (math.sqrt(((b * b) + (c * (a * -3.0)))) - b) / (a * 3.0) tmp = 0 if b <= -1.4e+146: tmp = ((b * 2.0) / a) / -3.0 elif b <= -1.6e-143: tmp = t_0 elif b <= -1.1e-181: tmp = 0.3333333333333333 * ((math.hypot(b, math.sqrt((a * (-3.0 * c)))) - b) / a) elif b <= 4.5e-14: tmp = t_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) t_0 = Float64(Float64(sqrt(Float64(Float64(b * b) + Float64(c * Float64(a * -3.0)))) - b) / Float64(a * 3.0)) tmp = 0.0 if (b <= -1.4e+146) tmp = Float64(Float64(Float64(b * 2.0) / a) / -3.0); elseif (b <= -1.6e-143) tmp = t_0; elseif (b <= -1.1e-181) tmp = Float64(0.3333333333333333 * Float64(Float64(hypot(b, sqrt(Float64(a * Float64(-3.0 * c)))) - b) / a)); elseif (b <= 4.5e-14) tmp = t_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) t_0 = (sqrt(((b * b) + (c * (a * -3.0)))) - b) / (a * 3.0); tmp = 0.0; if (b <= -1.4e+146) tmp = ((b * 2.0) / a) / -3.0; elseif (b <= -1.6e-143) tmp = t_0; elseif (b <= -1.1e-181) tmp = 0.3333333333333333 * ((hypot(b, sqrt((a * (-3.0 * c)))) - b) / a); elseif (b <= 4.5e-14) tmp = t_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_] := Block[{t$95$0 = 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, -1.4e+146], N[(N[(N[(b * 2.0), $MachinePrecision] / a), $MachinePrecision] / -3.0), $MachinePrecision], If[LessEqual[b, -1.6e-143], t$95$0, If[LessEqual[b, -1.1e-181], N[(0.3333333333333333 * N[(N[(N[Sqrt[b ^ 2 + N[Sqrt[N[(a * N[(-3.0 * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision] - b), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 4.5e-14], t$95$0, 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}
t_0 := \frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} - b}{a \cdot 3}\\
\mathbf{if}\;b \leq -1.4 \cdot 10^{+146}:\\
\;\;\;\;\frac{\frac{b \cdot 2}{a}}{-3}\\
\mathbf{elif}\;b \leq -1.6 \cdot 10^{-143}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b \leq -1.1 \cdot 10^{-181}:\\
\;\;\;\;0.3333333333333333 \cdot \frac{\mathsf{hypot}\left(b, \sqrt{a \cdot \left(-3 \cdot c\right)}\right) - b}{a}\\
\mathbf{elif}\;b \leq 4.5 \cdot 10^{-14}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot -0.5}{b}\\
\end{array}
Results
if b < -1.4e146Initial program 6.5%
Simplified6.4%
[Start]6.5 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
remove-double-neg [<=]6.5 | \[ \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 [<=]6.5 | \[ \frac{\color{blue}{\left(-b\right) - \left(-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}{3 \cdot a}
\] |
div-sub [=>]6.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 [=>]6.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/ [<=]6.5 | \[ \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 [=>]6.5 | \[ \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 [=>]6.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 [<=]6.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 [<=]6.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* [<=]6.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 [<=]6.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 [<=]6.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 [<=]6.5 | \[ \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 [=>]6.5 | \[ \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-rr6.5%
[Start]6.4 | \[ \left(b - \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right) \cdot \frac{-0.3333333333333333}{a}
\] |
|---|---|
clear-num [=>]6.4 | \[ \left(b - \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right) \cdot \color{blue}{\frac{1}{\frac{a}{-0.3333333333333333}}}
\] |
un-div-inv [=>]6.5 | \[ \color{blue}{\frac{b - \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{\frac{a}{-0.3333333333333333}}}
\] |
div-inv [=>]6.5 | \[ \frac{b - \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{\color{blue}{a \cdot \frac{1}{-0.3333333333333333}}}
\] |
metadata-eval [=>]6.5 | \[ \frac{b - \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{a \cdot \color{blue}{-3}}
\] |
associate-/r* [=>]6.5 | \[ \color{blue}{\frac{\frac{b - \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{a}}{-3}}
\] |
Taylor expanded in b around -inf 95.7%
Simplified95.7%
[Start]95.7 | \[ \frac{\frac{2 \cdot b}{a}}{-3}
\] |
|---|---|
*-commutative [=>]95.7 | \[ \frac{\frac{\color{blue}{b \cdot 2}}{a}}{-3}
\] |
if -1.4e146 < b < -1.5999999999999999e-143 or -1.09999999999999999e-181 < b < 4.4999999999999998e-14Initial program 75.9%
if -1.5999999999999999e-143 < b < -1.09999999999999999e-181Initial program 83.7%
Simplified83.6%
[Start]83.7 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
*-lft-identity [<=]83.7 | \[ \color{blue}{1 \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}}
\] |
metadata-eval [<=]83.7 | \[ \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 [<=]83.7 | \[ \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 [<=]83.7 | \[ \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 [=>]83.6 | \[ \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/ [=>]83.7 | \[ \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-rr88.3%
[Start]83.6 | \[ \frac{\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -3\right)\right)} - b}{3 \cdot a}
\] |
|---|---|
*-un-lft-identity [=>]83.6 | \[ \frac{\color{blue}{1 \cdot \left(\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -3\right)\right)} - b\right)}}{3 \cdot a}
\] |
times-frac [=>]83.5 | \[ \color{blue}{\frac{1}{3} \cdot \frac{\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -3\right)\right)} - b}{a}}
\] |
metadata-eval [=>]83.5 | \[ \color{blue}{0.3333333333333333} \cdot \frac{\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -3\right)\right)} - b}{a}
\] |
fma-udef [=>]83.5 | \[ 0.3333333333333333 \cdot \frac{\sqrt{\color{blue}{b \cdot b + a \cdot \left(c \cdot -3\right)}} - b}{a}
\] |
add-sqr-sqrt [=>]82.5 | \[ 0.3333333333333333 \cdot \frac{\sqrt{b \cdot b + \color{blue}{\sqrt{a \cdot \left(c \cdot -3\right)} \cdot \sqrt{a \cdot \left(c \cdot -3\right)}}} - b}{a}
\] |
hypot-def [=>]88.3 | \[ 0.3333333333333333 \cdot \frac{\color{blue}{\mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -3\right)}\right)} - b}{a}
\] |
if 4.4999999999999998e-14 < b Initial program 13.1%
Simplified13.1%
[Start]13.1 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
*-lft-identity [<=]13.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 [<=]13.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 [<=]13.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 [<=]13.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 [=>]13.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/ [=>]13.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 91.2%
Simplified91.2%
[Start]91.2 | \[ -0.5 \cdot \frac{c}{b}
\] |
|---|---|
associate-*r/ [=>]91.2 | \[ \color{blue}{\frac{-0.5 \cdot c}{b}}
\] |
*-commutative [=>]91.2 | \[ \frac{\color{blue}{c \cdot -0.5}}{b}
\] |
Final simplification83.8%
| Alternative 1 | |
|---|---|
| Accuracy | 83.6% |
| Cost | 7624 |
| Alternative 2 | |
|---|---|
| Accuracy | 83.7% |
| Cost | 7624 |
| Alternative 3 | |
|---|---|
| Accuracy | 78.5% |
| Cost | 7368 |
| Alternative 4 | |
|---|---|
| Accuracy | 78.5% |
| Cost | 7368 |
| Alternative 5 | |
|---|---|
| Accuracy | 78.6% |
| Cost | 7368 |
| Alternative 6 | |
|---|---|
| Accuracy | 64.8% |
| Cost | 580 |
| Alternative 7 | |
|---|---|
| Accuracy | 38.0% |
| Cost | 452 |
| Alternative 8 | |
|---|---|
| Accuracy | 64.7% |
| Cost | 452 |
| Alternative 9 | |
|---|---|
| Accuracy | 64.8% |
| Cost | 452 |
| Alternative 10 | |
|---|---|
| Accuracy | 64.9% |
| Cost | 452 |
| Alternative 11 | |
|---|---|
| Accuracy | 11.7% |
| Cost | 64 |
herbie shell --seed 2023133
(FPCore (a b c)
:name "Cubic critical"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))