Hi All: I am using cln with real numbers. I have a problem in the expt function... Wen I have, for example, #include <cln(/real.h> ... cl_R x,y,z; z=expt(x,y); I have problems with the prototypes defined in <real.h> that causes that expt cannot be used in this way. I also can define this function as: cln::cl_R expt(cln::cl_R x, cln::cl_R y) { return exp(x*ln(y)); } And It works fine, but I think that It have to be defined somewhere in the library. Cheers. -- *************************************************************************** * Dr. Isidro Cachadiña Gutiérrez * * Departamento de Física * * Facultad de Ciencias * * Universidad de Extremadura * * 06071 Badajoz ( SPAIN ) * * email: icacha@unex.es * * Teléfono: +34 924 289 300 Ext. 6826 Fax: +34 924 289 651 * *************************************************************************** * Usuario Linux: 8569 * * Para clave pública GnuPG: http://onsager.unex.es/firma.pub.asc * ***************************************************************************
On Tue, 16 Nov 2004, Isidro [iso-8859-15] Cachadiña Gutiérrez wrote:
I am using cln with real numbers. I have a problem in the expt function... [...]
I also can define this function as:
cln::cl_R expt(cln::cl_R x, cln::cl_R y) { return exp(x*ln(y)); }
And It works fine, but I think that It have to be defined somewhere in the library.
Well, only if `x' is positive, right? Or if `y' is integer. But that signature is there, as you've already seen. Otherwise, the range of the exponentiation function isn't R anyway, so you could equally well use expt(cl_N,cl_N), returning an cl_N object. Maybe it would be worthwhile though, considering the fact that we also have sqrt(cl_R) defined only for arguments >= 0 without type checks for that. But given the other signatures, I see only very limited use. Saludos -richy. -- Richard B. Kreckel <http://www.ginac.de/~kreckel/>
El Miércoles, 17 de Noviembre de 2004 22:28, Richard B. Kreckel escribió:
On Tue, 16 Nov 2004, Isidro [iso-8859-15] Cachadiña Gutiérrez wrote:
I am using cln with real numbers. I have a problem in the expt function...
[...]
I also can define this function as:
cln::cl_R expt(cln::cl_R x, cln::cl_R y) { return exp(x*ln(y)); }
And It works fine, but I think that It have to be defined somewhere in the library.
Well, only if `x' is positive, right? This is ok because the result is a complex number. Or if `y' is integer. No, y can be a real number. There isn't any problem with this.
Normally if you are using real numbers you don't expect to find things like this -5.34^7.32. Perhaphs it would be neccesary a warning in the function to prevent it uses with x<0.
Maybe it would be worthwhile though, considering the fact that we also have sqrt(cl_R) defined only for arguments >= 0 without type checks for that. But given the other signatures, I see only very limited use.
Where you see a limited use I see a mathematical consistency use. If you are working with real number, you don't expect complex numbers arriving elsewhere, or better, you have to know where there is the posibility to find a result that leads to complex numbers. I prefer an error warning if something like sqrt(-1) happen. Saludos.
Saludos -richy.
-- *************************************************************************** * Dr. Isidro Cachadiña Gutiérrez * * Departamento de Física * * Facultad de Ciencias * * Universidad de Extremadura * * 06071 Badajoz ( SPAIN ) * * email: icacha@unex.es * * Teléfono: +34 924 289 300 Ext. 6826 Fax: +34 924 289 651 * *************************************************************************** * Usuario Linux: 8569 * * Para clave pública GnuPG: http://onsager.unex.es/firma.pub.asc * ***************************************************************************
Isidro Cachadiña Gutiérrez wrote:
If you are working with real number, you don't expect complex numbers arriving elsewhere
That's a problem with your mathematical education, not a problem with CLN.
I prefer an error warning if something like sqrt(-1) happen.
You get a compilation error if you write cl_R x, y, z; z = expt(x, y); This makes you aware to check your formulas. You do that, then insert the cast cl_R x, y, z; z = As(cl_R)(expt(x, y)); then CLN checks that the result is indeed a real number. What more do you want? The signature sqrt : cl_R -> cl_R is a convenience function which omits the possibility of a compilation error. Maybe this is a disadvantage. Bruno
yOn Thu, 18 Nov 2004, Isidro Cachadiña Gutiérrez wrote: [...]
cln::cl_R expt(cln::cl_R x, cln::cl_R y) { return exp(x*ln(y)); }
And It works fine, but I think that It have to be defined somewhere in the library.
Well, only if `x' is positive, right? This is ok because the result is a complex number. Or if `y' is integer. No, y can be a real number. There isn't any problem with this.
Oops, I hadn't even noticed that you got `x' and `y' interchanged. My statement about `y' being integer only makes sense when you put `x' and `y' in the conventional order.
Normally if you are using real numbers you don't expect to find things like this -5.34^7.32.
Since "real number" is well defined, either your definition of "normally" or your definition of "to expect" does not agree with my definition. :-) Or, maybe, both. :-) Saludos quadrados -richy. -- Richard B. Kreckel <http://www.ginac.de/~kreckel/>
Isidro Cachadiña Gutiérrez wrote:
cl_R x,y,z;
z=expt(x,y);
I have problems with the prototypes defined in <real.h> that causes that expt cannot be used in this way.
If x is negative, the result can be a complex number. If you know a priori that the result will be real, you can use a checked cast: z = As(cl_R)(expt(x,y));
I also can define this function as:
cln::cl_R expt(cln::cl_R x, cln::cl_R y) { return exp(x*ln(y)); }
Actually this is the other way around: exp(x*ln(y)) is y^x, not x^y. By using 'ln' here, not the more general 'log', you have asserted that the base is > 0. No wonder you don't need a cast here. Bruno
El Jueves, 18 de Noviembre de 2004 13:13, Bruno Haible escribió:
Isidro Cachadiña Gutiérrez wrote:
cl_R x,y,z;
z=expt(x,y);
I have problems with the prototypes defined in <real.h> that causes that expt cannot be used in this way.
If x is negative, the result can be a complex number. If you know a priori that the result will be real, you can use a checked cast:
z = As(cl_R)(expt(x,y));
I also can define this function as:
cln::cl_R expt(cln::cl_R x, cln::cl_R y) { return exp(x*ln(y)); }
Actually this is the other way around: exp(x*ln(y)) is y^x, not x^y.
Correct. Must be exp(y*ln(x)).
By using 'ln' here, not the more general 'log', you have asserted that the base is > 0. No wonder you don't need a cast here.
Yes, of course. I'm insterested on real functions depending on real arguments. Now, I have the same problem with functions like cos, acos, etc. which depends on complex arguments, for example cl_R acos (cl_R x ) is not defined you have to do something like realpart(acos(complex(x,0))) or are there anything quicker and dirty ?.
Bruno
_______________________________________________ CLN-list mailing list CLN-list@thep.physik.uni-mainz.de http://thep.physik.uni-mainz.de/mailman/listinfo/cln-list
-- *************************************************************************** * Dr. Isidro Cachadiña Gutiérrez * * Departamento de Física * * Facultad de Ciencias * * Universidad de Extremadura * * 06071 Badajoz ( SPAIN ) * * email: icacha@unex.es * * Teléfono: +34 924 289 300 Ext. 6826 Fax: +34 924 289 651 * *************************************************************************** * Usuario Linux: 8569 * * Para clave pública GnuPG: http://onsager.unex.es/firma.pub.asc * ***************************************************************************
participants (3)
-
Bruno Haible
-
Isidro Cachadiña Gutiérrez
-
Richard B. Kreckel