chunky v0.13.0 Chunky.Math.Predicates View Source
Predicate functions are functions of the form is_*?/1
. Predicates take any integer, and return a boolean.
Using these functions you can test numbers for specific qualities. Some of the numeric qualities are useful
across a wide set of domains, like is_prime?/1
, some are specific to number theory, like is_pseudo_prime?/1
or is_carmichael_number?/1
. Others look at the representation of numbers as patterns of digits, like is_palindromic?/1
and is_cyclops_number?/1
.
The predicates are used throughout the Chunky math libraries and sequence generation libraries. They can be
used directly in any boolean context, or via special functions like Chunky.Math.next_number/3
and analyze_number/2
. Some
of the predicate functions assume that the number being evaluated is in Base 10 - these function will often have
counterparts in Chunky.Math
that work on numbers in any base.
All of the predicates can be used to analyze an integer with:
analyze_number/2
- Apply all of the predicates to an integer, and collect resulting labels
Factors and Divisors
These predicates deal with the factorization, or properties of factors, of a number.
Abundant, perfect, and deficient numbers take the sum of all proper divisors of a number n
, and compare that sum to the number
itself, or all numbers less than n
.
is_abundant?/1
- Is the sum of divisors ofn
great than to2 * n
?is_arithmetic_number?/1
- Is the average of the sum of divisors ofn
a whole number?is_deficient?/1
- Is the sum of divisors ofn
less than2 * n
?is_highly_abundant?/1
- Is the sum of divisors ofn
greater than the sum of divisors of any number less thann
?is_perfect?/1
- Is the sum of divisors ofn
equal ton
?
Variations on perfect numbers take different approaches to summing the divisors of n
.
is_erdos_nicolas_number?/1
- An abundant numbern
where the firstk
factors sum ton
.is_primary_pseudoperfect_number?/1
- A number is primary pseudoperfect if the sum of 1 overn
and 1 over the prime factors ofn
equals1
.is_pseudoperfect_number?/1
- Does any subset of the factors ofn
sum ton
?is_weird_number?/1
- Isn
abundant but not pseudoperfect?is_primitive_pseudoperfect_number?/1
- Isn
pseudoperfect, but all the proper divisors ofn
not pseudoperfect?is_primitive_weird_number?/1
- Isn
a weird number, but all the proper divisors ofn
are not weird?
Powerful numbers look at the exponents of prime factors of a number n
. For instance, 8
has the prime factorization
2 * 2 * 2
, or 2^3
. The number 72
has the prime factorization 2^3 * 3^2
.
is_achilles_number?/1
- Is the numbern
powerful but not a perfect power?is_highly_powerful_number?/1
- Is the product of the exponents of the prime factorization ofn
greater than the same property for any number less thann
?is_powerful_number?/1
- Do the squares of all prime factors ofn
also evenly dividen
?
Economical, equidigital, and wasteful numbers all look at how the prime factorization of a number can be written,
and how many digits that requires relative to the number of digits in the original number. The prime factorization of 16
, for
example, can be written with just 2
and 4
, while the prime factors of 24
(2^3 * 3^1
) requires only the digits 233
.
is_economical_number?/1
- Does writing the prime factors ofn
take fewer digits than writingn
?is_equidigital_number?/1
- Does writing the prime factors ofn
take exactly as many digits as writingn
?is_wasteful_number?/1
- Does writing the prime factors ofn
take more digits that writingn
?
Sums and Sequences
Some number properties are based on summations or sequences of numbers.
The polite and impolite numbers are based on writing a number n
as the sum of two or more consecutive positive
integers. The number 5
is a polite number, as it can be written as 2+3
. The number 8
is impolite, there are
no consecutive positive integers that add up to 8
.
is_impolite_number?/1
- The numbern
cannot be written as the sum of two or more consecutive positive integersis_polite_number?/1
- The numbern
can be written as the sum of two or more consecutive positive integers
The practical numbers extend the idea of polite numbers, such that a polite number is a positive integer n
where
all positive integers less than n
can be written as sums of the distinct divisors of n
.
is_practical_number?/1
- Allm
less thann
can be written as sums of distinct divisors ofn
.
The Smith and Hoax numbers involve the digit sum of a number compared to the digit sum of the prime factors of the number.
is_hoax_number?/1
- Hoax numbers have equal digits sums inn
and the summed unique prime factors ofn
.is_smith_number?/1
- Smith numbers have equal digit sums inn
and the summed prime factors ofn
.
The hypotenuse and nonhypotenuse numbers determine which numbers can be the hypotenuse of integer right triangles.
is_nonhypotenuse_number?/1
- Can the square ofn
not be written as the sum of two other squares?is_hypotenuse_number?/1
- Can the square ofn
be written as the sum of two other squares?
Number Theory
The general mathematical properties of numbers fall into the Number Theory cateogry.
is_even?/1
- Is an integer even?is_negative?/1
- Is an integer a negative number?is_odd?/1
- Is an integer odd?is_positive?/1
- Is an integer a positive number?is_zero?/1
- Is an integer0
?
The single and doubly even numbers put further constraints on the even numbers.
is_doubly_even_number?/1
- Isn
divisible by 4?is_singly_even_number?/1
- Isn
divisible by 2, but not by 4?
Convergences
Some numeric analysis is based on the eventual convergence of a function or iteration.
By repeatedly taking the digits of a number, squaring them, and summing the result, all
numbers will eventually converge to one of the numbers 0, 1, 4, 16, 20, 37, 42, 58, 89, or 145
.
is_happy_number?/1
- Happy numbers coverge to1
is_unhappy_number?/1
- Unhappy numbers converge to a value other than1
Patterns
Patterns of digits in numbers are a common topic in recreational math. These predicates deal with the sequencing, arrangement, or visual pattern of digits in numbers.
Palindromic numbers are like palindromic words, the same forwards and backwards. The number 12344321
is a palindromic number,
while 123432
is not.
is_palindromic?/1
- Isn
palindromic, the same number forward and backward, in base 10?is_palindromic_prime?/1
- Isn
a palindromic prime number?is_strictly_non_palindromic?/1
- Isn
non-palindromic in all bases2
throughn - 2
?
Rep-digits, or repunits in base 2, are number made up of a single, repeating, digit. The number 222222
is a repdigit. The
number 11111110
is not a repdigit number.
is_repdigit?/1
- Isn
a repdigit number?is_repunit?/1
- Isn
a Repunit - a sequence of only1
s?
Patterns specific to base-2:
is_evil_number?/1
- Does the binary expansion ofn
have an even number of1
s?is_odious_number?/1
- Does the binary expansion ofn
have odd number of1
s?
Powers of digits and digit sets:
is_kaprekar_number?/1
- When squared, does any set of leading digits ofn^2
plus the remaining dgits equaln
?is_kaprekar_strict_number?/1
- When squared, do the fist half of the digits ofn^2
plus the second half, equaln
?is_munchhausen_number?/1
- Do the digits ofn
, taken to their own power, sum ton
?is_narcissistic_number?/1
- Do the digits of lengthk
numbern
, individually taken to thek
th power and summed, equaln
?
Miscellaneous patterns:
is_cyclops_number?/1
- Doesn
have an odd number of digits and a single0
in the center most digit?is_pandigital?/1
- Doesn
contain all of the decimal digits at least once?is_plaindrome?/1
- Do the digits ofn
always stay the same or increase when read left to right?
Divisibility patterns:
is_harshad_number?/1
- Isn
divisible by the sum of the digits ofn
?is_moran_number?/1
- Isn
divided by the sum of the digits ofn
a prime number?is_zuckerman_number?/1
- Isn
divisible by the product of the digits ofn
?
The patterns of some numbers are related to numerology, the occult, or religion.
is_apocalypse_number?/1
- Isn
a 666 digit number?is_apocalypse_prime?/1
- Isn
a 666 digit prime number?is_beast_number?/1
- Doesn
contain the substring of digits666
?
Powers
Some predicate functions examine numbers as powers of other numbers.
The cubed numbers, of the form n^3
.
is_cubefree?/1
- Isn
a number that cannot be written as the cube of another number?is_perfect_cube?/1
- Isn
a perfect cube?
The square numbers, of the form n^2
.
is_perfect_square?/1
- Isn
a perfect square?is_squarefree?/1
- Isn
a number that cannot be written as the square of another number?
Other powers, of the form n^m
.
is_perfect_power?/1
- Cann
be written as another numberm
to a power?is_prime_power?/1
- Isn
a power greater than1
of a prime number?
Primes
Prime numbers and rearrangements and patterns in prime numbers, are the focus of these predicates.
Basic primality tests, based on the Rabin-Miller probabalistic primality test.
is_prime?/1
- Isn
a prime number?is_prime_fast?/1
- Isn
a prime number? An alternative tois_prime?/1
, that can be faster for values ofn
<2^16
.
Reading primes forwards and backwards:
is_palindromic_prime?/1
- Isn
a prime number, and a palindromic number?is_emirp_prime?/1
- Isn
a prime number, that is a different prime when reversed?
Re-arrangements or edited digits of prime numbers:
is_circular_prime?/1
- Isn
a prime number that remains prime through all possible circular rotations of digits?is_weakly_prime?/1
- Isn
a prime number that is never prime when any one digit is changed to any other value?
Truncation involves removing a digit of a number from the left, right, or both sides at once to create a new number. Truncatable primes are prime numbers that are still prime throughout the truncation down to a single or double digit number.
is_left_truncatable_prime?/1
- Isn
a prime number that remains prime through all left-truncations down to a single digit?is_left_right_truncatable_prime?/1
- Isn
a prime number that remains prime through all simultaneous truncation of left and right digits down to a double or single digit number?is_right_truncatable_prime?/1
- Isn
a prime number that remains prime through all right-trucations down to a single digit?is_two_sided_prime?/1
- Isn
a prime that is both a left and a right truncatable prime?
Some prime predicate functions check composite and prime numbers for prime factors:
is_prime_power?/1
- Isn
a powerm
of a primep
, wherem
>= 1, such thatn = p^m
.is_prime_vampire_number?/1
- Isn
a vampire number with prime fangs? See Vampire Numbers below.is_sphenic_number?/1
- Isn
a composite numer that is the product of three distinct primes?
Pseudo-primes
The pseudo-prime numbers are composite numbers (by definition not prime) that fulfill certain constraints, and are useful in various number theory and algebraic contexts.
The Euler and Euler-Jacobi pseudo primes are numbers n
that when used as powers for a base a
are congruent to
a specific value. Euler pseudo primes are more permissive in their congruence than Euler-Jacobi pseudo-primes. In
both of these cases, base 10 is used, hence any values that are found to be pseudo-prime by these functions are
pseudo-prime to base 10.
is_euler_jacobi_pseudo_prime?/1
- Isn
an Euler-jacobi pseudo prime to base 10?is_euler_pseudo_prime?/1
- Isn
an Euler pseudo-prime to base 10?
When no other label is given, pseudo-primes are generally understood to imply Fermat pseudo-primes. Like Euler and Euler-Jacobi psedu-primes, numbers that are Fermat pseudo-prime are calculated accoring to a congruence to a specific base; for these predicates that is base 10.
is_carmichael_number?/1
- Isn
a Carmichael number, a number pseudo-prime to all basesa
whena
is coprime ton
?is_poulet_number?/1
- Isn
a Poulet number, a Fermat pseudo-prime in base 2?is_pseudo_prime?/1
- Isn
a Fermat pseudo prime in base 10?
Generalizations of the Euler, Euler-Jacobi, and Fermat pseudo-prime functions across any base (not just base 10)
are available in Chunky.Math
.
Semiprime numbers are composite numbers that, similar to the pseudoprimes, fullfil certain criteria.
is_semiprime_number?/1
- Isn
a composite with exactly two prime factors?is_squarefree_semiprime?/1
- Isn
a composite with exactly two distinct prime factors?
Rhonda Numbers
A number n
is a Rhonda Number in base b
if the product of the digits of n
in base b
is equal to b
multiplied by
the sum of the prime factors of n
. Rhonda numbers seem to be primarily of interest as recreational terms - numbers
that display an interesting property, but have little or no use otherwise. The Chunky.Math
function Chunky.Math.is_rhonda_to_base?/2
is a generalization of checking Rhonda numbers to any base.
is_multiple_rhonda?/1
- Test ifn
is a Rhonda number in multiple bases (checks bases 4 to 1000)is_rhonda_to_base_4?/1
- Determine ifn
is a Rhonda number to base 4is_rhonda_to_base_6?/1
- Determine ifn
is a Rhonda number to base 6is_rhonda_to_base_8?/1
- Determine ifn
is a Rhonda number to base 8is_rhonda_to_base_9?/1
- Determine ifn
is a Rhonda number to base 9is_rhonda_to_base_10?/1
- Determine ifn
is a Rhonda number to base 10is_rhonda_to_base_12?/1
- Determine ifn
is a Rhonda number to base 12is_rhonda_to_base_14?/1
- Determine ifn
is a Rhonda number to base 14is_rhonda_to_base_15?/1
- Determine ifn
is a Rhonda number to base 15is_rhonda_to_base_16?/1
- Determine ifn
is a Rhonda number to base 16is_rhonda_to_base_20?/1
- Determine ifn
is a Rhonda number to base 20is_rhonda_to_base_30?/1
- Determine ifn
is a Rhonda number to base 30is_rhonda_to_base_60?/1
- Determine ifn
is a Rhonda number to base 60
Vampire Numbers
A number n
is a vampire numbers if it can be factored into two divisors (called fangs) a
and b
,
and meet the criteria that:
n
has an even number of digits- Both
a
andb
half exactly half as many digits asn
- One or the other of
a
orb
can have trailing zeros, but not both a
andb
contain all of the original digits ofn
, in any order, including duplicated digits inn
The canonical example of a true vampire number is 1260
, which has among its divisor pairs 21 x 60
. So
21
and 60
are the fangs of the vampire number 1260
. Each of the vampire number predicates is based
off of interpretations or modifications of these rules.
is_double_vampire_number?/1
- Isn
a vampire number whose fangs are also vampire numbers?is_prime_vampire_number?/1
- Isn
a vampire number with fangs that are prime numbers?is_pseudo_vampire_number?/1
- Isn
a vampire number with relaxed constraints, like fangs with unequal numbers of digits?is_vampire_number?/1
- Isn
a vampire number?
Cryptography
Smooth numbers, or b-smooth
numbers, are composite integers whose prime factors are all less than or equal to
a specific value. Numbers that are 3-smooth
, for instance, are composites that only have 2
and 3
as prime
factors. The number 8
is 3-smooth (factors 2 * 2 * 2
), as is 648
(factors 2^3 * 3^4
), while 15
is not
3-smooth (factors 3 * 5
). The generalized function for testing b-smooth
is Chunky.Math.is_b_smooth?/2
.
is_3_smooth?/1
- Isn
a composite with prime factors all less than or equal to3
?is_5_smooth?/1
- Isn
a composite with prime factors all less than or equal to5
?is_7_smooth?/1
- Isn
a composite with prime factors all less than or equal to7
?is_11_smooth?/1
- Isn
a composite with prime factors all less than or equal to11
?is_13_smooth?/1
- Isn
a composite with prime factors all less than or equal to13
?is_17_smooth?/1
- Isn
a composite with prime factors all less than or equal to17
?is_19_smooth?/1
- Isn
a composite with prime factors all less than or equal to19
?is_23_smooth?/1
- Isn
a composite with prime factors all less than or equal to23
?
Link to this section Summary
Functions
Apply all predicates to n
, and collect the resulting labels.
Is n
a composite with prime factors all less than or equal to 11
?
Is n
a composite with prime factors all less than or equal to 13
?
Is n
a composite with prime factors all less than or equal to 17
?
Is n
a composite with prime factors all less than or equal to 19
?
Is n
a composite with prime factors all less than or equal to 23
?
Is n
a composite with prime factors all less than or equal to 3
?
Is n
a composite with prime factors all less than or equal to 5
?
Is n
a composite with prime factors all less than or equal to 7
?
Determine if an integer is abundant.
Check if a number is an Achilles Number.
Is n
an integer with 666 digits?
Is n
a 666 digit prime number?
Determine if an integer is an arithmetic number.
Does the number n
contain the number sequence 666
somewhere in it's digits?
Check if n
is a Carmichael number.
Is n
a circular prime?
Check if an integer n
has no factors greater than 1
that are perfect cubes.
Check if n
is a Cyclops number in base 10.
Determine if an integer is deficient.
Check of n
is a double vampire number.
Is n
divisible by 4?
Does the prime factorization of n
have fewer digits (counting primes and powers) than n
?
Is n
an emirp - a prime number that is a different prime number when reversed?
Does the prime factorization of n
use exactly as many digits (counting primes and powers) as n
?
Is n
an abundant number whose first k
factors sum to n
?
Check if n
is an Euler-Jacobi pseudo-prime to base 10.
Check if n
is an Euler pseudo-prime in base 10.
Predicate version of is_even/1
Integer guard.
Does n
have an even number of 1
s in base 2?
Does the repeated sum of squares of the digits of n
converge to 1
?
Is the integer n
cleanly divisible by the sum of the digits of n
?
Check if a number n
is highly abundant.
Check if a number n
is a highly powerful number.
Is n
a hoax number? Hoax numbers have a digit sum of n
equal to the digit
sum of the unique prime factors of n
.
Is n
a hypotenuse number? A hypotenuse number is a numer whose square can be written as the sum of two other squares.
Is n
an impolite number? Impolite numbers cannot be written as the sum of two consecutive integers.
When n
is squared, does any set of the left digits of n^2
, added to the right set, equal n
?
When n
is squared, do the left half of the digits of n^2
, added to the right half, equal n
?
Is n
a left/right truncatable prime?
Is n
a left truncatable prime?
Is n
divided by the sum of the digits of n
a prime number?
Check if the integer n
is a Rhonda number to more than one base.
Do the digits of n
to their own power sum to n
?
Do the digits of length k
number n
, when individually taken to the k
th power and summed, equal n
?
Determine if a number is a negative integer.
Is n
a non-hypotenuse number? A non hypotenuse number is a numer whose square cannot be written as the sum of two other squares.
Predicate version of is_odd?/1
Integer guard.
Odious numbers have an odd number of 1
s in their binary expansion.
Check if n
is a palindromic number in base 10.
Is n
a palindromic prime number?
Check if n
is pandigital in base 10.
Determine if an integer is a perfect number.
Check if n
is a perfect cube.
Check if n
is a perfect power.
Check if n
is a perfect square.
Check if n
is a plaindrome in base 10.
Is n
a polite number? Polite numbers can be expressed as the sum of two consecutive digits.
Determine if a number is a positive integer.
Is n
a Poulet number?
Determine if an integer n
is a powerful number.
Is n
a practical number? A practical number is a positive integer n
where all positive
integers less than n
can be written as a sum of the distinct divisors of n
.
Is n
a primary pseudoperfect number? A number is primary pseudoperfect if the sum of 1 over n
and 1 over the
prime factors of n
equals 1
.
Determine if a positive integer is prime.
Determine if a positive integer is prime.
Check if n
is a power m
of a prime, where m
>= 1.
Check if n
is a prime vampire number.
Is n
pseudoperfect, but all the proper divisors of n
not pseudoperfect?
Is n
a weird number, but all proper divisors of n
are not weird numbers?
Determine if n
is pseudo-prime to base 10.
Check if n
is a pseudo vampire number.
Can n
be written as a sum of some or all of its divisors?
Check if n
is a Repdigit number.
Check if n
is a Repunit.
Determine if n
is a Rhonda number to base 10.
Determine if n
is a Rhonda number to base 12.
Determine if n
is a Rhonda number to base 14.
Determine if n
is a Rhonda number to base 15.
Determine if n
is a Rhonda number to base 16.
Determine if n
is a Rhonda number to base 20.
Determine if n
is a Rhonda number to base 30.
Determine if n
is a Rhonda number to base 4.
Determine if n
is a Rhonda number to base 60.
Determine if n
is a Rhonda number to base 6.
Determine if n
is a Rhonda number to base 8.
Determine if n
is a Rhonda number to base 9.
Is n
a right truncatable prime?
Is n
a composite number with exactly two prime factors?
Is n
a divisible by 2, but not by 4?
Is n
a Smith Number? Smith numbers have equal digit sums in n
and the summed factors of n
.
Check if n
is a sphenic number, the product of three distinct primes.
Check if an integer n
has no factors greater than 1
that are perfect squares.
Is n
a semiprime and also square free - a composite of two distinct primes?
Check if n
is strictly non-palindromic.
Is n
a two sided prime, a number that is both a left and right trucatable prime.
Does the repeated sum of squares of the digits of n
converge to a value other than 1
?
Check if n
is a true vampire number.
Does the prime factorization of n
have mored digits (counting primes and powers) than n
?
Is n
a weakly prime number?
Weird numbers are abundant but not pseudoperfect numbers.
Predicate for testing for 0
Is n
divisible by the product of the digits of n
?
Link to this section Functions
Apply all predicates to n
, and collect the resulting labels.
This function uses the names of all of the predicate functions as sources for labels, and collects
the resulting labels from a number being analyzed. This will work with all integers in the range (-∞..0..+∞)
.
Some predicate functions can take a long time to run depending on the size of n
, so the analyze_number/2
function
uses a timeout for each predicate. See the predicate_wait_time
option for more details.
Options
skip_smooth
- Boolean, defaultfalse
. Iftrue
, skip all smooth number predicates of formis_#_smooth?/1
predicate_wait_time
- Integer, default100
. Maximum number of milliseconds to wait for an answer from each predicate function
Examples
iex> Predicates.analyze_number(2048)
[:"11_smooth", :"13_smooth", :"17_smooth", :"19_smooth", :"23_smooth",:"3_smooth", :"5_smooth", :"7_smooth", :deficient, :doubly_even_number, :economical_number, :even, :impolite_number, :nonhypotenuse_number, :odious_number, :perfect_power, :positive, :powerful_number, :practical_number, :prime_power, :unhappy_number]
iex> Predicates.analyze_number(2048, skip_smooth: true)
[:deficient, :doubly_even_number, :economical_number, :even, :impolite_number, :nonhypotenuse_number, :odious_number, :perfect_power, :positive, :powerful_number, :practical_number, :prime_power, :unhappy_number]
iex> Predicates.analyze_number(-37)
[:negative, :odd, :odious_number]
iex> Predicates.analyze_number(0)
[:cyclops_number, :doubly_even_number, :even, :evil_number, :munchhausen_number, :palindromic, :perfect_square, :plaindrome, :repdigit, :zero]
iex> Predicates.analyze_number(105840, skip_smooth: true)
[:abundant, :arithmetic_number, :doubly_even_number, :even, :harshad_number, :hypotenuse_number, :odious_number, :polite_number, :positive, :practical_number, :unhappy_number, :wasteful_number]
iex> Predicates.analyze_number(105840, skip_smooth: true, predicate_wait_time: 20_000)
[:abundant, :arithmetic_number, :doubly_even_number, :even, :harshad_number, :highly_abundant, :hypotenuse_number, :odious_number, :polite_number, :positive, :practical_number, :pseudoperfect_number, :unhappy_number, :wasteful_number]
iex> Predicates.analyze_number(1000, skip_smooth: true)
[:abundant, :doubly_even_number, :equidigital_number, :even, :evil_number, :happy_number, :harshad_number, :hypotenuse_number, :multiple_rhonda, :perfect_cube, :perfect_power, :polite_number, :positive, :powerful_number, :practical_number, :pseudoperfect_number, :rhonda_to_base_16]
iex> Predicates.analyze_number(1435)
[:arithmetic_number, :cubefree, :deficient, :equidigital_number, :hypotenuse_number, :odd, :odious_number, :polite_number, :positive, :pseudo_vampire_number, :sphenic_number, :squarefree, :unhappy_number, :vampire_number]
Is n
a composite with prime factors all less than or equal to 11
?
Generalized function: Chunky.Math.is_b_smooth?/2
Examples
iex> Predicates.is_11_smooth?(3)
true
iex> Predicates.is_11_smooth?(40)
true
iex> Predicates.is_11_smooth?(107)
false
iex> Predicates.is_11_smooth?(2020)
false
Is n
a composite with prime factors all less than or equal to 13
?
Generalized function: Chunky.Math.is_b_smooth?/2
Examples
iex> Predicates.is_13_smooth?(3)
true
iex> Predicates.is_13_smooth?(40)
true
iex> Predicates.is_13_smooth?(107)
false
iex> Predicates.is_13_smooth?(2020)
false
Is n
a composite with prime factors all less than or equal to 17
?
Generalized function: Chunky.Math.is_b_smooth?/2
Examples
iex> Predicates.is_17_smooth?(3)
true
iex> Predicates.is_17_smooth?(40)
true
iex> Predicates.is_17_smooth?(107)
false
iex> Predicates.is_17_smooth?(2020)
false
Is n
a composite with prime factors all less than or equal to 19
?
Generalized function: Chunky.Math.is_b_smooth?/2
Examples
iex> Predicates.is_19_smooth?(3)
true
iex> Predicates.is_19_smooth?(40)
true
iex> Predicates.is_19_smooth?(107)
false
iex> Predicates.is_19_smooth?(2020)
false
Is n
a composite with prime factors all less than or equal to 23
?
Generalized function: Chunky.Math.is_b_smooth?/2
Examples
iex> Predicates.is_23_smooth?(3)
true
iex> Predicates.is_23_smooth?(40)
true
iex> Predicates.is_23_smooth?(107)
false
iex> Predicates.is_23_smooth?(2020)
false
Is n
a composite with prime factors all less than or equal to 3
?
Generalized function: Chunky.Math.is_b_smooth?/2
Examples
iex> Predicates.is_3_smooth?(3)
true
iex> Predicates.is_3_smooth?(40)
false
iex> Predicates.is_3_smooth?(107)
false
iex> Predicates.is_3_smooth?(2020)
false
Is n
a composite with prime factors all less than or equal to 5
?
Generalized function: Chunky.Math.is_b_smooth?/2
Examples
iex> Predicates.is_5_smooth?(3)
true
iex> Predicates.is_5_smooth?(40)
true
iex> Predicates.is_5_smooth?(107)
false
iex> Predicates.is_5_smooth?(2020)
false
Is n
a composite with prime factors all less than or equal to 7
?
Generalized function: Chunky.Math.is_b_smooth?/2
Examples
iex> Predicates.is_7_smooth?(3)
true
iex> Predicates.is_7_smooth?(40)
true
iex> Predicates.is_7_smooth?(107)
false
iex> Predicates.is_7_smooth?(2020)
false
Determine if an integer is abundant.
An abundant number is an integer n
, such that the sum of all proper divisors of n
(including itself)
is greater than 2 * n
.
Alternatively, an abundant number is a number that satisfies: 𝜎(n) > 2n
See also:
OEIS References:
Chunky.Sequence.OEIS.Core.create_sequence_a005101/1
- Abundant numbers
Examples
iex> Predicates.is_abundant?(3)
false
iex> Predicates.is_abundant?(12)
true
iex> Predicates.is_abundant?(945)
true
Check if a number is an Achilles Number.
Achilles numbers are n
that are powerful (see is_powerful_number?/1
) but not perfect powers (see is_perfect_power?/1
).
OEIS References:
See also:
Examples
iex> Predicates.is_achilles_number?(70)
false
iex> Predicates.is_achilles_number?(72)
true
iex> Predicates.is_achilles_number?(2700)
true
iex> Predicates.is_achilles_number?(784)
false
Is n
an integer with 666 digits?
See also:
Examples
iex> Math.pow(10, 665) + 37 |> Predicates.is_apocalypse_number?()
true
iex> Math.pow(10, 555) + 37 |> Predicates.is_apocalypse_number?()
false
iex> Math.pow(10, 665) + 300_337 |> Predicates.is_apocalypse_number?()
true
iex> Math.pow(10, 665) + Math.pow(10, 37) |> Predicates.is_apocalypse_number?()
true
Is n
a 666 digit prime number?
According to the OEIS, there are approximately 10^662 apocalypse primes, the last of which is 10^666-1157
.
OEIS References
See also:
Examples
iex> Math.pow(10, 665) + 123 |> Predicates.is_apocalypse_prime?()
true
iex> Math.pow(10, 665) + 7123 |> Predicates.is_apocalypse_prime?()
false
iex> Math.pow(10, 665) + 8569 |> Predicates.is_apocalypse_prime?()
true
iex> Math.pow(10, 665) + 53683 |> Predicates.is_apocalypse_prime?()
true
Determine if an integer is an arithmetic number.
An arithmetic number is an integer n
such that the average of the sum of the proper divisors of n
is
a whole integer. Alternatively, n
that satisfy 𝜎(n) / 𝜏(n) == 0
.
See also:
OEIS References:
Chunky.Sequence.OEIS.Sigma.create_sequence_a003601/1
- Arithmetic numbers
Examples
iex> Predicates.is_arithmetic_number?(11)
true
iex> Predicates.is_arithmetic_number?(32)
false
iex> Predicates.is_arithmetic_number?(12953)
true
Does the number n
contain the number sequence 666
somewhere in it's digits?
OEIS References:
See also:
Examples
iex> Predicates.is_beast_number?(6)
false
iex> Predicates.is_beast_number?(666)
true
iex> Predicates.is_beast_number?(64666)
true
iex> Predicates.is_beast_number?(116661)
true
iex> Predicates.is_beast_number?(306666)
true
Check if n
is a Carmichael number.
A Carmichael number n
is a composite number that satisfies the congruence:
for all b
that are coprime to n
.
See also:
Examples
iex> Predicates.is_carmichael_number?(517)
false
iex> Predicates.is_carmichael_number?(561)
true
iex> Predicates.is_carmichael_number?(1105)
true
iex> Predicates.is_carmichael_number?(1107)
false
iex> Predicates.is_carmichael_number?(41041)
true
Is n
a circular prime?
A circular prime is a number n
that remains a prime number through all
possible rotations of the digits of n
. For instance, 1193
is a circular
prime because 1193
, 1931
, 9311
, and 3119
are all prime.
See also:
Examples
iex> Predicates.is_circular_prime?(1193)
true
iex> Predicates.is_circular_prime?(3)
true
iex> Predicates.is_circular_prime?(193939)
true
iex> Predicates.is_circular_prime?(135)
false
Check if an integer n
has no factors greater than 1
that are perfect cubes.
See also:
Chunky.Math.factors/1
Chunky.Math.prime_factors/1
is_perfect_cube?/1
is_perfect_square?/1
is_squarefree?/1
Examples
iex> Predicates.is_cubefree?(3)
true
iex> Predicates.is_cubefree?(64)
false
iex> Predicates.is_cubefree?(2744)
false
Check if n
is a Cyclops number in base 10.
Cyclops numbers in base 10 are numbers with:
- an odd number of digits
- exactly one
0
- a
0
in the center-most digit ofn
So the numbers 101
, 904
, and 12034
are cyclops numbers, but 1023
and 10001
are not.
Generalized function: Chunky.Math.is_cyclops_number_in_base?/2
Examples
iex> Predicates.is_cyclops_number?(0)
true
iex> Predicates.is_cyclops_number?(50)
false
iex> Predicates.is_cyclops_number?(104)
true
iex> Predicates.is_cyclops_number?(1005)
false
iex> Predicates.is_cyclops_number?(19010)
false
iex> Predicates.is_cyclops_number?(1230456)
true
Determine if an integer is deficient.
A deficient number is an integer n
, such that the sum of all proper divisors of n
(including itself)
is less than 2 * n
.
Alternatively, a deficient number is a number that satisfies: 𝜎(n) < 2n
See also:
OEIS References:
Chunky.Sequence.OEIS.Core.create_sequence_a005100/1
- Deficient numbers
Examples
iex> Predicates.is_deficient?(1)
true
iex> Predicates.is_deficient?(71)
true
iex> Predicates.is_deficient?(33550336)
false
iex> Predicates.is_deficient?(60)
false
Check of n
is a double vampire number.
Double vampire numbers meet all the criteria of a regular vampire number (see is_vampire_number?/1
)
with the additional constraint:
- The two factors of
n
,a
andb
, must also be vampire numbers
See also:
Examples
iex> Predicates.is_double_vampire_number?(6880)
false
iex> Predicates.is_double_vampire_number?(1047527295416280)
true
Is n
divisible by 4?
Doubly even numbers are an extension of the even numbers.
OEIS References:
See also:
Examples
iex> Predicates.is_doubly_even_number?(4)
true
iex> Predicates.is_doubly_even_number?(14)
false
iex> Predicates.is_doubly_even_number?(892)
true
iex> Predicates.is_doubly_even_number?(3956)
true
Does the prime factorization of n
have fewer digits (counting primes and powers) than n
?
The economical numbers are sometimes called the frugal numbers. When counting digits of
the prime factorization the prime and it's exponent are combined together, so 125
is a frugal
number, because its prime factorization is 5^3
or 53
written out.
OEIS References:
See also:
Examples
iex> Predicates.is_economical_number?(125)
true
iex> Predicates.is_economical_number?(1875)
true
iex> Predicates.is_economical_number?(1880)
false
iex> Predicates.is_economical_number?(1946430)
true
Is n
an emirp - a prime number that is a different prime number when reversed?
Emirp primes are related to palindromic primes, except that the
reverse of n
must be a different prime number.
See also:
Examples
iex> Predicates.is_emirp_prime?(373)
false
iex> Predicates.is_emirp_prime?(13)
true
iex> Predicates.is_emirp_prime?(983)
true
iex> Predicates.is_emirp_prime?(947351)
true
Does the prime factorization of n
use exactly as many digits (counting primes and powers) as n
?
When counting digits of the prime factorization the prime and it's exponent are combined together,
so 16
is an equidigital number, because its prime factorization is 2^4
or 24
written out.
OEIS References:
See also:
Examples
iex> Predicates.is_equidigital_number?(2)
true
iex> Predicates.is_equidigital_number?(49)
true
iex> Predicates.is_equidigital_number?(433)
true
iex> Predicates.is_equidigital_number?(33701)
true
Is n
an abundant number whose first k
factors sum to n
?
The Erdős-Nicolas numbers are a variation on abundant and perfect numbers. The first k
factors
of n
must sum to n
; for instance 2016
is an Erdős-Nicolas number, as the first 31 factors (of 35
factors) sums to 2016
.
OEIS References
See also:
is_primary_pseudoperfect_number?/1
is_primitive_pseudoperfect_number?/1
is_primitive_weird_number?/1
is_pseudoperfect_number?/1
is_weird_number?/1
Examples
iex> Predicates.is_erdos_nicolas_number?(6)
false
iex> Predicates.is_erdos_nicolas_number?(24)
true
iex> Predicates.is_erdos_nicolas_number?(2016)
true
iex> Predicates.is_erdos_nicolas_number?(4096)
false
iex> Predicates.is_erdos_nicolas_number?(8190)
true
Check if n
is an Euler-Jacobi pseudo-prime to base 10.
Generalized function: Chunky.Math.is_euler_jacobi_pseudo_prime?/2
See also:
Examples
iex> Predicates.is_euler_jacobi_pseudo_prime?(17)
false
iex> Predicates.is_euler_jacobi_pseudo_prime?(481)
true
iex> Predicates.is_euler_jacobi_pseudo_prime?(487)
false
iex> Predicates.is_euler_jacobi_pseudo_prime?(6601)
true
Check if n
is an Euler pseudo-prime in base 10.
Generalized function: Chunky.Math.is_euler_pseudo_prime?/2
See also:
Examples
iex> Predicates.is_euler_pseudo_prime?(9)
true
iex> Predicates.is_euler_pseudo_prime?(14)
false
iex> Predicates.is_euler_pseudo_prime?(33)
true
iex> Predicates.is_euler_pseudo_prime?(91)
true
Predicate version of is_even/1
Integer guard.
Examples
iex> Predicates.is_even?(34)
true
iex> Predicates.is_even?(0)
true
iex> Predicates.is_even?(3)
false
Does n
have an even number of 1
s in base 2?
Evil numbers, and their counterpart the odious numbers, count the quantity of set bits (1
s) in
the base 2 expansion of a number.
OEIS References:
See also:
Examples
iex> Predicates.is_evil_number?(3)
true
iex> Predicates.is_evil_number?(23)
true
iex> Predicates.is_evil_number?(25)
false
iex> Predicates.is_evil_number?(19940)
true
Does the repeated sum of squares of the digits of n
converge to 1
?
By repeatedly taking the digits of a number, squaring them, and summing the result, all
numbers will eventually converge to one of the numbers 0, 1, 4, 16, 20, 37, 42, 58, 89, or 145
. Happy
numbers coverge to 1
.
OEIS References:
See also:
Examples
iex> Predicates.is_happy_number?(0)
false
iex> Predicates.is_happy_number?(1)
true
iex> Predicates.is_happy_number?(193)
true
iex> Predicates.is_happy_number?(3323)
true
iex> Predicates.is_happy_number?(999989)
true
Is the integer n
cleanly divisible by the sum of the digits of n
?
Also called Niven numbers. For example the number 27
is a Harshad
number, as 2 + 7 = 9
and 27 % 9 = 0
.
OEIS References:
Examples
iex> Predicates.is_harshad_number?(6)
true
iex> Predicates.is_harshad_number?(11)
false
iex> Predicates.is_harshad_number?(42)
true
iex> Predicates.is_harshad_number?(126)
true
iex> Predicates.is_harshad_number?(1180)
true
iex> Predicates.is_harshad_number?(99890)
true
Check if a number n
is highly abundant.
A number n
is highly abundant when the sum of the proper factors of n
is
greater than the sum of the proper factors of any number m
that is in 0 < m < n
.
Alternatively, for all natural numbers, m < n ; 𝜎(m) < 𝜎(n)
.
See also:
OEIS References:
Chunky.Sequence.OEIS.Sigma.create_sequence_a002093/1
- Highly abundant numbers
Examples
iex> Predicates.is_highly_abundant?(1)
true
iex> Predicates.is_highly_abundant?(5)
false
iex> Predicates.is_highly_abundant?(30)
true
iex> Predicates.is_highly_abundant?(2099)
false
iex> Predicates.is_highly_abundant?(2100)
true
Check if a number n
is a highly powerful number.
Highly powerful numbers are similar in concept to highly abundant numbers. For highly powerful numbers,
the product of the exponents of prime factors of the number n
need to be greater than the same property
for any number m
, such that 0 < m < n
.
If you need a sequence of highly powerful numbers, use the A005934
sequence in Chunky.Sequence.OEIS.Factors
, which
uses an max/compare method for building the sequence, which is vastly more efficient than repeated
calls to is_highly_powerful_number?/1
.
OEIS References:
See also:
Examples
iex> Predicates.is_highly_powerful_number?(4)
true
iex> Predicates.is_highly_powerful_number?(256)
false
iex> Predicates.is_highly_powerful_number?(62208)
true
Is n
a hoax number? Hoax numbers have a digit sum of n
equal to the digit
sum of the unique prime factors of n
.
For instance 22
has a digit sum of 4
, and the unique prime factors 2^1 * 11^1
,
with digit sum of 2 + 1 + 1
or 4
.
OEIS References:
See also:
Examples
iex> Predicates.is_hoax_number?(20)
false
iex> Predicates.is_hoax_number?(22)
true
iex> Predicates.is_hoax_number?(160)
true
iex> Predicates.is_hoax_number?(170)
false
iex> Predicates.is_hoax_number?(11209)
true
iex> Predicates.is_hoax_number?(11220)
false
Is n
a hypotenuse number? A hypotenuse number is a numer whose square can be written as the sum of two other squares.
A hypotenuse number is fairly literal - it can be the hypotenuse of an integer right triangle, i.e. it fullfils c
in
the equation a^2 + b^c = c^2
.
OEIS References:
See also:
Examples
iex> Predicates.is_hypotenuse_number?(5)
true
iex> Predicates.is_hypotenuse_number?(8)
false
iex> Predicates.is_hypotenuse_number?(25)
true
iex> Predicates.is_hypotenuse_number?(121)
false
iex> Predicates.is_hypotenuse_number?(592)
true
Is n
an impolite number? Impolite numbers cannot be written as the sum of two consecutive integers.
OEIS References:
See also:
Examples
iex> Predicates.is_impolite_number?(2)
true
iex> Predicates.is_impolite_number?(5)
false
iex> Predicates.is_impolite_number?(8)
true
iex> Predicates.is_impolite_number?(32)
true
iex> Predicates.is_impolite_number?(512)
true
When n
is squared, does any set of the left digits of n^2
, added to the right set, equal n
?
For example, 297
squared is 88209
, if we split digits so half (round up) are on the right, we
get the numbers 88
and 209
, and 88+209 = 297
. The number 4879
squared is 23804641
and
238 + 04641 == 4879
.
Note the difference between is_kaprekar_number?/1
and is_kaprekar_strict_number?/1
; the prior
can have any split of digits, so long as the first and second set of digits has at least one digit,
while the later splits the digits of n^2
into two equal (or near equal) numbers of digits.
OEIS References:
See also:
Examples
iex> Predicates.is_kaprekar_number?(9)
true
iex> Predicates.is_kaprekar_number?(40)
false
iex> Predicates.is_kaprekar_number?(45)
true
iex> Predicates.is_kaprekar_number?(4879)
true
iex> Predicates.is_kaprekar_number?(5292)
true
When n
is squared, do the left half of the digits of n^2
, added to the right half, equal n
?
For example, 297
squared is 88209
, if we split digits so half (round up) are on the right, we
get the numbers 88
and 209
, and 88+209 = 297
.
Note the difference between is_kaprekar_number?/1
and is_kaprekar_strict_number?/1
; the prior
can have any split of digits, so long as the first and second set of digits has at least one digit,
while the later splits the digits of n^2
into two equal (or near equal) numbers of digits.
OEIS References:
See also:
Examples
iex> Predicates.is_kaprekar_strict_number?(99)
true
iex> Predicates.is_kaprekar_strict_number?(703)
true
iex> Predicates.is_kaprekar_strict_number?(4950)
true
iex> Predicates.is_kaprekar_strict_number?(99999)
true
iex> Predicates.is_kaprekar_strict_number?(461539)
true
Is n
a left/right truncatable prime?
Truncatable primes are prime number that remain prime when successive digits are removed. For
a left/right truncatable prime, the number will start, and remain, prime as the left and right digits of the
number are recursively dropped at the same time, until the number is a single or double digit prime. For instance, 99729779
is a left/right-truncatable prime, because 99729779
, 972977
, 7297
, and 29
are all prime. For left/right
truncation the final number can be a one or two digit prime, depending on if the original number nad an odd or even
number of digits.
See also:
Examples
iex> Predicates.is_left_right_truncatable_prime?(433)
true
iex> Predicates.is_left_right_truncatable_prime?(1193)
true
iex> Predicates.is_left_right_truncatable_prime?(89)
true
iex> Predicates.is_left_right_truncatable_prime?(7)
true
iex> Predicates.is_left_right_truncatable_prime?(99729779)
true
Is n
a left truncatable prime?
Truncatable primes are prime number that remain prime when successive digits are removed. For
a left truncatable prime, the number will start, and remain, prime as the left digit of the
number is recursively dropped, until the number is a single digit prime. For instance, 967
is a left-truncatable prime, because 967
, 67
, and 7
are all prime.
See also:
Examples
iex> Predicates.is_left_truncatable_prime?(967)
true
iex> Predicates.is_left_truncatable_prime?(9137)
true
iex> Predicates.is_left_truncatable_prime?(9656934675)
false
iex> Predicates.is_left_truncatable_prime?(396334245663786197)
true
Is n
divided by the sum of the digits of n
a prime number?
The Moran numbers are n
such that the sum of digits divides evenly into n
, with the resulting
value p
being a prime number.
For instance, 399
is a Moran number, as 399 / (3 + 9 + 9) = 19
.
OEIS Referenes:
Examples
iex> Predicates.is_moran_number?(18)
true
iex> Predicates.is_moran_number?(36)
false
iex> Predicates.is_moran_number?(153)
true
iex> Predicates.is_moran_number?(1185)
true
iex> Predicates.is_moran_number?(26519)
true
iex> Predicates.is_moran_number?(194751)
true
Check if the integer n
is a Rhonda number to more than one base.
Generalized function: Chunky.Math.get_rhonda_to/2
See also:
Examples
iex> Predicates.is_multiple_rhonda?(1000)
true
iex> Predicates.is_multiple_rhonda?(1230)
false
Do the digits of n
to their own power sum to n
?
Münchhausen numbers are a small, finite set of numbers where each digit of n
taken to it's
own power, and then summed, equals n
. The four known numbers are 0, 1, 3435, 438579088
.
OEIS Reference:
See also:
Examples
iex> Predicates.is_munchhausen_number?(0)
true
iex> Predicates.is_munchhausen_number?(3)
false
iex> Predicates.is_munchhausen_number?(3435)
true
iex> Predicates.is_munchhausen_number?(9000)
false
iex> Predicates.is_munchhausen_number?(438579088)
true
Do the digits of length k
number n
, when individually taken to the k
th power and summed, equal n
?
For instance, the number 153
is narcissistic, because 1^3 + 5^3 + 3^3 = 153
.
OEIS References:
See also:
Examples
iex> Predicates.is_narcissistic_number?(9)
true
iex> Predicates.is_narcissistic_number?(20)
false
iex> Predicates.is_narcissistic_number?(370)
true
iex> Predicates.is_narcissistic_number?(8208)
true
iex> Predicates.is_narcissistic_number?(9800817)
true
Determine if a number is a negative integer.
Examples
iex> Predicates.is_negative?(-34)
true
iex> Predicates.is_negative?(0)
false
iex> Predicates.is_negative?(34)
false
Is n
a non-hypotenuse number? A non hypotenuse number is a numer whose square cannot be written as the sum of two other squares.
A non-hypotenuse number is fairly literal - it cannot be the hypotenuse of an integer right triangle, i.e. it cannot fullfil c
in
the equation a^2 + b^c = c^2
.
OEIS References:
See also:
Examples
iex> Predicates.is_nonhypotenuse_number?(1)
true
iex> Predicates.is_nonhypotenuse_number?(5)
false
iex> Predicates.is_nonhypotenuse_number?(22)
true
iex> Predicates.is_nonhypotenuse_number?(25)
false
iex> Predicates.is_nonhypotenuse_number?(332)
true
Predicate version of is_odd?/1
Integer guard.
Examples
iex> Predicates.is_odd?(33)
true
iex> Predicates.is_odd?(0)
false
iex> Predicates.is_odd?(34)
false
Odious numbers have an odd number of 1
s in their binary expansion.
See definition on MathWorld or Wikipedia.
OEIS References:
Chunky.Sequence.OEIS.Core.create_sequence_a000069/1
- Odious Numbers
See also:
Examples
iex> Predicates.is_odious_number?(2)
true
iex> Predicates.is_odious_number?(37)
true
iex> Predicates.is_odious_number?(144)
false
iex> Predicates.is_odious_number?(280)
true
iex> Predicates.is_odious_number?(19897)
true
Check if n
is a palindromic number in base 10.
Palindromic numbers, like palindromic words, are the same value when read forward and reversed.
See also:
OEIS References:
Chunky.Sequence.OEIS.Core.create_sequence_a002113/1
- Palindromes in base 10
Examples
iex> Predicates.is_palindromic?(1234)
false
iex> Predicates.is_palindromic?(123454321)
true
iex> Predicates.is_palindromic?(1004006004001)
true
Is n
a palindromic prime number?
Palindromic prime numbers are both palindromes (the same digits/number when the digits are reversed) and prime numbers. By definition palindromic primes are prime when their digits are reversed.
See also:
Examples
iex> Predicates.is_palindromic_prime?(373)
true
iex> Predicates.is_palindromic_prime?(78247074287)
true
iex> Predicates.is_palindromic_prime?(55)
false
Check if n
is pandigital in base 10.
Generalized function: Chunky.Math.is_pandigital_in_base?/2
Examples
iex> Predicates.is_pandigital?(123456789)
false
iex> Predicates.is_pandigital?(1023456789)
true
Determine if an integer is a perfect number.
A perfect integer is an n
where the sum of the proper divisors of n
is equal to n
. Alternatively,
an n
that satisfies 𝜎(n) == 2n
.
See also:
Examples
iex> Predicates.is_perfect?(5)
false
iex> Predicates.is_perfect?(6)
true
iex> Predicates.is_perfect?(20)
false
iex> Predicates.is_perfect?(33550336)
true
Check if n
is a perfect cube.
Perfect cubes are n
such that there exists an m
where m * m * m == n
or m^3 == n
.
See also:
Chunky.Math.factors/1
Chunky.Math.prime_factors/1
is_cubefree?/1
is_perfect_square?/1
is_squarefree?/1
Examples
iex> Predicates.is_perfect_cube?(6)
false
iex> Predicates.is_perfect_cube?(8000)
true
iex> Predicates.is_perfect_cube?(1879080904)
true
Check if n
is a perfect power.
Perfect powers are n
where positive integers m
and k
exist, such
that m^k == n
.
See also:
Examples
iex> Predicates.is_perfect_power?(4)
true
iex> Predicates.is_perfect_power?(100)
true
iex> Predicates.is_perfect_power?(226)
false
Check if n
is a perfect square.
Perfect squares are n
such that there exists an m
where m * m == n
.
See also:
Chunky.Math.factors/1
Chunky.Math.prime_factors/1
is_cubefree?/1
is_perfect_cube?/1
is_squarefree?/1
Examples
iex> Predicates.is_perfect_square?(0)
true
iex> Predicates.is_perfect_square?(1)
true
iex> Predicates.is_perfect_square?(3)
false
iex> Predicates.is_perfect_square?(25)
true
iex> Predicates.is_perfect_square?(123456)
false
Check if n
is a plaindrome in base 10.
The digits of n
always stay the same or increase when read left to right.
Generalized function: Chunky.Math.is_plaindrome_in_base?/2
Examples
iex> Predicates.is_plaindrome?(22367)
true
iex> Predicates.is_plaindrome?(2048)
false
Is n
a polite number? Polite numbers can be expressed as the sum of two consecutive digits.
OEIS References:
Chunky.Sequence.OEIS.Powers.create_sequence_a057716/1
- The non-powers of 2Chunky.Sequence.OEIS.Multiples.create_sequence_a138591/1
- Sums of two or more consecutive nonnegative integers
See also:
Examples
iex> Predicates.is_polite_number?(0)
false
iex> Predicates.is_polite_number?(3)
true
iex> Predicates.is_polite_number?(4)
false
iex> Predicates.is_polite_number?(17)
true
iex> Predicates.is_polite_number?(333)
true
iex> Predicates.is_polite_number?(4098)
true
Determine if a number is a positive integer.
Examples
iex> Predicates.is_positive?(4)
true
iex> Predicates.is_positive?(-3)
false
iex> Predicates.is_positive?(0)
false
Is n
a Poulet number?
Poulet numbers are Fermat pseudo-primes to base 2.
See also:
Examples
iex> Predicates.is_poulet_number?(107)
false
iex> Predicates.is_poulet_number?(271)
false
iex> Predicates.is_poulet_number?(341)
true
iex> Predicates.is_poulet_number?(1387)
true
iex> Predicates.is_poulet_number?(10261)
true
Determine if an integer n
is a powerful number.
A powerful number is an integer n
such that for all prime factors m
of n
,
m^2
also evenly divides n
. Alternatively, a powerful number n
can be written
as n = a^2 * b^3
for positive integers a
and b
; n
is the product of a square
and a cube.
See also:
Examples
iex> Predicates.is_powerful_number?(8)
true
iex> Predicates.is_powerful_number?(10)
false
iex> Predicates.is_powerful_number?(800)
true
iex> Predicates.is_powerful_number?(970)
false
Is n
a practical number? A practical number is a positive integer n
where all positive
integers less than n
can be written as a sum of the distinct divisors of n
.
For instance, 8
is a practical number. Given the divisors 1, 2, 4
, the non-divisors
smaller than 8
can be writen as 3 = 1 + 2, 5 = 2 + 3, 6 = 3 + 2 + 1, 7 = 4 + 2 + 1
.
Also called the panarithmic numbers.
OEIS References:
Examples
iex> Predicates.is_practical_number?(1)
true
iex> Predicates.is_practical_number?(11)
false
iex> Predicates.is_practical_number?(120)
true
iex> Predicates.is_practical_number?(124)
false
iex> Predicates.is_practical_number?(5152)
true
Is n
a primary pseudoperfect number? A number is primary pseudoperfect if the sum of 1 over n
and 1 over the
prime factors of n
equals 1
.
This summation over reciprocals of prime factors is also called the Egyptian fraction:
This function uses the alternate fractional summation of:
OEIS References:
See also:
is_erdos_nicolas_number?/1
is_primitive_pseudoperfect_number?/1
is_primitive_weird_number?/1
is_pseudoperfect_number?/1
is_weird_number?/1
Examples
iex> Predicates.is_primary_pseudoperfect_number?(2)
true
iex> Predicates.is_primary_pseudoperfect_number?(4)
false
iex> Predicates.is_primary_pseudoperfect_number?(6)
true
iex> Predicates.is_primary_pseudoperfect_number?(210)
false
iex> Predicates.is_primary_pseudoperfect_number?(1806)
true
Determine if a positive integer is prime.
This function uses a Miller-Rabin primality test, with 40 iterations.
See also:
OEIS References:
Chunky.Sequence.OEIS.Core.create_sequence_a000040/1
- The prime numbers
Examples
iex> Predicates.is_prime?(13)
true
iex> Predicates.is_prime?(233*444*727*456)
false
iex> Predicates.is_prime?(30762542250301270692051460539586166927291732754961)
true
Determine if a positive integer is prime.
This function uses a cache of the first 100 primes as a first stage sieve and comparison set. In some
cases using this method will result in a speed up over using is_prime?/1
:
- For numbers < 542,
is_prime_fast?/1
is a MapSet membership check - When iterating integers for prime candidates,
is_prime_fast?/1
can show an ~9% speed up overis_prime?/1
In all cases, is_prime_fast?/1
falls back to calling is_prime?
and the Miller-Rabin primality test code
in cases where the prime cache cannot conclusively prove or disprove primality.
See also:
OEIS References:
Chunky.Sequence.OEIS.Core.create_sequence_a000040/1
- The prime numbers
Examples
iex> 1299601 |> Predicates.is_prime_fast?()
true
iex> 1237940039285380274899124225 |> Predicates.is_prime_fast?()
false
Check if n
is a power m
of a prime, where m
>= 1.
This is functionally a combination of is_perfect_power?/1
and is_prime?/1
, but
interleaves the factorization, leading to a speed up over using the two functions
independently.
See also:
OEIS References:
Chunky.Sequence.OEIS.Core.create_sequence_a000961/1
- Powers of Primes
Examples
iex> Predicates.is_prime_power?(2)
true
iex> Predicates.is_prime_power?(9)
true
iex> Predicates.is_prime_power?(10)
false
iex> Predicates.is_prime_power?(144)
false
Check if n
is a prime vampire number.
A prime vampire number needs to mee the same criteria as a standard vampire number (see is_vampire_number?/1
),
with the additional criteria of:
- Both of the factors of
n
,a
andb
, must be prime
See also:
Examples
iex> Predicates.is_prime_vampire_number?(6881)
false
iex> Predicates.is_prime_vampire_number?(117067)
true
Is n
pseudoperfect, but all the proper divisors of n
not pseudoperfect?
OEIS References:
See also:
is_erdos_nicolas_number?/1
is_primary_pseudoperfect_number?/1
is_primitive_weird_number?/1
is_pseudoperfect_number?/1
is_weird_number?/1
Examples
iex> Predicates.is_primitive_pseudoperfect_number?(6)
true
iex> Predicates.is_primitive_pseudoperfect_number?(8)
false
iex> Predicates.is_primitive_pseudoperfect_number?(28)
true
iex> Predicates.is_primitive_pseudoperfect_number?(270)
false
iex> Predicates.is_primitive_pseudoperfect_number?(272)
true
Is n
a weird number, but all proper divisors of n
are not weird numbers?
OEIS References:
See also:
is_erdos_nicolas_number?/1
is_primary_pseudoperfect_number?/1
is_primitive_pseudoperfect_number?/1
is_pseudoperfect_number?/1
is_weird_number?/1
Examples
iex> Predicates.is_primitive_weird_number?(70)
true
iex> Predicates.is_primitive_weird_number?(800)
false
iex> Predicates.is_primitive_weird_number?(836)
true
iex> Predicates.is_primitive_weird_number?(4030)
true
Determine if n
is pseudo-prime to base 10.
Generalized function: Chunky.Math.is_pseudo_prime?/2
See also:
Examples
iex> Predicates.is_pseudo_prime?(9)
true
iex> Predicates.is_pseudo_prime?(33)
true
iex> Predicates.is_pseudo_prime?(47)
false
iex> Predicates.is_pseudo_prime?(481)
true
iex> Predicates.is_pseudo_prime?(559)
false
iex> Predicates.is_pseudo_prime?(8401)
true
Check if n
is a pseudo vampire number.
The pseudo-vampire numbers have more relaxed criteria than the standard
vampire numbers (see is_vampire_number?/1
). Pseudo-vampires change the restrictions on the number of
digits in n
and the factors a
and b
, such that:
n
can have an even or odd number of digits- The factors
a
andb
can be of any length, not strictly of half the length ofn
See also:
Examples
iex> Predicates.is_pseudo_vampire_number?(126)
true
iex> Predicates.is_pseudo_vampire_number?(128)
false
iex> Predicates.is_pseudo_vampire_number?(19026)
true
iex> Predicates.is_pseudo_vampire_number?(1025779)
true
Can n
be written as a sum of some or all of its divisors?
The pseudoperfect numbers are a super-set of the perfect numbers (where the sum of factors is equal to n
), such
that the sum of any combination of the factors of n
equal n
. Finding pseudoperfect numbers
is equivalent to solving the Subset Sum, an NP-Complete problem. For numbers with a lot of factors, this
algorithm will run in the worst case of exponential time.
OEIS References:
See also:
is_erdos_nicolas_number?/1
is_primary_pseudoperfect_number?/1
is_primitive_pseudoperfect_number?/1
is_primitive_weird_number?/1
is_weird_number?/1
Examples
iex> Predicates.is_pseudoperfect_number?(4)
false
iex> Predicates.is_pseudoperfect_number?(6)
true
iex> Predicates.is_pseudoperfect_number?(12)
true
iex> Predicates.is_pseudoperfect_number?(150)
true
iex> Predicates.is_pseudoperfect_number?(1944)
true
Check if n
is a Repdigit number.
Repdigits numbers are a generalization of a Repunit - a number consisting of a single repeating
digit. Repdigit numbers can occur in any numeric base > 1. When evaluating numbers in bases
greater than base 10, lists of digits should be used (see to_base/2
).
Examples
iex> Predicates.is_repdigit?(123)
false
iex> Predicates.is_repdigit?(22222)
true
iex> Predicates.is_repdigit?(88888888888)
true
iex> Math.to_base(9884745, 60) |> Predicates.is_repdigit?()
true
iex> Math.to_base(9884745, 60)
[45, 45, 45, 45]
Check if n
is a Repunit.
Repunits are numbers consisting of all 1
s in base 10. Hence, R1 == 1
, R2 == 11
, etc.
Examples
iex> Predicates.is_repunit?(0)
false
iex> Predicates.is_repunit?(11)
true
iex> Predicates.is_repunit?(11011)
false
iex> Predicates.is_repunit?(1111111)
true
iex> Predicates.is_repunit?(2071723 * 5363222357)
true
Determine if n
is a Rhonda number to base 10.
Generalized function: Chunky.Math.is_rhonda_to_base?/2
See also:
Examples
iex> Predicates.is_rhonda_to_base_10?(35581)
true
iex> Predicates.is_rhonda_to_base_10?(327)
false
Determine if n
is a Rhonda number to base 12.
Generalized function: Chunky.Math.is_rhonda_to_base?/2
See also:
Examples
iex> Predicates.is_rhonda_to_base_12?(32742)
true
iex> Predicates.is_rhonda_to_base_12?(327)
false
Determine if n
is a Rhonda number to base 14.
Generalized function: Chunky.Math.is_rhonda_to_base?/2
See also:
Examples
iex> Predicates.is_rhonda_to_base_14?(135196)
true
iex> Predicates.is_rhonda_to_base_14?(327)
false
Determine if n
is a Rhonda number to base 15.
Generalized function: Chunky.Math.is_rhonda_to_base?/2
See also:
Examples
iex> Predicates.is_rhonda_to_base_15?(15873)
true
iex> Predicates.is_rhonda_to_base_15?(327)
false
Determine if n
is a Rhonda number to base 16.
Generalized function: Chunky.Math.is_rhonda_to_base?/2
See also:
Examples
iex> Predicates.is_rhonda_to_base_16?(50055)
true
iex> Predicates.is_rhonda_to_base_16?(327)
false
Determine if n
is a Rhonda number to base 20.
Generalized function: Chunky.Math.is_rhonda_to_base?/2
See also:
Examples
iex> Predicates.is_rhonda_to_base_20?(86591)
true
iex> Predicates.is_rhonda_to_base_20?(327)
false
Determine if n
is a Rhonda number to base 30.
Generalized function: Chunky.Math.is_rhonda_to_base?/2
See also:
Examples
iex> Predicates.is_rhonda_to_base_30?(22784)
true
iex> Predicates.is_rhonda_to_base_30?(327)
false
Determine if n
is a Rhonda number to base 4.
Generalized function: Chunky.Math.is_rhonda_to_base?/2
See also:
Examples
iex> Predicates.is_rhonda_to_base_4?(94185)
true
iex> Predicates.is_rhonda_to_base_4?(327)
false
Determine if n
is a Rhonda number to base 60.
Generalized function: Chunky.Math.is_rhonda_to_base?/2
See also:
Examples
iex> Predicates.is_rhonda_to_base_60?(91224)
true
iex> Predicates.is_rhonda_to_base_60?(327)
false
Determine if n
is a Rhonda number to base 6.
Generalized function: Chunky.Math.is_rhonda_to_base?/2
See also:
Examples
iex> Predicates.is_rhonda_to_base_6?(15104)
true
iex> Predicates.is_rhonda_to_base_4?(327)
false
Determine if n
is a Rhonda number to base 8.
Generalized function: Chunky.Math.is_rhonda_to_base?/2
See also:
Examples
iex> Predicates.is_rhonda_to_base_8?(56420)
true
iex> Predicates.is_rhonda_to_base_8?(327)
false
Determine if n
is a Rhonda number to base 9.
Generalized function: Chunky.Math.is_rhonda_to_base?/2
See also:
Examples
iex> Predicates.is_rhonda_to_base_9?(47652)
true
iex> Predicates.is_rhonda_to_base_9?(327)
false
Is n
a right truncatable prime?
Truncatable primes are prime number that remain prime when successive digits are removed. For
a right truncatable prime, the number will start, and remain, prime as the right digit of the
number is recursively dropped, until the number is a single digit prime. For instance, 23399
is a right-truncatable prime, because 23399
, 2339
, 233
, 23
, and 2
are all prime.
See also:
Examples
iex> Predicates.is_right_truncatable_prime?(23399)
true
iex> Predicates.is_right_truncatable_prime?(37)
true
iex> Predicates.is_right_truncatable_prime?(59393)
true
iex> Predicates.is_right_truncatable_prime?(59397)
false
Is n
a composite number with exactly two prime factors?
OEIS References:
See also:
Examples
iex> Predicates.is_semiprime_number?(4)
true
iex> Predicates.is_semiprime_number?(11)
false
iex> Predicates.is_semiprime_number?(21)
true
iex> Predicates.is_semiprime_number?(128)
false
iex> Predicates.is_semiprime_number?(40773)
true
Is n
a divisible by 2, but not by 4?
Singly divisible numbers are of the form 4*n + 2
.
OEIS References:
See also:
Examples
iex> Predicates.is_singly_even_number?(2)
true
iex> Predicates.is_singly_even_number?(8)
false
iex> Predicates.is_singly_even_number?(1930)
true
iex> Predicates.is_singly_even_number?(79874)
true
Is n
a Smith Number? Smith numbers have equal digit sums in n
and the summed factors of n
.
The canonical example of a Smith number is 4937775
. The digits sum is 42
(4 + 9 + 3 + 7 + 7 + 7 + 5
),
as is the sum of the prime factorization 3^1 + 5^2 + 65837^1
(3 + (5 * 2) + (6 + 5 + 8 + 3 + 7)
).
OEIS References:
See also:
Examples
iex> Predicates.is_smith_number?(4)
true
iex> Predicates.is_smith_number?(5)
false
iex> Predicates.is_smith_number?(8)
false
iex> Predicates.is_smith_number?(382)
true
iex> Predicates.is_smith_number?(436)
false
iex> Predicates.is_smith_number?(8545)
true
iex> Predicates.is_smith_number?(13444)
false
iex> Predicates.is_smith_number?(4937775)
true
Check if n
is a sphenic number, the product of three distinct primes.
See also:
Example
iex> Predicates.is_sphenic_number?(4)
false
iex> Predicates.is_sphenic_number?(66)
true
iex> Predicates.is_sphenic_number?(51339)
true
Check if an integer n
has no factors greater than 1
that are perfect squares.
See also:
Chunky.Math.factors/1
Chunky.Math.prime_factors/1
is_cubefree?/1
is_perfect_cube?/1
is_perfect_square?/1
OEIS References:
Chunky.Sequence.OEIS.Core.create_sequence_a005117/1
- Squarefree numbers
Examples
iex> Predicates.is_squarefree?(3)
true
iex> Predicates.is_squarefree?(8)
false
iex> Predicates.is_squarefree?(99935)
true
Is n
a semiprime and also square free - a composite of two distinct primes?
This function is an optimization of combining is_semiprime_number?/1
and is_squarefree?/1
.
OEIS References:
See also:
Examples
iex> Predicates.is_squarefree_semiprime?(4)
false
iex> Predicates.is_squarefree_semiprime?(21)
true
iex> Predicates.is_squarefree_semiprime?(58)
true
iex> Predicates.is_squarefree_semiprime?(187)
true
iex> Predicates.is_squarefree_semiprime?(4414)
true
Check if n
is strictly non-palindromic.
These numbers are non-palindromic in any numeric base from 2 to n - 2
. For larger
numbers this can be a very expensive check.
See also:
Examples
iex> Predicates.is_strictly_non_palindromic?(6)
true
iex> Predicates.is_strictly_non_palindromic?(19)
true
iex> Predicates.is_strictly_non_palindromic?(80)
false
iex> Predicates.is_strictly_non_palindromic?(317)
true
Is n
a two sided prime, a number that is both a left and right trucatable prime.
Truncatable primes are prime number that remain prime when successive digits are removed. For
a two sided prime, the number will start, and remain, prime under both left and right truncation.
For instance, 3137
is a two-sided prime, because:
3137
is prime313
,31
, and3
are prime (right truncation)137
,37
, and7
are prime (left truncation)
See also:
Examples
iex> Predicates.is_two_sided_prime?(7)
true
iex> Predicates.is_two_sided_prime?(313)
true
iex> Predicates.is_two_sided_prime?(3137)
true
iex> Predicates.is_two_sided_prime?(739397)
true
Does the repeated sum of squares of the digits of n
converge to a value other than 1
?
By repeatedly taking the digits of a number, squaring them, and summing the result, all
numbers will eventually converge to one of the numbers 0, 1, 4, 16, 20, 37, 42, 58, 89, or 145
. Unhappy
numbers coverge to a value other than 1
.
OEIS References:
See also:
Examples
iex> Predicates.is_unhappy_number?(2)
true
iex> Predicates.is_unhappy_number?(25)
true
iex> Predicates.is_unhappy_number?(475)
true
iex> Predicates.is_unhappy_number?(953)
true
iex> Predicates.is_unhappy_number?(11728)
true
Check if n
is a true vampire number.
A vampire number is a number n
that fullfils the following criteria:
n
has an even number of digitsn
can be factored into two digitsa
andb
- Both
a
andb
half exactly half as many digits asn
- One or the other of
a
orb
can have trailing zeros, but not both a
andb
contain all of the original digits ofn
, in any order, including duplicated digits inn
See also:
Examples
iex> Predicates.is_vampire_number?(1260)
true
iex> Predicates.is_vampire_number?(6000)
false
iex> Predicates.is_vampire_number?(6880)
true
iex> Predicates.is_vampire_number?(125500)
true
Does the prime factorization of n
have mored digits (counting primes and powers) than n
?
The wasteful numbers are sometimes called the extravagant numbers. When counting digits of
the prime factorization the prime and it's exponent are combined together, so 4
is an extravagant
number, because its prime factorization is 2^2
or 22
written out.
OEIS References:
See also:
Examples
iex> Predicates.is_wasteful_number?(4)
true
iex> Predicates.is_wasteful_number?(24)
true
iex> Predicates.is_wasteful_number?(110)
true
iex> Predicates.is_wasteful_number?(14330)
true
Is n
a weakly prime number?
A prime number n
is called weakly prime if it becomes not prime when any one of its digits
is changed to every single other digit. Testing the number 347
would involve testing all
of the numbers 147
, 247
, 447
, 547
, ..., 348
, and 349
to see if they were prime. The
number 347
is not weakly prime because 947
is prime.
See also:
Examples
iex> Predicates.is_weakly_prime?(294001)
true
iex> Predicates.is_weakly_prime?(294007)
false
iex> Predicates.is_weakly_prime?(3085553)
true
Weird numbers are abundant but not pseudoperfect numbers.
A weird number n
has a sum of factors that is greater than n
(see is_abundant?/1
), but no subset of
factors that sum to exactly n
(see is_pseudoperfect_number?/1
).
OEIS References:
See also:
is_erdos_nicolas_number?/1
is_primary_pseudoperfect_number?/1
is_primitive_pseudoperfect_number?/1
is_primitive_weird_number?/1
is_pseudoperfect_number?/1
Examples
iex> Predicates.is_weird_number?(24)
false
iex> Predicates.is_weird_number?(70)
true
iex> Predicates.is_weird_number?(820)
false
iex> Predicates.is_weird_number?(836)
true
iex> Predicates.is_weird_number?(10792)
true
Predicate for testing for 0
Examples
iex> Predicates.is_zero?(0)
true
iex> Predicates.is_zero?(34)
false
iex> Predicates.is_zero?(-34)
false
Is n
divisible by the product of the digits of n
?
The Zuckerman numbers in base 10 - numbers n
such that the product of the digits of n
cleanly divides n
. For example, 624
is a Zuckerman number, as 624 / (6 * 2 * 4) = 13
.
OEIS References:
Examples
iex> Predicates.is_zuckerman_number?(9)
true
iex> Predicates.is_zuckerman_number?(13)
false
iex> Predicates.is_zuckerman_number?(36)
true
iex> Predicates.is_zuckerman_number?(612)
true
iex> Predicates.is_zuckerman_number?(1344)
true
iex> Predicates.is_zuckerman_number?(1148424192)
true