5

In one example of Sage math (search for octahedral) there is this line:

K.<v> = sage.groups.matrix_gps.finitely_generated.CyclotomicField(10)

What does this .<v> do?

Martin Ueding
  • 8,245
  • 6
  • 46
  • 92
  • 4
    Can you link to the example? That doesn't look like anything Python I'm familiar with. – Mad Physicist Jan 02 '19 at 18:07
  • 2
    I'm fairly certain that would be a SyntaxError in any version Python. – juanpa.arrivillaga Jan 02 '19 at 18:09
  • 4
    "*SageMath is a free open-source mathematics software system [...]. Access their combined power through a common, Python-based language*" - i.e. not bare Python directly. – melpomene Jan 02 '19 at 18:10
  • 2
    I have never even heard of this However 2 mins of reading the documentation describes this as `We can specify a different generator name as follows`. so `v` would be the generator name returned by `k.gen()`. I would suggest to read the documentation. – Chris Doyle Jan 02 '19 at 18:14
  • 2
    http://doc.sagemath.org/html/en/reference/repl/sage/repl/preparse.html#sage.repl.preparse.preparse_generators looks relevant. – melpomene Jan 02 '19 at 18:18
  • 1
    Oh, I get it! You are not supposed to start up `python2` and `import sage` but rather start `sage`; at least not for this example. Okay, then it is no surprise that there is special syntax. – Martin Ueding Jan 02 '19 at 18:21
  • @ChrisDoyle: Thanks for the pointer. It did not occur to me that Sage might have a custom interpreter. Therefore I thought this was some Python syntax I never saw before. – Martin Ueding Jan 02 '19 at 18:22

1 Answers1

6

SageMath code is not Python, albeit very similar. The syntax

A.<b> = C(d, e, f)

in SageMath is roughly equivalent to the following Python code

A = C(d, e, f, names=('b',))
b = A.gen()

I.e., first the parent ring A is created, with generator named 'b', then a variable b is initialized to the generator of A.

You can see what any SageMath statement is translated to using the function preparse():

sage: preparse('A.<b> = C(d, e, f)')
"A = C(d, e, f, names=('b',)); (b,) = A._first_ngens(1)"
Luca De Feo
  • 704
  • 5
  • 12