| Michael Stoll on Tue, 21 Apr 1998 11:16:04 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Re: quote |
I wrote:
> Hi all --
>
> by now I've had a look at the source and it seems to me that there
> is no straightforward way to obtain the variable number of an identifier
> once it has got some value.
> (a) Is this true?
> (b) Do you agree that this is a design flaw?
> (c) Why not put the variable number into the entree structure?
> (d) Introducing quote won't be necessary if we make the following
> change to the semantics of gp. Whenever a variable number is required,
> simply use the identifier's variable number as given in its entree
> (assuming (c)) (unless it's the name of a function, of course).
> This seems to me the better solution; it is also (at least to my
> taste) nearer to mathematical intuition.
As to (a), I had a more thorough look, and it seems that you can find
the polx of the variable at initial_value(ep), when ep is the corresponding
entree. (Not that this is documented somewhere...) So (b) and (c) are
probably obsolete.
As to (d), thinking again, I see that you do want to have both
possibilities. So dump (d) and go back to quote. I did some hacking,
so here is a patch (pre-alpha :) ). (BTW, this also groups the things
belonging to sumiter.c together in paridecl.h .)
It now works like this.
lordly:/Users/micha/UnixProjects/pari/pari-2.0.7.alpha> ./gp
GP/PARI CALCULATOR Version 2.0.7 (alpha)
i486 running nextstep (ix86 kernel) 32-bit version
(readline enabled, extended help available)
Copyright 1989-1998 by
C. Batut, K. Belabas, D. Bernardi, H. Cohen and M. Olivier.
Type ? for help.
realprecision = 28 significant digits
seriesprecision = 16 significant terms
format = g0.28
parisize = 8000000, primelimit = 1000000, buffersize = 30000
gp (11:14)> a=x
%1 = x
gp (11:14)> a
%2 = x
gp (11:14)> 'a
%3 = a
gp (11:14)> quote(a)
%4 = a
gp (11:14)> 'thue
*** variable name expected: 'thue
^---
gp (11:14)> quote(thue)
*** variable name expected: quote(thue)
^----
gp (11:14)> quote(7)
*** variable name expected: quote(7)
^-
gp (11:14)> '+
*** variable name expected: '+
^
gp (11:14)> 'a^2+5*'a
%5 = a^2 + 5*a
gp (11:14)> subst(%5,a,4)
%6 = a^2 + 5*a
gp (11:15)> subst(%5,'a,4)
%7 = 36
gp (11:15)>
Good bye!
Enjoy!
Michael
----8<--------PATCH--------------------------------------------------
lordly:/Users/micha/UnixProjects/pari/pari-2.0.7.alpha> diff -c2
src/headers/paridecl.h.orig src/headers/paridecl.h
*** src/headers/paridecl.h.orig Tue Apr 21 10:54:39 1998
--- src/headers/paridecl.h Tue Apr 21 11:04:57 1998
***************
*** 508,520 ****
GEN cyclo(long n, long v);
GEN dirdiv(GEN x, GEN y);
- GEN direuler(entree *ep, GEN a, GEN b, char *ch);
GEN dirmul(GEN x, GEN y);
GEN dirzetak(GEN nf, GEN b);
- GEN divsum(GEN num,entree *ep, char *ch);
- void fordiv(GEN a, entree *ep, char *ch);
- void forpari(entree *ep, GEN a, GEN b, char *ch);
- void forprime(entree *ep, GEN a, GEN b, char *ch);
- void forstep(entree *ep, GEN a, GEN b, GEN s, char *ch);
- void forvec(entree *ep, GEN x, char *ch);
GEN gen_sort(GEN x, int cmp(GEN,GEN), int flag);
GEN genrand(GEN N);
--- 508,513 ----
***************
*** 528,532 ****
GEN indexlexsort(GEN x);
GEN indexsort(GEN x);
- GEN intnum0(entree *ep, GEN a, GEN b, char *ch,long flag,long prec);
GEN laplace(GEN x);
GEN legendre(long n, long v);
--- 521,524 ----
***************
*** 534,538 ****
GEN mathilbert(long n);
GEN matpascal(long n);
- GEN matrice(GEN nlig, GEN ncol,entree *ep1, entree *ep2, char *ch);
long mymyrand();
GEN permute(long n, GEN x);
--- 526,529 ----
***************
*** 540,555 ****
GEN polint(GEN xa, GEN ya, GEN x, GEN *dy);
GEN polymodrecip(GEN x);
- GEN polzag(long n, long m);
- GEN polzagreel(long n, long m, long prec);
- GEN prodeuler(entree *ep, GEN a, GEN b, char *ch, long prec);
- GEN prodinf(entree *ep, GEN a, char *ch, long prec);
- GEN prodinf0(entree *ep, GEN a, char *ch, long flag, long prec);
- GEN prodinf1(entree *ep, GEN a, char *ch, long prec);
- GEN produit(entree *ep, GEN a, GEN b, char *ch, GEN x);
- GEN qromb(entree *ep, GEN a, GEN b, char *ch, long prec);
- GEN qromi(entree *ep, GEN a, GEN b, char *ch, long prec);
- GEN qromo(entree *ep, GEN a, GEN b, char *ch, long prec);
GEN reorder(GEN x);
- GEN rombint(entree *ep, GEN a, GEN b, char *ch, long prec);
GEN setintersect(GEN x, GEN y);
long setisset(GEN x);
--- 531,535 ----
***************
*** 560,579 ****
GEN sindexlexsort(GEN x);
GEN sindexsort(GEN x);
- GEN somme(entree *ep, GEN a, GEN b, char *ch, GEN x);
GEN sort(GEN x);
- GEN sumalt(entree *ep, GEN a, char *ch, long prec);
- GEN sumalt0(entree *ep, GEN a, char *ch,long flag, long prec);
- GEN sumalt2(entree *ep, GEN a, char *ch, long prec);
- GEN suminf(entree *ep, GEN a, char *ch, long prec);
- GEN sumpos(entree *ep, GEN a, char *ch, long prec);
- GEN sumpos0(entree *ep, GEN a, char *ch, long flag,long prec);
- GEN sumpos2(entree *ep, GEN a, char *ch, long prec);
GEN tayl(GEN x, long v, long precdl);
GEN tchebi(long n, long v);
GEN vecsort(GEN x, GEN k);
GEN vecsort0(GEN x, GEN k);
- GEN vecteur(GEN nmax, entree *ep, char *ch);
- GEN vvecteur(GEN nmax, entree *ep, char *ch);
- GEN zbrent(entree *ep, GEN a, GEN b, char *ch, long prec);
/* buch1.c */
--- 540,548 ----
***************
*** 1029,1032 ****
--- 998,1036 ----
GEN bnrstark(GEN bnr, GEN subgroup, long flag, long prec);
+ /* sumiter.c */
+
+ GEN direuler(entree *ep, GEN a, GEN b, char *ch);
+ GEN divsum(GEN num,entree *ep, char *ch);
+ void fordiv(GEN a, entree *ep, char *ch);
+ void forpari(entree *ep, GEN a, GEN b, char *ch);
+ void forprime(entree *ep, GEN a, GEN b, char *ch);
+ void forstep(entree *ep, GEN a, GEN b, GEN s, char *ch);
+ void forvec(entree *ep, GEN x, char *ch);
+ GEN intnum0(entree *ep, GEN a, GEN b, char *ch,long flag,long prec);
+ GEN matrice(GEN nlig, GEN ncol,entree *ep1, entree *ep2, char *ch);
+ GEN polzag(long n, long m);
+ GEN polzagreel(long n, long m, long prec);
+ GEN prodeuler(entree *ep, GEN a, GEN b, char *ch, long prec);
+ GEN prodinf(entree *ep, GEN a, char *ch, long prec);
+ GEN prodinf0(entree *ep, GEN a, char *ch, long flag, long prec);
+ GEN prodinf1(entree *ep, GEN a, char *ch, long prec);
+ GEN produit(entree *ep, GEN a, GEN b, char *ch, GEN x);
+ GEN qromb(entree *ep, GEN a, GEN b, char *ch, long prec);
+ GEN qromi(entree *ep, GEN a, GEN b, char *ch, long prec);
+ GEN qromo(entree *ep, GEN a, GEN b, char *ch, long prec);
+ GEN quote(entree* ep);
+ GEN rombint(entree *ep, GEN a, GEN b, char *ch, long prec);
+ GEN somme(entree *ep, GEN a, GEN b, char *ch, GEN x);
+ GEN sumalt(entree *ep, GEN a, char *ch, long prec);
+ GEN sumalt0(entree *ep, GEN a, char *ch,long flag, long prec);
+ GEN sumalt2(entree *ep, GEN a, char *ch, long prec);
+ GEN suminf(entree *ep, GEN a, char *ch, long prec);
+ GEN sumpos(entree *ep, GEN a, char *ch, long prec);
+ GEN sumpos0(entree *ep, GEN a, char *ch, long flag,long prec);
+ GEN sumpos2(entree *ep, GEN a, char *ch, long prec);
+ GEN vecteur(GEN nmax, entree *ep, char *ch);
+ GEN vvecteur(GEN nmax, entree *ep, char *ch);
+ GEN zbrent(entree *ep, GEN a, GEN b, char *ch, long prec);
+
/* thue.c */
lordly:/Users/micha/UnixProjects/pari/pari-2.0.7.alpha> diff -c2
src/language/anal.c.orig src/language/anal.c
*** src/language/anal.c.orig Tue Apr 21 10:31:33 1998
--- src/language/anal.c Tue Apr 21 10:56:52 1998
***************
*** 81,84 ****
--- 81,85 ----
* or constante
* or ! truc
+ * or ' identifier
* or matrix_block (no_affect=1)
* or (expr)
***************
*** 662,665 ****
--- 663,677 ----
return i ? gun : gzero;
}
+ if (*analyseur == '\'')
+ {
+ const char* old;
+ entree *ep;
+ analyseur++; old = analyseur;
+ if(!isalpha(*analyseur)) err(varer1,old,mark.start);
+ ep = entry();
+ if (EpVALENCE(ep)!=EpVAR) /* not a variable */
+ err(varer1,old,mark.start);
+ return quote(ep);
+ }
if (isalpha(*analyseur)) return identifier();
***************
*** 1874,1877 ****
--- 1886,1895 ----
if (*analyseur == '"') { skipstring(); return 0; }
if (*analyseur == '!') { analyseur++; skiptruc(); return 0; }
+ if (*analyseur == '\'')
+ {
+ analyseur++;
+ if (isalpha(*analyseur)) { skipentry(); return 0; }
+ err(varer1,analyseur,mark.start);
+ }
if (isalpha(*analyseur)) { skipidentifier(); return 0; }
if (isdigit(*analyseur) || *analyseur== '.') { skipconstante(); return 0; }
lordly:/Users/micha/UnixProjects/pari/pari-2.0.7.alpha> diff -c2
src/language/helpmessages.c.orig src/language/helpmessages.c
*** src/language/helpmessages.c.orig Tue Apr 21 10:29:08 1998
--- src/language/helpmessages.c Tue Apr 21 10:29:47 1998
***************
*** 343,346 ****
--- 343,347 ----
"quadregulator(x): regulator of the real quadratic field of discriminant x",
"quadunit(x): fundamental unit of the quadratic field of discriminant x
where x must be positive",
+ "quote(v): returns the variable v unevaluated",
"random({N=2^31}): random integer between 0 and N-1",
"real(x): real part of x",
lordly:/Users/micha/UnixProjects/pari/pari-2.0.7.alpha> diff -c2
src/language/init.c.orig src/language/init.c
*** src/language/init.c.orig Tue Apr 21 10:27:23 1998
--- src/language/init.c Tue Apr 21 10:28:59 1998
***************
*** 1517,1520 ****
--- 1517,1521 ----
{"quadregulator",1,(void*)gregula,4,"Gp"},
{"quadunit",1,(void*)gfundunit,4,"Gp"},
+ {"quote",1,(void*)quote,11,"V"},
{"random",0,(void*)genrand,2,"DG"},
{"real",1,(void*)greal,2,"G"},
lordly:/Users/micha/UnixProjects/pari/pari-2.0.7.alpha> diff -c2
src/language/sumiter.c.orig src/language/sumiter.c
*** src/language/sumiter.c.orig Tue Apr 21 10:25:01 1998
--- src/language/sumiter.c Tue Apr 21 11:05:34 1998
***************
*** 13,16 ****
--- 13,29 ----
/********************************************************************/
/** **/
+ /** QUOTE **/
+ /** **/
+ /********************************************************************/
+
+ /* quote takes a variable name and returns the varaible unevaluated */
+ GEN
+ quote(entree *ep)
+ {
+ return (GEN) initial_value(ep);
+ }
+
+ /********************************************************************/
+ /** **/
/** ITERATIONS **/
/** **/