Karim Belabas on Fri, 05 Oct 2007 14:56:58 +0200

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: two (stupid) questions

* Alessandro Languasco [2007-10-05 11:39]:
> Dear all,
> I'm writing a pari/gp script and I have two problems that,
> for sure, are described and solved in the User's Guide.... but I wasn't
> able to find a solution there.... so I'm asking for your help.
> Thanks in advance !
> 1) I would like to save the results of the gp-script on a file but  
> using just
> a part of the avalible decimal digits; i.e. I'm computing the results
> with 100 decimal digits but I would like that just the first
> 25 are saved on the file in TeX format. I think that
> some suffix has to be added to the writetex(namefile, result)
> istruction, but which one ?

Two possibilities:

1) Round the input to smaller accuracy, then print using the default

  writetex(namefile, precision(result,28))

No way to obtain exactly 25 digits in this way [ either 28 or 19 ]

2) Use an ugly hack:

  oldprec = default(realprecision);
  writetex(namefile, result)
  default(realprecision, oldprec);

N.B in most cases, you can keep the realprecision very low from some
point on and don't need to constantly change / restore as above: gp only
uses the realprecision for printing and to convert exact inputs to
inexact ones; the precision of the inputs is used otherwise.

3) The last one is so ugly I'd never recommend it, so it doesn't count towards
the two possibilities :-)

           Strchr( vecextract(Vec(Vecsmall(Str(result))), Str("..26")) )

> 2) In my script I have two parts: a precomputation and
> a final part. I would like to be able to know the computation time for
> both of them but it is not clear to me
> how to use the timer in a script.

  gettime();  \\ initialize
  print("Precomputation: ", gettime());
  print("Computation: ", gettime());


Karim Belabas                  Tel: (+33) (0)5 40 00 26 17
Universite Bordeaux 1          Fax: (+33) (0)5 40 00 69 50
351, cours de la Liberation    http://www.math.u-bordeaux.fr/~belabas/
F-33405 Talence (France)       http://pari.math.u-bordeaux.fr/  [PARI/GP]