Factor of large numbers in matlab and then get the numbers as a result

I want to add ( these ) large numbers, and Matlab does it perfectly. ( These are the results.)

The result of the factor (NumberOfTypeSym) is another symbolic object:

>> factor( sym('79228162514264337589248983040') ) ans = 2^32*3*5*17*257*641*65537*6700417 

But there is nothing I can do about it except to look at it.

Is there a way to access single strokes and metrics?

(I don’t understand why they will not just give me the nx2 matrix, but prime numbers on the left and exponents on the right).

What I especially need at the moment is the number of primes as a result, i.e. the sum of all indicators.

+4
source share
4 answers

It is easy to use the vpi tool found during file sharing. This returns a direct list of integers.

 x=factor(vpi('79228162514264337589248983040')) x = Columns 1 through 7 2 2 2 2 2 2 2 Columns 8 through 14 2 2 2 2 2 2 2 Columns 15 through 21 2 2 2 2 2 2 2 Columns 22 through 28 2 2 2 2 2 2 2 Columns 29 through 35 2 2 2 2 3 5 17 Columns 36 through 39 257 641 65537 6700417 

The replacement (essentially ready for release) for vpi is vpij, which takes half the time to determine this number, but vpij can handle significantly larger numbers than vpi can. In fact, the last thing to write is an even better version of the factor, but I will most likely release vpij before this is done.

Of course, factors must also be integer variables of accuracy, since some of these factors will be quite large. Here is a number with 50 + digits that someone has commented on on a math site recently.

 N = vpij(84)^27 + 1 N = 9026943488964407632833018690186861978797224381906945 x = factor(N) x = 5 17 19 109 367 757 2017 230077 397741265470599434164843152148837 
+3
source

How about this:

 >> x=factor( sym('79228162514264337589248983040') ) x = 2^32*3*5*17*257*641*65537*6700417 >> p=char(x) p = 2^32*3*5*17*257*641*65537*6700417 >> s=regexp(p,'*','split') s = '2^32' '3' '5' '17' '257' '641' '65537' '6700417' >> exp=regexp(s{1},'\^','split') exp = '2' '32' >> [exp s(2:end)] ans = '2' '32' '3' '5' '17' '257' '641' '65537' '6700417' 

Now play with the characters, convert them to numbers, if necessary.

+3
source

Just an extension of the answer provided by P0W:

 function [ y ] = symfactor2mat( x ) Str = char(x) ; Parts = regexp(Str,'*','split') ; Long = length(Parts) ; Mat = sym(ones(Long,2)) ; for m=1:Long Part = Parts{m} ; if isempty(strfind( Part, '^' )) Mat(m,1) = sym(Part) ; else PE = regexp(Part,'\^','split') ; % prime and exponent Mat(m,1) = sym(PE{1}) ; Mat(m,2) = sym(PE{2}) ; end end y = Mat ; end 
+1
source

Just add another option:

 N = sym('79228162514264337589248983040'); F = children(factor(N)); primefactors = F(2:2:end) primefactors = [ 2, 3, 5, 17, 257, 641, 65537, 6700417] multiplicities = F(3:2:end) multiplicities = [ 32, 1, 1, 1, 1, 1, 1, 1] sum(multiplicities) ans = 39 

Or using the function found in the MuPAD documentation ,

 feval(symengine, 'numlib::Omega', N) ans = 39 
0
source

Source: https://habr.com/ru/post/1495088/


All Articles