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 2010-08-31 20:43

[CODE]mt(i,j=i)= for(x=1,i,for(n=1,j,print1(x*n"\t"));print(""))[/CODE]

is my best idea so far shortens the name and if a variable is missing it knows they are equal so to get to a square we only need one input.

the trouble comes when the width is more than one page. seems to print to 20,20 perfectly any higher next thing that shows up is the last one.

CRGreathouse 2010-08-31 21:02

[QUOTE=science_man_88;227955]I tried your idea:

[CODE][COLOR="Red"]*** too many arguments: ...[/COLOR]plication(i,j=i)=x=Mat(i,j,x,y,x*y);for(i=1,i
[COLOR="Red"]^--------------------[/COLOR][/CODE][/QUOTE]

You used "Mat" instead of "matrix".

CRGreathouse 2010-08-31 21:07

[QUOTE=science_man_88;227956][CODE]mt(i,j=i)= for(x=1,i,for(n=1,j,print1(x*n"\t"));print(""))[/CODE]

is my best idea so far shortens the name and if a variable is missing it knows they are equal so to get to a square we only need one input.[/QUOTE]

Yep, works pretty well.

[QUOTE=science_man_88;227956]the trouble comes when the width is more than one page. seems to print to 20,20 perfectly any higher next thing that shows up is the last one.[/QUOTE]

That's a limitation of the terminal. If you want bigger tables, or better-looking tables, I recommend using write() and write1() to create an HTML file which you can display in a browser. Something like this:

[code]table(h,w)={
write("output.html", "<!doctype html>");
write("output.html", "<html><head><meta charset='utf-8'><title>Multiplication</title></head>");
write("output.html", "<body><table>");
for(i=1,h,
write1("output.html", "<tr>");
for(j=1,w,
write1("output.html", "<td>", i*j, "</td>")
);
write("output.html", "</tr>");
);
write("output.html", "</table></body></html>");
};[/code]

science_man_88 2010-08-31 21:37

[QUOTE=CRGreathouse;227963]Yep, works pretty well.



That's a limitation of the terminal. If you want bigger tables, or better-looking tables, I recommend using write() and write1() to create an HTML file which you can display in a browser. Something like this:

[code]table(h,w)={
write("output.html", "<!doctype html>");
write("output.html", "<html><head><meta charset='utf-8'><title>Multiplication</title></head>");
write("output.html", "<body><table>");
for(i=1,h,
write1("output.html", "<tr>");
for(j=1,w,
write1("output.html", "<td>", i*j, "</td>")
);
write("output.html", "</tr>");
);
write("output.html", "</table></body></html>");
};[/code][/QUOTE]

I may make it more efficient I tested it twice in a row and it was going about 452.5 bits/s = baud ? each time.

CRGreathouse 2010-08-31 21:45

The inefficiency comes from opening and closing the file for every write1() statement. You might get more speed by creating a string with the whole row, then writing that; I'm not sure.

3.14159 2010-08-31 22:11

[quote=CRGreathouse]The inefficiency comes from opening and closing the file for every write1() statement. You might get more speed by creating a string with the whole row, then writing that; I'm not sure.[/quote]

What's sm88 trying to do?

science_man_88 2010-08-31 22:25

[CODE]mt(i,j=i)=for(n=1,i,v=vector(j,x,n*x);write1("E:\\output.txt",v);write("E:\\output.txt","\n"))[/CODE]

this seems nice to me though it's a .txt (still able to open in a browser(well dah)) and writes at a rate of about 5881.4 bits/s = baud ? . For someone with so many programming books I sure suck lol, lets see: Dynamic html (useful to remember Pari's escape characters), Advanced MS-DOS (don't know if i have much use for it as it's the 1986 edition I think). Advanced Programming in the Unix environment (didn't check title until later and did nothing),the art of assembly language 2nd edition,and I think "Beginning Programming all in one desk reference for dummies" is the last one.

CRGreathouse 2010-09-01 01:40

[QUOTE=3.14159;227980]What's sm88 trying to do?[/QUOTE]

He's writing a multiplication table -- at first to the terminal, now to a file. I don't know his underlying motivation, but since this teaches valuable tools (matrices, file I/O) I'm not really concerned.

CRGreathouse 2010-09-01 01:47

[QUOTE=science_man_88;227983][CODE]mt(i,j=i)=for(n=1,i,v=vector(j,x,n*x);write1("E:\\output.txt",v);write("E:\\output.txt","\n"))[/CODE]

this seems nice to me though it's a .txt (still able to open in a browser(well dah)) and writes at a rate of about 5881.4 bits/s = baud ?[/QUOTE]

Yes, it's faster since it's writing a whole row at a time. Pari's file I/O performance is bad -- actually there's been an outstanding 'todo' on that particular feature for a while (some suggested a "t_FILE" type to avoid this performance penalty).

[QUOTE=science_man_88;227983]For someone with so many programming books I sure suck lol, lets see: Dynamic html (useful to remember Pari's escape characters), Advanced MS-DOS (don't know if i have much use for it as it's the 1986 edition I think). Advanced Programming in the Unix environment (didn't check title until later and did nothing),the art of assembly language 2nd edition,and I think "Beginning Programming all in one desk reference for dummies" is the last one.[/QUOTE]

You'll learn programming faster than I did when I started, since I was younger than you are now, when I started. Just remember that while books can help, you can [i]only[/i] learn programming by doing. You can read a dozen books about how to read a bike, the physics of bike-riding, etc. without learning to ride. :grin:

CRGreathouse 2010-09-01 01:50

[QUOTE=3.14159;227878]A180362![/QUOTE]

Ok. When [url=http://oeis.org/classic/A180362]A180362[/url] shows up, I'll edit it to add
[code]%S A180362 5,13,109,163,257,271,379,433,487,541,769,3329,7681,7937,9473,10753,11777,
%T A180362 12289,13313,14081,14593,15361,17921,18433,19457,22273,23041,23297,25601,
%U A180362 26113,26881,30977,31489,32257,36097,36353,37501,37633,37889,39937,40193
%H A180362 Charles R Greathouse IV, <a href="b180362.txt">Table of n, a(n) for n = 1..10000</a>[/code]
and whatever else it may need. Did you already put the cross-refs in?

science_man_88 2010-09-01 11:14

it's up, and doesn't look like he did.


All times are UTC. The time now is 23:14.

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