Print LIST of polynomials in Magma in one line instead of multiline

348 Views Asked by At

Suppose I have list of two polynomials and want to print it. I will get multi line output:

> P<x> := PolynomialRing(Rationals());
> list := [x^2 - 2*x + 2, x^2 + x];   
> print list;
[
    x^2 - 2*x + 2,
    x^2 + x
]

Even more:

> print x^2 - 2*x + 2, ",", x^2 + x;
x^2 - 2*x + 2
, x^2 + x

So after any polynomial (and may be some other type of objects) print statement (or underlying conversion polynomial to string) always put new line symbol.

My goal is to print all elements of list in one line, like this

> one_line_print(list);
[x^2 - 2*x + 2, x^2 + x]

Is it possible?

1

There are 1 best solutions below

0
On BEST ANSWER

You can try the printf function. To format it exactly how you want you would type

one_line_print := procedure(list);
  printf "[";
    for i in [1..#list] do
      if i eq #list then
        str := "%o]";
      else
        str := "%o, ";
      end if;
    printf str, list[i]; 
  end for;
end procedure;

If you have to do it a bunch of times, you can make this a procedure that takes your list as an argument and then prints it in the proper format.