Repository: sympy/sympy
Pull request: Pretty printing bug fix
<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->

#### References to other Issues or PRs
<!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
format, e.g. "Fixes #1234" (see
https://tinyurl.com/auto-closing for more information). Also, please
write a comment on that issue linking back to this pull request once it is
open. -->
Fixes #17616 
Closes https://github.com/sympy/sympy/pull/17620
Closes https://github.com/sympy/sympy/pull/17628

#### Brief description of what is fixed or changed
Earlier, 
```
>>> pprint(pi**(1/exp(1)))
-1___
╲╱ π 
```
Now,
```
>>> pprint(pi**(1/exp(1)))
 ⎛ -1⎞
 ⎝ℯ  ⎠
π     
```

#### Release Notes

<!-- Write the release notes for this release below. See
https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more information
on how to write release notes. The bot will check your release notes
automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->
* printing
    * irrational powers are no longer printed with square root sign, they are printed as fractional powers
<!-- END RELEASE NOTES -->

Problem statement:
inaccurate rendering of pi**(1/E)
This claims to be version 1.5.dev; I just merged from the project master, so I hope this is current.  I didn't notice this bug among others in printing.pretty.

```
In [52]: pi**(1/E)                                                               
Out[52]: 
-1___
╲╱ π 

```
LaTeX and str not fooled:
```
In [53]: print(latex(pi**(1/E)))                                                 
\pi^{e^{-1}}

In [54]: str(pi**(1/E))                                                          
Out[54]: 'pi**exp(-1)'
```

Hints from issue discussion:
I can confirm this bug on master. Looks like it's been there a while
https://github.com/sympy/sympy/blob/2d700c4b3c0871a26741456787b0555eed9d5546/sympy/printing/pretty/pretty.py#L1814

`1/E` is `exp(-1)` which has totally different arg structure than something like `1/pi`:

```
>>> (1/E).args
(-1,)
>>> (1/pi).args
(pi, -1)
```
@ethankward nice!  Also, the use of `str` there isn't correct:
```
>>> pprint(7**(1/(pi)))                                                                                                                                                          
pi___
╲╱ 7 

>>> pprint(pi**(1/(pi)))                                                                                                                                                        
pi___
╲╱ π 

>>> pprint(pi**(1/(EulerGamma)))                                                                                                                                                
EulerGamma___
        ╲╱ π 
```
(`pi` and `EulerGamma` were not pretty printed)
I guess str is used because it's hard to put 2-D stuff in the corner of the radical like that. But I think it would be better to recursively call the pretty printer, and if it is multiline, or maybe even if it is a more complicated expression than just a single number or symbol name, then print it without the radical like

```
  1
  ─
  e
π
```

or

```
 ⎛ -1⎞
 ⎝e  ⎠
π
For this https://github.com/sympy/sympy/blob/eb926a1d0c1158bf43f01eaf673dc84416b5ebb1/sympy/printing/pretty/tests/test_pretty.py#L5945
I think it should also be changed to 
```
 1
 --
 pi
x 
```

Commit message: Removed use of assumptions in pretty printing

Patch to review:
diff --git a/sympy/printing/pretty/pretty.py b/sympy/printing/pretty/pretty.py
index df7452ee873f..b0b297d93103 100644
--- a/sympy/printing/pretty/pretty.py
+++ b/sympy/printing/pretty/pretty.py
@@ -1902,7 +1902,7 @@ def _print_Mul(self, product):
             return prettyForm.__mul__(*a)/prettyForm.__mul__(*b)
 
     # A helper function for _print_Pow to print x**(1/n)
-    def _print_nth_root(self, base, expt):
+    def _print_nth_root(self, base, expt, den_p):
         bpretty = self._print(base)
 
         # In very simple cases, use a single-char root sign
@@ -1916,12 +1916,15 @@ def _print_nth_root(self, base, expt):
         _zZ = xobj('/', 1)
         rootsign = xobj('\\', 1) + _zZ
         # Make exponent number to put above it
+        #print(dir(expt))
         if isinstance(expt, Rational):
             exp = str(expt.q)
             if exp == '2':
                 exp = ''
         else:
-            exp = str(expt.args[0])
+            if den_p.height() > 1 or den_p.width() > 1:
+                return self._print(base)**self._print(expt)
+            exp = str(den_p)
         exp = exp.ljust(2)
         if len(exp) > 2:
             rootsign = ' '*(len(exp) - 2) + rootsign
@@ -1954,8 +1957,10 @@ def _print_Pow(self, power):
             if e is S.NegativeOne:
                 return prettyForm("1")/self._print(b)
             n, d = fraction(e)
-            if n is S.One and d.is_Atom and not e.is_Integer and self._settings['root_notation']:
-                return self._print_nth_root(b, e)
+            if n is S.One and d.is_Atom and not e.is_Integer and (e.is_Rational or d.is_Symbol)\
+                    and self._settings['root_notation']:
+                den_p = self._print(d)
+                return self._print_nth_root(b, e, den_p)
             if e.is_Rational and e < 0:
                 return prettyForm("1")/self._print(Pow(b, -e, evaluate=False))
 
diff --git a/sympy/printing/pretty/tests/test_pretty.py b/sympy/printing/pretty/tests/test_pretty.py
index d33795d155cf..3f0ec100d7c8 100644
--- a/sympy/printing/pretty/tests/test_pretty.py
+++ b/sympy/printing/pretty/tests/test_pretty.py
@@ -5942,7 +5942,11 @@ def test_PrettyPoly():
 
 def test_issue_6285():
     assert pretty(Pow(2, -5, evaluate=False)) == '1 \n--\n 5\n2 '
-    assert pretty(Pow(x, (1/pi))) == 'pi___\n\\/ x '
+    assert pretty(Pow(x, (1/pi))) == \
+    ' 1 \n'\
+    ' --\n'\
+    ' pi\n'\
+    'x  '
 
 
 def test_issue_6359():
@@ -7250,3 +7254,51 @@ def test_diffgeom():
     assert pretty(rect) == "rect"
     b = BaseScalarField(rect, 0)
     assert pretty(b) == "x"
+
+def test_issue_17616():
+    assert pretty(pi**(1/exp(1))) == \
+   '  / -1\\\n'\
+   '  \e  /\n'\
+   'pi     '
+
+    assert upretty(pi**(1/exp(1))) == \
+   ' ⎛ -1⎞\n'\
+   ' ⎝ℯ  ⎠\n'\
+   'π     '
+
+    assert pretty(pi**(1/pi)) == \
+    '  1 \n'\
+    '  --\n'\
+    '  pi\n'\
+    'pi  '
+
+    assert upretty(pi**(1/pi)) == \
+    ' 1\n'\
+    ' ─\n'\
+    ' π\n'\
+    'π '
+
+    assert pretty(pi**(1/EulerGamma)) == \
+    '      1     \n'\
+    '  ----------\n'\
+    '  EulerGamma\n'\
+    'pi          '
+
+    assert upretty(pi**(1/EulerGamma)) == \
+    ' 1\n'\
+    ' ─\n'\
+    ' γ\n'\
+    'π '
+
+    z = Symbol("x_17")
+    assert upretty(7**(1/z)) == \
+    '  1 \n'\
+    ' ───\n'\
+    ' x₁₇\n'\
+    '7   '
+
+    assert pretty(7**(1/z)) == \
+    '  1  \n'\
+    ' ----\n'\
+    ' x_17\n'\
+    '7    '


Code review comments:
diff_hunk: @@ -1916,12 +1916,15 @@ def _print_nth_root(self, base, expt):
         _zZ = xobj('/', 1)
         rootsign = xobj('\\', 1) + _zZ
         # Make exponent number to put above it
+        #print(dir(expt))
path: sympy/printing/pretty/pretty.py
text: @user1:
This change should not be here