Пример #1
0
    def _print_Pow(self, power):
        if isinstance(power.exp, Basic.Half):
            # If it's a square root
            bpretty = self._print(power.base)
            H = bpretty.height()

            _zZ= xobj('/',1)
            s2 = stringPict(xobj('\\',1)+_zZ+' '*(H-1))
            for x in xrange(1, H):
                s3 = stringPict(' '*(x+1) + _zZ + ' '*(H-(x+1)))
                s2 = stringPict(*s2.above(s3))

            s2.baseline = bpretty.baseline  # vertical: each-to-each

            s = prettyForm(hobj('_', 2+ bpretty.width()))
            s = prettyForm(*bpretty.above(s))
            s = prettyForm(*s.left(s2))
            return s
        elif power.exp == -1:
            # Things like 1/x
            return prettyForm("1") / self._print(power.base)

        # None of the above special forms, do a standard power
        b,e = power.as_base_exp()
        return self._print(b)**self._print(e)
Пример #2
0
    def _print_nth_root(self, base, expt):
        bpretty = self._print(base)

        # Construct root sign, start with the \/ shape
        _zZ = xobj('/', 1)
        rootsign = xobj('\\', 1) + _zZ
        # Make exponent number to put above it
        if isinstance(expt, C.Rational):
            exp = str(expt.q)
            if exp == '2':
                exp = ''
        else:
            exp = str(expt.args[0])
        exp = exp.ljust(2)
        if len(exp) > 2:
            rootsign = ' ' * (len(exp) - 2) + rootsign
        # Stack the exponent
        rootsign = stringPict(exp + '\n' + rootsign)
        rootsign.baseline = 0
        # Diagonal: length is one less than height of base
        linelength = bpretty.height() - 1
        diagonal = stringPict('\n'.join(' ' * (linelength - i - 1) + _zZ +
                                        ' ' * i for i in range(linelength)))
        # Put baseline just below lowest line: next to exp
        diagonal.baseline = linelength - 1
        # Make the root symbol
        rootsign = prettyForm(*rootsign.right(diagonal))
        # Det the baseline to match contents to fix the height
        # but if the height of bpretty is one, the rootsign must be one higher
        rootsign.baseline = max(1, bpretty.baseline)
        #build result
        s = prettyForm(hobj('_', 2 + bpretty.width()))
        s = prettyForm(*bpretty.above(s))
        s = prettyForm(*s.left(rootsign))
        return s
Пример #3
0
    def _print_Product(self, expr):
        func = expr.term
        pretty_func = self._print(func)

        horizontal_chr = xobj('_', 1)
        corner_chr = xobj('_', 1)
        vertical_chr = xobj('|', 1)

        if self._use_unicode:
            # use unicode corners
            horizontal_chr = xobj('-', 1)
            corner_chr = u'\u252c'

        func_height = pretty_func.height()

        first = True
        max_upper = 0
        sign_height = 0

        for lim in expr.limits:
            width = (func_height + 2) * 5 // 3 - 2
            sign_lines = []
            sign_lines.append(corner_chr + (horizontal_chr * width) +
                              corner_chr)
            for i in range(func_height + 1):
                sign_lines.append(vertical_chr + (' ' * width) + vertical_chr)

            pretty_sign = stringPict('')
            pretty_sign = prettyForm(*pretty_sign.stack(*sign_lines))

            pretty_upper = self._print(lim[2])
            pretty_lower = self._print(C.Equality(lim[0], lim[1]))

            max_upper = max(max_upper, pretty_upper.height())

            if first:
                sign_height = pretty_sign.height()

            pretty_sign = prettyForm(*pretty_sign.above(pretty_upper))
            pretty_sign = prettyForm(*pretty_sign.below(pretty_lower))

            if first:
                pretty_func.baseline = 0
                first = False

            height = pretty_sign.height()
            padding = stringPict('')
            padding = prettyForm(*padding.stack(*[' '] * (height - 1)))
            pretty_sign = prettyForm(*pretty_sign.right(padding))

            pretty_func = prettyForm(*pretty_sign.right(pretty_func))

        #pretty_func.baseline = 0

        pretty_func.baseline = max_upper + sign_height // 2
        return pretty_func
Пример #4
0
    def _print_Product(self, expr):
        func = expr.term
        pretty_func = self._print(func)

        horizontal_chr = xobj('_', 1)
        corner_chr = xobj('_', 1)
        vertical_chr = xobj('|', 1)

        if self._use_unicode:
            # use unicode corners
            horizontal_chr = xobj('-', 1)
            corner_chr = u'\u252c'

        func_height = pretty_func.height()

        first = True
        max_upper = 0
        sign_height = 0

        for lim in expr.limits:
            width = (func_height + 2) * 5 // 3 - 2
            sign_lines = []
            sign_lines.append(corner_chr+(horizontal_chr*width)+corner_chr)
            for i in range(func_height+1):
                sign_lines.append(vertical_chr+(' '*width)+vertical_chr)

            pretty_sign = stringPict('')
            pretty_sign = prettyForm(*pretty_sign.stack(*sign_lines))

            pretty_upper = self._print(lim[2])
            pretty_lower = self._print(C.Equality(lim[0], lim[1]))

            max_upper = max(max_upper, pretty_upper.height())

            if first:
                sign_height = pretty_sign.height()

            pretty_sign = prettyForm(*pretty_sign.above(pretty_upper))
            pretty_sign = prettyForm(*pretty_sign.below(pretty_lower))

            if first:
                pretty_func.baseline = 0
                first = False

            height = pretty_sign.height()
            padding = stringPict('')
            padding = prettyForm(*padding.stack(*[' ']*(height-1)))
            pretty_sign = prettyForm(*pretty_sign.right(padding))

            pretty_func = prettyForm(*pretty_sign.right(pretty_func))

        #pretty_func.baseline = 0

        pretty_func.baseline = max_upper + sign_height//2
        return pretty_func
Пример #5
0
    def _print_Pow(self, power):
        # square roots, other roots or n-th roots
        # test for fraction 1/n or power x**-1
        if power.is_commutative:
            if (isinstance(power.exp, C.Rational) and power.exp.p == 1 and power.exp.q != 1) or (
                isinstance(power.exp, C.Pow)
                and isinstance(power.exp.args[0], C.Symbol)
                and power.exp.args[1] == S.NegativeOne
            ):
                bpretty = self._print(power.base)

                # construct root sign, start with the \/ shape
                _zZ = xobj("/", 1)
                rootsign = xobj("\\", 1) + _zZ
                # make exponent number to put above it
                if isinstance(power.exp, C.Rational):
                    exp = str(power.exp.q)
                    if exp == "2":
                        exp = ""
                else:
                    exp = str(power.exp.args[0])
                exp = exp.ljust(2)
                if len(exp) > 2:
                    rootsign = " " * (len(exp) - 2) + rootsign
                # stack the exponent
                rootsign = stringPict(exp + "\n" + rootsign)
                rootsign.baseline = 0
                # diagonal: length is one less than height of base
                linelength = bpretty.height() - 1
                diagonal = stringPict("\n".join(" " * (linelength - i - 1) + _zZ + " " * i for i in range(linelength)))
                # put baseline just below lowest line: next to exp
                diagonal.baseline = linelength - 1
                # make the root symbol
                rootsign = prettyForm(*rootsign.right(diagonal))
                # set the baseline to match contents to fix the height
                # but if the height of bpretty is one, the rootsign must be one higher
                rootsign.baseline = max(1, bpretty.baseline)
                # build result
                s = prettyForm(hobj("_", 2 + bpretty.width()))
                s = prettyForm(*bpretty.above(s))
                s = prettyForm(*s.left(rootsign))
                return s
            elif power.exp.is_Rational and power.exp.is_negative:
                # Things like 1/x
                return prettyForm("1") / self._print(C.Pow(power.base, -power.exp))

        # None of the above special forms, do a standard power
        b, e = power.as_base_exp()
        return self._print(b) ** self._print(e)
Пример #6
0
    def _print_Pow(self, power):
        # square roots, other roots or n-th roots
        #test for fraction 1/n or power x**-1
        if power.is_commutative:
            if (isinstance(power.exp, C.Rational) and power.exp.p==1 and power.exp.q !=1) or \
               (   isinstance(power.exp, C.Pow) and
                   isinstance(power.exp.args[0], C.Symbol) and
                   power.exp.args[1]==S.NegativeOne):
                bpretty = self._print(power.base)

                #construct root sign, start with the \/ shape
                _zZ = xobj('/', 1)
                rootsign = xobj('\\', 1) + _zZ
                #make exponent number to put above it
                if isinstance(power.exp, C.Rational):
                    exp = str(power.exp.q)
                    if exp == '2': exp = ''
                else: exp = str(power.exp.args[0])
                exp = exp.ljust(2)
                if len(exp) > 2: rootsign = ' ' * (len(exp) - 2) + rootsign
                #stack the exponent
                rootsign = stringPict(exp + '\n' + rootsign)
                rootsign.baseline = 0
                #diagonal: length is one less than height of base
                linelength = bpretty.height() - 1
                diagonal = stringPict('\n'.join(' ' * (linelength - i - 1) +
                                                _zZ + ' ' * i
                                                for i in range(linelength)))
                #put baseline just below lowest line: next to exp
                diagonal.baseline = linelength - 1
                #make the root symbol
                rootsign = prettyForm(*rootsign.right(diagonal))
                #set the baseline to match contents to fix the height
                #but if the height of bpretty is one, the rootsign must be one higher
                rootsign.baseline = max(1, bpretty.baseline)
                #build result
                s = prettyForm(hobj('_', 2 + bpretty.width()))
                s = prettyForm(*bpretty.above(s))
                s = prettyForm(*s.left(rootsign))
                return s
            elif power.exp.is_Rational and power.exp.is_negative:
                # Things like 1/x
                return prettyForm("1") / self._print(
                    C.Pow(power.base, -power.exp))

        # None of the above special forms, do a standard power
        b, e = power.as_base_exp()
        return self._print(b)**self._print(e)
Пример #7
0
 def leftslash(self):
     """Precede object by a slash of the proper size.
     """
     # XXX not used anywhere ?
     height = max(self.baseline, self.height() - 1 - self.baseline) * 2 + 1
     slash = "\n".join(" " * (height - i - 1) + xobj("/", 1) + " " * i for i in range(height))
     return self.left(stringPict(slash, height // 2))
Пример #8
0
 def leftslash(self):
     """Precede object by a slash of the proper size.
     """
     # XXX not used anywhere ?
     height = max(self.baseline, self.height() - 1 - self.baseline) * 2 + 1
     slash = '\n'.join(' ' * (height - i - 1) + xobj('/', 1) + ' ' * i
                       for i in range(height))
     return self.left(stringPict(slash, height // 2))
Пример #9
0
    def _print_Product(self, expr):
        func = expr.term
        pretty_func = self._print(func)

        horizontal_chr = xobj('_', 1)
        corner_chr = xobj('_', 1)
        vertical_chr = xobj('|', 1)

        if self._use_unicode:
            # use unicode corners
            horizontal_chr = xobj('-', 1)
            corner_chr = u'\u252c'

        func_height = pretty_func.height()

        width = (func_height + 2) * 5 // 3 - 2
        sign_lines = []
        sign_lines.append(corner_chr + (horizontal_chr * width) + corner_chr)
        for i in range(func_height + 1):
            sign_lines.append(vertical_chr + (' ' * width) + vertical_chr)

        pretty_sign = stringPict('')
        pretty_sign = prettyForm(*pretty_sign.stack(*sign_lines))

        pretty_upper = self._print(expr.upper)
        pretty_lower = self._print(C.Equality(expr.index, expr.lower))

        pretty_sign = prettyForm(*pretty_sign.above(pretty_upper))
        pretty_sign = prettyForm(*pretty_sign.below(pretty_lower))

        height = pretty_sign.height()
        padding = stringPict('')
        padding = prettyForm(*padding.stack(*[' '] * (height - 1)))
        pretty_sign = prettyForm(*pretty_sign.right(padding))

        pretty_func.baseline = 0

        pretty_func = prettyForm(*pretty_sign.right(pretty_func))
        return pretty_func
Пример #10
0
    def _print_Product(self, expr):
        func = expr.term
        pretty_func = self._print(func)

        horizontal_chr = xobj('_', 1)
        corner_chr = xobj('_', 1)
        vertical_chr = xobj('|', 1)

        if self._use_unicode:
            # use unicode corners
            horizontal_chr = xobj('-', 1)
            corner_chr = u'\u252c'

        func_height = pretty_func.height()

        width = (func_height + 2) * 5 // 3 - 2
        sign_lines = []
        sign_lines.append(corner_chr+(horizontal_chr*width)+corner_chr)
        for i in range(func_height+1):
            sign_lines.append(vertical_chr+(' '*width)+vertical_chr)

        pretty_sign = stringPict('')
        pretty_sign = prettyForm(*pretty_sign.stack(*sign_lines))

        pretty_upper = self._print(expr.upper)
        pretty_lower = self._print(C.Equality(expr.index, expr.lower))

        pretty_sign = prettyForm(*pretty_sign.above(pretty_upper))
        pretty_sign = prettyForm(*pretty_sign.below(pretty_lower))

        height = pretty_sign.height()
        padding = stringPict('')
        padding = prettyForm(*padding.stack(*[' ']*(height-1)))
        pretty_sign = prettyForm(*pretty_sign.right(padding))

        pretty_func.baseline = 0

        pretty_func = prettyForm(*pretty_sign.right(pretty_func))
        return pretty_func
Пример #11
0
    def _print_nth_root (self, base, expt):
        bpretty = self._print(base)

        # Construct root sign, start with the \/ shape
        _zZ = xobj('/',1)
        rootsign = xobj('\\',1) + _zZ
        # Make exponent number to put above it
        if isinstance(expt, C.Rational):
            exp = str(expt.q)
            if exp == '2':
                exp = ''
        else:
            exp = str(expt.args[0])
        exp = exp.ljust(2)
        if len(exp) > 2:
            rootsign = ' '*(len(exp) - 2) + rootsign
        # Stack the exponent
        rootsign = stringPict(exp + '\n' + rootsign)
        rootsign.baseline = 0
        # Diagonal: length is one less than height of base
        linelength = bpretty.height() - 1
        diagonal = stringPict('\n'.join(
            ' '*(linelength - i - 1) + _zZ + ' '*i
            for i in range(linelength)
            ))
        # Put baseline just below lowest line: next to exp
        diagonal.baseline = linelength - 1
        # Make the root symbol
        rootsign = prettyForm(*rootsign.right(diagonal))
        # Det the baseline to match contents to fix the height
        # but if the height of bpretty is one, the rootsign must be one higher
        rootsign.baseline = max(1, bpretty.baseline)
        #build result
        s = prettyForm(hobj('_', 2 + bpretty.width()))
        s = prettyForm(*bpretty.above(s))
        s = prettyForm(*s.left(rootsign))
        return s