package / initilaizer problem...

23 views
Skip to first unread message

Thierry Dumont

unread,
Apr 21, 2025, 4:35:09 AMApr 21
to sage-support
May be this problem is trivial (RTFM...) but:

1) Suppose I run this in the REPL:

from sage.all import *
from rkkit.RKRungeKutta import * #my code
class RK4(RungeKutta):
def __init__(self):
title="Classical Runge-Kutta 4 explicit method"
A=matrix(AA,[[0,0,0,0],[1/2,0,0,0],[0,1/2,0,0],[0,0,1,0]])
B=vector(AA,[1/6,2/6,2/6,1/6])
super().__init__(A,B,title)


then I can do:

R=RK4()
everything is ok.

2) Now, in a directory "methods" I put the same piece of code as above
in a file called "RK4.py".

I add a file __init__.py in methods/, which is:

from sage.all import *
from rkkit.RKRungeKutta import *
__all__=["RK4"]

So, I have
methods/
__init__.py
RK4.py

Now, typing:

from methods import *
R=RK4.RK4()

I get the error message:

typeError: Illegal initializer for algebraic number

How can I avoid this?

(something like putting Integer() around the elements of the list in
matrix(AA,[[0,0,0,0],[1/2,0,0,0],[0,1/2,0,0],[0,0,1,0]])
is something I want (need) to avoid).

Yours,
Thierry

pedrito...@gmail.com

unread,
Apr 21, 2025, 5:05:21 AMApr 21
to sage-s...@googlegroups.com
Hi,
I would do
A=matrix([[0,0,0,0],[1/2,0,0,0],[0,1/2,0,0],[0,0,1,0]])*AA.one()
B=vector([1/6,2/6,2/6,1/6])*AA.one()
Best, Pedro

--
You received this message because you are subscribed to the Google Groups "sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-support...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/sage-support/9fbe6b5b-1bd1-4bf2-bc66-ee0ff7343826%40math.univ-lyon1.fr.

Thierry Dumont

unread,
Apr 21, 2025, 5:22:26 AMApr 21
to sage-s...@googlegroups.com
Mhh, interesting.

In the REPL it works:
A=matrix([[0,0,0,0],[1/2,0,0,0],[0,1/2,0,0],[0,0,1,0]])*AA.one()
ok
and:
sage: A.parent().is_exact()
True

But an other problem happens:
The class "RungeKutta" (the parent class of RK4) as a test:

class RungeKutta(SageObject):
def __init__(self,A,B,Title,C=[]):
if not A.parent().is_exact():
<raise an Exception">

and I get the exception, which seems to mean that, seen from the
RungeKutta class the parent af A is not exact.

Then putting a
print(A.parent())
just before the test in the constructor of RungeKutta, I get:

Full MatrixSpace of 4 by 4 dense matrices over Real Double Field

which, for me, is very surprising... why ?

Thank you!

thierry


Le 21/04/2025 à 11:05, pedrito...@gmail.com a écrit :
> Hi,
> I would do
> A=matrix([[0,0,0,0],[1/2,0,0,0],[0,1/2,0,0],[0,0,1,0]])*AA.one()
> B=vector([1/6,2/6,2/6,1/6])*AA.one()
> Best, Pedro
>
> El lun, 21 abr 2025 a las 10:35, Thierry Dumont (<tdu...@math.univ-
> lyon1.fr <mailto:tdu...@math.univ-lyon1.fr>>) escribió:
> <mailto:sage-support%2Bunsu...@googlegroups.com>.
> To view this discussion visit https://groups.google.com/d/msgid/
> sage-support/9fbe6b5b-1bd1-4bf2-bc66-ee0ff7343826%40math.univ-
> lyon1.fr <https://groups.google.com/d/msgid/sage-
> support/9fbe6b5b-1bd1-4bf2-bc66-ee0ff7343826%40math.univ-lyon1.fr>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to sage-support...@googlegroups.com <mailto:sage-
> support+u...@googlegroups.com>.
> To view this discussion visit https://groups.google.com/d/msgid/sage-
> support/
> CAOAJP6qRM47LOaFx_nQhmubGELzfj_f8ASkQfP%3D5aZkG2DOSdA%40mail.gmail.com
> <https://groups.google.com/d/msgid/sage-support/
> CAOAJP6qRM47LOaFx_nQhmubGELzfj_f8ASkQfP%3D5aZkG2DOSdA%40mail.gmail.com?
> utm_medium=email&utm_source=footer>.

Dima Pasechnik

unread,
Apr 21, 2025, 10:14:46 AMApr 21
to sage-s...@googlegroups.com
To unsubscribe from this group and stop receiving emails from it, send an email to sage-support...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/sage-support/b5590e4a-7628-4782-9bde-0cc96f39151b%40math.univ-lyon1.fr.

Dima Pasechnik

unread,
Apr 21, 2025, 10:17:42 AMApr 21
to sage-s...@googlegroups.com
On Mon, Apr 21, 2025 at 4:22 AM Thierry Dumont <tdu...@math.univ-lyon1.fr> wrote:
Mhh, interesting.

In the REPL it works:
A=matrix([[0,0,0,0],[1/2,0,0,0],[0,1/2,0,0],[0,0,1,0]])*AA.one()
ok
and:
sage: A.parent().is_exact()
True

But an other problem happens:
The class "RungeKutta" (the parent class of RK4) as a test:

class RungeKutta(SageObject):
def __init__(self,A,B,Title,C=[]):
         if not A.parent().is_exact():
          <raise an Exception">

and I get the exception, which seems to mean that, seen from the
RungeKutta class the parent af A is not exact.

Then putting a
print(A.parent())
just before the test in the constructor of RungeKutta, I get:

Full MatrixSpace of 4 by 4 dense matrices over Real Double Field

which, for me, is very surprising... why ?

because non-integers are immediately converted into floats

 $ python3
Python 3.12.9 (main, Feb 22 2025, 21:25:23) [GCC 14.2.1 20241221] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> a=1/2; a
0.5

To unsubscribe from this group and stop receiving emails from it, send an email to sage-support...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/sage-support/b5590e4a-7628-4782-9bde-0cc96f39151b%40math.univ-lyon1.fr.
Reply all
Reply to author
Forward
0 new messages