Ask Your Question

Revision history [back]

One possibility is to

  • input a mutli-line string from the GAP output
  • evaluate it as a list of "[list of lists, number]" lists
  • run a small loop to extract the data in the desired form

Here is how it would go.

The initial string:

sage: s = """
....: [ [ [ [ 1, 1, 1, 1, 1 ], [ 0, 1, 0, 0, 1 ], [ 0, 0, 1, 0, 1 ], [ 0, 0, 0, 1, 1 ], [ 0, 0, 0, 0, 1 ] ], 2 ],
....: [ [ [ 1, 1, 1, 1, 1 ], [ 0, 1, 0, 1, 1 ], [ 0, 0, 1, 1, 1 ], [ 0, 0, 0, 1, 1 ], [ 0, 0, 0, 0, 1 ] ], 2 ],
....: [ [ [ 1, 1, 1, 1, 1 ], [ 0, 1, 0, 0, 1 ], [ 0, 0, 1, 1, 1 ], [ 0, 0, 0, 1, 1 ], [ 0, 0, 0, 0, 1 ] ], 2 ],
....: [ [ [ 1, 1, 1, 1, 1 ], [ 0, 1, 1, 1, 1 ], [ 0, 0, 1, 1, 1 ], [ 0, 0, 0, 1, 1 ], [ 0, 0, 0, 0, 1 ] ], 1 ],
....: [ [ [ 1, 1, 1, 1, 1 ], [ 0, 1, 1, 1, 1 ], [ 0, 0, 1, 0, 1 ], [ 0, 0, 0, 1, 1 ], [ 0, 0, 0, 0, 1 ] ], 2 ] ]
....: """

Turn it into a list:

sage: stats = sage_eval(s)
sage: stats
[[[[1, 1, 1, 1, 1],
   [0, 1, 0, 0, 1],
   [0, 0, 1, 0, 1],
   [0, 0, 0, 1, 1],
   [0, 0, 0, 0, 1]],
  2],
 [[[1, 1, 1, 1, 1],
   [0, 1, 0, 1, 1],
   [0, 0, 1, 1, 1],
   [0, 0, 0, 1, 1],
   [0, 0, 0, 0, 1]],
  2],
 [[[1, 1, 1, 1, 1],
   [0, 1, 0, 0, 1],
   [0, 0, 1, 1, 1],
   [0, 0, 0, 1, 1],
   [0, 0, 0, 0, 1]],
  2],
 [[[1, 1, 1, 1, 1],
   [0, 1, 1, 1, 1],
   [0, 0, 1, 1, 1],
   [0, 0, 0, 1, 1],
   [0, 0, 0, 0, 1]],
  1],
 [[[1, 1, 1, 1, 1],
   [0, 1, 1, 1, 1],
   [0, 0, 1, 0, 1],
   [0, 0, 0, 1, 1],
   [0, 0, 0, 0, 1]],
  2]]

Run the small loop to format as desired:

sage: for m, s in stats:
....:     a = matrix(m)
....:     i = a.parent().one()
....:     d = (a - i).dict()
....:     stat = list(d.keys()), a.ncols()
....:     print(f"{stat} => {s}")
....:
([(0, 1), (0, 2), (0, 3), (0, 4), (1, 4), (2, 4), (3, 4)], 5) => 2
([(0, 1), (0, 2), (0, 3), (0, 4), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)], 5) => 2
([(0, 1), (0, 2), (0, 3), (0, 4), (1, 4), (2, 3), (2, 4), (3, 4)], 5) => 2
([(0, 1), (0, 2), (0, 3), (0, 4), (1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)], 5) => 1
([(0, 1), (0, 2), (0, 3), (0, 4), (1, 2), (1, 3), (1, 4), (2, 4), (3, 4)], 5) => 2

One possibility is to

  • input a mutli-line string from the GAP output
  • evaluate it as a list of "[list of lists, number]" lists
  • run a small loop to extract the data in the desired form

Here is how it would go.

The initial string:

sage: s = """
....: [ [ [ [ 1, 1, 1, 1, 1 ], [ 0, 1, 0, 0, 1 ], [ 0, 0, 1, 0, 1 ], [ 0, 0, 0, 1, 1 ], [ 0, 0, 0, 0, 1 ] ], 2 ],
....: [ [ [ 1, 1, 1, 1, 1 ], [ 0, 1, 0, 1, 1 ], [ 0, 0, 1, 1, 1 ], [ 0, 0, 0, 1, 1 ], [ 0, 0, 0, 0, 1 ] ], 2 ],
....: [ [ [ 1, 1, 1, 1, 1 ], [ 0, 1, 0, 0, 1 ], [ 0, 0, 1, 1, 1 ], [ 0, 0, 0, 1, 1 ], [ 0, 0, 0, 0, 1 ] ], 2 ],
....: [ [ [ 1, 1, 1, 1, 1 ], [ 0, 1, 1, 1, 1 ], [ 0, 0, 1, 1, 1 ], [ 0, 0, 0, 1, 1 ], [ 0, 0, 0, 0, 1 ] ], 1 ],
....: [ [ [ 1, 1, 1, 1, 1 ], [ 0, 1, 1, 1, 1 ], [ 0, 0, 1, 0, 1 ], [ 0, 0, 0, 1, 1 ], [ 0, 0, 0, 0, 1 ] ], 2 ] ]
....: [[[[1, 1, 1, 1, 1], [0, 1, 0, 0, 1], [0, 0, 1, 0, 1], [0, 0, 0, 1, 1], [0, 0, 0, 0, 1]], 2],
 [[[1, 1, 1, 1, 1], [0, 1, 0, 1, 1], [0, 0, 1, 1, 1], [0, 0, 0, 1, 1], [0, 0, 0, 0, 1]], 2],
 [[[1, 1, 1, 1, 1], [0, 1, 0, 0, 1], [0, 0, 1, 1, 1], [0, 0, 0, 1, 1], [0, 0, 0, 0, 1]], 2],
 [[[1, 1, 1, 1, 1], [0, 1, 1, 1, 1], [0, 0, 1, 1, 1], [0, 0, 0, 1, 1], [0, 0, 0, 0, 1]], 1],
 [[[1, 1, 1, 1, 1], [0, 1, 1, 1, 1], [0, 0, 1, 0, 1], [0, 0, 0, 1, 1], [0, 0, 0, 0, 1]], 2]]
"""

Turn it into a list:

sage: stats = sage_eval(s)
sage: stats
[[[[1, 1, 1, 1, 1],
   [0, 1, 0, 0, 1],
   [0, 0, 1, 0, 1],
   [0, 0, 0, 1, 1],
   [0, 0, 0, 0, 1]],
  2],
 [[[1, 1, 1, 1, 1],
   [0, 1, 0, 1, 1],
   [0, 0, 1, 1, 1],
   [0, 0, 0, 1, 1],
   [0, 0, 0, 0, 1]],
  2],
 [[[1, 1, 1, 1, 1],
   [0, 1, 0, 0, 1],
   [0, 0, 1, 1, 1],
   [0, 0, 0, 1, 1],
   [0, 0, 0, 0, 1]],
  2],
 [[[1, 1, 1, 1, 1],
   [0, 1, 1, 1, 1],
   [0, 0, 1, 1, 1],
   [0, 0, 0, 1, 1],
   [0, 0, 0, 0, 1]],
  1],
 [[[1, 1, 1, 1, 1],
   [0, 1, 1, 1, 1],
   [0, 0, 1, 0, 1],
   [0, 0, 0, 1, 1],
   [0, 0, 0, 0, 1]],
  2]]

Run the small loop to format as desired:

sage: for m, s in stats:
....:     a = matrix(m)
....:     i = a.parent().one()
....:     d = (a - i).dict()
....:     stat = list(d.keys()), a.ncols()
....:     print(f"{stat} => {s}")
....:
([(0, 1), (0, 2), (0, 3), (0, 4), (1, 4), (2, 4), (3, 4)], 5) => 2
([(0, 1), (0, 2), (0, 3), (0, 4), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)], 5) => 2
([(0, 1), (0, 2), (0, 3), (0, 4), (1, 4), (2, 3), (2, 4), (3, 4)], 5) => 2
([(0, 1), (0, 2), (0, 3), (0, 4), (1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)], 5) => 1
([(0, 1), (0, 2), (0, 3), (0, 4), (1, 2), (1, 3), (1, 4), (2, 4), (3, 4)], 5) => 2