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).
'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.
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.
- Qian
For our purposes it does not matter much.
We just need to be consistent: tests used in various places
should be "uniformly dumb", otherwise there is danger that
something which we consider real will be transformed into
something visibly complex by "too smart" transformation,
leading to possible bugs. And ideally we should not depend
on 'real?' at all: when we really care about expressions having
real values we should use stronger (or at least more reliable)
tests.
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/fricas-devel/6bddcc85-f58c-4c44-bbc5-c3354ab6608a%40gmail.com.