Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions src/sage/typeset/ascii_art.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

EXAMPLES::

sage: # needs sage.symbolic
sage: n = var('n')
sage: integrate(n^2/x, x)
n^2*log(x)
Expand All @@ -27,7 +26,7 @@
---------
pi

sage: ascii_art(list(Partitions(6))) # needs sage.combinat sage.libs.flint
sage: ascii_art(list(Partitions(6)))
[ * ]
[ ** * ]
[ *** ** * * ]
Expand All @@ -41,19 +40,19 @@
sage: from sage.repl.interpreter import get_test_shell
sage: shell = get_test_shell()
sage: shell.run_cell('%display ascii_art')
sage: shell.run_cell("i = var('i')") # needs sage.symbolic
sage: shell.run_cell('sum(factorial(i)*x^i, i, 0, 10)') # needs sage.symbolic
sage: shell.run_cell("i = var('i')")
sage: shell.run_cell('sum(factorial(i)*x^i, i, 0, 10)')
10 9 8 7 6 5 4 3...
3628800*x + 362880*x + 40320*x + 5040*x + 720*x + 120*x + 24*x + 6*x...
<BLANKLINE>
...2
...+ 2*x + x + 1

sage: shell.run_cell('3/(7*x)') # needs sage.symbolic
sage: shell.run_cell('3/(7*x)')
3
---
7*x
sage: shell.run_cell('list(Compositions(5))') # needs sage.combinat
sage: shell.run_cell('list(Compositions(5))')
[ *
[ * ** * * *
[ * * ** *** * ** * * ** * *
Expand Down Expand Up @@ -175,8 +174,8 @@ class AsciiArt(CharacterArt):

EXAMPLES::

sage: i = var('i') # needs sage.symbolic
sage: ascii_art(sum(pi^i/factorial(i)*x^i, i, 0, oo)) # needs sage.symbolic
sage: i = var('i')
sage: ascii_art(sum(pi^i/factorial(i)*x^i, i, 0, oo))
pi*x
e
"""
Expand Down Expand Up @@ -215,9 +214,9 @@ def ascii_art(*obj, **kwds):

EXAMPLES::

sage: result = ascii_art(integral(exp(x+x^2)/(x+1), x)) # needs sage.symbolic
sage: result = ascii_art(integral(exp(x+x^2)/(x+1), x))
...
sage: result # needs sage.symbolic
sage: result
/
|
| 2
Expand All @@ -231,21 +230,21 @@ def ascii_art(*obj, **kwds):
We can specify a separator object::

sage: ident = lambda n: identity_matrix(ZZ, n)
sage: ascii_art(ident(1), ident(2), ident(3), sep=' : ') # needs sage.modules
sage: ascii_art(ident(1), ident(2), ident(3), sep=' : ')
[1 0 0]
[1 0] [0 1 0]
[1] : [0 1] : [0 0 1]

We can specify the baseline::

sage: ascii_art(ident(2), baseline=-1) + ascii_art(ident(3)) # needs sage.modules
sage: ascii_art(ident(2), baseline=-1) + ascii_art(ident(3))
[1 0][1 0 0]
[0 1][0 1 0]
[0 0 1]

We can determine the baseline of the separator::

sage: ascii_art(ident(1), ident(2), ident(3), sep=' -- ', sep_baseline=-1) # needs sage.modules
sage: ascii_art(ident(1), ident(2), ident(3), sep=' -- ', sep_baseline=-1)
[1 0 0]
-- [1 0] -- [0 1 0]
[1] [0 1] [0 0 1]
Expand All @@ -254,7 +253,7 @@ def ascii_art(*obj, **kwds):
an ascii art separator::

sage: sep_line = ascii_art('\n'.join(' | ' for _ in range(6)), baseline=6)
sage: ascii_art(*Partitions(6), separator=sep_line, sep_baseline=0) # needs sage.combinat sage.libs.flint
sage: ascii_art(*Partitions(6), separator=sep_line, sep_baseline=0)
| | | | | | | | | | *
| | | | | | | | | ** | *
| | | | | | *** | | ** | * | *
Expand All @@ -264,14 +263,14 @@ def ascii_art(*obj, **kwds):

TESTS::

sage: n = var('n') # needs sage.symbolic
sage: ascii_art(sum(binomial(2 * n, n + 1) * x^n, n, 0, oo)) # needs sage.symbolic
sage: n = var('n')
sage: ascii_art(sum(binomial(2 * n, n + 1) * x^n, n, 0, oo))
/ _________ \
-\2*x + \/ 1 - 4*x - 1/
-------------------------
_________
2*x*\/ 1 - 4*x
sage: ascii_art(list(DyckWords(3))) # needs sage.combinat
sage: ascii_art(list(DyckWords(3)))
[ /\ ]
[ /\ /\ /\/\ / \ ]
[ /\/\/\, /\/ \, / \/\, / \, / \ ]
Expand Down
10 changes: 5 additions & 5 deletions src/sage/typeset/character_art.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def __init__(self, lines=[], breakpoints=[], baseline=None) -> None:

EXAMPLES::

sage: i = var('i') # needs sage.symbolic
sage: ascii_art(sum(pi^i/factorial(i)*x^i, i, 0, oo)) # needs sage.symbolic
sage: i = var('i')
sage: ascii_art(sum(pi^i/factorial(i)*x^i, i, 0, oo))
pi*x
e

Expand Down Expand Up @@ -158,10 +158,10 @@ def __format__(self, fmt):

EXAMPLES::

sage: M = matrix([[1,2],[3,4]]) # needs sage.modules
sage: format(ascii_art(M)) # needs sage.modules
sage: M = matrix([[1,2],[3,4]])
sage: format(ascii_art(M))
'[1 2]\n[3 4]'
sage: format(unicode_art(M)) # needs sage.modules
sage: format(unicode_art(M))
'\u239b1 2\u239e\n\u239d3 4\u23a0'
"""
return format(str(self), fmt)
Expand Down
41 changes: 20 additions & 21 deletions src/sage/typeset/character_art_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ def build(self, obj, baseline=None):

EXAMPLES::

sage: result = ascii_art(integral(exp(x+x^2)/(x+1), x)) # needs sage.symbolic
sage: result = ascii_art(integral(exp(x+x^2)/(x+1), x))
...
sage: result # needs sage.symbolic
sage: result
/
|
| 2
Expand All @@ -93,14 +93,14 @@ def build(self, obj, baseline=None):

TESTS::

sage: n = var('n') # needs sage.symbolic
sage: ascii_art(sum(binomial(2 * n, n + 1) * x^n, n, 0, oo)) # needs sage.symbolic
sage: n = var('n')
sage: ascii_art(sum(binomial(2 * n, n + 1) * x^n, n, 0, oo))
/ _________ \
-\2*x + \/ 1 - 4*x - 1/
-------------------------
_________
2*x*\/ 1 - 4*x
sage: ascii_art(list(DyckWords(3))) # needs sage.combinat
sage: ascii_art(list(DyckWords(3)))
[ /\ ]
[ /\ /\ /\/\ / \ ]
[ /\/\/\, /\/ \, / \/\, / \, / \ ]
Expand Down Expand Up @@ -150,10 +150,10 @@ def build_from_magic_method(self, obj, baseline=None):
EXAMPLES::

sage: from sage.typeset.ascii_art import _ascii_art_factory as factory
sage: out = factory.build_from_magic_method(identity_matrix(2)); out # needs sage.modules
sage: out = factory.build_from_magic_method(identity_matrix(2)); out
[1 0]
[0 1]
sage: type(out) # needs sage.modules
sage: type(out)
<class 'sage.typeset.ascii_art.AsciiArt'>
"""
magic_method = getattr(obj, self.magic_method_name)
Expand Down Expand Up @@ -228,12 +228,12 @@ def build_container(self, content, left_border, right_border, baseline=0):

TESTS::

sage: l = ascii_art(list(DyckWords(3))) # indirect doctest # needs sage.combinat
sage: l # needs sage.combinat
sage: l = ascii_art(list(DyckWords(3))) # indirect doctest
sage: l
[ /\ ]
[ /\ /\ /\/\ / \ ]
[ /\/\/\, /\/ \, / \/\, / \, / \ ]
sage: l._breakpoints # needs sage.combinat
sage: l._breakpoints
[9, 17, 25, 33]

Check that zero-height strings are handled (:issue:`28527`)::
Expand Down Expand Up @@ -274,7 +274,7 @@ def build_set(self, s, baseline=0):
iteration over sets is non-deterministic so too is the results of this
test::

sage: ascii_art(set(DyckWords(3))) # indirect doctest random # needs sage.combinat
sage: ascii_art(set(DyckWords(3))) # indirect doctest random
{ /\ }
{ /\ /\/\ /\ / \ }
{ / \/\, / \, /\/\/\, /\/ \, / \ }
Expand All @@ -283,7 +283,7 @@ def build_set(self, s, baseline=0):
a set, but still obtain the same output formatting::

sage: from sage.typeset.ascii_art import _ascii_art_factory as factory
sage: factory.build_set(sorted(set(DyckWords(3)))) # needs sage.combinat
sage: factory.build_set(sorted(set(DyckWords(3))))
{ /\ }
{ /\ /\ /\/\ / \ }
{ /\/\/\, /\/ \, / \/\, / \, / \ }
Expand All @@ -300,7 +300,6 @@ def build_dict(self, d, baseline=0):

TESTS::

sage: # needs sage.combinat
sage: from collections import OrderedDict
sage: d = OrderedDict(enumerate(DyckWords(3)))
sage: art = ascii_art(d) # indirect doctest
Expand Down Expand Up @@ -343,18 +342,18 @@ def build_list(self, l, baseline=0):

TESTS::

sage: l = ascii_art(list(DyckWords(3))) # indirect doctest # needs sage.combinat
sage: l # needs sage.combinat
sage: l = ascii_art(list(DyckWords(3))) # indirect doctest
sage: l
[ /\ ]
[ /\ /\ /\/\ / \ ]
[ /\/\/\, /\/ \, / \/\, / \, / \ ]
sage: l._breakpoints # needs sage.combinat
sage: l._breakpoints
[9, 17, 25, 33]

The breakpoints of the object are used as breakpoints::

sage: l = ascii_art([DyckWords(2).list(), DyckWords(2).list()]) # needs sage.combinat
sage: l._breakpoints # needs sage.combinat
sage: l = ascii_art([DyckWords(2).list(), DyckWords(2).list()])
sage: l._breakpoints
[(2, [7]), 17, (18, [7])]

The parentheses only stretch as high as the content (:issue:`28527`)::
Expand Down Expand Up @@ -385,7 +384,7 @@ def build_tuple(self, t, baseline=0):

TESTS::

sage: ascii_art(tuple(DyckWords(3))) # indirect doctest # needs sage.combinat
sage: ascii_art(tuple(DyckWords(3))) # indirect doctest
( /\ )
( /\ /\ /\/\ / \ )
( /\/\/\, /\/ \, / \/\, / \, / \ )
Expand Down Expand Up @@ -426,8 +425,8 @@ def concatenate(self, iterable, separator, empty=None, baseline=0,

EXAMPLES::

sage: i2 = identity_matrix(2) # needs sage.modules
sage: ascii_art(i2, i2, i2, sep=ascii_art(1/x)) # needs sage.modules sage.symbolic
sage: i2 = identity_matrix(2)
sage: ascii_art(i2, i2, i2, sep=ascii_art(1/x))
1 1
[1 0]-[1 0]-[1 0]
[0 1]x[0 1]x[0 1]
Expand Down
18 changes: 9 additions & 9 deletions src/sage/typeset/unicode_art.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class UnicodeArt(CharacterArt):

EXAMPLES::

sage: i = var('i') # needs sage.symbolic
sage: unicode_art(sum(pi^i/factorial(i)*x^i, i, 0, oo)) # needs sage.symbolic
sage: i = var('i')
sage: unicode_art(sum(pi^i/factorial(i)*x^i, i, 0, oo))
π⋅x
"""
Expand Down Expand Up @@ -83,17 +83,17 @@ def unicode_art(*obj, **kwds):

EXAMPLES::

sage: result = unicode_art(integral(exp(sqrt(x))/(x+pi), x)) # needs sage.symbolic
sage: result = unicode_art(integral(exp(sqrt(x))/(x+pi), x))
...
sage: result # needs sage.symbolic
sage: result
⎮ √x
⎮ ℯ
⎮ ───── dx
⎮ x + π
sage: ident = lambda n: identity_matrix(ZZ, n)
sage: unicode_art(ident(1), ident(2), ident(3), sep=' : ') # needs sage.modules
sage: unicode_art(ident(1), ident(2), ident(3), sep=' : ')
⎛1 0 0⎞
⎛1 0⎞ ⎜0 1 0⎟
(1) : ⎝0 1⎠ : ⎝0 0 1⎠
Expand All @@ -102,7 +102,7 @@ def unicode_art(*obj, **kwds):
an unicode art separator::

sage: sep_line = unicode_art('\n'.join(' ⎟ ' for _ in range(5)), baseline=5)
sage: unicode_art(*AlternatingSignMatrices(3), # needs sage.combinat sage.modules
sage: unicode_art(*AlternatingSignMatrices(3),
....: separator=sep_line, sep_baseline=1)
⎟ ⎟ ⎟ ⎟ ⎟ ⎟
⎛1 0 0⎞ ⎟ ⎛0 1 0⎞ ⎟ ⎛1 0 0⎞ ⎟ ⎛ 0 1 0⎞ ⎟ ⎛0 0 1⎞ ⎟ ⎛0 1 0⎞ ⎟ ⎛0 0 1⎞
Expand All @@ -112,14 +112,14 @@ def unicode_art(*obj, **kwds):

TESTS::

sage: n = var('n') # needs sage.symbolic
sage: unicode_art(sum(binomial(2 * n, n + 1) * x^n, n, 0, oo)) # needs sage.symbolic
sage: n = var('n')
sage: unicode_art(sum(binomial(2 * n, n + 1) * x^n, n, 0, oo))
⎛ _________ ⎞
-⎝2⋅x + ╲╱ 1 - 4⋅x - 1⎠
─────────────────────────
_________
2⋅x⋅╲╱ 1 - 4⋅x
sage: unicode_art(list(DyckWords(3))) # needs sage.combinat
sage: unicode_art(list(DyckWords(3)))
⎡ ╱╲ ⎤
⎢ ╱╲ ╱╲ ╱╲╱╲ ╱ ╲ ⎥
⎣ ╱╲╱╲╱╲, ╱╲╱ ╲, ╱ ╲╱╲, ╱ ╲, ╱ ╲ ⎦
Expand Down
Loading