On Sun, Mar 16, 2025 at 03:31:43PM +0100, 'Ralf Hemmecke' via FriCAS - computer algebra system wrote: > On 3/16/25 12:21, Waldek Hebisch wrote: > > On Sun, Mar 16, 2025 at 07:46:43AM +0100, 'Ralf Hemmecke' via FriCAS - > > computer algebra system wrote: > > > I would suggest to avoid creating new kernels in AlgebraicNumber. > > At implementation level AlgebraicNumber is essentially a slightly > > changed view of Expression(Integer) and IIRC corresponding > > kernels live in cache for Kernel(Expression(Integer)). > > Aaaahh.... I was just about to test and wondered why the cache for > SortedCache(Kernel(AlgebraicNumber)) printed as empty though I entered > sqrt(2) into the session. Additionally, I get > > %%% (1) -> a2:=sqrt(2) > > +-+ > (1) \|2 > Type: AlgebraicNumber > %%% (2) -> k2 := kernels(a2).1 > > +-+ > (2) \|2 > Type: Kernel(AlgebraicNumber) > %%% (3) -> position(k2) > > (3) 2048 > Type: PositiveInteger > %%% (4) -> position(k2)$Kernel(AlgebraicNumber) > > (4) 2048 > Type: NonNegativeInteger > > I added > getCache(): PrimitiveArray S == cache > to SortedCache. > > %%% (5) -> getCache()$SortedCache(Kernel(Expression(Integer))) > > +-+ > (5) [%%var, \|2 , %%var, %%var, %%var, %%var, %%var, %%var, %%var, > %%var] > Type: PrimitiveArray(Kernel(Expression(Integer))) > %%% (6) -> getCache()$SortedCache(Kernel(AlgebraicNumber)) > > (6) [] > Type: PrimitiveArray(Kernel(AlgebraicNumber)) > > So certainly I must create kernels in Kernel(Expression Integer). That's a > good hint. > > However, why position gives such a big number whereas the true position in > the primitive array should actually be 2, is a mystery for me.
Positions have gaps, that is deliberate to limit renumbering. > Anyhow, if I could ensure all my kernels are truely in Kernel(AN) (which I > probably cannot), then all would be fine? > > > BTW: It probably would be better to change our declarations so > > that AlgebraicNumber does not export FunctionSpace, but doing > > that without removing useful operations looks tricky. > > Erm, according to https://fricas.github.io/api/AlgebraicNumber.html, it > doesn´t. You probably meant ExpressionSpace. Yes, ExpressionSpace. > My first thought was to implement explicitly all those exports in AN via > coercion to E==>Expression(INT), calling the respective function from E and > then converting back the result. But that cannot work without confusion, > because if a result contains Kernel(AN), then an entry in > SortedCache(Kernel(AN)) would be created, and two kernels from AN might have > different positions in SortedCache(Kernel(AN)) and SortedCache(Kernel(E)). > So when k1 < k2 in Kernel(AN) may give a different result then the one in > Kernel(E). > Wait, something must be wrong with my thinking. How would otherwise > getCache()$SortedCache(Kernel(AlgebraicNumber)) still return the empty list > although I clearly have created an element of Kernel(AN) in (2) above? AFAICS this is really Kernel(Expression(Integer)). They share representation, so in many case it does not matter if it is Kernel(AlgebraicNumber) or Kernel(Expression(Integer)). But it matters for cache. And once you mix kernels from two caches you may get weird results. ATM I do not have good solution to this. Correct solution would probably remove all traces of Kernel(AlgebraicNumber) from algebra code, but currently it is used in several important operations. BTW: Are you recompiling some domains? More precisely, do you get wrong results when you )LIB files that you recompiled separately and avoid any operations that could clear kernel cache? -- 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 visit https://groups.google.com/d/msgid/fricas-devel/Z9bxU90-jLeoF1SF%40fricas.org.