mersenneforum.org

mersenneforum.org (https://www.mersenneforum.org/index.php)
-   PARI/GP (https://www.mersenneforum.org/forumdisplay.php?f=155)
-   -   PARI's commands (https://www.mersenneforum.org/showthread.php?t=13636)

science_man_88 2011-09-08 23:47

[QUOTE=science_man_88;270856]a few codes I've sent through PM:

[CODE]ali(n)=a=n-1;b=[];for(x=0,floor(.5*a),if(x==0,if(sigma(a^2)-a^2==n,b=concat(b,a^2)),if(sigma((x)*(a-x))-((x)*(a-x))==n,b=concat(b,(x)*(a-x)))));b=vecsort(b,,8)[/CODE]

checks up to floor(.5*a) in matching pairs multiplying them together and if the sigma checks go through puts them into b. sorts the vector at the end.


[CODE]for(z=6,6,print(z);for(x=1,#ali(z),print("\t"ali(z)[x]);for(y=1,#ali(ali(z)[x]),print("\t\t"ali(ali(z)[x])[y]);for(h=1,#ali(ali(z)[x])[y],print("\t\t\t"ali(ali(ali(z)[x])[y])[h]);for(i=1,#ali(ali(ali(z)[x])[y])[h],print("\t\t\t\t"ali(ali(ali(ali(z)[x])[y])[h])[i]))))))[/CODE]

z can be changed to any group of consecutive numbers this basically does the previous one on top of each other forming generation in later talk I believe I talk of it as aligen(n), please note these codes only find ones that have (n-1) split into 2 divisors.

the attachment has been scanned since I want to double check it, it represents most that I have tried with these codes.[/QUOTE]

does anyone else know the way to extend the first code to check for 3 values to multiply that add up to a? I get the sigma check change would be something like: sigma(<new variable>*x*(a-(x+<new variable>)))==n but I want it to act correct so it checks sums of 2 numbers first then three.

science_man_88 2011-09-09 02:08

[QUOTE=science_man_88;271229]does anyone else know the way to extend the first code to check for 3 values to multiply that add up to a? I get the sigma check change would be something like: sigma(<new variable>*x*(a-(x+<new variable>)))==n but I want it to act correct so it checks sums of 2 numbers first then three.[/QUOTE]

wasteful ( doesn't solve for 2 as well because if so it throws 0 into sigma) method found!

[CODE](n)->a=n-1;for(x=1,a,for(y=1,a,for(z=1,a,if(1+x+y+z==a&&sigma(x*y)-(x*y)==n,print(x*y),if(1+x+y+z==a&&sigma(x*z)-(x*z)==n,print(x*z),if(1+x+y+z==a&&sigma(y*z)-(y*z)==n,print(y*z),if(1+x+y+z==a&&sigma(x*y*z)-(x*y*z)==n,print(x*y*z))))))))[/CODE]

LaurV 2011-09-09 05:41

Asking the pari experts....
 
Question 1:
I have a file with a million lines. (So what?)
ASCII.
Each line is a number (no other characters except 0..9)
I have (in a separate variable) the number k. (not your business where did I get it from)

I want to read in a variable the number on the line k on the file.

How the hell I do that in pari/gp???

There is no "seek", "readline" or equivalents. The only possibility I found is to read all the file in a vector with "readvec" and take the component I need. What it would take (beside of "ages") few wheelbarrows of memory.

Question 2:
How the hell I can take the class "c" in "x=Mod(c,m)" as integer? Beside of the "ugly" construction "component(x,2)", which took me 2 days to find it (no specs in the help). They provide the member function ".mod" to take the m (like x.mod will return m), but no function to take the c. I figured later that I can apply a "component()" function to any internal structure, and from that it did not take me long to find out the the class c is in fact... the second component of the structure (the Mod structure is stored internally "viceversa").

In spite of the fact this question looks somehow tendentious, or picky, the reason is the fact that the only way to do a (somehow fast) "modexp" in pari is "a=Mod(x,m)^y" (which is taking modular reduction at each step, that is why is just "somehow" fast, and not really fast as in yafu), and latter if I want to compare "a==b" this will promote b from t_INT into t_INTMOD, killing all the process further. That is why the "component()" step has to be added.

Any idea? (Question 1 is really important, otherwise I have to write a separate application, and use "extern()" to read the line and put it in a separate file, and feed that to pari. Question 2 is just a curiosity.)

Thanks in advance.

science_man_88 2011-09-09 11:44

[QUOTE=science_man_88;271237]wasteful ( doesn't solve for 2 as well because if so it throws 0 into sigma) method found!

[CODE](n)->a=n-1;for(x=1,a,for(y=1,a,for(z=1,a,if(1+x+y+z==a&&sigma(x*y)-(x*y)==n,print(x*y),if(1+x+y+z==a&&sigma(x*z)-(x*z)==n,print(x*z),if(1+x+y+z==a&&sigma(y*z)-(y*z)==n,print(y*z),if(1+x+y+z==a&&sigma(x*y*z)-(x*y*z)==n,print(x*y*z))))))))[/CODE][/QUOTE]

few changes got it working for both 2 and 3 number combinations:

[CODE]a=n-1;for(x=0,a,for(y=1,a,for(z=1,a,if(x+y+z==a&&x!=0&&sigma(x*y)-(x*y)==n,print(x*y),if(x+y+z==a&&x!=0&&sigma(x*z)-(x*z)==n,print(x*z),if(x+y+z==a&&sigma(y*z)-(y*z)==n,print(y*z),if(x+y+z==a&&x!=0&&sigma(x*y*z)-(x*y*z)==n,print(x*y*z))))))))[/CODE]

okay testing proves I stupidly forgot to print a^2 ( later will turn to a concat) and use a vecsort at the end.

axn 2011-09-09 12:58

[QUOTE=LaurV;271261]Question 2:
How the hell I can take the class "c" in "x=Mod(c,m)" as integer? [/QUOTE]

Look at lift() and centerlift()

Christenson 2011-09-09 18:17

I'm out of practice, but getting line N out of a file is a one-liner in perl.

3.14159 2011-10-23 23:07

Pardon the question.. but similar to how (4!+1) = 5^2; (5!+1) = 11^2; (7!+1) = 71^2.. are there any examples of (n!+1) = x^3 (where n and x are integers)

CRGreathouse 2011-10-23 23:37

[QUOTE=3.14159;275455]Pardon the question.. but similar to how (4!+1) = 5^2; (5!+1) = 11^2; (7!+1) = 71^2.. are there any examples of (n!+1) = x^3 (where n and x are integers)[/QUOTE]

Doubtful, since x would have to be divisible by only cubes of large primes which are very rare (sum converges). Just to be divisible by one prime cube where the prime is over 10,000 is a one-in-two billion chance, and most of that is on the lower end (which doesn't take care of the bulk of the number).

3.14159 2011-10-24 03:28

[QUOTE=CRGreathouse;275461]Doubtful, since x would have to be divisible by only cubes of large primes which are very rare (sum converges). Just to be divisible by one prime cube where the prime is over 10,000 is a one-in-two billion chance, and most of that is on the lower end (which doesn't take care of the bulk of the number).[/QUOTE]

Ah, cool. Thanks for the heads-up.

So would it be safe to say that (n!+1) = x^y has no solutions when y > 2?
(n, x, and y all being integers, of course.)

Lastly, reading through this thread.. can't help but feel a slight bit of embarrassment at what I've posted so far.

science_man_88 2011-10-26 00:49

making a new variable name via script ?
 
[QUOTE](x,y)->eval(Str(x))==y[/QUOTE]

the problem is when I retyped the name with a question mark it worked, But the flaw was copying in the name or other ways of getting the value behind the variable like typing it's name don't seem to work on my end.

science_man_88 2011-10-26 00:58

[QUOTE=science_man_88;275749]the problem is when I retyped the name with a question mark it worked, But the flaw was copying in the name or other ways of getting the value behind the variable like typing it's name don't seem to work on my end.[/QUOTE]

from a fresh window of gp.exe:

[QUOTE](21:55)>var(x,y) = eval(Str(x))==return(y)
%1 = (x,y)->eval(Str(x))==return(y)
(21:55)>?weekend
weekend: unknown identifier

(21:55)>var(weekend,5)
%2 = 5
(21:55)>?weekend
weekend: user defined variable

(21:56)>weekend
%3 = weekend[/QUOTE]

okay so retyping the equality with one equal sign can add the value after creation


All times are UTC. The time now is 22:54.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.