Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have very large numbers (million digits).

number = A*10^partlen + B

As of now, I split the numbers by this way:

 TotalLen = IntegerLength[a]; 
 partlen = IntegerPart[TotalLen/2];
 Print[First[Timing[A = IntegerPart[number/(10^partlen )]]]];
 Print[First[Timing[B = Mod[number, 10^partlen ]]]]

And the timings for a 6 million digits number are:

4.703

0.36

Converting the number to strings and rebuilding the parts is even slower than this.

Is there any faster way?

share|improve this question
2  
You're aware of Mod[]'s partner Quotient[], aren't you? For that matter, have you seen QuotientRemainder[]? –  J. M. Nov 24 '12 at 10:32
add comment

1 Answer

Per J.M. suggestion, I've got a ten fold increase in speed:

TotalLen = IntegerLength[a]; 

RightLen = Quotient[TotalLen, 2]; 

Print[First[Timing[{A, B} = QuotientRemainder[a, (10^RightLen)]]]];

Timing:

0.344

Although the time decreased but it is yet so large just for pre-processing.

share|improve this answer
    
You didn't totally take my suggestion. Try RightLen = Quotient[TotalLen, 2]; Also, Mathematica is perfectly capable of parallel assignment: {A, B} = QuotientRemainder[number, 10^RightLen]. –  J. M. Nov 24 '12 at 12:27
    
Quotient[] and QuotientRemainder[] are two different functions, see... –  J. M. Nov 24 '12 at 13:11
    
Oh sorry, I mistyped it –  Mohsen Afshin Nov 24 '12 at 13:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.