mersenneforum.org  

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

Reply
 
Thread Tools
Old 2010-12-03, 21:09   #1981
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3×1,993 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
I've also tried css javascript and html and c and php but only the first 4 ever made it and now I forgot most of them I should start using them lol. also ASM beginner is a understatement lol, I can't get anything I've learned from books to work but if I ever do maybe it will be worth it.
I just thought I'd give you a start. Now that you know the format you can add your own languages and whatever else you like. You can always put something like

{{mylang|PHP|rank neophyte}}
{{mylang|JavaScript|I once knew this, but not anymore.}}

if you like.
CRGreathouse is offline   Reply With Quote
Old 2010-12-03, 21:11   #1982
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
I just thought I'd give you a start. Now that you know the format you can add your own languages and whatever else you like. You can always put something like

{{mylang|PHP|rank neophyte}}
{{mylang|JavaScript|I once knew this, but not anymore.}}

if you like.
then I'm idiot second class lol
science_man_88 is offline   Reply With Quote
Old 2010-12-03, 21:12   #1983
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3×1,993 Posts
Default

You can even do

{{mylang|Python|I'd love to learn this some day.}}
CRGreathouse is offline   Reply With Quote
Old 2010-12-03, 21:23   #1984
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
You can even do

{{mylang|Python|I'd love to learn this some day.}}
http://rosettacode.org/wiki/User:Science_man_88


{{mylangbegin}}
{{mylang|PARI/GP|intermediate}}
{{mylang|x86 assembly|beginner}}
{{mylang|HTML|idiot}}
{{mylang|PHP|can't find the ini to start}}
{{mylang|C|tried, should get a compiler again unless notepad++ will work}}
{{mylang|Javascript|forgotten}}
{{mylang|CSS|have a book on it as well as many others}}
{{mylangend}}
science_man_88 is offline   Reply With Quote
Old 2010-12-03, 21:36   #1985
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

135338 Posts
Default

So post it. (You might also order the languages somehow, maybe alphabetically?)
CRGreathouse is offline   Reply With Quote
Old 2010-12-03, 21:55   #1986
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

20C016 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
So post it. (You might also order the languages somehow, maybe alphabetically?)
If I added all the ones I have book(s) on I might as well list 20-30 lol

programming books i have include:

Advanced MS-dos:the microsoft guide for assembly language and C programmers (copyright 1986)

Beginning programming all in one desk reference for dummies (copyright 2008)<- syntax basics with examples in 15 languages I think.

The art of assembly language 2nd edition ( copyright 2010)

Dynamic HTML the definitive reference (last copyright 2007)

Advanced programming in the unix environment (messed up looking for C books in windows;copyright 2003)

Last fiddled with by science_man_88 on 2010-12-03 at 22:00
science_man_88 is offline   Reply With Quote
Old 2010-12-04, 04:27   #1987
kar_bon
 
kar_bon's Avatar
 
Mar 2006
Germany

22·727 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
on another script:

http://rosettacode.org/wiki/Day_of_the_week

is in the can't be done etc.
The above from post #1936 makes me thinking, why this shouldn't be implementable in PARI.

All those tasks from here are marked (by whom?) not doable in PARI but I don't think so.

I decided to install PARI/GP (I used first V2.3.4 but noticed it doesn't recognize 'my'-blocks, but 'local').
After some small examples I installed the newer V2.4.2 and begun to play around and read some docs and understanding some examples.

Now here's the solution of the above task "Day of the week":

Code:
JulianDate(YYYY,MM,DD)={

  my(a=0, b=0, Y=YYYY, M=MM);

  if(MM < 3, Y--; M+=12);
  a=floor(Y/100);
  b=2-a+floor(a/4);

  if(YYYY<=1582 && MM<=10 && DD<=15, b=0);

  return(floor(365.25*(Y+4716)) + floor(30.6001*(M+1)) + DD + b - 1524.5);
}

DayOfWeek(JD)={
  my(DayName=["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]);
  return(DayName[floor(divrem(JD+0.5,7)[2])+1]);
}

Day_of_the_week={
  my(year);
  for(year=2008,2121,
       if(DayOfWeek(JulianDate(year,12,25))=="Sunday",print(year)));
}
The main point of start is to convert the date (year,month,day) into a Julian Day (like a counter for every day from 4716-01-01 B.C.).
The function "JulianDate" returns this day-counter from the input of year, month and day.

Next step is to determine the day of the week by getting the value JulianDate MOD 7.
This value is '0' for a Monday, '1' for a Tuesday and so on.
The function "DayOfWeek" returns the string of this value.

The third part is the task which finds the years, for which the 25. of December is a Sunday for the years from 2008 to 2121.

This is my first PARI code so perhaps someone can find any issue or could improve it.

Note:
I think, no, I know the other two tasks (Date format, Date manipulation) are also doable now.
kar_bon is offline   Reply With Quote
Old 2010-12-04, 05:01   #1988
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

135338 Posts
Default

Quote:
Originally Posted by kar_bon View Post
All those tasks from here are marked (by whom?) not doable in PARI but I don't think so.
I populated most of that category.

The description says:
These tasks are not generally counted toward "unimplemented", as somebody, somewhere, decided that PARI/GP was inappropriate for these tasks, or implementations of them would be unenlightening. Feel free to try your hand at them anyway.
For some tasks, like this one, I thought that the task was doable but would be unenlightening. (In principle, all tasks are doable: create a vector representing an assembly program, convert it to a string with Strchr, write it to a file, and execute it with system().)

But as the description says, feel free to ignore the {{omit}} and add the task -- I certainly won't mind. (Ideally, if you do add it, you would remove the {{omit|PARI/GP}} line at the bottom.)
CRGreathouse is offline   Reply With Quote
Old 2010-12-04, 05:03   #1989
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3·1,993 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
If I added all the ones I have book(s) on I might as well list 20-30 lol
List whatever you like. You might choose to limit yourself to those languages for which you pass the FizzBuzz test.
CRGreathouse is offline   Reply With Quote
Old 2010-12-04, 05:16   #1990
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3·1,993 Posts
Smile

Quote:
Originally Posted by kar_bon View Post
I decided to install PARI/GP (I used first V2.3.4 but noticed it doesn't recognize 'my'-blocks, but 'local').
Yes, the newer ("development") version is far better. You made the right call.

Quote:
Originally Posted by kar_bon View Post
Code:
JulianDate(YYYY,MM,DD)={

  my(a=0, b=0, Y=YYYY, M=MM);

  if(MM < 3, Y--; M+=12);
  a=floor(Y/100);
  b=2-a+floor(a/4);

  if(YYYY<=1582 && MM<=10 && DD<=15, b=0);

  return(floor(365.25*(Y+4716)) + floor(30.6001*(M+1)) + DD + b - 1524.5);
}

DayOfWeek(JD)={
  my(DayName=["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]);
  return(DayName[floor(divrem(JD+0.5,7)[2])+1]);
}

Day_of_the_week={
  my(year);
  for(year=2008,2121,
       if(DayOfWeek(JulianDate(year,12,25))=="Sunday",print(year)));
}
Looks good -- very good, if this is your first script. Minor stuff:
  • floor(foo/4) can be written more succinctly with the integer division operator: foo\4. This is also faster if your precision is high. (Unrelated: you can also write it as foo >> 2, but this is of course only for powers of two.)
  • You can leave a value on the last line of a script (no ;) and the function will return it.*
  • I'm not sure why you write floor(divrem(JD+0.5,7)[2]); I would write round(JD)%7.
  • You shouldn't put loop variables in your my() list. This actually creates two separate values that happen to have the same value -- most confusing.

* You certainly don't need to, but sometimes it's nicer to write
Code:
square(x)={
  x^2
};
than
Code:
square(x)={
  return(x^2);
};

Last fiddled with by CRGreathouse on 2010-12-04 at 05:21
CRGreathouse is offline   Reply With Quote
Old 2010-12-04, 10:21   #1991
kar_bon
 
kar_bon's Avatar
 
Mar 2006
Germany

55348 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
  • floor(foo/4) can be written more succinctly with the integer division operator: foo\4. This is also faster if your precision is high. (Unrelated: you can also write it as foo >> 2, but this is of course only for powers of two.)
  • You can leave a value on the last line of a script (no ;) and the function will return it.*
  • I'm not sure why you write floor(divrem(JD+0.5,7)[2]); I would write round(JD)%7.
  • You shouldn't put loop variables in your my() list. This actually creates two separate values that happen to have the same value -- most confusing.
Thanks for the notes.
I've not yet read much about the special cases of PARI, so for example the 'return' I did is more from others languages they do this.
The "foo>>2" shift (like a division by a power of 2) is like in C but I don't want to use it to be more closer to the algorithm of the calculation of the Julian Date.
The round-part was not in my mind... I have to develop more in PARI first to know all basic parts and how to use.

Here's the code with your hints and suggestions:
Code:
JulianDate(YYYY,MM,DD)={
  my(a=0, b=0, Y=YYYY, M=MM);
  if(MM<3, Y--; M+=12);
  a=Y\100;
  b=2-a+a\4;
  if(YYYY<=1582 && MM<=10 && DD<=15, b=0);
  floor(365.25*(Y+4716)) + floor(30.6001*(M+1)) + DD + b - 1524.5
};

DayOfWeek(JD)={
  my(DayName=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]);
  DayName[round(JD)%7+1]
};

Day_of_the_week={
  for(year=2008,2121,
       if(DayOfWeek(JulianDate(year,12,25))=="Sunday",print(year)));
}
Please feel free to insert this code in the related page and perhaps the other two tasks.
kar_bon 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 22:51.


Fri Aug 6 22:51:15 UTC 2021 up 14 days, 17:20, 1 user, load averages: 3.65, 4.04, 3.89

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.