Repository: sympy/sympy
Pull request: Added is_abundant and is_deficient with test cases
<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->

#### References to other Issues or PRs
<!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
format, e.g. "Fixes #1234". See
https://github.com/blog/1506-closing-issues-via-pull-requests . Please also
write a comment on that issue linking back to this pull request once it is
open. -->
Fixes #15926 
closes #16112 as an alternative
Function for perfect number has already been merged on PR #16101 
#### Brief description of what is fixed or changed
Added functions for abundant and deficient numbers and a function to compute the abundance of a number.
#### Other comments


#### Release Notes

<!-- Write the release notes for this release below. See
https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more information
on how to write release notes. The bot will check your release notes
automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->

- ntheory
     - actor_: added funtions `abundance`, `is_abundant` and `is_deficient`

 

<!-- END RELEASE NOTES -->


Problem statement:
Function for perfect, deficient, abundant numbers
There should be a separate function for checking whether a number is perfect, deficient or abundant. If you liked this idea then I can add a pull request.

- [x] perfect
- [x] deficient
- [x] abundant

Hints from issue discussion:
I think it would be good to have. 

For perfect numbers, there are only [51 known ones](https://en.wikipedia.org/wiki/Mersenne_prime), so we could just check against a list. I don't know if there is an efficient way to test if a number is abundant. 
I think ntheory/factor_.py would be the appropriate place
@asmeurer I can think of the following heuristics for this.
1. All primes and its powers are deficient.
2. Every multiple of abundant and perfect number is abundant.
This will need some changes. Please suggest. I have checked outputs. It takes some time to calculate 40th Perfect Numbers to 51th Perfect Numbers. but We can show it with symbol. 
I also have test cases for Perfect Numbers. I can add them if you want to.
I have not added comments yet. Comments can also be added.
I'm working on deficient and will try to cover abundant as well.

Commit message: Slight change

Patch to review:
diff --git a/sympy/ntheory/__init__.py b/sympy/ntheory/__init__.py
index bf0065221703..1cd470b3f305 100644
--- a/sympy/ntheory/__init__.py
+++ b/sympy/ntheory/__init__.py
@@ -8,7 +8,8 @@
 from .factor_ import divisors, factorint, multiplicity, perfect_power, \
     pollard_pm1, pollard_rho, primefactors, totient, trailing, divisor_count, \
     divisor_sigma, factorrat, reduced_totient, primenu, primeomega, \
-         mersenne_prime_exponent, is_perfect, is_mersenne_prime
+    mersenne_prime_exponent, is_perfect, is_mersenne_prime, is_abundant, \
+    is_deficient
 from .partitions_ import npartitions
 from .residue_ntheory import is_primitive_root, is_quad_residue, \
     legendre_symbol, jacobi_symbol, n_order, sqrt_mod, quadratic_residues, \
diff --git a/sympy/ntheory/factor_.py b/sympy/ntheory/factor_.py
index ac3c62983615..9641c247a9f4 100644
--- a/sympy/ntheory/factor_.py
+++ b/sympy/ntheory/factor_.py
@@ -2129,3 +2129,55 @@ def is_mersenne_prime(n):
 
     r, b = integer_log(n + 1, 2)
     return b and r in MERSENNE_PRIME_EXPONENTS
+
+
+def is_abundant(n):
+    """Returns True if ``n`` is a abundant number, else False.
+
+    A perfect number is smaller to the sum of its positive, proper divisors.
+
+    Examples
+    ========
+
+    >>> from sympy.ntheory.factor_ import is_abundant
+    >>> is_abundant(20)
+    True
+    >>> is_abundant(15)
+    False
+
+    References
+    ==========
+
+    .. [1] http://mathworld.wolfram.com/AbundantNumber.html
+
+    """
+
+    if 2 * n < sum(divisors(n)):
+        return True
+    return False
+
+
+def is_deficient(n):
+    """Returns True if ``n`` is a deficient number, else False.
+
+    A perfect number is greater to the sum of its positive, proper divisors.
+
+    Examples
+    ========
+
+    >>> from sympy.ntheory.factor_ import is_deficient
+    >>> is_deficient(20)
+    False
+    >>> is_deficient(15)
+    True
+
+    References
+    ==========
+
+    .. [1] http://mathworld.wolfram.com/DeficientNumber.html
+
+    """
+
+    if 2 * n > sum(divisors(n)):
+        return True
+    return False
diff --git a/sympy/ntheory/tests/test_factor_.py b/sympy/ntheory/tests/test_factor_.py
index 6226323e26ac..55e6d207cb89 100644
--- a/sympy/ntheory/tests/test_factor_.py
+++ b/sympy/ntheory/tests/test_factor_.py
@@ -13,7 +13,8 @@
     factorrat, reduced_totient)
 from sympy.ntheory.factor_ import (smoothness, smoothness_p,
     antidivisors, antidivisor_count, core, digits, udivisors, udivisor_sigma,
-    udivisor_count, primenu, primeomega, small_trailing, mersenne_prime_exponent, is_perfect, is_mersenne_prime)
+    udivisor_count, primenu, primeomega, small_trailing, mersenne_prime_exponent,
+    is_perfect, is_mersenne_prime, is_abundant, is_deficient)
 from sympy.ntheory.generate import cycle_length
 from sympy.ntheory.multinomial import (
     multinomial_coefficients, multinomial_coefficients_iterator)
@@ -589,3 +590,19 @@ def test_is_mersenne_prime():
     assert is_mersenne_prime(511) is False
     assert is_mersenne_prime(131071) is True
     assert is_mersenne_prime(2147483647) is True
+
+
+def test_is_abundant():
+    assert is_abundant(10) is False
+    assert is_abundant(12) is True
+    assert is_abundant(18) is True
+    assert is_abundant(21) is False
+    assert is_abundant(945) is True
+
+
+def test_is_deficient():
+    assert is_deficient(10) is True
+    assert is_deficient(22) is True
+    assert is_deficient(56) is False
+    assert is_deficient(20) is False
+    assert is_deficient(36) is False


Code review comments:
diff_hunk: @@ -2129,3 +2129,55 @@ def is_mersenne_prime(n):
 
     r, b = integer_log(n + 1, 2)
     return b and r in MERSENNE_PRIME_EXPONENTS
+
+
+def is_abundant(n):
+    """Returns True if ``n`` is a abundant number, else False.
+
+    A perfect number is smaller to the sum of its positive, proper divisors.
path: sympy/ntheory/factor_.py
text: @user1:
update for this function