| Alternative 1 | |
|---|---|
| Accuracy | 85.0% |
| 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
(let* ((t_0 (* c (* a -3.0))))
(if (<= b -7.5e+107)
(+ (/ (* b -0.6666666666666666) a) (* 0.5 (/ c b)))
(if (<= b -2e-137)
(/ (- (sqrt (+ (* b b) t_0)) b) (* a 3.0))
(if (<= b 1.22e-61)
(* 0.3333333333333333 (/ (- (hypot b (sqrt t_0)) b) a))
(* (/ c b) -0.5))))))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 = c * (a * -3.0);
double tmp;
if (b <= -7.5e+107) {
tmp = ((b * -0.6666666666666666) / a) + (0.5 * (c / b));
} else if (b <= -2e-137) {
tmp = (sqrt(((b * b) + t_0)) - b) / (a * 3.0);
} else if (b <= 1.22e-61) {
tmp = 0.3333333333333333 * ((hypot(b, sqrt(t_0)) - b) / a);
} else {
tmp = (c / b) * -0.5;
}
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 = c * (a * -3.0);
double tmp;
if (b <= -7.5e+107) {
tmp = ((b * -0.6666666666666666) / a) + (0.5 * (c / b));
} else if (b <= -2e-137) {
tmp = (Math.sqrt(((b * b) + t_0)) - b) / (a * 3.0);
} else if (b <= 1.22e-61) {
tmp = 0.3333333333333333 * ((Math.hypot(b, Math.sqrt(t_0)) - b) / a);
} else {
tmp = (c / b) * -0.5;
}
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 = c * (a * -3.0) tmp = 0 if b <= -7.5e+107: tmp = ((b * -0.6666666666666666) / a) + (0.5 * (c / b)) elif b <= -2e-137: tmp = (math.sqrt(((b * b) + t_0)) - b) / (a * 3.0) elif b <= 1.22e-61: tmp = 0.3333333333333333 * ((math.hypot(b, math.sqrt(t_0)) - b) / a) else: tmp = (c / b) * -0.5 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(c * Float64(a * -3.0)) tmp = 0.0 if (b <= -7.5e+107) tmp = Float64(Float64(Float64(b * -0.6666666666666666) / a) + Float64(0.5 * Float64(c / b))); elseif (b <= -2e-137) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) + t_0)) - b) / Float64(a * 3.0)); elseif (b <= 1.22e-61) tmp = Float64(0.3333333333333333 * Float64(Float64(hypot(b, sqrt(t_0)) - b) / a)); else tmp = Float64(Float64(c / b) * -0.5); 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 = c * (a * -3.0); tmp = 0.0; if (b <= -7.5e+107) tmp = ((b * -0.6666666666666666) / a) + (0.5 * (c / b)); elseif (b <= -2e-137) tmp = (sqrt(((b * b) + t_0)) - b) / (a * 3.0); elseif (b <= 1.22e-61) tmp = 0.3333333333333333 * ((hypot(b, sqrt(t_0)) - b) / a); else tmp = (c / b) * -0.5; 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[(c * N[(a * -3.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -7.5e+107], N[(N[(N[(b * -0.6666666666666666), $MachinePrecision] / a), $MachinePrecision] + N[(0.5 * N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, -2e-137], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.22e-61], N[(0.3333333333333333 * N[(N[(N[Sqrt[b ^ 2 + N[Sqrt[t$95$0], $MachinePrecision] ^ 2], $MachinePrecision] - b), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] * -0.5), $MachinePrecision]]]]]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\begin{array}{l}
t_0 := c \cdot \left(a \cdot -3\right)\\
\mathbf{if}\;b \leq -7.5 \cdot 10^{+107}:\\
\;\;\;\;\frac{b \cdot -0.6666666666666666}{a} + 0.5 \cdot \frac{c}{b}\\
\mathbf{elif}\;b \leq -2 \cdot 10^{-137}:\\
\;\;\;\;\frac{\sqrt{b \cdot b + t_0} - b}{a \cdot 3}\\
\mathbf{elif}\;b \leq 1.22 \cdot 10^{-61}:\\
\;\;\;\;0.3333333333333333 \cdot \frac{\mathsf{hypot}\left(b, \sqrt{t_0}\right) - b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} \cdot -0.5\\
\end{array}
Results
if b < -7.4999999999999996e107Initial program 24.1%
Simplified24.0%
[Start]24.1 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
remove-double-neg [<=]24.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 [<=]24.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 [=>]24.2 | \[ \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 [=>]24.2 | \[ \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/ [<=]24.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 [=>]24.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 [=>]24.2 | \[ \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 [<=]24.2 | \[ \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 [<=]24.2 | \[ \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* [<=]24.2 | \[ \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 [<=]24.2 | \[ \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 [<=]24.2 | \[ \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 [<=]24.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 [=>]24.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 93.7%
Applied egg-rr93.7%
if -7.4999999999999996e107 < b < -1.99999999999999996e-137Initial program 89.8%
if -1.99999999999999996e-137 < b < 1.22e-61Initial program 72.5%
Simplified72.3%
[Start]72.5 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
*-lft-identity [<=]72.5 | \[ \color{blue}{1 \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}}
\] |
metadata-eval [<=]72.5 | \[ \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 [<=]72.5 | \[ \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 [<=]72.5 | \[ \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 [=>]72.4 | \[ \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/ [=>]72.5 | \[ \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-rr73.5%
Applied egg-rr40.6%
Simplified73.6%
[Start]40.6 | \[ 0.3333333333333333 \cdot \frac{\mathsf{hypot}\left(b, e^{\mathsf{log1p}\left(\sqrt{a \cdot \left(c \cdot -3\right)}\right)} - 1\right) - b}{a}
\] |
|---|---|
expm1-def [=>]71.2 | \[ 0.3333333333333333 \cdot \frac{\mathsf{hypot}\left(b, \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{a \cdot \left(c \cdot -3\right)}\right)\right)}\right) - b}{a}
\] |
expm1-log1p [=>]73.5 | \[ 0.3333333333333333 \cdot \frac{\mathsf{hypot}\left(b, \color{blue}{\sqrt{a \cdot \left(c \cdot -3\right)}}\right) - b}{a}
\] |
associate-*r* [=>]73.6 | \[ 0.3333333333333333 \cdot \frac{\mathsf{hypot}\left(b, \sqrt{\color{blue}{\left(a \cdot c\right) \cdot -3}}\right) - b}{a}
\] |
*-commutative [=>]73.6 | \[ 0.3333333333333333 \cdot \frac{\mathsf{hypot}\left(b, \sqrt{\color{blue}{\left(c \cdot a\right)} \cdot -3}\right) - b}{a}
\] |
associate-*l* [=>]73.6 | \[ 0.3333333333333333 \cdot \frac{\mathsf{hypot}\left(b, \sqrt{\color{blue}{c \cdot \left(a \cdot -3\right)}}\right) - b}{a}
\] |
if 1.22e-61 < b Initial program 17.3%
Simplified17.2%
[Start]17.3 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
remove-double-neg [<=]17.3 | \[ \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 [<=]17.3 | \[ \frac{\color{blue}{\left(-b\right) - \left(-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}{3 \cdot a}
\] |
div-sub [=>]15.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 [=>]15.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/ [<=]14.4 | \[ \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 [=>]14.4 | \[ \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 [=>]10.7 | \[ \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 [<=]10.7 | \[ \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 [<=]10.7 | \[ \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* [<=]10.7 | \[ \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 [<=]10.7 | \[ \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 [<=]10.7 | \[ \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 [<=]14.4 | \[ \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 [=>]14.4 | \[ \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 86.7%
Final simplification84.9%
| Alternative 1 | |
|---|---|
| Accuracy | 85.0% |
| Cost | 13964 |
| Alternative 2 | |
|---|---|
| Accuracy | 84.6% |
| Cost | 7624 |
| Alternative 3 | |
|---|---|
| Accuracy | 84.7% |
| Cost | 7624 |
| Alternative 4 | |
|---|---|
| Accuracy | 79.0% |
| Cost | 7368 |
| Alternative 5 | |
|---|---|
| Accuracy | 79.0% |
| Cost | 7368 |
| Alternative 6 | |
|---|---|
| Accuracy | 64.4% |
| Cost | 452 |
| Alternative 7 | |
|---|---|
| Accuracy | 64.4% |
| Cost | 452 |
| Alternative 8 | |
|---|---|
| Accuracy | 37.2% |
| Cost | 320 |
herbie shell --seed 2023125
(FPCore (a b c)
:name "Cubic critical"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))