On Sun, Mar 16, 2025 at 07:46:43AM +0100, 'Ralf Hemmecke' via FriCAS - computer algebra system wrote: > Dear Waldek, > > Basic question: How can I see what kernels are cached?
When I needed to debug kernel related functions I added bunch of printouts to SortedCache and Kernel. They were not suitable for normal use, so I did not commit them. If you want to debug this you may add your own printouts. > Explanation follows. > > In some program I recursively traverse the operator/kernel/ratfun tree of an > algebraic number and rebuild another algebraic number. I seemingly have a > bug there, but cannot easily find it. 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)). If you manage to put kernel into cache for Kernel(AlgebraicNumber), this is likely to lead to confusion, possibly with effects like below. It is better to keep kernel transformations in Expression(Integer). I think that currently all operations on kernels within AlgebraicNumber are delegated to Expression(Integer). 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. > The lines > > dbgPrint("csfX z", z) > dbgPrint("csfXxx", x) > t := z*x > dbgPrint("CSFX t", t) > > > gave me the following output > > [:> , csfX z, sqrt(-1)*nthRoot(-1, 3)*sqrt(3)] > [:> , csfXxx, nthRoot(-sqrt(-1)*sqrt(3)+1, 3)] > [:> , CSFX t, 3*sqrt(-1)*nthRoot(-1, 3)] > > The value of t is completely wrong. Look at position fields of kernels. Kernel equality assumes that kernels with the same nonzero positions are equal: k1 = k2 == p1 := position(k1) p2 := position(k2) p1 ~= 0 and p2 ~= 0 => p1 = p2 if p1 = 0 then k1 := kernelEnterInCache(k1) if p2 = 0 then k2 := kernelEnterInCache(k2) position(k1) = position(k2) If you manage to mix kernels from different caches, then this leads to unexpected results. Similarly, when kernel is removed from the cache, but is position filed in not set to 0 (I hope that problems with removal are fixed now, but it happende in the past). > In another place I see two algebraic numbers that print in my program as > > -- aa:=(sqrt(-1)*nthRoot(-1, 3)*sqrt(3)+nthRoot(-1, > 3))*nthRoot(-sqrt(-1)*sqrt(3)+1, 3)-2*nthRoot(2, 3) > -- ab:=sqrt(-1)*nthRoot(-1, 3)*sqrt(3)*nthRoot(-sqrt(-1)*sqrt(3)+1, > 3)+nthRoot(-1, 3)*nthRoot(-sqrt(-1)*sqrt(3)+1, 3)-2*nthRoot(2, 3) > > with respective towers > > -- ta:=[sqrt(-1),_ > nthRoot(-1, 3),_ > nthRoot(2, 3),_ > sqrt(3),_ > nthRoot(-sqrt(-1)*sqrt(3)+1, 3)] > -- tb:=[sqrt(-1),_ > nthRoot(-1, 3),_ > sqrt(3),_ > nthRoot(2, 3),_ > nthRoot(-sqrt(-1)*sqrt(3)+1, 3),_ > nthRoot(-sqrt(-1)*sqrt(3)+1, 3)] > > The surprising fact for me is in this double entry in tb. > Entering ab and computing "tower ab" in the same session gives: > > %%% (6) -> ab:=sqrt(-1)*nthRoot(-1, 3)*sqrt(3)*nthRoot(-sqrt(-1)*sqrt(3)+1, > 3)+nthRoot(-1, 3)*nthRoot(-sqrt(-1)*sqrt(3)+1, 3)-2*nthRoot(2, 3) > > +----------------+ > +---+3+---+ +-+ 3+---+ 3| +---+ +-+ 3+-+ > (6) (\|- 1 \|- 1 \|3 + \|- 1 )\|- \|- 1 \|3 + 1 - 2 \|2 > Type: AlgebraicNumber > %%% (7) -> tower ab > > +----------------+ > +---+ 3+---+ 3+-+ +-+ 3| +---+ +-+ > (7) [\|- 1 , \|- 1 , \|2 , \|3 , \|- \|- 1 \|3 + 1 ] > Type: List(Kernel(AlgebraicNumber)) > > That is, no duplication of the last kernel. > > Long story short... it seems that my program creates a kernel and the cache > does not recognize that it is the same. In order to find exactly where this > happens, I would like to know how I can look at the kernel cache from SPAD. -- 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/Z9a0ItOLvs6PLr6x%40fricas.org.