mersenneforum.org  

Go Back   mersenneforum.org > Math Stuff > Computer Science & Computational Number Theory > PARI/GP

Reply
 
Thread Tools
Old 2010-08-31, 20:43   #1266
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

100000110000002 Posts
Default

Code:
mt(i,j=i)= for(x=1,i,for(n=1,j,print1(x*n"\t"));print(""))
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.

Last fiddled with by science_man_88 on 2010-08-31 at 20:44
science_man_88 is offline   Reply With Quote
Old 2010-08-31, 21:02   #1267
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

135338 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
I tried your idea:

Code:
***   too many arguments: ...plication(i,j=i)=x=Mat(i,j,x,y,x*y);for(i=1,i
                                                      ^--------------------
You used "Mat" instead of "matrix".
CRGreathouse is offline   Reply With Quote
Old 2010-08-31, 21:07   #1268
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

175B16 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
Code:
mt(i,j=i)= for(x=1,i,for(n=1,j,print1(x*n"\t"));print(""))
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.
Yep, works pretty well.

Quote:
Originally Posted by science_man_88 View Post
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.
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>");
};

Last fiddled with by CRGreathouse on 2010-08-31 at 21:07
CRGreathouse is offline   Reply With Quote
Old 2010-08-31, 21:37   #1269
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
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>");
};
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.

Last fiddled with by science_man_88 on 2010-08-31 at 21:39
science_man_88 is offline   Reply With Quote
Old 2010-08-31, 21:45   #1270
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3·1,993 Posts
Default

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.
CRGreathouse is offline   Reply With Quote
Old 2010-08-31, 22:11   #1271
3.14159
 
3.14159's Avatar
 
May 2010
Prime hunting commission.

24·3·5·7 Posts
Default

Quote:
Originally Posted by 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.
What's sm88 trying to do?
3.14159 is offline   Reply With Quote
Old 2010-08-31, 22:25   #1272
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

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"))
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.
science_man_88 is offline   Reply With Quote
Old 2010-09-01, 01:40   #1273
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

135338 Posts
Default

Quote:
Originally Posted by 3.14159 View Post
What's sm88 trying to do?
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 is offline   Reply With Quote
Old 2010-09-01, 01:47   #1274
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

597910 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
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"))
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 ?
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:
Originally Posted by science_man_88 View Post
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.
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 only 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.
CRGreathouse is offline   Reply With Quote
Old 2010-09-01, 01:50   #1275
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3·1,993 Posts
Default

Quote:
Originally Posted by 3.14159 View Post
A180362!
Ok. When A180362 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>
and whatever else it may need. Did you already put the cross-refs in?
CRGreathouse is offline   Reply With Quote
Old 2010-09-01, 11:14   #1276
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

20C016 Posts
Default

it's up, and doesn't look like he did.
science_man_88 is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why do I sometimes see all the <> formatting commands when I quote or edit? cheesehead Forum Feedback 3 2013-05-25 12:56
Passing commands to PARI on Windows James Heinrich Software 2 2012-05-13 19:19
Ubiquity commands Mini-Geek Aliquot Sequences 1 2009-09-22 19:33
64-bit Pari? CRGreathouse Software 2 2009-03-13 04:22
Are these commands correct? jasong Linux 2 2007-10-18 23:40

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


Fri Aug 6 23:13:27 UTC 2021 up 14 days, 17:42, 1 user, load averages: 4.36, 4.27, 4.08

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

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.