5

I'm using Sagemath / Cocalc (feel free to run it in your browser, no sign-up no nothing required). As far as I understand, Sagemath is just a library on top of Python and the Sagemath notebook implicitly imports many things from the Sagemath library.

What puzzles me though is the following syntax:

R.<x,y> = AA[]
I = R.ideal(x^2 * y - 18,x * y^3  - 24, x * y - 6)
I.variety()

(This solves the system of polynomials x^2 * y - 18=0, x * y^3 - 24=, x * y - 6=0, and returns x=2,y=3, nice!)

Running type(AA), I see that it is

<class 'sage.rings.qqbar.AlgebraicRealField_with_category'>. 

Running type(R), I see that it is

<class 'sage.rings.polynomial.multi_polynomial_ring.MPolynomialRing_polydict_domain_with_category'>

Ok, b what does it mean in Python to use brackets [] at a class, i.e. AA[]?

What does it mean, in Python's syntax, to do R.<x,y>? Mind you, I haven't defined previously x and y as strings or anything, so this syntax seems very weird to me.

chepner
  • 497,756
  • 71
  • 530
  • 681
user719220
  • 71
  • 2
  • 1
    Does really no one have an idea? I can't imagine that this question is so hard... – user719220 Jun 16 '20 at 04:45
  • 1
    may be the AA[] is a matrix as the function declare as polynomial one. – Dark debo Jun 16 '20 at 04:49
  • 2
    This isn't Python syntax. Sagemath may be implementing its own `type` function in terms of Python's `type` and exposing classes through its own syntax, but Python itself doesn't allow empty brackets or whatever `R.` is. – chepner Jun 18 '20 at 20:40
  • 2
    I've added the `[sage]` tag in hopes that it will attract the attention of someone who knows that this code means. – chepner Jun 18 '20 at 20:41

1 Answers1

4

SageMath is built on top of Python, but it preparses input, and this is an example. Within SageMath:

sage: preparse('R.<x,y> = AA[]')
"R = AA['x, y']; (x, y,) = R._first_ngens(2)"
  • The preparse command tells you how Sage will convert the string before evaluating it as standard Python.
  • The __getitem__ method (which is what gets called when you do AA[args]) for rings like AA creates a polynomial ring with the named generators.
  • So R.<x,y> = AA[] creates a polynomial ring, and also defines R, x, and y as the ring and its two generators.

You can achieve the same thing by R.<x,y> = PolynomialRing(AA).

John Palmieri
  • 1,531
  • 8
  • 13
  • See https://doc.sagemath.org/html/en/reference/repl/sage/repl/preparse.html#sage.repl.preparse.preparse_generators for the relevant function. – John Palmieri Jun 18 '20 at 21:02