| Alternative 1 | |
|---|---|
| Accuracy | 83.7% |
| 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 -8.8e+43)
(/ -0.6666666666666666 (/ a b))
(if (<= b 1.9e-71)
(/ (- (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 <= -8.8e+43) {
tmp = -0.6666666666666666 / (a / b);
} else if (b <= 1.9e-71) {
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 <= (-8.8d+43)) then
tmp = (-0.6666666666666666d0) / (a / b)
else if (b <= 1.9d-71) 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 <= -8.8e+43) {
tmp = -0.6666666666666666 / (a / b);
} else if (b <= 1.9e-71) {
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 <= -8.8e+43: tmp = -0.6666666666666666 / (a / b) elif b <= 1.9e-71: 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 <= -8.8e+43) tmp = Float64(-0.6666666666666666 / Float64(a / b)); elseif (b <= 1.9e-71) 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 <= -8.8e+43) tmp = -0.6666666666666666 / (a / b); elseif (b <= 1.9e-71) 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, -8.8e+43], N[(-0.6666666666666666 / N[(a / b), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.9e-71], 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 -8.8 \cdot 10^{+43}:\\
\;\;\;\;\frac{-0.6666666666666666}{\frac{a}{b}}\\
\mathbf{elif}\;b \leq 1.9 \cdot 10^{-71}:\\
\;\;\;\;\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 < -8.80000000000000002e43Initial program 43.4%
Applied egg-rr43.4%
[Start]43.4 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
associate-/r* [=>]43.5 | \[ \color{blue}{\frac{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3}}{a}}
\] |
div-inv [=>]43.4 | \[ \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3} \cdot \frac{1}{a}}
\] |
Simplified43.5%
[Start]43.4 | \[ \frac{b - \sqrt{\mathsf{fma}\left(b, b, -3 \cdot \left(a \cdot c\right)\right)}}{-3} \cdot \frac{1}{a}
\] |
|---|---|
*-commutative [<=]43.4 | \[ \color{blue}{\frac{1}{a} \cdot \frac{b - \sqrt{\mathsf{fma}\left(b, b, -3 \cdot \left(a \cdot c\right)\right)}}{-3}}
\] |
associate-*l/ [=>]43.5 | \[ \color{blue}{\frac{1 \cdot \frac{b - \sqrt{\mathsf{fma}\left(b, b, -3 \cdot \left(a \cdot c\right)\right)}}{-3}}{a}}
\] |
*-lft-identity [=>]43.5 | \[ \frac{\color{blue}{\frac{b - \sqrt{\mathsf{fma}\left(b, b, -3 \cdot \left(a \cdot c\right)\right)}}{-3}}}{a}
\] |
fma-def [<=]43.5 | \[ \frac{\frac{b - \sqrt{\color{blue}{b \cdot b + -3 \cdot \left(a \cdot c\right)}}}{-3}}{a}
\] |
+-commutative [=>]43.5 | \[ \frac{\frac{b - \sqrt{\color{blue}{-3 \cdot \left(a \cdot c\right) + b \cdot b}}}{-3}}{a}
\] |
fma-def [=>]43.5 | \[ \frac{\frac{b - \sqrt{\color{blue}{\mathsf{fma}\left(-3, a \cdot c, b \cdot b\right)}}}{-3}}{a}
\] |
*-commutative [=>]43.5 | \[ \frac{\frac{b - \sqrt{\mathsf{fma}\left(-3, \color{blue}{c \cdot a}, b \cdot b\right)}}{-3}}{a}
\] |
Taylor expanded in b around -inf 90.1%
Simplified90.1%
[Start]90.1 | \[ \frac{\frac{2 \cdot b}{-3}}{a}
\] |
|---|---|
*-commutative [=>]90.1 | \[ \frac{\frac{\color{blue}{b \cdot 2}}{-3}}{a}
\] |
Applied egg-rr40.7%
[Start]90.1 | \[ \frac{\frac{b \cdot 2}{-3}}{a}
\] |
|---|---|
add-exp-log [=>]40.7 | \[ \color{blue}{e^{\log \left(\frac{\frac{b \cdot 2}{-3}}{a}\right)}}
\] |
associate-/l/ [=>]40.7 | \[ e^{\log \color{blue}{\left(\frac{b \cdot 2}{a \cdot -3}\right)}}
\] |
times-frac [=>]40.7 | \[ e^{\log \color{blue}{\left(\frac{b}{a} \cdot \frac{2}{-3}\right)}}
\] |
metadata-eval [=>]40.7 | \[ e^{\log \left(\frac{b}{a} \cdot \color{blue}{-0.6666666666666666}\right)}
\] |
metadata-eval [<=]40.7 | \[ e^{\log \left(\frac{b}{a} \cdot \color{blue}{\left(2 \cdot -0.3333333333333333\right)}\right)}
\] |
metadata-eval [<=]40.7 | \[ e^{\log \left(\frac{b}{a} \cdot \left(2 \cdot \color{blue}{\frac{1}{-3}}\right)\right)}
\] |
*-commutative [=>]40.7 | \[ e^{\log \color{blue}{\left(\left(2 \cdot \frac{1}{-3}\right) \cdot \frac{b}{a}\right)}}
\] |
metadata-eval [=>]40.7 | \[ e^{\log \left(\left(2 \cdot \color{blue}{-0.3333333333333333}\right) \cdot \frac{b}{a}\right)}
\] |
metadata-eval [=>]40.7 | \[ e^{\log \left(\color{blue}{-0.6666666666666666} \cdot \frac{b}{a}\right)}
\] |
Applied egg-rr90.0%
[Start]40.7 | \[ e^{\log \left(-0.6666666666666666 \cdot \frac{b}{a}\right)}
\] |
|---|---|
add-exp-log [<=]90.0 | \[ \color{blue}{-0.6666666666666666 \cdot \frac{b}{a}}
\] |
associate-*r/ [=>]90.1 | \[ \color{blue}{\frac{-0.6666666666666666 \cdot b}{a}}
\] |
associate-/l* [=>]90.0 | \[ \color{blue}{\frac{-0.6666666666666666}{\frac{a}{b}}}
\] |
if -8.80000000000000002e43 < b < 1.89999999999999996e-71Initial program 77.5%
if 1.89999999999999996e-71 < b Initial program 17.2%
Simplified17.2%
[Start]17.2 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
remove-double-neg [<=]17.2 | \[ \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.2 | \[ \frac{\color{blue}{\left(-b\right) - \left(-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}{3 \cdot a}
\] |
div-sub [=>]16.4 | \[ \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 [=>]16.4 | \[ \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/ [<=]15.2 | \[ \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 [=>]15.2 | \[ \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.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 [<=]11.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 [<=]11.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* [<=]11.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 [<=]11.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 [<=]11.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 [<=]15.2 | \[ \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 [=>]15.2 | \[ \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.5%
Applied egg-rr86.5%
[Start]86.5 | \[ -0.5 \cdot \frac{c}{b}
\] |
|---|---|
associate-*r/ [=>]86.5 | \[ \color{blue}{\frac{-0.5 \cdot c}{b}}
\] |
Final simplification83.6%
| Alternative 1 | |
|---|---|
| Accuracy | 83.7% |
| Cost | 7624 |
| Alternative 2 | |
|---|---|
| Accuracy | 78.8% |
| Cost | 7368 |
| Alternative 3 | |
|---|---|
| Accuracy | 78.7% |
| Cost | 7368 |
| Alternative 4 | |
|---|---|
| Accuracy | 79.0% |
| Cost | 7368 |
| Alternative 5 | |
|---|---|
| Accuracy | 78.8% |
| Cost | 7368 |
| Alternative 6 | |
|---|---|
| Accuracy | 64.4% |
| Cost | 964 |
| Alternative 7 | |
|---|---|
| Accuracy | 64.4% |
| Cost | 836 |
| Alternative 8 | |
|---|---|
| Accuracy | 64.5% |
| Cost | 580 |
| Alternative 9 | |
|---|---|
| Accuracy | 42.8% |
| Cost | 452 |
| Alternative 10 | |
|---|---|
| Accuracy | 64.5% |
| Cost | 452 |
| Alternative 11 | |
|---|---|
| Accuracy | 64.5% |
| Cost | 452 |
| Alternative 12 | |
|---|---|
| Accuracy | 37.7% |
| Cost | 320 |
| Alternative 13 | |
|---|---|
| Accuracy | 12.3% |
| Cost | 64 |
herbie shell --seed 2023137
(FPCore (a b c)
:name "Cubic critical"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))