Some bugs

9 views
Skip to first unread message

Waldek Hebisch

unread,
Jun 9, 2025, 6:50:11 PMJun 9
to fricas...@googlegroups.com
There are some bugs that I looked up, but ATM do not know how to
solve.

1)

((%i*t-1)*z*(z^2-3*t^2-3))/(sqrt(2)*sqrt(3)*(t^4+4*%i*t^3-6*t^2-4*%i*t+1))

give type UnivariatePolynomial(t,Expression(Complex(Integer))). Result
is biggish, so I do not put it here, but one can see that t-s from
numerater are treated as variable in UnivariatePolynomial, while
t-s in denominator are treated as belonging to Expression(Complex(Integer)).

2)

f := operator 'f
SSOLVE ==> EXPRSOL(INT, EXPR INT, UFPS EXPR INT, UFPS SMPEXPR EXPR INT)
coefficient(seriesSolve(1/2-f x, f, x, [])$SSOLVE, 0)

gives no result and no error message. It seems that trouble is in
interpreter coercions of power series, namely that interpreter
builds a function to do needed coercion, but this function is
called in lazy way and fails during evaluation of coefficients.

3)

Old bug reported by Tobias Neumann. Slightly simplified version
is below:

)clear completely

EI ==> Expression(Integer)

-- It looks that trouble is due to the function call. Probably
-- function caches types ???
matrixKernels(x) == removeDuplicates(reduce(append, map(tower, listOfLists(x))))

mymat := matrix([[sqrt('x1)]])
matrixKernels(mymat)

myexpr := sqrt('x1)
eval(tower(myexpr)(1) :: EI, ['x1=4])

)boot clearConstructorCaches()

matrixKernels(mymat)
eval(tower(myexpr)(1) :: EI, ['x1=4])

Apparently the second call to 'matrixKernels' puts 'x1' into
wrong cache.

To explan more: currently clearConstructorCaches() resets positions
of all kernels in caches to 0. Such kernels either should be
re-inserted to the cache on use, or keep position 0. That is,
when new equal kernel is inserted first, we can not insert old
kernel, so it should keep position 0 and use slow methods for
kernel access. But checking position on kernel corresponding
to 'x1' we can see that position is set to 0 by
clearConstructorCaches(), and after call to 'matrixKernels'
this kernel gets nozero position. But checking 'x1' later
we can see that 'x1' from command line has different
position, which suggests that old 'x1' is inserted to the
old cache.

--
Waldek Hebisch

Grégory Vanuxem

unread,
Jun 10, 2025, 5:57:18 AMJun 10
to fricas...@googlegroups.com
Hello,

Le mar. 10 juin 2025 à 00:50, Waldek Hebisch <de...@fricas.org> a écrit :
There are some bugs that I looked up, but ATM do not know how to
solve.

1)

((%i*t-1)*z*(z^2-3*t^2-3))/(sqrt(2)*sqrt(3)*(t^4+4*%i*t^3-6*t^2-4*%i*t+1))

give type UnivariatePolynomial(t,Expression(Complex(Integer))).  Result
is biggish, so I do not put it here, but one can see that t-s from
numerater are treated as variable in UnivariatePolynomial, while
t-s in denominator are treated as belonging to Expression(Complex(Integer)).

That may be unsatisfactory but, comment out:

  t1 = '(AlgebraicNumber) and t2 is ['Complex,.] =>
    resolveTT1('(Expression (Integer)), t2)

in resolveTTSpecial (line 176 of src/interp/i-resolve.boot) and let the user choose the type of arg(s) of sqrt and consort or coerce algebraic numbers himself. And, eventually, implement some specific coercion(s)/conversion(s) in Spad. Commenting this breaks for example operation between Complex(*) * AlgebraicNumber (sqrt(2)*complex(1,2).

Or

--- /home/greg/Tmp/fricas/src/interp/i-resolv.boot      2025-06-08 17:07:09.731630604 +0200
+++ src/interp/i-resolv.boot    2025-06-10 11:34:56.189106604 +0200
@@ -190,12 +190,15 @@
   t1 = '(AlgebraicNumber) and (t2 = ['Complex, $Float] or t2 = ['Complex, $DoubleFloat]) =>
     ['Expression, CADR t2]

-  t1 = '(AlgebraicNumber) and t2 is ['Complex,.] =>
-    resolveTT1('(Expression (Integer)), t2)
-
   t1 = ['AlgebraicNumber] and t2 is ['Polynomial, ['Fraction, ['Integer]]] =>
       ['Polynomial, ['AlgebraicNumber]]

+  t1 = '(AlgebraicNumber) and t2 is ['Polynomial,.] =>
+    resolveTT1('(Expression (Integer)), t2)
+
+  t1 = '(AlgebraicNumber) and t2 is ['Complex,.] =>
+    resolveTT1('(Expression (Integer)), t2)
+
   t1 = ['AlgebraicNumber] and
     t2 is ['Fraction, ['Polynomial, ['Fraction, ['Integer]]]] =>
         ['Fraction, ['Polynomial, ['AlgebraicNumber]]]

?

-  Greg

Waldek Hebisch

unread,
Jun 10, 2025, 9:37:41 AMJun 10
to fricas...@googlegroups.com
On Tue, Jun 10, 2025 at 11:56:28AM +0200, Grégory Vanuxem wrote:
> Hello,
>
> Le mar. 10 juin 2025 à 00:50, Waldek Hebisch <de...@fricas.org> a écrit :
>
> > There are some bugs that I looked up, but ATM do not know how to
> > solve.
> >
> > 1)
> >
> > ((%i*t-1)*z*(z^2-3*t^2-3))/(sqrt(2)*sqrt(3)*(t^4+4*%i*t^3-6*t^2-4*%i*t+1))
> >
> > give type UnivariatePolynomial(t,Expression(Complex(Integer))). Result
> > is biggish, so I do not put it here, but one can see that t-s from
> > numerater are treated as variable in UnivariatePolynomial, while
> > t-s in denominator are treated as belonging to
> > Expression(Complex(Integer)).
> >
>
> That may be unsatisfactory but, comment out:
>
> t1 = '(AlgebraicNumber) and t2 is ['Complex,.] =>
> resolveTT1('(Expression (Integer)), t2)
>
> in resolveTTSpecial (line 176 of src/interp/i-resolve.boot) and let the
> user choose the type of arg(s) of sqrt and consort or coerce algebraic
> numbers himself. And, eventually, implement some specific
> coercion(s)/conversion(s) in Spad. Commenting this breaks for example
> operation between Complex(*) * AlgebraicNumber (sqrt(2)*complex(1,2).

Yes, this is unsatisfactory. The rule above is dubious, but
since we forbid Complex(AlgebraicNumber) the next possibilty
is Expression (Integer). Simply removing it breaks many
uses of %i.

> Or
>
> --- /home/greg/Tmp/fricas/src/interp/i-resolv.boot 2025-06-08
> 17:07:09.731630604 +0200
> +++ src/interp/i-resolv.boot 2025-06-10 11:34:56.189106604 +0200
> @@ -190,12 +190,15 @@
> t1 = '(AlgebraicNumber) and (t2 = ['Complex, $Float] or t2 = ['Complex,
> $DoubleFloat]) =>
> ['Expression, CADR t2]
>
> - t1 = '(AlgebraicNumber) and t2 is ['Complex,.] =>
> - resolveTT1('(Expression (Integer)), t2)
> -
> t1 = ['AlgebraicNumber] and t2 is ['Polynomial, ['Fraction, ['Integer]]]
> =>
> ['Polynomial, ['AlgebraicNumber]]
>
> + t1 = '(AlgebraicNumber) and t2 is ['Polynomial,.] =>
> + resolveTT1('(Expression (Integer)), t2)
> +
> + t1 = '(AlgebraicNumber) and t2 is ['Complex,.] =>
> + resolveTT1('(Expression (Integer)), t2)
> +
> t1 = ['AlgebraicNumber] and
> t2 is ['Fraction, ['Polynomial, ['Fraction, ['Integer]]]] =>
> ['Fraction, ['Polynomial, ['AlgebraicNumber]]]

Also, the rule

t1 = '(AlgebraicNumber) and t2 is ['Polynomial,.] =>
resolveTT1('(Expression (Integer)), t2)

in general is undesirable. We probably want rule

t1 = ['AlgebraicNumber] and t2 is ['Polynomial, t3] and
(t4 := resolveTT1(t1, t3)) => ['Polynomial, t4]

More generally, AFAICS core of the trouble is that resolve works
on subexpressions and commits to choice inside subexpressions,
without noting that choices in various parts are inconsistent.
We can tweak rules so that some specific cases work OK and
it makes sense to do so when there is no regression for other
cases. But this example seem to be too complicated for current
tactic.

--
Waldek Hebisch

Waldek Hebisch

unread,
Jun 10, 2025, 11:23:32 AMJun 10
to fricas...@googlegroups.com
On Tue, Jun 10, 2025 at 11:56:28AM +0200, Grégory Vanuxem wrote:
> Hello,
>
> Le mar. 10 juin 2025 à 00:50, Waldek Hebisch <de...@fricas.org> a écrit :
>
> > There are some bugs that I looked up, but ATM do not know how to
> > solve.
> >
> > 1)
> >
> > ((%i*t-1)*z*(z^2-3*t^2-3))/(sqrt(2)*sqrt(3)*(t^4+4*%i*t^3-6*t^2-4*%i*t+1))
> >
> > give type UnivariatePolynomial(t,Expression(Complex(Integer))). Result
> > is biggish, so I do not put it here, but one can see that t-s from
> > numerater are treated as variable in UnivariatePolynomial, while
> > t-s in denominator are treated as belonging to
> > Expression(Complex(Integer)).
> >
>
<snip>
> Or
>
> --- /home/greg/Tmp/fricas/src/interp/i-resolv.boot 2025-06-08
> 17:07:09.731630604 +0200
> +++ src/interp/i-resolv.boot 2025-06-10 11:34:56.189106604 +0200
> @@ -190,12 +190,15 @@
> t1 = '(AlgebraicNumber) and (t2 = ['Complex, $Float] or t2 = ['Complex,
> $DoubleFloat]) =>
> ['Expression, CADR t2]
>
> - t1 = '(AlgebraicNumber) and t2 is ['Complex,.] =>
> - resolveTT1('(Expression (Integer)), t2)
> -
> t1 = ['AlgebraicNumber] and t2 is ['Polynomial, ['Fraction, ['Integer]]]
> =>
> ['Polynomial, ['AlgebraicNumber]]
>
> + t1 = '(AlgebraicNumber) and t2 is ['Polynomial,.] =>
> + resolveTT1('(Expression (Integer)), t2)
> +
> + t1 = '(AlgebraicNumber) and t2 is ['Complex,.] =>
> + resolveTT1('(Expression (Integer)), t2)
> +
> t1 = ['AlgebraicNumber] and
> t2 is ['Fraction, ['Polynomial, ['Fraction, ['Integer]]]] =>
> ['Fraction, ['Polynomial, ['AlgebraicNumber]]]
>

Looking more, this:

t1 = '(AlgebraicNumber) and t2 is ['Complex,.] =>
resolveTT1('(Expression (Integer)), t2)

- t1 = ['AlgebraicNumber] and t2 is ['Polynomial, ['Fraction, ['Integer]]] =>
- ['Polynomial, ['AlgebraicNumber]]
+ t1 = ['AlgebraicNumber] and t2 is ['Polynomial, t3] and
+ (t4 := resolveTT1(t1, t3)) =>
+ t4 is ['Expression, .] => t4
+ ['Polynomial, t4]

t1 = ['AlgebraicNumber] and
t2 is ['Fraction, ['Polynomial, ['Fraction, ['Integer]]]] =>

Seem to work without ill effects. Still, after applying it some
similar examples like:

(t + sqrt(2))*(%i*t + 1)

(t + sqrt(2))/(%i*t + 1)

(t + z + sqrt(2))*(%i*t + 1)

sqrt(2)*((t - 1)/(%i*t + 1))

either produce strange type or fail.

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