From: Pascal Bourguignon <pascal@af...>  20030717 14:24:46

lin8080 wrote: > >Kaz Kylheku schrieb: > > > >This is what HyperSpec says in section SQRT, ISQRT (file >/body/fun_sqrtcm_isqrt.html.) "... if the number is not a complex but is >negative, then the result is a complex" (12.1. ff). This case seems to >be clear. > >The mathematicans also say that a negativ sqrt is complex (right?), but >the same mathematicans say that (sqrt) is the reverse function of (* >zahl zahl) (which will returned only positiv numbers) and they also >describe for what kind of numbers this is valid. > You have to take into account the domain of the function. To take the reverse function, you must consider the function only on a subdomain where it's a bijection. For example, if you consider: f : ]infinity, 0] > [0, +infinity[ x > x*x then the reverse is: f^1 : [0, +infinity[ > ]infinity, 0] x >  sqrt(x) Note that this other function: g : [0, +infinity[ > [0, +infinity[ x > x*x which looks a lot like f, has not the same reverse function! And of course, a function square : R > R, x > x*x is not a bijection, so it has no reverse. So you see, you cannot expect the operators implemented in Lisp to correspond to the mathematical function you're manipulating. In maths, there are a lot of square root function, all defined on a different domain, and with a different image set. In computer languages we choose to implement one specific function, with a domain and image set considered useful. Since Lisp knows about complex, it naturally defines sqrt over the complexes and returns a complex (unless the imaginary part is null, in which case it's a real). > > >The practical reason why there is +, in trigononic functions, is to say >where the point of the graph is in the xysystem. And for that no >complex is needed, only 2 values. > >So the question should be: is there a way to suppress the complex number >representation in negative trigonomic values, when a sqrt is involved? > Yes, define properly your functions, and implement them accordingly. (defun mysquareoverRplus (x) (assert (and (realp x) (<= 0 x))) (* x x)) (defun mysquarerootoverRplus (x) (assert (and (realp x) (<= 0 x))) (sqrt x))  __Pascal Bourguignon__ mailto:pascal@... mailto:pjb@... 