How to debug error "Invalid argument" from integrate(uts, sym)

2 views
Skip to first unread message

Neven Sajko

unread,
Aug 7, 2021, 5:52:31 AM8/7/21
to fricas-devel
Hello,

I have a certain Taylor series (uts) that I'd like to integrate over a
certain variable (sym).

Uts is of type UnivariateTaylorSeries(Expression(Integer),eps,0).

Sym is just 'sigma::Symbol.

I checked that the problem is not in the types of either uts or sym,
because a call with equivalent types proceeds fine.

The same problem appears if I do
map(c +-> integrate(c, sym), uts)
instead of
integrate(uts, sym)

The actual error that Fricas reports is this:
>> Error detected within library code:
Invalid argument

I searched for "Invalid argument" in Spad files, and it seems that
there are just two files that have that string: elemntry.spad and
liouv.spad.
https://github.com/fricas/fricas/blob/master/src/algebra/elemntry.spad
https://github.com/fricas/fricas/blob/master/src/algebra/liouv.spad

I got an idea to debug this problem by replacing each occurence of the
`error "Invalid argument"` statement in those two files with a
statement that would cause a stack trace to be printed. That would
help further narrow down the issue.

However, I don't even know if Fricas has the ability to issue stack
traces (from Spad code)?

Could any help with that, or give other ideas?


Thanks,
Neven

Neven Sajko

unread,
Aug 7, 2021, 8:54:55 AM8/7/21
to fricas-devel
On Sat, 7 Aug 2021 at 09:52, Neven Sajko <nsa...@gmail.com> wrote:
> I got an idea to debug this problem by replacing each occurence of the
> `error "Invalid argument"` statement in those two files with a
> statement that would cause a stack trace to be printed. That would
> help further narrow down the issue.
>
> However, I don't even know if Fricas has the ability to issue stack
> traces (from Spad code)?

I found out a bit more. This page has very useful info on debugging:
http://fricas-wiki.math.uni.wroc.pl/DebuggingFriCAS

Guided by that page, I did
)set break break
and then `backtrace` after running the offending integration.

This seems to be the relevant call chain:
error < valueOrPole < specialTrigs < itan < evaluate < elt < k2Elem0 < map

Here valueOrPole, specialTrigs and itan, at least, are from
elemntry.spad. However, specialTrigs calls valueOrPole in multiple
places, so now I have to figure out on which line does the call
happen.


Neven

Ralf Hemmecke

unread,
Aug 7, 2021, 11:05:24 AM8/7/21
to fricas...@googlegroups.com
On 07.08.21 11:52, Neven Sajko wrote:
> Hello,
>
> I have a certain Taylor series (uts) that I'd like to integrate over a
> certain variable (sym).
>
> Uts is of type UnivariateTaylorSeries(Expression(Integer),eps,0).
>
> Sym is just 'sigma::Symbol.
>
> I checked that the problem is not in the types of either uts or sym,
> because a call with equivalent types proceeds fine.
>
> The same problem appears if I do
> map(c +-> integrate(c, sym), uts)
> instead of
> integrate(uts, sym)>
> The actual error that Fricas reports is this:
> >> Error detected within library code:
> Invalid argument

I do not know what you are doing, but the following session seems to
show that integrate even works without using the map construction. The
FriCAS interpreter seems to be pretty smart here.

If you post a problem, then accompany it with a .input file that
demonstrates the problem.

BTW, as you see below I usually make the types explicit. I do not trust
the interpreter's guesses.

Ralf

========================================================================

(1) -> )set stream calc 4
(1) -> eps := "eps"::Symbol;

Type:
Symbol
(2) -> sigma := "sigma"::Symbol;

Type:
Symbol
(3) -> Z ==> Integer
Type:
Void
(4) -> E ==> Expression Z
Type:
Void
(5) -> T ==> UnivariateTaylorSeries(E,eps,0)
Type:
Void
(6) -> e := eps::T

(6) eps
Type:
UnivariateTaylorSeries(Expression(Integer),eps,0)
(7) -> s := sigma::E

(7) sigma
Type:
Expression(Integer)
(8) -> t := series([sin(s)^n/factorial(n) for n in 0..])$T

(8)
2 3 4
sin(sigma) 2 sin(sigma) 3
sin(sigma) 4
1 + sin(sigma)eps + ----------- eps + ----------- eps +
----------- eps
2 6 24
+
5
O(eps )
Type:
UnivariateTaylorSeries(Expression(Integer),eps,0)
(9) -> integrate(t,sigma)

(9)
- cos(sigma)sin(sigma) + sigma 2
sigma - cos(sigma)eps + ------------------------------ eps
4
+
3
cos(sigma) - 3 cos(sigma) 3
-------------------------- eps
18
+
3
(2 cos(sigma) - 5 cos(sigma))sin(sigma) + 3 sigma 4 5
-------------------------------------------------- eps + O(eps )
192
Type:
UnivariateTaylorSeries(Expression(Integer),eps,0)

neven.input

Neven Sajko

unread,
Aug 7, 2021, 1:58:25 PM8/7/21
to fricas-devel
I resolved the issue for me: the problem seems to have been caused by
me using subst instead of eval and then not simplifying (thus I had
some expressions like cos(%pi) and cos(0)).

The manual says that the user is responsible for simplification before
calling other functions, so I guess this can't be a Fricas bug.


Regards,
Neven
Reply all
Reply to author
Forward
0 new messages