Rendering tables in jupyter notebook

110 views
Skip to first unread message

Gaurish Telang

unread,
Nov 20, 2022, 1:39:27 AM11/20/22
to sage-support

I want to create a neat table of the factorization of several polynomials of the form x^n-1 in the ring Z/3Z [x].

This is my code, which I am using inside of a Jupyter notebook that works as expected:

R = IntegerModRing(3) 
x = PolynomialRing(R, 'x').gen()

rows  = []
for k in range(1,10):
    f = x^k - 1
    factor = f.factor()
    rows.append((f,factor))

table(rows, header_row=["Polynomial ", "Factorization"], frame=True)

However, the output produced is ugly and looks like the one in the attachment; it leaves a lot of space on the right but the factorization is spread across multiple rows. How can I ask Sage to place each factorization in the right column on a single line.

Also is it possible for me to write x^k-1 for various powers of k in latex in place of x^k+2. i.e. I want to write -1 wherever there is a 2 in the left column. Sure I can do this with print, but the output won’t be Latex rendered.

ksnip_20221120-111633.png

Emmanuel Charpentier

unread,
Nov 20, 2022, 5:06:52 AM11/20/22
to sage-support
> How can I ask Sage to place each factorization in the right column on a single line.

Both the display in a console and the LaTeX display given by `view` are single-lined. I can reproduce your problem in Jupyter ; therefore, I think that the question should be directed to a Jupyter-centered mailing list, newsgroup, forum or whatever...

> Also is it possible for me to write x^k-1 for various powers of k in latex in place of x^k+2. i.e. I want to write -1 wherever there is a 2 in the left column. Sure I can do this with print, but the output won’t be Latex rendered.

I cant't make head or tail of this gibberish. Could you rephrase ?

HTH,

Gaurish Telang

unread,
Nov 20, 2022, 1:16:44 PM11/20/22
to sage-s...@googlegroups.com
Thanks! I will ask on the Jupyter mailing list. 

Also is it possible for me to write x^k-1 for various powers of k in latex in place of x^k+2. i.e. I want to write -1 wherever there is a 2 in the left column. Sure I can do this with print, but the output won’t be Latex rendered.

I apologize that it was terribly worded.   It was just a dumb question that occured while trying to understand how the `table` function outputs data into a jupyter notebook cell. 

I basically wanted the left hand-side to contain x^k-1 in place of x^k+2 for different values of k i.e. x-1 in place of x+2  
 x^2-1 in place of x^2+2 and so on.  I know of course -1 and 2  are identical in Z/3Z, but I was wondering if there was a  way to display (-1) in place of 2 while using the `table` command and working Z/3Z. 

Regards
G

--
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 on the web visit https://groups.google.com/d/msgid/sage-support/a737f888-3397-4be7-aab6-1e9e8230b20en%40googlegroups.com.

Emmanuel Charpentier

unread,
Nov 21, 2022, 2:50:37 AM11/21/22
to sage-support
Le dimanche 20 novembre 2022 à 19:16:44 UTC+1, gauri...@gmail.com a écrit :
Thanks! I will ask on the Jupyter mailing list. 

Also is it possible for me to write x^k-1 for various powers of k in latex in place of x^k+2. i.e. I want to write -1 wherever there is a 2 in the left column. Sure I can do this with print, but the output won’t be Latex rendered.

I apologize that it was terribly worded.   It was just a dumb question that occured while trying to understand how the `table` function outputs data into a jupyter notebook cell. 

I basically wanted the left hand-side to contain x^k-1 in place of x^k+2 for different values of k i.e. x-1 in place of x+2  
 x^2-1 in place of x^2+2 and so on.  I know of course -1 and 2  are identical in Z/3Z, but I was wondering if there was a  way to display (-1) in place of 2 while using the `table` command and working Z/3Z. 

I doubt it : Sage is strngly opinionated (you could say asinine) about its presentation choices, and, for example, systematically rewrite `1/sqrt(2)` as `sqrt(2)/2`. Even if you sacrifice a goat ;-)...

Gaurish Telang

unread,
Nov 21, 2022, 3:58:42 AM11/21/22
to sage-s...@googlegroups.com


Both the display in a console and the LaTeX display given by `view` are single-lined. I can reproduce your problem in Jupyter ; therefore, I think that the question should be directed to a Jupyter-centered mailing list, newsgroup, forum or whatever...

I just wanted to add, I noticed that the bad alignment goes away if I remove the header_row argument in the call to table

Thus, I get the expected output with the following code (without the column names of course): see attachment.

R = IntegerModRing(3) 
x = PolynomialRing(R, 'x').gen()

rows  = []
for k in range(1,10):
    f = x^k - 1
    factor = f.factor()
    rows.append((f,factor))

table(rows, frame=True)

I wonder how the header_row argument messes up the alignment for Latex in the other rows of the table.


no-header-row.png

Jan Groenewald

unread,
Nov 21, 2022, 4:21:49 AM11/21/22
to sage-s...@googlegroups.com
Hi

On Mon, 21 Nov 2022 at 10:58, Gaurish Telang <gauri...@gmail.com> wrote:


Both the display in a console and the LaTeX display given by `view` are single-lined. I can reproduce your problem in Jupyter ; therefore, I think that the question should be directed to a Jupyter-centered mailing list, newsgroup, forum or whatever...

I just wanted to add, I noticed that the bad alignment goes away if I remove the header_row argument in the call to table

Thus, I get the expected output with the following code (without the column names of course): see attachment.

R = IntegerModRing(3) 
x = PolynomialRing(R, 'x').gen()

rows  = []
for k in range(1,10):
    f = x^k - 1
    factor = f.factor()
    rows.append((f,factor))

table(rows, frame=True)

I wonder how the header_row argument messes up the alignment for Latex in the other rows of the table.


Note it still doesn't align left if you use table(rows, frame=True, align='left')

Regards,
Jan

--
  .~.
  /V\     Jan Groenewald
 /( )\    www.aims.ac.za
 ^^-^^ 

Dima Pasechnik

unread,
Nov 21, 2022, 5:12:09 AM11/21/22
to sage-s...@googlegroups.com
I'd guess that the header_row is used to determined the column width, without checking the rest of the table.
(That's how it works in LaTeX, anyway.)

PS. I also notice  that documentation for table() is rather patchy, and does not even tell you about the
possibility of having anything except True/False/None in the header row. (There are examples there thate tell
that it's possible)...

 

Reply all
Reply to author
Forward
0 new messages