| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 14080 |
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
(FPCore (a b c)
:precision binary64
(/
(/
(* 4.0 (* c a))
(-
(- b)
(sqrt
(/
(- (* c (* c (* (* a a) 16.0))) (pow b 4.0))
(- (* (* c a) -4.0) (* b b))))))
(* a 2.0)))double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
double code(double a, double b, double c) {
return ((4.0 * (c * a)) / (-b - sqrt((((c * (c * ((a * a) * 16.0))) - pow(b, 4.0)) / (((c * a) * -4.0) - (b * b)))))) / (a * 2.0);
}
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) - ((4.0d0 * a) * c)))) / (2.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 = ((4.0d0 * (c * a)) / (-b - sqrt((((c * (c * ((a * a) * 16.0d0))) - (b ** 4.0d0)) / (((c * a) * (-4.0d0)) - (b * b)))))) / (a * 2.0d0)
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
public static double code(double a, double b, double c) {
return ((4.0 * (c * a)) / (-b - Math.sqrt((((c * (c * ((a * a) * 16.0))) - Math.pow(b, 4.0)) / (((c * a) * -4.0) - (b * b)))))) / (a * 2.0);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)
def code(a, b, c): return ((4.0 * (c * a)) / (-b - math.sqrt((((c * (c * ((a * a) * 16.0))) - math.pow(b, 4.0)) / (((c * a) * -4.0) - (b * b)))))) / (a * 2.0)
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a)) end
function code(a, b, c) return Float64(Float64(Float64(4.0 * Float64(c * a)) / Float64(Float64(-b) - sqrt(Float64(Float64(Float64(c * Float64(c * Float64(Float64(a * a) * 16.0))) - (b ^ 4.0)) / Float64(Float64(Float64(c * a) * -4.0) - Float64(b * b)))))) / Float64(a * 2.0)) end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a); end
function tmp = code(a, b, c) tmp = ((4.0 * (c * a)) / (-b - sqrt((((c * (c * ((a * a) * 16.0))) - (b ^ 4.0)) / (((c * a) * -4.0) - (b * b)))))) / (a * 2.0); end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_] := N[(N[(N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision] / N[((-b) - N[Sqrt[N[(N[(N[(c * N[(c * N[(N[(a * a), $MachinePrecision] * 16.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Power[b, 4.0], $MachinePrecision]), $MachinePrecision] / N[(N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision] - N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\frac{\frac{4 \cdot \left(c \cdot a\right)}{\left(-b\right) - \sqrt{\frac{c \cdot \left(c \cdot \left(\left(a \cdot a\right) \cdot 16\right)\right) - {b}^{4}}{\left(c \cdot a\right) \cdot -4 - b \cdot b}}}}{a \cdot 2}
Results
Initial program 18.3%
Simplified18.3%
[Start]18.3 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
*-commutative [=>]18.3 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}}
\] |
Applied egg-rr18.7%
[Start]18.3 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}
\] |
|---|---|
flip-+ [=>]18.3 | \[ \frac{\color{blue}{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}{a \cdot 2}
\] |
sub-neg [=>]18.3 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{\left(-b\right) + \left(-\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}}{a \cdot 2}
\] |
add-sqr-sqrt [=>]18.3 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(-\color{blue}{\sqrt{b} \cdot \sqrt{b}}\right) + \left(-\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}{a \cdot 2}
\] |
sqrt-prod [<=]18.3 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(-\color{blue}{\sqrt{b \cdot b}}\right) + \left(-\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}{a \cdot 2}
\] |
sqr-neg [<=]18.3 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(-\sqrt{\color{blue}{\left(-b\right) \cdot \left(-b\right)}}\right) + \left(-\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}{a \cdot 2}
\] |
sqrt-unprod [<=]0.0 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(-\color{blue}{\sqrt{-b} \cdot \sqrt{-b}}\right) + \left(-\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}{a \cdot 2}
\] |
add-sqr-sqrt [<=]0.4 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(-\color{blue}{\left(-b\right)}\right) + \left(-\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}{a \cdot 2}
\] |
distribute-neg-in [<=]0.4 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{-\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}}{a \cdot 2}
\] |
add-sqr-sqrt [=>]0.0 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{-\color{blue}{\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}}{a \cdot 2}
\] |
distribute-rgt-neg-in [=>]0.0 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \left(-\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\right)}}}{a \cdot 2}
\] |
Simplified18.8%
[Start]18.7 | \[ \frac{\frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}{\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}{-\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}{a \cdot 2}
\] |
|---|---|
associate-/l/ [=>]18.7 | \[ \frac{\color{blue}{\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}{\left(-\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}\right) \cdot \sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}}{a \cdot 2}
\] |
/-rgt-identity [<=]18.7 | \[ \frac{\frac{\color{blue}{\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}{1}}}{\left(-\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}\right) \cdot \sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}{a \cdot 2}
\] |
/-rgt-identity [=>]18.7 | \[ \frac{\frac{\color{blue}{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}{\left(-\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}\right) \cdot \sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}{a \cdot 2}
\] |
fma-def [<=]18.8 | \[ \frac{\frac{b \cdot b - \color{blue}{\left(b \cdot b + c \cdot \left(a \cdot -4\right)\right)}}{\left(-\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}\right) \cdot \sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}{a \cdot 2}
\] |
+-commutative [=>]18.8 | \[ \frac{\frac{b \cdot b - \color{blue}{\left(c \cdot \left(a \cdot -4\right) + b \cdot b\right)}}{\left(-\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}\right) \cdot \sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}{a \cdot 2}
\] |
fma-def [=>]18.8 | \[ \frac{\frac{b \cdot b - \color{blue}{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}{\left(-\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}\right) \cdot \sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}{a \cdot 2}
\] |
distribute-lft-neg-in [<=]18.8 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}{\color{blue}{-\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}} \cdot \sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}}{a \cdot 2}
\] |
rem-square-sqrt [=>]18.8 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}{-\color{blue}{\left(b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}\right)}}}{a \cdot 2}
\] |
*-lft-identity [<=]18.8 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}{-\color{blue}{1 \cdot \left(b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}\right)}}}{a \cdot 2}
\] |
*-lft-identity [=>]18.8 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}{-\color{blue}{\left(b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}\right)}}}{a \cdot 2}
\] |
Taylor expanded in b around 0 99.4%
Applied egg-rr99.4%
[Start]99.4 | \[ \frac{\frac{4 \cdot \left(c \cdot a\right)}{-\left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\right)}}{a \cdot 2}
\] |
|---|---|
fma-udef [=>]99.4 | \[ \frac{\frac{4 \cdot \left(c \cdot a\right)}{-\left(b + \sqrt{\color{blue}{c \cdot \left(a \cdot -4\right) + b \cdot b}}\right)}}{a \cdot 2}
\] |
flip-+ [=>]99.4 | \[ \frac{\frac{4 \cdot \left(c \cdot a\right)}{-\left(b + \sqrt{\color{blue}{\frac{\left(c \cdot \left(a \cdot -4\right)\right) \cdot \left(c \cdot \left(a \cdot -4\right)\right) - \left(b \cdot b\right) \cdot \left(b \cdot b\right)}{c \cdot \left(a \cdot -4\right) - b \cdot b}}}\right)}}{a \cdot 2}
\] |
pow2 [=>]99.4 | \[ \frac{\frac{4 \cdot \left(c \cdot a\right)}{-\left(b + \sqrt{\frac{\left(c \cdot \left(a \cdot -4\right)\right) \cdot \left(c \cdot \left(a \cdot -4\right)\right) - \color{blue}{{b}^{2}} \cdot \left(b \cdot b\right)}{c \cdot \left(a \cdot -4\right) - b \cdot b}}\right)}}{a \cdot 2}
\] |
pow2 [=>]99.4 | \[ \frac{\frac{4 \cdot \left(c \cdot a\right)}{-\left(b + \sqrt{\frac{\left(c \cdot \left(a \cdot -4\right)\right) \cdot \left(c \cdot \left(a \cdot -4\right)\right) - {b}^{2} \cdot \color{blue}{{b}^{2}}}{c \cdot \left(a \cdot -4\right) - b \cdot b}}\right)}}{a \cdot 2}
\] |
pow-sqr [=>]99.4 | \[ \frac{\frac{4 \cdot \left(c \cdot a\right)}{-\left(b + \sqrt{\frac{\left(c \cdot \left(a \cdot -4\right)\right) \cdot \left(c \cdot \left(a \cdot -4\right)\right) - \color{blue}{{b}^{\left(2 \cdot 2\right)}}}{c \cdot \left(a \cdot -4\right) - b \cdot b}}\right)}}{a \cdot 2}
\] |
metadata-eval [=>]99.4 | \[ \frac{\frac{4 \cdot \left(c \cdot a\right)}{-\left(b + \sqrt{\frac{\left(c \cdot \left(a \cdot -4\right)\right) \cdot \left(c \cdot \left(a \cdot -4\right)\right) - {b}^{\color{blue}{4}}}{c \cdot \left(a \cdot -4\right) - b \cdot b}}\right)}}{a \cdot 2}
\] |
Simplified99.4%
[Start]99.4 | \[ \frac{\frac{4 \cdot \left(c \cdot a\right)}{-\left(b + \sqrt{\frac{\left(c \cdot \left(a \cdot -4\right)\right) \cdot \left(c \cdot \left(a \cdot -4\right)\right) - {b}^{4}}{c \cdot \left(a \cdot -4\right) - b \cdot b}}\right)}}{a \cdot 2}
\] |
|---|---|
swap-sqr [=>]99.4 | \[ \frac{\frac{4 \cdot \left(c \cdot a\right)}{-\left(b + \sqrt{\frac{\color{blue}{\left(c \cdot c\right) \cdot \left(\left(a \cdot -4\right) \cdot \left(a \cdot -4\right)\right)} - {b}^{4}}{c \cdot \left(a \cdot -4\right) - b \cdot b}}\right)}}{a \cdot 2}
\] |
associate-*l* [=>]99.4 | \[ \frac{\frac{4 \cdot \left(c \cdot a\right)}{-\left(b + \sqrt{\frac{\color{blue}{c \cdot \left(c \cdot \left(\left(a \cdot -4\right) \cdot \left(a \cdot -4\right)\right)\right)} - {b}^{4}}{c \cdot \left(a \cdot -4\right) - b \cdot b}}\right)}}{a \cdot 2}
\] |
swap-sqr [=>]99.4 | \[ \frac{\frac{4 \cdot \left(c \cdot a\right)}{-\left(b + \sqrt{\frac{c \cdot \left(c \cdot \color{blue}{\left(\left(a \cdot a\right) \cdot \left(-4 \cdot -4\right)\right)}\right) - {b}^{4}}{c \cdot \left(a \cdot -4\right) - b \cdot b}}\right)}}{a \cdot 2}
\] |
metadata-eval [=>]99.4 | \[ \frac{\frac{4 \cdot \left(c \cdot a\right)}{-\left(b + \sqrt{\frac{c \cdot \left(c \cdot \left(\left(a \cdot a\right) \cdot \color{blue}{16}\right)\right) - {b}^{4}}{c \cdot \left(a \cdot -4\right) - b \cdot b}}\right)}}{a \cdot 2}
\] |
associate-*r* [=>]99.4 | \[ \frac{\frac{4 \cdot \left(c \cdot a\right)}{-\left(b + \sqrt{\frac{c \cdot \left(c \cdot \left(\left(a \cdot a\right) \cdot 16\right)\right) - {b}^{4}}{\color{blue}{\left(c \cdot a\right) \cdot -4} - b \cdot b}}\right)}}{a \cdot 2}
\] |
Final simplification99.4%
| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 14080 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 7744 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 7744 |
| Alternative 4 | |
|---|---|
| Accuracy | 95.1% |
| Cost | 7232 |
| Alternative 5 | |
|---|---|
| Accuracy | 95.0% |
| Cost | 1600 |
| Alternative 6 | |
|---|---|
| Accuracy | 94.9% |
| Cost | 1344 |
| Alternative 7 | |
|---|---|
| Accuracy | 90.1% |
| Cost | 256 |
| Alternative 8 | |
|---|---|
| Accuracy | 1.7% |
| Cost | 192 |
herbie shell --seed 2023138
(FPCore (a b c)
:name "Quadratic roots, wide range"
:precision binary64
:pre (and (and (and (< 4.930380657631324e-32 a) (< a 2.028240960365167e+31)) (and (< 4.930380657631324e-32 b) (< b 2.028240960365167e+31))) (and (< 4.930380657631324e-32 c) (< c 2.028240960365167e+31)))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))