On Sun, Nov 19, 2023 at 09:49:10PM +0800, Qian Yun wrote:
> 
> 
> On 11/19/23 21:36, Waldek Hebisch wrote:
> > On Sun, Nov 19, 2023 at 07:58:50PM +0800, Qian Yun wrote:
> > > "real? sqrt (-sqrt 2)" returns "true" by default.
> > 
> > You mean should return false?  We get this when working
> > with expressions:
> > 
> > (2) -> real? sqrt (-sqrt 2::EXPR(INT))
> > 
> >     (2)  false
> > 
> > > Because interpreter prefers CTRIGMNP over TRIGMNIP
> > > as shown by ")set mes bot on":
> > > 
> > >   Function Selection for real?
> > >        Arguments: AN
> > > 
> > >   [1]  signature:   EXPR(COMPLEX(INT)) -> BOOLEAN
> > >        implemented: slot (Boolean)(Expression (Complex (Integer))) from
> > > CTRIGMNP(INT,EXPR(COMPLEX(INT)))
> > >   [2]  signature:   EXPR(INT) -> BOOLEAN
> > >        implemented: slot (Boolean)(Expression (Integer)) from
> > > TRIGMNIP(INT,EXPR(INT))
> > > 
> > > 
> > > Shall we consider this a bug?
> > 
> > I do not think so.  IIUC 'real?' in CTRIGMNP is quite different
> > function than 'real?' in TRIGMNIP.  Namely, CTRIGMNP deals
> > with COMPLEX(EXPR(INT)), which is formal linear combination
> > 'a + %i*b' where 'a' and 'b' are expressions and 'real?'
> > here tests if 'b' equals 0, which AFAICS is true.
> 
> I don't think 'real?' in CTRIGMNP is wrong.
> 
> I think the interpreter choose EXPR(COMPLEX(INT)) over EXPR(INT)
> for AN is wrong.  Isn't AN the same as EXPR(INT) in Rep?
> So I think the interpreter auto coercion should prefer EXPR(INT).

Interpreter has no idea what is Rep of AN.  One can argue that
COMPLEX(INT) is more complex than INT, so should be preferable.
OTOH letter C is before letter I and letter T.  Consequently,
interpreter sorting puts complex variant first in search list.

>From somewhat different point of view, one can ask if the two
functions should share the name.  Or if CTRIGMNP and TRIGMNIP
should be exposed.  Or maybe more things should be hidden in
ITRIGMNP.

> > 'real?' in TRIGMNIP is making reasonable effort to find out if
> > "real" transformations of functions will give correct results.
> > Your expression is affected by trouble, what is meant by
> > 'sqrt'?  '-sqrt(2)' have two possible values, positive and negative.
> > So numerical value depends on choice of branches.
> 
> I think for sqrt which is 'nthRoot, should be interpreted as the
> positive branch.
>
> While the algebraic number generated by "rootsOf(x^2-2)", which
> is 'rootOf, have two possible values.

Well, even for AlgebraicNumber you almost immediately get complex
numbers.  And no, there is no deep difference between 'nthRoot
and 'rootOf.
 
> >  One possible
> > meaning of 'real?' could be "argument is real for all possible choices
> > of branches".  Another could be "argument is real for some choice
> > of branches".  Yet another (and it is more or less what we use)
> > is that argument is "formally real", that is consists of
> > applications of "real" functions to "formally real" argument
> > with exception made for roots: even root of negative constant
> > is considered not-real.  Each meaning have some sense.  The first
> > two are problemantic, because in general branch questions are
> > undecidable.  The third one is decidable and useful in some
> >   contexts.  But may be confusing for some users.  And your case
> > is borderline for this definition: if sqrt(2) is considered as function
> > applied to a constant, than correct answer is "true".  If
> > sqrt(2) is considered to be a positive constant, then
> > answer is "false".
> 
> I think we should have "sign", "real?" well defined for AlgebraicNumber.

Well, if you want then well defined use RealClosure(Fraction(Integer))
for real things and Complex(RealClosure(Fraction(Integer))) in
general case.  But this really do not generalize to expressions,
so you are basically throwing away current expression-based
AlgebraicNumber.

-- 
                              Waldek Hebisch

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fricas-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/fricas-devel/ZVoeaTvVdIN2wJIO%40fricas.org.

Reply via email to