| Alternative 1 | |
|---|---|
| Accuracy | 85.1% |
| Cost | 14852 |
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))
(FPCore (a b c)
:precision binary64
(/
(/
(* 3.0 (* c a))
(-
(- b)
(sqrt
(/
(- (* (* (* c a) (* c a)) 9.0) (pow b 4.0))
(- (* c (* a -3.0)) (* b b))))))
(* 3.0 a)))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) {
return ((3.0 * (c * a)) / (-b - sqrt((((((c * a) * (c * a)) * 9.0) - pow(b, 4.0)) / ((c * (a * -3.0)) - (b * b)))))) / (3.0 * a);
}
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
code = ((3.0d0 * (c * a)) / (-b - sqrt((((((c * a) * (c * a)) * 9.0d0) - (b ** 4.0d0)) / ((c * (a * (-3.0d0))) - (b * b)))))) / (3.0d0 * a)
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) {
return ((3.0 * (c * a)) / (-b - Math.sqrt((((((c * a) * (c * a)) * 9.0) - Math.pow(b, 4.0)) / ((c * (a * -3.0)) - (b * b)))))) / (3.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a)
def code(a, b, c): return ((3.0 * (c * a)) / (-b - math.sqrt((((((c * a) * (c * a)) * 9.0) - math.pow(b, 4.0)) / ((c * (a * -3.0)) - (b * b)))))) / (3.0 * a)
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) return Float64(Float64(Float64(3.0 * Float64(c * a)) / Float64(Float64(-b) - sqrt(Float64(Float64(Float64(Float64(Float64(c * a) * Float64(c * a)) * 9.0) - (b ^ 4.0)) / Float64(Float64(c * Float64(a * -3.0)) - Float64(b * b)))))) / Float64(3.0 * a)) end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a); end
function tmp = code(a, b, c) tmp = ((3.0 * (c * a)) / (-b - sqrt((((((c * a) * (c * a)) * 9.0) - (b ^ 4.0)) / ((c * (a * -3.0)) - (b * b)))))) / (3.0 * a); 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_] := N[(N[(N[(3.0 * N[(c * a), $MachinePrecision]), $MachinePrecision] / N[((-b) - N[Sqrt[N[(N[(N[(N[(N[(c * a), $MachinePrecision] * N[(c * a), $MachinePrecision]), $MachinePrecision] * 9.0), $MachinePrecision] - N[Power[b, 4.0], $MachinePrecision]), $MachinePrecision] / N[(N[(c * N[(a * -3.0), $MachinePrecision]), $MachinePrecision] - N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\frac{\frac{3 \cdot \left(c \cdot a\right)}{\left(-b\right) - \sqrt{\frac{\left(\left(c \cdot a\right) \cdot \left(c \cdot a\right)\right) \cdot 9 - {b}^{4}}{c \cdot \left(a \cdot -3\right) - b \cdot b}}}}{3 \cdot a}
Results
Initial program 55.3%
Applied egg-rr56.5%
[Start]55.3 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
flip-+ [=>]55.3 | \[ \frac{\color{blue}{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{\left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}}{3 \cdot a}
\] |
sub-neg [=>]55.3 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{\color{blue}{\left(-b\right) + \left(-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}}{3 \cdot a}
\] |
add-sqr-sqrt [=>]55.2 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{\left(-\color{blue}{\sqrt{b} \cdot \sqrt{b}}\right) + \left(-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}{3 \cdot a}
\] |
sqrt-prod [<=]55.3 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{\left(-\color{blue}{\sqrt{b \cdot b}}\right) + \left(-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}{3 \cdot a}
\] |
sqr-neg [<=]55.3 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{\left(-\sqrt{\color{blue}{\left(-b\right) \cdot \left(-b\right)}}\right) + \left(-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}{3 \cdot a}
\] |
sqrt-unprod [<=]0.0 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{\left(-\color{blue}{\sqrt{-b} \cdot \sqrt{-b}}\right) + \left(-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}{3 \cdot a}
\] |
add-sqr-sqrt [<=]1.3 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{\left(-\color{blue}{\left(-b\right)}\right) + \left(-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}{3 \cdot a}
\] |
distribute-neg-in [<=]1.3 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{\color{blue}{-\left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}}{3 \cdot a}
\] |
add-sqr-sqrt [=>]0.0 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-\color{blue}{\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}} \cdot \sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}}}{3 \cdot a}
\] |
distribute-rgt-neg-in [=>]0.0 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{\color{blue}{\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}} \cdot \left(-\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}\right)}}}{3 \cdot a}
\] |
Simplified56.8%
[Start]56.5 | \[ \frac{\frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}{\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}}}}{-\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}}}}{3 \cdot a}
\] |
|---|---|
associate-/r* [<=]56.5 | \[ \frac{\color{blue}{\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}{\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}} \cdot \left(-\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}}\right)}}}{3 \cdot a}
\] |
fma-def [<=]56.8 | \[ \frac{\frac{b \cdot b - \color{blue}{\left(b \cdot b + c \cdot \left(a \cdot -3\right)\right)}}{\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}} \cdot \left(-\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}}\right)}}{3 \cdot a}
\] |
+-commutative [=>]56.8 | \[ \frac{\frac{b \cdot b - \color{blue}{\left(c \cdot \left(a \cdot -3\right) + b \cdot b\right)}}{\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}} \cdot \left(-\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}}\right)}}{3 \cdot a}
\] |
fma-def [=>]56.8 | \[ \frac{\frac{b \cdot b - \color{blue}{\mathsf{fma}\left(c, a \cdot -3, b \cdot b\right)}}{\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}} \cdot \left(-\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}}\right)}}{3 \cdot a}
\] |
distribute-rgt-neg-in [<=]56.8 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(c, a \cdot -3, b \cdot b\right)}{\color{blue}{-\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}} \cdot \sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}}}}}{3 \cdot a}
\] |
rem-square-sqrt [=>]56.8 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(c, a \cdot -3, b \cdot b\right)}{-\color{blue}{\left(b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}\right)}}}{3 \cdot a}
\] |
fma-def [<=]56.8 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(c, a \cdot -3, b \cdot b\right)}{-\left(b + \sqrt{\color{blue}{b \cdot b + c \cdot \left(a \cdot -3\right)}}\right)}}{3 \cdot a}
\] |
+-commutative [=>]56.8 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(c, a \cdot -3, b \cdot b\right)}{-\left(b + \sqrt{\color{blue}{c \cdot \left(a \cdot -3\right) + b \cdot b}}\right)}}{3 \cdot a}
\] |
fma-def [=>]56.8 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(c, a \cdot -3, b \cdot b\right)}{-\left(b + \sqrt{\color{blue}{\mathsf{fma}\left(c, a \cdot -3, b \cdot b\right)}}\right)}}{3 \cdot a}
\] |
Taylor expanded in b around 0 99.1%
Applied egg-rr99.1%
[Start]99.1 | \[ \frac{\frac{3 \cdot \left(c \cdot a\right)}{-\left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -3, b \cdot b\right)}\right)}}{3 \cdot a}
\] |
|---|---|
fma-udef [=>]99.1 | \[ \frac{\frac{3 \cdot \left(c \cdot a\right)}{-\left(b + \sqrt{\color{blue}{c \cdot \left(a \cdot -3\right) + b \cdot b}}\right)}}{3 \cdot a}
\] |
flip-+ [=>]99.1 | \[ \frac{\frac{3 \cdot \left(c \cdot a\right)}{-\left(b + \sqrt{\color{blue}{\frac{\left(c \cdot \left(a \cdot -3\right)\right) \cdot \left(c \cdot \left(a \cdot -3\right)\right) - \left(b \cdot b\right) \cdot \left(b \cdot b\right)}{c \cdot \left(a \cdot -3\right) - b \cdot b}}}\right)}}{3 \cdot a}
\] |
associate-*r* [=>]99.1 | \[ \frac{\frac{3 \cdot \left(c \cdot a\right)}{-\left(b + \sqrt{\frac{\color{blue}{\left(\left(c \cdot a\right) \cdot -3\right)} \cdot \left(c \cdot \left(a \cdot -3\right)\right) - \left(b \cdot b\right) \cdot \left(b \cdot b\right)}{c \cdot \left(a \cdot -3\right) - b \cdot b}}\right)}}{3 \cdot a}
\] |
associate-*r* [=>]99.1 | \[ \frac{\frac{3 \cdot \left(c \cdot a\right)}{-\left(b + \sqrt{\frac{\left(\left(c \cdot a\right) \cdot -3\right) \cdot \color{blue}{\left(\left(c \cdot a\right) \cdot -3\right)} - \left(b \cdot b\right) \cdot \left(b \cdot b\right)}{c \cdot \left(a \cdot -3\right) - b \cdot b}}\right)}}{3 \cdot a}
\] |
pow2 [=>]99.1 | \[ \frac{\frac{3 \cdot \left(c \cdot a\right)}{-\left(b + \sqrt{\frac{\left(\left(c \cdot a\right) \cdot -3\right) \cdot \left(\left(c \cdot a\right) \cdot -3\right) - \color{blue}{{b}^{2}} \cdot \left(b \cdot b\right)}{c \cdot \left(a \cdot -3\right) - b \cdot b}}\right)}}{3 \cdot a}
\] |
pow2 [=>]99.1 | \[ \frac{\frac{3 \cdot \left(c \cdot a\right)}{-\left(b + \sqrt{\frac{\left(\left(c \cdot a\right) \cdot -3\right) \cdot \left(\left(c \cdot a\right) \cdot -3\right) - {b}^{2} \cdot \color{blue}{{b}^{2}}}{c \cdot \left(a \cdot -3\right) - b \cdot b}}\right)}}{3 \cdot a}
\] |
pow-sqr [=>]99.1 | \[ \frac{\frac{3 \cdot \left(c \cdot a\right)}{-\left(b + \sqrt{\frac{\left(\left(c \cdot a\right) \cdot -3\right) \cdot \left(\left(c \cdot a\right) \cdot -3\right) - \color{blue}{{b}^{\left(2 \cdot 2\right)}}}{c \cdot \left(a \cdot -3\right) - b \cdot b}}\right)}}{3 \cdot a}
\] |
metadata-eval [=>]99.1 | \[ \frac{\frac{3 \cdot \left(c \cdot a\right)}{-\left(b + \sqrt{\frac{\left(\left(c \cdot a\right) \cdot -3\right) \cdot \left(\left(c \cdot a\right) \cdot -3\right) - {b}^{\color{blue}{4}}}{c \cdot \left(a \cdot -3\right) - b \cdot b}}\right)}}{3 \cdot a}
\] |
associate-*r* [=>]99.1 | \[ \frac{\frac{3 \cdot \left(c \cdot a\right)}{-\left(b + \sqrt{\frac{\left(\left(c \cdot a\right) \cdot -3\right) \cdot \left(\left(c \cdot a\right) \cdot -3\right) - {b}^{4}}{\color{blue}{\left(c \cdot a\right) \cdot -3} - b \cdot b}}\right)}}{3 \cdot a}
\] |
Simplified99.1%
[Start]99.1 | \[ \frac{\frac{3 \cdot \left(c \cdot a\right)}{-\left(b + \sqrt{\frac{\left(\left(c \cdot a\right) \cdot -3\right) \cdot \left(\left(c \cdot a\right) \cdot -3\right) - {b}^{4}}{\left(c \cdot a\right) \cdot -3 - b \cdot b}}\right)}}{3 \cdot a}
\] |
|---|---|
swap-sqr [=>]99.1 | \[ \frac{\frac{3 \cdot \left(c \cdot a\right)}{-\left(b + \sqrt{\frac{\color{blue}{\left(\left(c \cdot a\right) \cdot \left(c \cdot a\right)\right) \cdot \left(-3 \cdot -3\right)} - {b}^{4}}{\left(c \cdot a\right) \cdot -3 - b \cdot b}}\right)}}{3 \cdot a}
\] |
metadata-eval [=>]99.1 | \[ \frac{\frac{3 \cdot \left(c \cdot a\right)}{-\left(b + \sqrt{\frac{\left(\left(c \cdot a\right) \cdot \left(c \cdot a\right)\right) \cdot \color{blue}{9} - {b}^{4}}{\left(c \cdot a\right) \cdot -3 - b \cdot b}}\right)}}{3 \cdot a}
\] |
associate-*l* [=>]99.1 | \[ \frac{\frac{3 \cdot \left(c \cdot a\right)}{-\left(b + \sqrt{\frac{\left(\left(c \cdot a\right) \cdot \left(c \cdot a\right)\right) \cdot 9 - {b}^{4}}{\color{blue}{c \cdot \left(a \cdot -3\right)} - b \cdot b}}\right)}}{3 \cdot a}
\] |
Final simplification99.1%
| Alternative 1 | |
|---|---|
| Accuracy | 85.1% |
| Cost | 14852 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 14080 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 7808 |
| Alternative 4 | |
|---|---|
| Accuracy | 84.8% |
| Cost | 7492 |
| Alternative 5 | |
|---|---|
| Accuracy | 84.8% |
| Cost | 7492 |
| Alternative 6 | |
|---|---|
| Accuracy | 81.5% |
| Cost | 960 |
| Alternative 7 | |
|---|---|
| Accuracy | 64.4% |
| Cost | 320 |
herbie shell --seed 2023135
(FPCore (a b c)
:name "Cubic critical, narrow range"
:precision binary64
:pre (and (and (and (< 1.0536712127723509e-8 a) (< a 94906265.62425156)) (and (< 1.0536712127723509e-8 b) (< b 94906265.62425156))) (and (< 1.0536712127723509e-8 c) (< c 94906265.62425156)))
(/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))