示例#1
0
文件: spin.py 项目: hitej/meta-core
    def _pretty(self, printer, *args):
        top = printer._print(self.j)

        bot = printer._print(self.m)
        bot = prettyForm(*bot.right(","))
        bot = prettyForm(*bot.right(printer._print(self.mp)))

        pad = max(top.width(), bot.width())
        top = prettyForm(*top.left(" "))
        bot = prettyForm(*bot.left(" "))
        if pad > top.width():
            top = prettyForm(*top.right(" " * (pad - top.width())))
        if pad > bot.width():
            bot = prettyForm(*bot.right(" " * (pad - bot.width())))

        if self.alpha == 0 and self.gamma == 0:
            args = printer._print(self.beta)

            s = stringPict("d" + " " * pad)
        else:
            args = printer._print(self.alpha)
            args = prettyForm(*args.right(","))
            args = prettyForm(*args.right(printer._print(self.beta)))
            args = prettyForm(*args.right(","))
            args = prettyForm(*args.right(printer._print(self.gamma)))

            s = stringPict("D" + " " * pad)

        args = prettyForm(*args.parens())
        s = prettyForm(*s.above(top))
        s = prettyForm(*s.below(bot))
        s = prettyForm(*s.right(args))
        return s
示例#2
0
    def _pretty_brackets(self, height, use_unicode=True):
        # Return pretty printed brackets for the state
        # Ideally, this could be done by pform.parens but it does not support the angled < and >

        # Setup for unicode vs ascii
        if use_unicode:
            lbracket, rbracket = self.lbracket_ucode, self.rbracket_ucode
            slash, bslash, vert = u'\u2571', u'\u2572', u'\u2502'
        else:
            lbracket, rbracket = self.lbracket, self.rbracket
            slash, bslash, vert = '/', '\\', '|'

        # If height is 1, just return brackets
        if height == 1:
            return stringPict(lbracket), stringPict(rbracket)
        # Make height even
        height += (height % 2)

        brackets = []
        for bracket in lbracket, rbracket:
            # Create left bracket
            if bracket in set([_lbracket, _lbracket_ucode]):
                bracket_args = [ ' ' * (height//2-i-1) + slash for i in range(height // 2)]
                bracket_args.extend([ ' ' * i + bslash for i in range(height // 2)])
            # Create right bracket
            elif bracket in set([_rbracket, _rbracket_ucode]):
                bracket_args = [ ' ' * i + bslash for i in range(height // 2)]
                bracket_args.extend([ ' ' * (height//2-i-1) + slash for i in range(height // 2)])
            # Create straight bracket
            elif bracket in set([_straight_bracket, _straight_bracket_ucode]):
                bracket_args = [vert for i in range(height)]
            else:
                raise ValueError(bracket)
            brackets.append(stringPict('\n'.join(bracket_args), baseline=height//2))
        return brackets
示例#3
0
    def _pretty(self, printer, *args):
        top = printer._print(self.j)

        bot = printer._print(self.m)
        bot = prettyForm(*bot.right(','))
        bot = prettyForm(*bot.right(printer._print(self.mp)))

        pad = max(top.width(), bot.width())
        top = prettyForm(*top.left(' '))
        bot = prettyForm(*bot.left(' '))
        if pad > top.width():
            top = prettyForm(*top.right(' ' * (pad - top.width())))
        if pad > bot.width():
            bot = prettyForm(*bot.right(' ' * (pad - bot.width())))

        if self.alpha == 0 and self.gamma == 0:
            args = printer._print(self.beta)

            s = stringPict('d' + ' ' * pad)
        else:
            args = printer._print(self.alpha)
            args = prettyForm(*args.right(','))
            args = prettyForm(*args.right(printer._print(self.beta)))
            args = prettyForm(*args.right(','))
            args = prettyForm(*args.right(printer._print(self.gamma)))

            s = stringPict('D' + ' ' * pad)

        args = prettyForm(*args.parens())
        s = prettyForm(*s.above(top))
        s = prettyForm(*s.below(bot))
        s = prettyForm(*s.right(args))
        return s
示例#4
0
 def _pretty(self, printer, *args):
     pform = printer._print(self.args[0], *args)
     pform = prettyForm(*pform.right((prettyForm(','))))
     pform = prettyForm(*pform.right((printer._print(self.args[1], *args))))
     a = stringPict(u'\u03b4')
     b = pform
     top = stringPict(*b.left(' ' * a.width()))
     bot = stringPict(*a.right(' ' * b.width()))
     return prettyForm(binding=prettyForm.POW, *bot.below(top))
示例#5
0
 def _pretty(self, printer, *args):
     pform = printer._print(self.args[0], *args)
     pform = prettyForm(*pform.right((prettyForm(','))))
     pform = prettyForm(*pform.right((printer._print(self.args[1], *args))))
     a = stringPict(u'\u03b4')
     b = pform
     top = stringPict(*b.left(' '*a.width()))
     bot = stringPict(*a.right(' '*b.width()))
     return prettyForm(binding=prettyForm.POW, *bot.below(top))
示例#6
0
文件: state.py 项目: sidhu1012/sympy
    def _pretty_brackets(self, height, use_unicode=True):
        # Return pretty printed brackets for the state
        # Ideally, this could be done by pform.parens but it does not support the angled < and >

        # Setup for unicode vs ascii
        if use_unicode:
            lbracket, rbracket = getattr(self, 'lbracket_ucode',
                                         ""), getattr(self, 'rbracket_ucode',
                                                      "")
            slash, bslash, vert = '\N{BOX DRAWINGS LIGHT DIAGONAL UPPER RIGHT TO LOWER LEFT}', \
                                  '\N{BOX DRAWINGS LIGHT DIAGONAL UPPER LEFT TO LOWER RIGHT}', \
                                  '\N{BOX DRAWINGS LIGHT VERTICAL}'
        else:
            lbracket, rbracket = getattr(self, 'lbracket',
                                         ""), getattr(self, 'rbracket', "")
            slash, bslash, vert = '/', '\\', '|'

        # If height is 1, just return brackets
        if height == 1:
            return stringPict(lbracket), stringPict(rbracket)
        # Make height even
        height += (height % 2)

        brackets = []
        for bracket in lbracket, rbracket:
            # Create left bracket
            if bracket in {_lbracket, _lbracket_ucode}:
                bracket_args = [
                    ' ' * (height // 2 - i - 1) + slash
                    for i in range(height // 2)
                ]
                bracket_args.extend(
                    [' ' * i + bslash for i in range(height // 2)])
            # Create right bracket
            elif bracket in {_rbracket, _rbracket_ucode}:
                bracket_args = [' ' * i + bslash for i in range(height // 2)]
                bracket_args.extend([
                    ' ' * (height // 2 - i - 1) + slash
                    for i in range(height // 2)
                ])
            # Create straight bracket
            elif bracket in {_straight_bracket, _straight_bracket_ucode}:
                bracket_args = [vert] * height
            else:
                raise ValueError(bracket)
            brackets.append(
                stringPict('\n'.join(bracket_args), baseline=height // 2))
        return brackets
示例#7
0
    def _print_Sequence(self, seq):
        from sympy.printing.pretty.stringpict import prettyForm, stringPict

        pforms = []
        if seq.start_trunc:
            pforms.append('...')

        for item, n1 in zip(seq.vals, seq.n):
            if pforms:
                pforms.append(', ')
            if n1 == 0:
                pforms.append('_')
            pform = self._print(item)
            pforms.append(pform)

        if seq.end_trunc:
            if pforms:
                pforms.append(', ')
            pforms.append('...')

        if not pforms:
            s = stringPict('')
        else:
            s = prettyForm(*stringPict.next(*pforms))

        s = prettyForm(*s.parens('{', '}', ifascii_nougly=True))
        return s
示例#8
0
    def _pretty_brackets(self, height, use_unicode=True):
        # Return pretty printed brackets for the state
        # Ideally, this could be done by pform.parens but it does not support the angled < and >

        # Setup for unicode vs ascii
        if use_unicode:
            lbracket, rbracket = self.lbracket_ucode, self.rbracket_ucode
            slash, bslash, vert = (
                u"\N{BOX DRAWINGS LIGHT DIAGONAL UPPER RIGHT TO LOWER LEFT}",
                u"\N{BOX DRAWINGS LIGHT DIAGONAL UPPER LEFT TO LOWER RIGHT}",
                u"\N{BOX DRAWINGS LIGHT VERTICAL}",
            )
        else:
            lbracket, rbracket = self.lbracket, self.rbracket
            slash, bslash, vert = "/", "\\", "|"

        # If height is 1, just return brackets
        if height == 1:
            return stringPict(lbracket), stringPict(rbracket)
        # Make height even
        height += height % 2

        brackets = []
        for bracket in lbracket, rbracket:
            # Create left bracket
            if bracket in {_lbracket, _lbracket_ucode}:
                bracket_args = [
                    " " * (height // 2 - i - 1) + slash
                    for i in range(height // 2)
                ]
                bracket_args.extend(
                    [" " * i + bslash for i in range(height // 2)])
            # Create right bracket
            elif bracket in {_rbracket, _rbracket_ucode}:
                bracket_args = [" " * i + bslash for i in range(height // 2)]
                bracket_args.extend([
                    " " * (height // 2 - i - 1) + slash
                    for i in range(height // 2)
                ])
            # Create straight bracket
            elif bracket in {_straight_bracket, _straight_bracket_ucode}:
                bracket_args = [vert for i in range(height)]
            else:
                raise ValueError(bracket)
            brackets.append(
                stringPict("\n".join(bracket_args), baseline=height // 2))
        return brackets
示例#9
0
def test_printing():
    for c in (LatexPrinter, LatexPrinter(), MathMLPrinter,
              PrettyPrinter, prettyForm, stringPict, stringPict("a"), Printer,
              Printer(), PythonPrinter, PythonPrinter()):
        #FIXME-py3k: sympy/printing/printer.py", line 220, in order
        #FIXME-py3k: return self._settings['order']
        #FIXME-py3k: KeyError: 'order'
        check(c)
示例#10
0
 def _pretty(self, printer, *args):
     controls = self._print_sequence_pretty(self.controls, ",", printer, *args)
     gate = printer._print(self.gate)
     gate_name = stringPict(unicode(self.gate_name))
     first = self._print_subscript_pretty(gate_name, controls)
     gate = self._print_parens_pretty(gate)
     final = prettyForm(*first.right((gate)))
     return final
示例#11
0
文件: gate.py 项目: yangle/sympy
 def _pretty(self, printer, *args):
     controls = self._print_sequence_pretty(self.controls, ',', printer, *args)
     gate = printer._print(self.gate)
     gate_name = stringPict(unicode(self.gate_name))
     first = self._print_subscript_pretty(gate_name, controls)
     gate = self._print_parens_pretty(gate)
     final = prettyForm(*first.right((gate)))
     return final
示例#12
0
def test_printing():
    for c in (LatexPrinter, LatexPrinter(), MathMLPrinter,
              PrettyPrinter, prettyForm, stringPict, stringPict("a"),
              Printer, Printer(), PythonPrinter, PythonPrinter()):
        #FIXME-py3k: sympy/printing/printer.py", line 220, in order
        #FIXME-py3k: return self._settings['order']
        #FIXME-py3k: KeyError: 'order'
        check(c)
示例#13
0
def test_printing():
    for c in (
        LatexPrinter,
        LatexPrinter(),
        MathMLPrinter,
        PrettyPrinter,
        prettyForm,
        stringPict,
        stringPict("a"),
        Printer,
        Printer(),
        PythonPrinter,
        PythonPrinter(),
    ):
        check(c)
示例#14
0
文件: cg.py 项目: BDGLunde/sympy
    def _pretty(self, printer, *args):
        bot = printer._print_seq((self.j1, self.m1, self.j2, self.m2), delimiter=',')
        top = printer._print_seq((self.j3, self.m3), delimiter=',')

        pad = max(top.width(), bot.width())
        bot = prettyForm(*bot.left(' '))
        top = prettyForm(*top.left(' '))

        if not pad == bot.width():
            bot = prettyForm(*bot.right(' ' * (pad-bot.width())))
        if not pad == top.width():
            top = prettyForm(*top.right(' ' * (pad-top.width())))
        s = stringPict('C' + ' '*pad)
        s = prettyForm(*s.below(bot))
        s = prettyForm(*s.above(top))
        return s
示例#15
0
def test_printing():
    for c in (
            LatexPrinter,
            LatexPrinter(),
            MathMLContentPrinter,
            MathMLPresentationPrinter,
            PrettyPrinter,
            prettyForm,
            stringPict,
            stringPict("a"),
            Printer,
            Printer(),
            PythonPrinter,
            PythonPrinter(),
    ):
        check(c)
示例#16
0
文件: cg.py 项目: nvlrules/sympy
    def _pretty(self, printer, *args):
        bot = printer._print(self.j1)
        bot = prettyForm(*bot.right(","))
        bot = prettyForm(*bot.right(printer._print(self.m1)))
        bot = prettyForm(*bot.right(","))
        bot = prettyForm(*bot.right(printer._print(self.j2)))
        bot = prettyForm(*bot.right(","))
        bot = prettyForm(*bot.right(printer._print(self.m2)))
        top = printer._print(self.j3)
        top = prettyForm(*top.right(","))
        top = prettyForm(*top.right(printer._print(self.m3)))

        pad = max(top.width(), bot.width())

        bot = prettyForm(*bot.left(" "))
        top = prettyForm(*top.left(" "))
        if not pad == bot.width():
            bot = prettyForm(*bot.right(" " * (pad - bot.width())))
        if not pad == top.width():
            top = prettyForm(*top.right(" " * (pad - top.width())))
        s = stringPict("C" + " " * pad)
        s = prettyForm(*s.below(bot))
        s = prettyForm(*s.above(top))
        return s
示例#17
0
 def _pretty(self, printer, *args):
     targets = self._print_sequence_pretty(self.targets, ",", printer, *args)
     gate_name = stringPict(unicode(self.gate_name))
     return self._print_subscript_pretty(gate_name, targets)
示例#18
0
 def _print_contents_pretty(self, printer, *args):
     a = stringPict(unicode(self.name))
     b = stringPict(self._coord)
     return self._print_subscript_pretty(a, b)
示例#19
0
 def _pretty(self, printer, *args):
     a = stringPict('J')
     b = stringPict('2')
     top = stringPict(*b.left(' ' * a.width()))
     bot = stringPict(*a.right(' ' * b.width()))
     return prettyForm(binding=prettyForm.POW, *bot.above(top))
示例#20
0
文件: gate.py 项目: yangle/sympy
 def _pretty(self, printer, *args):
     targets = self._print_sequence_pretty(self.targets, ',', printer, *args)
     gate_name = stringPict(unicode(self.gate_name))
     return self._print_subscript_pretty(gate_name, targets)
示例#21
0
 def _pretty(self, printer, *args):
     a = stringPict(unicode(self.gate_name))
     b = self._print_label_pretty(printer, *args)
     return self._print_subscript_pretty(a, b)
示例#22
0
文件: gate.py 项目: yangle/sympy
 def _pretty(self, printer, *args):
     a = stringPict(unicode(self.gate_name))
     b = self._print_label_pretty(printer, *args)
     return self._print_subscript_pretty(a, b)
示例#23
0
文件: spin.py 项目: hitej/meta-core
 def _pretty(self, printer, *args):
     a = stringPict("J")
     b = stringPict("2")
     top = stringPict(*b.left(" " * a.width()))
     bot = stringPict(*a.right(" " * b.width()))
     return prettyForm(binding=prettyForm.POW, *bot.above(top))
示例#24
0
文件: spin.py 项目: hitej/meta-core
 def _print_contents_pretty(self, printer, *args):
     a = stringPict(unicode(self.name))
     b = stringPict(self._coord)
     return self._print_subscript_pretty(a, b)