| Alternative 1 | |
|---|---|
| Accuracy | 84.2% |
| 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.9e+134)
(* b (/ (/ 1.0 a) -1.5))
(if (<= b 4.2e-68)
(/ (- (sqrt (+ (* b b) (* c (* a -3.0)))) 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.9e+134) {
tmp = b * ((1.0 / a) / -1.5);
} else if (b <= 4.2e-68) {
tmp = (sqrt(((b * b) + (c * (a * -3.0)))) - 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.9d+134)) then
tmp = b * ((1.0d0 / a) / (-1.5d0))
else if (b <= 4.2d-68) then
tmp = (sqrt(((b * b) + (c * (a * (-3.0d0))))) - 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.9e+134) {
tmp = b * ((1.0 / a) / -1.5);
} else if (b <= 4.2e-68) {
tmp = (Math.sqrt(((b * b) + (c * (a * -3.0)))) - 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.9e+134: tmp = b * ((1.0 / a) / -1.5) elif b <= 4.2e-68: tmp = (math.sqrt(((b * b) + (c * (a * -3.0)))) - 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.9e+134) tmp = Float64(b * Float64(Float64(1.0 / a) / -1.5)); elseif (b <= 4.2e-68) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) + Float64(c * Float64(a * -3.0)))) - 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.9e+134) tmp = b * ((1.0 / a) / -1.5); elseif (b <= 4.2e-68) tmp = (sqrt(((b * b) + (c * (a * -3.0)))) - 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.9e+134], N[(b * N[(N[(1.0 / a), $MachinePrecision] / -1.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 4.2e-68], 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], 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.9 \cdot 10^{+134}:\\
\;\;\;\;b \cdot \frac{\frac{1}{a}}{-1.5}\\
\mathbf{elif}\;b \leq 4.2 \cdot 10^{-68}:\\
\;\;\;\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} - b}{a \cdot 3}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot -0.5}{b}\\
\end{array}
Results
if b < -2.90000000000000012e134Initial program 11.9%
Simplified11.9%
[Start]11.9 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
remove-double-neg [<=]11.9 | \[ \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 [<=]11.9 | \[ \frac{\color{blue}{\left(-b\right) - \left(-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}{3 \cdot a}
\] |
div-sub [=>]11.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 [=>]11.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/ [<=]11.9 | \[ \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 [=>]11.9 | \[ \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 [=>]11.9 | \[ \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 [<=]11.9 | \[ \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 [<=]11.9 | \[ \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* [<=]11.9 | \[ \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 [<=]11.9 | \[ \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 [<=]11.9 | \[ \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 [<=]11.9 | \[ \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 [=>]11.9 | \[ \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 95.8%
Simplified95.8%
[Start]95.8 | \[ -0.6666666666666666 \cdot \frac{b}{a}
\] |
|---|---|
*-commutative [=>]95.8 | \[ \color{blue}{\frac{b}{a} \cdot -0.6666666666666666}
\] |
Applied egg-rr95.7%
[Start]95.8 | \[ \frac{b}{a} \cdot -0.6666666666666666
\] |
|---|---|
associate-*l/ [=>]95.8 | \[ \color{blue}{\frac{b \cdot -0.6666666666666666}{a}}
\] |
clear-num [=>]95.7 | \[ \color{blue}{\frac{1}{\frac{a}{b \cdot -0.6666666666666666}}}
\] |
Applied egg-rr95.4%
[Start]95.7 | \[ \frac{1}{\frac{a}{b \cdot -0.6666666666666666}}
\] |
|---|---|
add-sqr-sqrt [=>]95.4 | \[ \frac{1}{\frac{a}{\color{blue}{\sqrt{b \cdot -0.6666666666666666} \cdot \sqrt{b \cdot -0.6666666666666666}}}}
\] |
pow2 [=>]95.4 | \[ \frac{1}{\frac{a}{\color{blue}{{\left(\sqrt{b \cdot -0.6666666666666666}\right)}^{2}}}}
\] |
Applied egg-rr95.8%
[Start]95.4 | \[ \frac{1}{\frac{a}{{\left(\sqrt{b \cdot -0.6666666666666666}\right)}^{2}}}
\] |
|---|---|
div-inv [=>]95.3 | \[ \frac{1}{\color{blue}{a \cdot \frac{1}{{\left(\sqrt{b \cdot -0.6666666666666666}\right)}^{2}}}}
\] |
associate-/r* [=>]95.4 | \[ \color{blue}{\frac{\frac{1}{a}}{\frac{1}{{\left(\sqrt{b \cdot -0.6666666666666666}\right)}^{2}}}}
\] |
unpow2 [=>]95.4 | \[ \frac{\frac{1}{a}}{\frac{1}{\color{blue}{\sqrt{b \cdot -0.6666666666666666} \cdot \sqrt{b \cdot -0.6666666666666666}}}}
\] |
add-sqr-sqrt [<=]95.6 | \[ \frac{\frac{1}{a}}{\frac{1}{\color{blue}{b \cdot -0.6666666666666666}}}
\] |
*-commutative [=>]95.6 | \[ \frac{\frac{1}{a}}{\frac{1}{\color{blue}{-0.6666666666666666 \cdot b}}}
\] |
associate-/r* [=>]95.8 | \[ \frac{\frac{1}{a}}{\color{blue}{\frac{\frac{1}{-0.6666666666666666}}{b}}}
\] |
associate-/r/ [=>]95.8 | \[ \color{blue}{\frac{\frac{1}{a}}{\frac{1}{-0.6666666666666666}} \cdot b}
\] |
metadata-eval [=>]95.8 | \[ \frac{\frac{1}{a}}{\color{blue}{-1.5}} \cdot b
\] |
if -2.90000000000000012e134 < b < 4.20000000000000016e-68Initial program 80.0%
if 4.20000000000000016e-68 < b Initial program 17.6%
Simplified17.6%
[Start]17.6 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
*-lft-identity [<=]17.6 | \[ \color{blue}{1 \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}}
\] |
metadata-eval [<=]17.6 | \[ \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 [<=]17.6 | \[ \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 [<=]17.6 | \[ \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 [=>]17.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/ [=>]17.6 | \[ \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 85.8%
Simplified85.8%
[Start]85.8 | \[ -0.5 \cdot \frac{c}{b}
\] |
|---|---|
associate-*r/ [=>]85.8 | \[ \color{blue}{\frac{-0.5 \cdot c}{b}}
\] |
*-commutative [=>]85.8 | \[ \frac{\color{blue}{c \cdot -0.5}}{b}
\] |
Final simplification84.2%
| Alternative 1 | |
|---|---|
| Accuracy | 84.2% |
| Cost | 7624 |
| Alternative 2 | |
|---|---|
| Accuracy | 75.7% |
| Cost | 7368 |
| Alternative 3 | |
|---|---|
| Accuracy | 75.7% |
| Cost | 7368 |
| Alternative 4 | |
|---|---|
| Accuracy | 63.5% |
| Cost | 6980 |
| Alternative 5 | |
|---|---|
| Accuracy | 64.1% |
| Cost | 580 |
| Alternative 6 | |
|---|---|
| Accuracy | 64.0% |
| Cost | 452 |
| Alternative 7 | |
|---|---|
| Accuracy | 64.0% |
| Cost | 452 |
| Alternative 8 | |
|---|---|
| Accuracy | 64.1% |
| Cost | 452 |
| Alternative 9 | |
|---|---|
| Accuracy | 37.5% |
| Cost | 320 |
herbie shell --seed 2023153
(FPCore (a b c)
:name "Cubic critical"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))