mersenneforum.org  

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

Reply
 
Thread Tools
Old 2013-07-26, 22:07   #2421
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

10111010110112 Posts
Default

Oh, another general tip: don't use variables in a function without declaring them with my(). You'll avoid a lot of trouble this way.

So I wrote
Code:
cw(w)={
   my(v=Vecsmall(w));
   sum(i=1,#v,v[i]-64)
};
instead of
Code:
cw(w)={
   v=Vecsmall(w);
   sum(i=1,#v,v[i]-64)
};
which means that if I type
Code:
v=1;w=cw("ABC");v
I get 1 instead of Vectorsmall(65, 66, 67).

There are other reasons to use my() other than just variable clobbering. For example, the scripts tend to be faster and are compatible with gp2c. But don't worry about the reasoning, just get into the habit of doing this.
CRGreathouse is offline   Reply With Quote
Old 2013-07-26, 22:37   #2422
ismillo
 
Jul 2013
Brazil

19 Posts
Default

Oh, Thanks for the hint, I was wondering why was returning Vectorsmall(x).

I have a few more questions.

1) Does PARI has a friendly developing interface? I have found "Pari-tty", however, its not up-to-date (it runs only with PARI 2.2.11).

2) Somehow can I return the decimal fraction of a number? For exemple: \pi=3.1415[...]. I want only the "1415[...]".

Once again, Thank you.

Last fiddled with by ismillo on 2013-07-26 at 22:41
ismillo is offline   Reply With Quote
Old 2013-07-27, 02:36   #2423
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3·1,993 Posts
Default

Quote:
Originally Posted by ismillo View Post
1) Does PARI has a friendly developing interface? I have found "Pari-tty", however, its not up-to-date (it runs only with PARI 2.2.11).
I consider gp pretty friendly.

Quote:
Originally Posted by ismillo View Post
2) Somehow can I return the decimal fraction of a number? For exemple: \pi=3.1415[...]. I want only the "1415[...]".
You could write a function to do that.
Code:
fracpart(x)=x - floor(x)
or even
Code:
fracpart(x)=x - x\1
where \ means "divide and round down".
CRGreathouse is offline   Reply With Quote
Old 2013-07-27, 03:42   #2424
ismillo
 
Jul 2013
Brazil

19 Posts
Default

.-.

I have several issues with Command Prompt interface , such as copy and paste (right-click all time is a lame). Does not show all the code writen before the last hundred lines (up arrow key all time is a lame).

I don't know if it's because I'm not used to, or lazy, or too new in this area. Or all of them.


Btw, I did't even think in doing this function. Now it's 1am, later today I'll try something with this. Thanks.

Last fiddled with by ismillo on 2013-07-27 at 03:44
ismillo is offline   Reply With Quote
Old 2013-07-27, 03:50   #2425
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3×1,993 Posts
Default

Quote:
Originally Posted by ismillo View Post
I have several issues with Command Prompt interface , such as copy and paste (right-click all time is a lame).
If you're in Windows, right-click the shortcut that starts the program and click "Quick Edit" on the appropriate tab. This should allow you to copy with the mouse + Enter and paste with a right click. Copy/paste should work in Linux out of the box (but if you're having trouble let me know).

Quote:
Originally Posted by ismillo View Post
Does not show all the code writen before the last hundred lines (up arrow key all time is a lame).
Write programs in your favorite text editor and then just read the file into gp with \r filename. You can even edit the gprc.txt or .gprc file to automatically read this file when you start your session to make this more convenient.

See http://math.crg4.com/pari/highlight.html for syntax highlighting if your text editor does not have this already. If you're on a friend's computer (or at school, work, etc. and can't install programs) you can get syntax highlighting online at pastebin.com.
CRGreathouse is offline   Reply With Quote
Old 2013-07-27, 15:24   #2426
ismillo
 
Jul 2013
Brazil

19 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
Write programs in your favorite text editor and then just read the file into gp with \r filename. You can even edit the gprc.txt or .gprc file to automatically read this file when you start your session to make this more convenient.
Yeah, I'm doing it quite often actually, but instead of creting the file and reading using PARI, I am just creating the code and pasting. Only the functions I'm making PARI read.

Quote:
Originally Posted by CRGreathouse View Post
See http://math.crg4.com/pari/highlight.html for syntax highlighting if your text editor does not have this already. If you're on a friend's computer (or at school, work, etc. and can't install programs) you can get syntax highlighting online at pastebin.com.
I saw your site few days ago, it's very good from your part do that, but my favorite text editor isn't in your list of highlight syntax.

Quote:
Originally Posted by CRGreathouse View Post
You could write a function to do that.
Code:
fracpart(x)=x - floor(x)
or even
Code:
fracpart(x)=x - x\1
where \ means "divide and round down".
I just saw PARI have the function "frac(x)", I feel stupid for asking that.
Using "frac(x)" I could do that:

Code:
a=1.2345;
f=frac(a)*10^4;
c=ceil(f)
Using this logic I could kinda make what I was needing, but it won't be automatic, I'll have to set the value "10^n" manually. :/
ismillo is offline   Reply With Quote
Old 2013-07-27, 22:38   #2427
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3×1,993 Posts
Default

Quote:
Originally Posted by ismillo View Post
I saw your site few days ago, it's very good from your part do that, but my favorite text editor isn't in your list of highlight syntax.
What do you use?

In addition to the editors I mentioned explicitly, anything GtkSourceView-based or GeSHi-based should work as well, though you may need an update or download for it. Alternately you can use a different editor for GP than for your other work -- I did this for Ruby, where I found an editor that was particularly good for it even though I didn't prefer it overall.

Or just use your existing one without highlighting, it's not that big of a deal unless you work with it a lot.

Quote:
Originally Posted by ismillo View Post
Using this logic I could kinda make what I was needing, but it won't be automatic, I'll have to set the value "10^n" manually. :/
So write a function that does it!

I don't quite understand what you need but this seems very easy to automate.
CRGreathouse is offline   Reply With Quote
Old 2013-07-27, 22:59   #2428
ismillo
 
Jul 2013
Brazil

19 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
What do you use?

In addition to the editors I mentioned explicitly, anything GtkSourceView-based or GeSHi-based should work as well, though you may need an update or download for it. Alternately you can use a different editor for GP than for your other work -- I did this for Ruby, where I found an editor that was particularly good for it even though I didn't prefer it overall.

Or just use your existing one without highlighting, it's not that big of a deal unless you work with it a lot.
I do use Sublime Text.
The truth is, my problem isn't highlight syntax, my problem is the lack of freedom in PARI interface. I do like very much see what I'm writing and testing them while I writing.


Quote:
Originally Posted by CRGreathouse View Post

So write a function that does it!

I don't quite understand what you need but this seems very easy to automate.
I was trying to get the fractional part of the number in put 'em in an array. Just like "digits(n)", but instead of the number, only the fractional part.

Something like this:

Code:
gp>a=1.23456;
gp>c=digits(ceil(frac(a)*((#Str(a)-#Str(a))+10^10)))
%1 = [2,3,4,5,6,0,0,0,0,0,0]
But when I get "length" of the number, returns the precision series.

It works awesome with numbers like \pi and \sqrt[]{2}.

Somehow if I could remove the 0s from the last digits, but the 0s must be in a large sequence, otherwise it would break the number.

Last fiddled with by ismillo on 2013-07-27 at 23:15
ismillo is offline   Reply With Quote
Old 2013-07-28, 00:10   #2429
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3·1,993 Posts
Default

Quote:
Originally Posted by ismillo View Post
I do use Sublime Text.
I don't own a copy. You might be able to make your own syntax highlighting file by following their instructions here:
http://docs.sublimetext.info/en/late...yntaxdefs.html
if you like.

Quote:
Originally Posted by ismillo View Post
my problem is the lack of freedom in PARI interface. I do like very much see what I'm writing and testing them while I writing.
Sorry to hear that. But I don't really understand -- I can see what I'm writing in gp and I very often iterate small functions directly in gp. Is that not working for you, or do I not understand what you want to see?

gp uses readline to provide these facilities and it works very well for me. It lets you edit previous lines, has tab completion (type "isps" and hit TAB to get "ispseudoprime()"), and so forth.

Quote:
Originally Posted by ismillo View Post
I was trying to get the fractional part of the number in put 'em in an array. Just like "digits(n)", but instead of the number, only the fractional part.
Does this do what you want?
Code:
fracpart(x)={
  x-=x/1;
  my(t=precision(x),s=log(x)\log(10),v=vector(t));
  x/=10^s;
  for(i=1,t,
    v[i]=x\1;
    x=10*(x-v[i])
  );
  v
};
I'm sure it could be made more efficient but the basic idea is sound.
CRGreathouse is offline   Reply With Quote
Old 2013-07-28, 00:32   #2430
ismillo
 
Jul 2013
Brazil

19 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
I don't own a copy. You might be able to make your own syntax highlighting file by following their instructions here:
http://docs.sublimetext.info/en/late...yntaxdefs.html
if you like.



Sorry to hear that. But I don't really understand -- I can see what I'm writing in gp and I very often iterate small functions directly in gp. Is that not working for you, or do I not understand what you want to see?

gp uses readline to provide these facilities and it works very well for me. It lets you edit previous lines, has tab completion (type "isps" and hit TAB to get "ispseudoprime()"), and so forth.
I will try to make gp highlight for Sublime with I succeed I'll post here. :D

It's basically this but, it's ok soon or later I'll get used to it. :D

Quote:
Originally Posted by CRGreathouse View Post

Does this do what you want?
Code:
fracpart(x)={
  x-=x/1;
  my(t=precision(x),s=log(x)\log(10),v=vector(t));
  x/=10^s;
  for(i=1,t,
    v[i]=x\1;
    x=10*(x-v[i])
  );
  v
};
I'm sure it could be made more efficient but the basic idea is sound.
Didn't work here, I get this error:

"*** log: domain error in log: argument = 0"

It's pointed to "s=log(x)".

Edit: I think the error is here "x-=x/1", it should be "x-=x\1;", I guess?
When I changed common slash to backslash it's gave no error, and the result is giving the digits normally, however the last digits is "0" or "9".

Last fiddled with by ismillo on 2013-07-28 at 00:42
ismillo is offline   Reply With Quote
Old 2013-07-28, 02:07   #2431
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

597910 Posts
Default

Quote:
Originally Posted by ismillo View Post
I will try to make gp highlight for Sublime with I succeed I'll post here.
Cool, I look forward to it!
CRGreathouse is offline   Reply With Quote
Reply



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 06:55.


Fri Aug 6 06:55:29 UTC 2021 up 14 days, 1:24, 1 user, load averages: 2.49, 2.64, 2.71

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.