![]() |
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) };[/code] instead of [code]cw(w)={ v=Vecsmall(w); sum(i=1,#v,v[i]-64) };[/code] which means that if I type [code]v=1;w=cw("ABC");v[/code] 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. :smile: |
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: [TEX]\pi[/TEX]=3.1415[...]. I want only the "1415[...]". Once again, Thank you. |
[QUOTE=ismillo;347475]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).[/QUOTE]
I consider gp pretty friendly. :ermm: [QUOTE=ismillo;347475]2) Somehow can I return the decimal fraction of a number? For exemple: [TEX]\pi[/TEX]=3.1415[...]. I want only the "1415[...]".[/QUOTE] You could write a function to do that. [code]fracpart(x)=x - floor(x)[/code] or even [code]fracpart(x)=x - x\1[/code] where \ means "divide and round down". |
.-.
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. |
[QUOTE=ismillo;347485]I have several issues with Command Prompt interface , such as copy and paste (right-click all time is a lame).[/QUOTE]
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=ismillo;347485]Does not show all the code writen before the last hundred lines (up arrow key all time is a lame).[/QUOTE] 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 [url]http://math.crg4.com/pari/highlight.html[/url] 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. |
[QUOTE=CRGreathouse;347486]
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. [/QUOTE] 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=CRGreathouse;347486] See [url]http://math.crg4.com/pari/highlight.html[/url] 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.[/QUOTE] 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=CRGreathouse;347482] You could write a function to do that. [code]fracpart(x)=x - floor(x)[/code] or even [code]fracpart(x)=x - x\1[/code] where \ means "divide and round down". [/QUOTE] 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) [/CODE] 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. :/ |
[QUOTE=ismillo;347524]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]
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=ismillo;347524]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. :/[/QUOTE] So write a function that does it! I don't quite understand what you need but this seems very easy to automate. |
[QUOTE=CRGreathouse;347554]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] 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=CRGreathouse;347554] So write a function that does it! I don't quite understand what you need but this seems very easy to automate. [/QUOTE] 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] [/CODE] But when I get "length" of the number, returns the precision series. It works awesome with numbers like [TEX]\pi[/TEX] and [TEX]\sqrt[]{2}[/TEX]. 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. |
[QUOTE=ismillo;347555]I do use Sublime Text.[/QUOTE]
I don't own a copy. You might be able to make your own syntax highlighting file by following their instructions here: [url]http://docs.sublimetext.info/en/latest/extensibility/syntaxdefs.html[/url] if you like. [QUOTE=ismillo;347555]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] 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 [url=http://en.wikipedia.org/wiki/GNU_readline]readline[/url] 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=ismillo;347555]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.[/QUOTE] 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 };[/code] I'm sure it could be made more efficient but the basic idea is sound. |
[QUOTE=CRGreathouse;347561]I don't own a copy. You might be able to make your own syntax highlighting file by following their instructions here:
[url]http://docs.sublimetext.info/en/latest/extensibility/syntaxdefs.html[/url] 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 [url=http://en.wikipedia.org/wiki/GNU_readline]readline[/url] 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] 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=CRGreathouse;347561] 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 };[/code] I'm sure it could be made more efficient but the basic idea is sound.[/QUOTE] 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". |
[QUOTE=ismillo;347564]I will try to make gp highlight for Sublime with I succeed I'll post here.[/QUOTE]
Cool, I look forward to it! |
| All times are UTC. The time now is 22:21. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.