def _ascii_art_generator(self, m): r""" Return an ascii art representing the generator indexed by ``m``. TESTS:: sage: R = NonCommutativeSymmetricFunctions(QQ).R() sage: ascii_art(R[1,2,2,4]) R **** ** ** * sage: Partitions.options(diagram_str="#", convention="french") sage: ascii_art(R[1,2,2,4]) R # ## ## #### sage: Partitions.options._reset() """ from sage.typeset.ascii_art import AsciiArt, ascii_art pref = AsciiArt([self.prefix()]) r = pref * (AsciiArt([" "**Integer(len(pref))]) + ascii_art(m)) r._baseline = r._h - 1 return r
def ascii_art_gen(m): if m[1] != 1: r = AsciiArt([" " ** Integer(len(pref))]) + ascii_art(m[1]) else: r = empty_ascii_art r = r * P._ascii_art_generator(m[0]) r._baseline = r._h - 2 return r
def _ascii_art_(self, number=None): r""" Return an ascii art representation of ``self``. EXAMPLES:: sage: G = cellular_automata.GraftalLace([5,1,2,5,4,5,5,0]) sage: G.evolve(10) sage: ascii_art(G) o | o / \ o o o / \ / \ o o o o o / \ | / \ o o o o o o o / \ / X X \ / \ o o o o o o o o o / \ |/ \|/ \| / \ o o o o o o o o o o o / \ / \ \ / \ / / \ / \ o o o o o o o o o o o o o / \ | / \| |/ \ | / \ o o o o o o o o o o o o o o o / \ / X X \ / \ / X X \ / \ o o o o o o o o o o o o o o o o o / \ |/ \|/ \| |/ \|/ \| / \ o o o o o o o o o o o o o o o o o o o / \ / \ \ / \ / \ / \ / / \ / \ o o o o o o o o o o o o o o o o o o o o o """ if number is None: number = len(self._states) space = len(self._states[:number]) * 2 - 1 ret = AsciiArt([' ' * space + 'o']) space += 1 for i, state in enumerate(self._states[:number]): temp = ' ' * (space - 2) last = ' ' for x in state: if x & 0x4: if last == '/': temp += 'X' else: temp += '\\' else: temp += last temp += '|' if x & 0x2 else ' ' last = '/' if x & 0x1 else ' ' ret *= AsciiArt([temp + last]) space -= 1 ret *= AsciiArt( [' ' * space + ' '.join('o' for dummy in range(2 * i + 1))]) space -= 1 return ret
def _ascii_art_(self): """ Return Ascii Art OUTPUT: Ascii art of the constraint (in)equality. EXAMPLES:: sage: mip.<x> = MixedIntegerLinearProgram() sage: ascii_art(x[0] * vector([1,2]) >= 0) (0.0, 0.0) <= (1.0, 2.0)*x_0 sage: ascii_art(x[0] * matrix([[1,2],[3,4]]) >= 0) [0 0] <= [x_0 2*x_0] [0 0] [3*x_0 4*x_0] """ from sage.typeset.ascii_art import AsciiArt def matrix_art(m): lines = str(m).splitlines() return AsciiArt(lines, baseline=len(lines) // 2) comparator = AsciiArt([' == ' if self.is_equation() else ' <= ']) return matrix_art(self.lhs()) + comparator + matrix_art(self.rhs())
def _ascii_art_term(self, m): """ Return an ascii art representation of the term indexed by ``m``. TESTS:: sage: C = CombinatorialFreeModule(QQ, Partitions()) sage: TA = TensorAlgebra(C) sage: s = TA([Partition([3,2,2,1]), Partition([3])]).leading_support() sage: TA._ascii_art_term(s) B # B *** *** ** ** * sage: s = TA([Partition([3,2,2,1])]*2 + [Partition([3])]*3 + [Partition([1])]*2).leading_support() sage: TA._ascii_art_term(s) B # B # B # B # B # B # B *** *** *** *** *** * * ** ** ** ** * * sage: I = TA.indices() sage: TA._ascii_art_term(I.one()) '1' """ if len(m) == 0: return '1' from sage.typeset.ascii_art import AsciiArt symb = self._print_options['tensor_symbol'] if symb is None: symb = tensor.symbol M = self._base_module it = iter(m._monomial) k, e = next(it) rpr = M._ascii_art_term(k) for i in range(e-1): rpr += AsciiArt([symb], [len(symb)]) rpr += M._ascii_art_term(k) for k,e in it: for i in range(e): rpr += AsciiArt([symb], [len(symb)]) rpr += M._ascii_art_term(k) return rpr
def ascii_art_gen(m): if m[1] != 1: r = (AsciiArt([" " * len(pref)]) + ascii_art(m[1])) else: r = empty_ascii_art r = r * P._ascii_art_generator(m[0]) r._baseline = r._h - 2 return r
def _ascii_art_term(self, t): """ Return an ascii art representation of the term indexed by ``t``. TESTS:: sage: Q = QSystem(QQ, ['A',4]) sage: ascii_art(Q.an_element()) 2 2 3 (1) ( (1)) ( (2)) ( (3)) (2) 1 + 2*Q1 + (Q1 ) *(Q1 ) *(Q1 ) + 3*Q1 """ from sage.typeset.ascii_art import AsciiArt if t == self.one_basis(): return AsciiArt(["1"]) ret = AsciiArt("") first = True for k, exp in t._sorted_items(): if not first: ret += AsciiArt(['*'], baseline=0) else: first = False a, m = k var = AsciiArt([" ({})".format(a), "Q{}".format(m)], baseline=0) #print var #print " "*(len(str(m))+1) + "({})".format(a) + '\n' + "Q{}".format(m) if exp > 1: var = (AsciiArt(['(', '('], baseline=0) + var + AsciiArt([')', ')'], baseline=0)) var = AsciiArt([" " * len(var) + str(exp)], baseline=-1) * var ret += var return ret
def _ascii_art_(self): r""" Return an ASCII art representation of ``self``. EXAMPLES:: sage: F = FreeAbelianMonoid(index_set=ZZ) sage: a,b,c,d,e = [F.gen(i) for i in range(5)] sage: ascii_art(a*e*d) F *F *F 0 3 4 sage: ascii_art(a*b^2*e*d) 2 F *F *F *F 0 1 3 4 """ from sage.typeset.ascii_art import AsciiArt, ascii_art, empty_ascii_art if not self._monomial: return AsciiArt(["1"]) monomial = self._sorted_items() P = self.parent() scalar_mult = P._print_options['scalar_mult'] if all(x[1] == 1 for x in monomial): ascii_art_gen = lambda m: P._ascii_art_generator(m[0]) else: pref = AsciiArt([P.prefix()]) def ascii_art_gen(m): if m[1] != 1: r = (AsciiArt([" " * len(pref)]) + ascii_art(m[1])) else: r = empty_ascii_art r = r * P._ascii_art_generator(m[0]) r._baseline = r._h - 2 return r b = ascii_art_gen(monomial[0]) for x in monomial[1:]: b = b + AsciiArt([scalar_mult]) + ascii_art_gen(x) return b
def character_art(self, num_lines): """ Return the ASCII art of the symbol EXAMPLES:: sage: from sage.typeset.symbols import * sage: ascii_left_curly_brace.character_art(3) { { { """ from sage.typeset.ascii_art import AsciiArt return AsciiArt(self(num_lines))
def _ascii_art_(self): """ Return an ascii art representation. Note that arrows go to the left so that composition of differentials is the usual matrix multiplication. EXAMPLES:: sage: F.<x,y> = FreeAlgebra(ZZ) sage: H = F.hochschild_complex(F) sage: a = H({0: x - y, ....: 1: H.module(1).basis().an_element(), ....: 2: H.module(2).basis().an_element()}) sage: ascii_art(a) d_0 d_1 d_2 d_3 0 <---- F - F <---- 1 # 1 <---- 1 # 1 # 1 <---- 0 x y """ from sage.typeset.ascii_art import AsciiArt, ascii_art if not self._vec: # 0 chain return AsciiArt(['0']) def arrow_art(d): d_str = [' d_{0} '.format(d)] arrow = ' <' + '-' * (len(d_str[0]) - 3) + ' ' d_str.append(arrow) return AsciiArt(d_str, baseline=0) result = AsciiArt(['0']) max_deg = max(self._vec) for deg in range(min(self._vec), max_deg + 1): A = ascii_art(self.vector(deg)) A._baseline = A.height() // 2 result += arrow_art(deg) + A return result + arrow_art(max_deg + 1) + AsciiArt(['0'])
def _ascii_art_(self): r""" Return an ascii art representation of ``self``. EXAMPLES:: sage: print(PlanePartition([[4,3,3,1],[2,1,1],[1,1]])._ascii_art_()) / \ |\ /| |\|/ \ / \|\ / \ |\ /|\|\ /| / \|/ \|\|/| |\ / \ / \|/ \ \|\ /|\ /|\ /| \|/ \|/ \|/ """ from sage.typeset.ascii_art import AsciiArt return AsciiArt(self._repr_diagram().splitlines(), baseline=0)
def _ascii_art_(self): r""" Return an ascii art representation of ``self``. EXAMPLES:: sage: ECA = cellular_automata.Elementary(22, width=30, initial_state=[1]) sage: ECA.evolve(30) sage: ascii_art(ECA) X XX X XXX X X XXX XX X XXX X X XXX XXX X X XXX XXX X X X X XXX XXX XXX XX X XXX X X XXX XXX X X XXX XXX X X X X XXX XXX XXX XXX X X XXX XXX X X X X XXX XXX XXX XXX X X X X XXX XXX XXX XXX X X X X X X X X XXX XXX XXX XXX XXX XXX XXX XX """ return AsciiArt([ ''.join('X' if x else ' ' for x in state) for state in self._states ])
def _ascii_art_(self): r""" Return an ascii art representation of ``self``. EXAMPLES:: sage: y = crystals.infinity.GeneralizedYoungWalls(2)([[0,2,1],[1,0,2,1,0],[],[0],[1,0,2],[],[],[1]]) sage: ascii_art(y) 1| | | 2|0|1| 0| | 0|1|2|0|1| 1|2|0| """ from sage.typeset.ascii_art import AsciiArt return AsciiArt(self._repr_diagram().splitlines())
def _ascii_art_(self): r""" Return an ASCII art representation of ``self``. EXAMPLES:: sage: B = crystals.Tableaux(['Q',3], shape=[3,2,1]) sage: t = B.an_element() sage: t._ascii_art_() 3 3 3 2 2 1 """ from sage.typeset.ascii_art import AsciiArt ret = [ " " * (3 * i) + "".join("%3s" % str(x) for x in reversed(row)) for i, row in enumerate(self.rows()) ] return AsciiArt(ret)
def _ascii_art_(self): r""" Return an ascii art representation of ``self``. EXAMPLES:: sage: PP = PlanePartition([[4,3,3,1],[2,1,1],[1,1]]) sage: ascii_art(PP) __ /\_\ __/\/_/ __/\_\/\_\ /\_\/_/\/\_\ \/\_\_\/\/_/ \/_/\_\/_/ \/_/\_\ \/_/ """ from sage.typeset.ascii_art import AsciiArt return AsciiArt(self._repr_diagram().splitlines(), baseline=0)
def _ascii_art_term(self, m): """ Return an ascii art representation of the term indexed by ``m``. TESTS:: sage: C = CombinatorialFreeModule(QQ, Partitions()) sage: TA = TensorAlgebra(C) sage: s = TA([Partition([3,2,2,1]), Partition([3])]).leading_support() sage: TA._ascii_art_term(s) B # B *** *** ** ** * sage: s = TA([Partition([3,2,2,1])]*2 + [Partition([3])]*3 + [Partition([1])]*2).leading_support() sage: t = TA._ascii_art_term(s); t B # B # B # B # B # B # B *** *** *** *** *** * * ** ** ** ** * * sage: t._breakpoints [7, 14, 21, 28, 35, 40] sage: I = TA.indices() sage: TA._ascii_art_term(I.one()) '1' """ if len(m) == 0: return '1' from sage.typeset.ascii_art import AsciiArt, ascii_art symb = self._print_options['tensor_symbol'] if symb is None: symb = tensor.symbol M = self._base_module return ascii_art(*(M._ascii_art_term(k) for k, e in m._monomial for _ in range(e)), sep=AsciiArt([symb], breakpoints=[len(symb)]))
def _ascii_art_(self): r""" TESTS:: sage: from pGroupCohomology import CohomologyRing sage: CohomologyRing.doctest_setup() # reset, block web access, use temporary workspace sage: H = CohomologyRing(8,3) sage: H.make() sage: B = H.bar_code('UpperCentralSeries',degree=3) sage: ascii_art(B) #indirect doctest * * *-* *-* * * * """ L = [(' ' * (self._length + X[0]) + '*' + '-*' * ((X[1] - X[0]))) for X in self._bars] return AsciiArt(L)
def arrow_art(d): d_str = [' d_{0} '.format(d)] arrow = ' <' + '-' * (len(d_str[0]) - 3) + ' ' d_str.append(arrow) return AsciiArt(d_str, baseline=0)
def matrix_art(m): lines = str(m).splitlines() return AsciiArt(lines, baseline=len(lines) // 2)