Professional Documents
Culture Documents
To see the usage of these functions, a lengthy set of demos has been
provided. You can view them as html simply by opening the file
demo_vpi.html into your web browser. In general, this toolbox contains
every operation that I could implement on a scalar integer variable.
Note that you can add, subtract, multiply, or divide two vpi numbers
exactly as you would do in matlab, you can also do those same
operations on a vpi number with any integer. You can even work with
simple arrays of vpi numbers. For example, you can do things like this:
>> a = vpi(2);
>> b = 17*a^112 + 3;
>> [a,b]*[b;a+1]
These vpi tools are not truly infinite precision, in the sense that if you
work with such large numbers that you run out of memory, they will
still fail. This will be a really big number however, and any operations
on something even close to that huge will be really slow to work with
in MATLAB. But most operations on numbers with only a few hundred
or even many thousands of digits will be quite acceptably fast.
Working with the factors of vpi numbers, generating those factors, and
primality testing
factor - Computes the factors of an integer
gcd - Greatest Common Divisor of two (or more) vpi objects
isprime - use a specified primality test to check if a number is prime
lcm - Least Common Multiple of two (or more) vpi objects
legendresymbol - computes the Legendre symbol (a/p)
mersenne - identify whether 2^p-1 is a Mersenne prime, using the
Lucas-Lehmer test
modroot - Find x such that (mod(x^2,p) == a), the sqrt of a quadratic
residue
quadraticresidues - list all the quadratic residues of a number
totient - The number of positive integers less than N that are
coprime to N
Base conversion
base2vpi - Converts an integer in an arbitrary base into vpi (decimal)
form
bin2vpi - Converts a binary representation of an integer into vpi
(decimal) form
double - Conversion from a vpi object to a double
single - Conversion from a vpi object to a single.
vpi2base - Converts a vpi number to an arbitrary base (highest order
"digit" first)
vpi2bin - Converts a vpi number to binary (highest order bit first)
vpi2english - Generate a readable text version of the number
As far as the general design of this toolbox, I chose to use the older
style of having separate functions to create the class, since not yet
enough people (in my opinion) have the most recent MATLAB release.
In general, I'll invite you to have fun with these tools as I did in writing
them. They are not an adequate substitute for those in the symbolic
toolbox, but even after 20 years of working with the language I still
find myself amazed at what you can do in MATLAB for only a few days
of work invested.
John D'Errico
woodchips@rochester.rr.com
1/26/09