why it makes difference using %i vs. sqrt(-1) in Fricas?

11 views
Skip to first unread message

Nasser M. Abbasi

unread,
Jun 19, 2022, 4:02:42 AM6/19/22
to FriCAS - computer algebra system
I was looking at another question at difference forum. I noticed integrate hangs when 
using %i for sqrt(-1) but returns right away when type sqrt(-1). But returns with an error message.

But these two should be the same.

===========================
(14) -> %i*%i

   (14)  - 1
                                                       Type: Complex(Integer)
(15) -> sqrt(-1)*sqrt(-1)

   (15)  - 1
=========================

So why this gives error
==========================
(16) -> setSimplifyDenomsFlag(true)

integrate(x/( (x^2 - 1/5 - 2*sqrt(-1)/5)*sqrt(x^3 - x)),x)

   There are 9 exposed and 6 unexposed library operations named -
      having 2 argument(s) but none was determined to be applicable.
      Use HyperDoc Browse, or issue
                                )display op -
      to learn more about the available operations. Perhaps
      package-calling the operation or using coercions on the arguments
      will allow you to apply the operation.

   Cannot find a definition or applicable library operation named -
      with argument type(s)
                        Polynomial(Fraction(Integer))
                               AlgebraicNumber

      Perhaps you should use "@" to indicate the required return type,
      or "$" to specify which version of the function you need.
======================

But this does not give error (but seems to hang, or take long time for me to wait)

 integrate(x/( (x^2 - 1/5 - 2*%i/5)*sqrt(x^3 - x)),x)

I just changed sqrt(-1) by %i  and nothing else.

--Nasser

Qian Yun

unread,
Jun 19, 2022, 4:32:59 AM6/19/22
to fricas...@googlegroups.com
There are 2 different issues in your question.

First, difference between %i and sqrt(-1):

When used in expression, one gives EXPR(COMPLEX INT),
the other gives EXPR INT:

(7) -> sin(%i)

(7) sin(%i)
Type: Expression(Complex(Integer))
(8) -> sin sqrt(-1)

+---+
(8) sin(\|- 1 )
Type: Expression(Integer)

And the integration code will treat differently for
Expression(Complex(Integer)) and Expression(Integer).

Second, the error in
integrate(x/( (x^2 - 1/5 - 2*sqrt(-1)/5)*sqrt(x^3 - x)),x)

That's because the interpreter can't automatically figure out
the type for this. Not sure if it's a bug. Give it a hint can help:

x/( (x^2 - 1/5 - 2*sqrt(-1::EXPR INT)/5)*sqrt(x^3 - x))

- Qian

On 6/19/22 16:02, 'Nasser M. Abbasi' via FriCAS - computer algebra
> --
> 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...@googlegroups.com
> <mailto:fricas-devel...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/fricas-devel/f6d9d25d-00aa-4069-8192-33e2f443ea6cn%40googlegroups.com
> <https://groups.google.com/d/msgid/fricas-devel/f6d9d25d-00aa-4069-8192-33e2f443ea6cn%40googlegroups.com?utm_medium=email&utm_source=footer>.

Waldek Hebisch

unread,
Jun 19, 2022, 9:14:49 AM6/19/22
to 'Nasser M. Abbasi' via FriCAS - computer algebra system
On Sun, Jun 19, 2022 at 01:02:41AM -0700, 'Nasser M. Abbasi' via FriCAS - computer algebra system wrote:
> I was looking at another question at difference forum. I noticed integrate
> hangs when
> using %i for sqrt(-1) but returns right away when type sqrt(-1). But
> returns with an error message.
<snip>
> So why this gives error
> ==========================
> (16) -> setSimplifyDenomsFlag(true)
>
> integrate(x/( (x^2 - 1/5 - 2*sqrt(-1)/5)*sqrt(x^3 - x)),x)
>
> There are 9 exposed and 6 unexposed library operations named -
> having 2 argument(s) but none was determined to be applicable.
> Use HyperDoc Browse, or issue
> )display op -
> to learn more about the available operations. Perhaps
> package-calling the operation or using coercions on the arguments
> will allow you to apply the operation.
>
> Cannot find a definition or applicable library operation named -
> with argument type(s)
> Polynomial(Fraction(Integer))
> AlgebraicNumber
>
> Perhaps you should use "@" to indicate the required return type,
> or "$" to specify which version of the function you need.
> ======================

This is weakness in machinery assigning types. Instead write:

integrate(x/((- 2*sqrt(-1)/5 + x^2 - 1/5)*sqrt(x^3 - x)),x)

And yes, addition should be commutative, but type assignment
works from left to right, so is noncommutative...

--
Waldek Hebisch
Reply all
Reply to author
Forward
0 new messages