Home  |  About Us  |  Link To Us  |  FAQ  |  Contact

# Math::Numbers 0.000000001

Date Added: September 13, 2010  |  Visits: 768

Math::Numbers is a Perl module that contains methods for mathematical approaches of concepts of the number theory. SYNOPSIS use Math::Numbers; my \$a = 123; my \$b = 34; my \$numbers = Math::Numbers->new(\$a, \$b [, ...]); print "They are coprimes (relatively primes)!n" if \$numbers->are_coprimes; print "The greatest common divisor of these at least two numbers is ", \$numbers->gcd; my \$number = Math::Numbers->new(\$a); print "It is prime!n" if \$number->is_prime; my @divisors = \$number->get_divisors; print "\$a is divisor of \$b!n" if \$number->is_divisor_of(\$b); Math::Numbers is quite a simple module on matters of programming. What its interesting is the focus and approach it is intended to be made from the Number Theory basis for Perl beginners (like me) and also for young mathematicians (like me). The normal topics of Number Theory include divisibility, prime numbers (which is separately intended to be covered by Math::Primes), congruences, quadratic residues, approximation for Real numbers, diophantine equations, etc. and all this is intended to be convered by the module on the concept on getting and setting values and also retriving the proof methods. METHODS new # Some methods require more than only one argument. my \$numbers = Math::Numbers->new(\$p, \$q, ...); # Some methods require only one. my \$number = Math::Numbers->new(\$p); Create a Math::Numbers object. Note that some of the methods will require objects created with only one or a defined numbers of arguments. gcd my \$gcd = \$numbers->gcd; Calculation of the Greatest Common Divisor. This is made by two different methods which are described below: Blutos algorithm and Euclidean algorithm: The former is used when computing GCD for more than two integers; the latter is used when getting the GCD for two numbers to improve speed. See below for information on each. Bluto_algorithm You will mostly not require to call this method, but directly gcd(). Blutos algorithm uses a brute force calculation used by mathematicians to get divisors and then GCD also called Primality Test. Bluto takes some spinaches stolen from Popeye and starts dividing m all the way through 2 to m/2. Euclidean_algorithm Euclid rocks. I have a very nice Budgerigar (http://en.wikipedia.org/wiki/Budgerigar) called the same in honor of him (have to upload a pic of him). As of now, this algorithm is only computed on two integers. From the Wikipedia entry: Given two natural numbers a and b: check if b is zero; if yes, a is the gcd. If not, repeat the process using (respectively) b, and the remainder after dividing a by b. This is exactly what our method does. is_divisor_of print "Yes, \$p is divisor of \$a...n" if \$number->is_divisor_of(\$a); Lets see if the number from the object is a divisor of \$a, which means that the division \$number/\$a will return an integer (not necesarily a natural). If it does, itll return 1; 0, otherwise. get_divisors my @divisors = \$number->get_divisors; What are the divisors of the number brought by the object? This only includes the Natural numbers. is_prime print "\$p is not prime!n" unless \$number->is_prime Returns 0 or 1 if the number from the object is prime or not, respectively. This method uses the, a bit slow, primality test. are_coprimes print "They are coprimes because their GCD is 1!n" if \$numbers->are_coprimes; Are the numbers from the object coprimes (relatively primes)? This means, the GCD is 1; (a, b, c, ...) = 1. Returns 1 or 0..

 Requirements: No special requirements Platforms: Linux Keyword: Divisor,  Gcd,  Libraries,  Mathnumbers,  Methods,  Number,  Numbers,  Perl Module,  Prime,  Programming Users rating: 0/10