Group Abstract Group Abstract

Message Boards Message Boards

0
|
229 Views
|
2 Replies
|
1 Total Like
View groups...
Share
Share this post:

Extracting results from Table[Solve[]...] functions return

Posted 1 month ago

Hi...

When using the Table[Solve[...]] command, the format of the returned data is not what I was expecting (the actual integer value solution), but instead some sort of {m -> value} format for each of the roots. For example:

p = {2, 3, 5, 7, 13, 17, 19, 31, 61, 89, 
   107, 127, 521, 607, 1279, 2203, 2281, 3217, 4253, 4423,
   9689, 9941, 11213, 19937, 21701, 23209, 44497, 86243, 110503, 132049,
   216091, 756839, 859433, 1257787, 1398269, 2976221, 3021377, 6972593, 13466917, 20996011,
   24036583, 25964951, 30402457, 32582657, 37156667, 42643801, 43112609, 57885161, 74207281, 77232917,
   82589933, 136279841};
numElements=10;

Do[
 mp[[nn]] = 2^p[[nn]] - 1;
 pn[[nn]] = mp[[nn]]*(mp[[nn]] + 1)/2;
 , {nn, 1, numElements}]
cs = Table[Solve[(m^2*(2 m^2 - 1) - pn[[ii]]) == 0 && m > 0, m, Integers], {ii, 1, numElements}];

And if I try and see the elements of the cs array, I don't get the expected numbers, and then if I try to use IntegerLength[] function to see how many digits in an individual item in the cs array is, I get the following:

In[473]:= cs[[1 ;; 10]]
IntegerLength[cs[[5]]]

Out[473]= {{}, {{m -> 2}}, {{m -> 4}}, {{m -> 8}}, {{m -> 64}}, {{m ->
     256}}, {{m -> 512}}, {{m -> 32768}}, {{m -> 1073741824}}, {{m -> 
    17592186044416}}}

Out[474]= {{IntegerLength[m -> 64]}}

So, rather than the expected "2" (which is the number of digits in 64), I get something I don't see how to further process.

So, what exactly do you call what the Table[Solve[]] command returns and how to save the returned integer roots for other work??

This is on Mathematica 14.3 on macOS.

Thanks very much...
-bob

POSTED BY: Bob Freeman
2 Replies
Posted 1 month ago

That is exactly what I was hoping for - thanks so much!!

The reason I'm doing things this way is because using the Mathematica MersennePrime[] function takes forever for anything above 18. Just using Mathematica to do the calculations from the known exponents is so much quicker. The ease with which it handles really big numbers is just amazing...

Thanks again...

-bob

POSTED BY: Bob Freeman

Maybe you want

Table[m /. Solve[(m^2*(2 m^2 - 1) - pn[[ii]]) == 0 && m > 0, m, Integers],
  {ii, 1, numElements}]

Solve[] returns a set of replacement rules of the form {{variable -> value},...}. You can plug them into any expression with /. (a.k.a. ReplaceAll[]).

You might also prefer SolveValues[] instead of Solve[]. It returns values instead of substitution rules.

POSTED BY: Michael Rogers
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard