Expression vs AlgebraicNumber --- Caching?

3 views
Skip to first unread message

Ralf Hemmecke

unread,
Jul 4, 2024, 8:23:03 AM (14 days ago) Jul 4
to fricas-devel
The following session surprised me.

%%% (1) -> e7:=nthRoot((3*sqrt(7)::Expression(INT)+2*sqrt(3))/sqrt(3),3)

+---------------+
| +-+ +-+
|3 \|7 + 2 \|3
(1) |---------------
3| +-+
\| \|3
Type: Expression(Integer)
%%% (2) -> a7 := nthRoot((3*sqrt(7)+2*sqrt(3))/sqrt(3),3)

+---------------+
| +-+ +-+
|3 \|7 + 2 \|3
(2) |---------------
3| +-+
\| \|3
Type: AlgebraicNumber
%%% (3) -> b7 := nthRoot((3*sqrt(7)+5*sqrt(3))/sqrt(3),3)

+------------+
3| +-+ +-+
(3) \|\|3 \|7 + 5
Type: AlgebraicNumber
%%% (4) -> a5 := nthRoot((3*sqrt(5)+2*sqrt(3))/sqrt(3),3)

+------------+
3| +-+ +-+
(4) \|\|3 \|5 + 2
Type: AlgebraicNumber

When you remove the comment sign from the first line of the attached
file and execute foo.input in a fresh session, the output will look
different.

Well, of course, it shouldn't surprise me. There is caching done in FriCAS.

I did not manage to get a rational denominator of e7

%%% (5) -> ratDenom e7

+---------------+
| +-+ +-+
|3 \|7 + 2 \|3
(5) |---------------
3| +-+
\| \|3
Type: Expression(Integer)

And this I find somewhat user-unfriendly.

Ralf
foo.input

Waldek Hebisch

unread,
Jul 4, 2024, 10:05:59 AM (13 days ago) Jul 4
to fricas...@googlegroups.com
There is caching and worse, AlgebraicNumber uses the same cache as
Expression(Integer).

> I did not manage to get a rational denominator of e7
>
> %%% (5) -> ratDenom e7
>
> +---------------+
> | +-+ +-+
> |3 \|7 + 2 \|3
> (5) |---------------
> 3| +-+
> \| \|3
> Type: Expression(Integer)
>
> And this I find somewhat user-unfriendly.

Yes, unfortunately current caching mechanizm works in this way.
If you want expressions with rational denominators you can use
'setSimplifyDenomsFlag(true)'. But once you get kernel with
denominator it will stay in the cache till say ')clear all'.

That is one of motivations for recent FunctionSpace change.
It should allow using local caches, so limit pollution to
global cache. And maybe somebody will develop different
caching mechanizm, with nicer behaviour.

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