NAME

Math::Numbers - 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);

DESCRIPTION

Math::Numbers is quite a simple module on matters of programming. What it's 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: Bluto's 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(). Bluto's 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);

Let's 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, it'll 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.

DEPENDENCIES

You will need List::Util to get Bluto_algorithm to work.

TODO

Lots of things are still left. A few examples are:

  • Admit any number of arguments from the object and returning evaluations for each.

  • Adding a method for proofs.

  • More, more number theory!

AUTHOR

David Moreno Garza, <damog@ciencias.unam.mx>

THANKS

Thanks go, as usual to the National Autonomous University of Mexico (UNAM, Universidad Nacional Autónoma de México, http://www.unam.mx/) for providing such a beautiful career. Thanks also to Raquel (http://www.maggit.com.mx) for being my day-to-day inspiration and special thanks to the #perl at FreeNode dudes and Marco Antonio Manzo (http://www.unixmonkeys.com/amnesiac/blog/) and Gunnarcito Wolf (http://www.gwolf.org).

COPYRIGHT AND LICENSE

Copyright (C) 2007 by David Moreno Garza

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.

The Do What The Fuck You Want To public license also applies. It's really up to you.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 292:

Non-ASCII character seen before =encoding in 'Autónoma'. Assuming UTF-8