VPI has no problem dividing a number by 2. Here, for example, is one of my favorite moderately large primes. (That is, it is the smallest value of n, such that (n+1)*17^n-1 is a prime.)
N = 42*vpi(17)^41 - 1;
N
N =
11793835525721281286023333792285550996689383337325513
mod(N,2)
ans =
1
N/2
ans =
5896917762860640643011666896142775498344691668662756
[Q,R] = quotient(N,2)
Q =
5896917762860640643011666896142775498344691668662756
R =
1
You can use quotient divides by 2, also returning the remainder of that integer divide.
But, if you absolutely need to use syms...
N = 42*sym(17)^41 - 1
N =
11793835525721281286023333792285550996689383337325513
mod(N,2)
ans =
1
The reason you had a problem with sym is because you used it improperly. When you did this:
n = sym(85098710871039482877157098724987234509871123545)
you made a mistake. When you type it like this:
n = sym(85098710871039482877157098724987234509871123545)
n =
85098710871039487337987513201467377652091322368
MATLAB does NOT look at what you will be doing with the number 85098710871039482877157098724987234509871123545. It converts it to a DOUBLE, so roughly 16 decimal digits. Then it passes that to sym, so you get garbage. Remember that when you want a number to be interpreted NOT as a double, you cannot let MATLAB create the number as a double. Both VPI and SYM have a simple way to avoid that problem.
See the difference here:
n = sym('85098710871039482877157098724987234509871123545')
n =
85098710871039482877157098724987234509871123545
In fact, VPI has the same problem. You cannot just pass that number to VPI as a double. syms actually has no problem with factoring that number.
factor(sym('85098710871039482877157098724987234509871123545'))
ans =
[ 3, 5, 59, 144864327936049, 663770969827375707224424962533]
In fact, sym is quicker than is VPI on that number, in fact, syms even beats my replacement for VPI, thus is much faster than VPIJ in factoring. (One thing I always wanted to improve. One day I'll get a nice quadratic sieve code running for VPIJ.)
Best Answer