ZMath
Documentation
Loading
the addin:
- Download the file, ZZMath.xll, to your machine. E.g. C:\ZMath.xll
- Start Excel and choose ‘Open’ from the File menu.
- Browse to where you saved the ZZMath.xll file and click open.
- The addin should now be loaded.
A quick
test to verify addin is working properly
- Click on a cell
- Type =ZPow(2, 200)
You should see the number 1606938044258990275541962092341162602522202993782792835301376
Finding
available functions:
- Choose ‘Function’ from Excel’s Insert menu.
- In the ‘Select a category’ box, select ‘ZMath’. Note: It will most likely be at the very bottom of this menu and you’ll have to scroll down.
- Click on a function displayed to see a short description. Choosing one then allows you to enter parameters through a wizard.
Usage
Notes
- Numbers passed to the ZMath functions need to either by strings or numbers less than 12 digits. This is done to prevent Excel from rounding or shortening the number in any way.
- This version only supports numbers up to 250 digits. This is a limitation on string lengths returned from Excel XLL addins.
Function
Documentation:
ZAdd
Adds two integers.
E.g.
=ZAdd(10,20) Returns 30
ZDigits
Returns number of decimal digits in a given integer.
E.g.
=ZDigits(123) Returns 3
ZDiv
Performs Integer Division.
E.g.
=ZDiv(11,2) Returns 5
ZDLog
(x,c,n)
Performs a discrete log.
Finds k such
that x^k = c (mod n). If no such k exists, the return returns the string
“None”
WARNING: This is a slow implementation so be careful for large n.
E.g.
=ZDLog(7,3,11) Returns 4 because 7^4 = 3 mod 11
ZFactor
(n)
Factors an integer into primes. Uses a combination of trial division and the p-1 method. It will return an incomplete factorization if it cannot finish factoring in reasonable time. If it does abort this way, composite cofactors are prefixed with “C_” so you know which factors are prime and what factors are composite.
NEW: If you download http://www.spacefire.com/numbertheory/factor.exe and put it in a directory called “bin” such that the path to it is “C:\bin\factor.exe” the addin will use it for factorization. This allows for complete factorization of numbers otherwise not factorable using trial division or Pollard p-1. However, it will not return until factor.exe either gives up or factors the number so be careful passing large numbers or you’ll be waiting a long time for it to return.
E.g.
=ZFactor(“12345678987654321234567898765432123456789”);
If C:\bin\factor.exe is found, it will return
13 * 1158617 * 1486982106607 * 551221297394805607487
Otherwise, it will return
“13*1158617*C_819656206006771683200275631366609”
ZGCD
(x,y)
Returns Greatest Common Divisor (GCD) of two integers. Very fast.
E.g.
=ZGCD(15,25) Returns 5
ZInvMod
(A,M)
Returns X such that A*X=1 (mod M).
=ZInvMod(7,11) Returns "8" because 7*8 = 1 (mod 11)
ZJacobi
(a,n)
Computes the Jacobi symbol (a/n). This is often used to test for quadratic non-residues. If Jacobi(a,n) is not +1 then a cannot be a quadratic residue mod n.
E.g.
=ZJacobi(3,7) Returns -1
ZKAdic
(x,y,k)
Returns TRUE if x is k-adic
mod y. I.e. z^k = x (mod y), z exists
WARNING: This implementation
is slow so be careful using large y.
E.g.
=ZKAdic(3,4,5) Returns TRUE
ZKRootMod
(c,n,k)
Finds x such that x^k = c
(mod n).
WARNING: Slow implementation
so be careful using large n.
E.g.
=ZKRootMod(17,101,5) Returns 13 because 13^5=17 mod 101
ZKthRoot (x,
k)
Returns kth integer root of x
E.g.
=ZKthRoot(101, 3) Returns 4 because 3^4<=101 and 3^5>=101
ZLog
(x)
Returns natural log of x.
E.g.
=ZLog(2) Returns 0.693147
ZMod
(x,y)
Returns x mod y
E.g.
=ZMod(10, 3) Returns 1 because 10 mod 3 equals 1
ZMul
(x,y)
Returns product of two integers x and y
E.g.
=ZMul(5,7) Returns 35
ZNextPrime
(x)
Returns least prime greater than a given number
E.g.
=ZNextPrime(5) Returns 7
ZOrder
(b,n)
Finds least k
such that b^k = 1 (mod n)
E.g.
=ZOrder(2,71)
Returns 35. Note: 2^35 = 1
(mod 71)
ZPalindrome
(n)
Returns TRUE if n
is a palindrome (e.g. 123454321)
E.g.
=ZPalindrome(12321)
Returns TRUE
=ZPalindrome(12345)
Returns FALSE
ZPellSolve
(D)
Returns (x,y)
where x^2 - D*y^2 = +1
E.g.
=ZPellSolve(456)
Returns “(4205626175871,62245831984)”
ZPhi
(n)
Returns Euler’s totient function on n.
E.g.
=ZPhi(123) Returns 80. Note z^(phi(n)) = 1 (mod n)
ZPow (x,
y)
Returns x raised to the power y.
E.g.
=ZPow(2, 50) Returns 1125899906842624
ZPowMod (x, y,
z)
Returns x^y mod z.
E.g.
=ZPowMod(2, 123, 345) Returns 188
ZPrevPrime
(N)
Returns greatest prime less than N.
E.g.
=ZPrevPrime(5) Returns 3
ZProbPrime
(N)
Returns TRUE if N is a probable prime.
E.g.
=ZProbPrime(561) Returns FALSE.
ZReverse
(N)
Returns reversed base-10 representation of N.
E.g.
=ZReverse(123) Returns 321
ZRSA
(D)
Returns RSA challenge number of a given length. Historically RSA has had factorization challenges with large two-prime composite numbers growing in lengths of 10 digits. Valid D are D divisible by 10 between 100 and 250, or the values 129, 155, or 232.
E.g.
=ZRSA(100)
Returns:
1522605027922533360535618378132637429718068114961380688657908494580122963258952897654000350692006139
Note: Don’t expect to find factors for RSA numbers above 160. However, the addin actually has a database of known RSA factorizations, so running ZFactor on RSA 100, 110, 120, 129,130,140,155 will succeed!
ZSmallDivisor
(N)
Returns
smallest prime divisor of N (if under 2*10^9).
E.g.
=ZSmallDivisor(123) Returns 3
ZSquareFit
(a,b,c)
Returns polynomial f(x) such that f(1)=a, f(2)=b, f(3)=c using polynomial interpolation.
=ZSquareFit(1,4,11) Returns "2x^2 - 3x + 2"
ZSquareExtrap
(a,b,c,i)
Predicts i'th value of sequence starting with {a,b,c}. More specifically it creates a quadratic as in ZSquareFit(a,b,c) then returns f(i).
=ZSquareExtrap(1,4,11,4) Returns 22.
ZSqrt
(N)
Returns integer square root of N.
E.g.
=ZSqrt(10) Returns 3
ZSqrtMod (x,
y)
Finds z such
that z^2 = x (mod y).
Requires x to be
a quadratic residue mod y.
Requires y to be
an odd prime.
E.g.
=ZSqrtMod(5,
101)
Returns 45. Note 45^2 = 5 (mod 101)
ZSub (x,
y)
Returns x –
y.
E.g.
=ZSub(5, 3)
Returns 2
ZSuperPowerMod (q,
m)
Returns 2^(2^q) mod m.
E.g
=ZSuperPowerMod(12345, 54321) Returns 52411
ZXGCD(a,
b)
Returns (x,y) where ax+by=1.
E.g
=ZXGCD(3,5) Returns (2,-1)