# Galgebra not able to print some products and inverses of multivectors #15

Closed
opened this issue Feb 26, 2019 · 17 comments · Fixed by #17
Labels
Milestone

### FreddyBaudine commented Feb 26, 2019

 Dear all, Galgebra does not seem to be able to print out quantities such as the following: Products (inner, left contraction, right contraction or geometric) of a (multi)vector with itself, e.g., a * a. It should be noted that the product of a vector with a different one is OK, e.g., a * b is printed out correctly. By the same token, no inverse of an invertible multi(vector) is printed out. It looks as if squares of the components of (multi)vectors were the culprits, as these appear in the above calculations. Python (3.4 and 3.7): The computer hangs. Here’s a print screen “ C:\Users\Freddy\Desktop\Python\programs>C:\Python34-37\python "spacetimePython3.py" latex file = spacetimePython3.tex pdflatex path = C:\Program Files\MiKTeX 2.9\miktex\bin\x64\pdflatex.exe “ Here’s the message returned to the console after exiting with a ctrl-C: “ Traceback (most recent call last): File "spacetimePython3.py", line 65, in xpdf(paper=(8,9),crop=True) File "C:\Python34-37\lib\site-packages\galgebra\printer.py", line 1165, in xpdf os.system(latex_str + ' ' + filename[:-4] + sys_cmd['null']) KeyboardInterrupt Terminate batch job (Y/N)? “ I tried IPython (notebook), i.e. Jupyter (with both browsers, viz., Firefox and Chrome). In this case, the unevaluated latex code is returned and the computer does not hang. Is there any workaround available? Kind regards, Freddy Baudine

### utensil commented Feb 26, 2019

 Thanks for reporting this, I'll look into it ASAP. Sent with GitHawk

### utensil commented Feb 27, 2019 • edited

 @FreddyBaudine Would it be convenient for you to attach spacetimePython3.py , spacetimePython3.tex or a minimal version of them to reproduce the problem? Or you could manually run pdflatex spacetimePython3 to inspect the output, because LaTeX is known to stop and wait for user input when it encounter certain errors and galgebra redirected the output to the NUL device so you might miss it. If you solved the problem and proceed, as I recall, you are also likely to encounter the following problems too: prompts !!!!Return to continue!!!! and stop there and fails unless you enter a valid Python expression (e.g. any number like 1) and hit Enter fails if program pdfcrop is missing from the PATH

### utensil commented Feb 27, 2019 • edited

 I have a minimal reproduction at https://github.com/pygae/galgebra/blob/15-self-product/doc/python/Dop.py#L22 (on my MacBookPro so it's not a OS related problem) , the script "hangs" because the following pdflatex error: ! Double superscript. \mathsup l.54 ...{equation*} \bm{A} \cdot \bm{A} = A^{x} ^2 + A^{y} ^2 + A^{z} ^2 \en...  triggered by A = o3d.mv('A', 'vector', f=True) print(r'\bm{A} \cdot \bm{A} =', A | A) Still investigating this case.
added a commit that referenced this issue Feb 27, 2019
 Reproduce #15 
 dfe47b3 

### FreddyBaudine commented Feb 27, 2019

 Dear Utensil, You will find here attached the files you asked for. For your convenience I have enclosed two bunches of files. The first, spacetimePython2.7, running the old version of Galgebra, Python 2.7. No problem here. The second, spacetimePython3, running the pygae version of Galgebra, Python 3.4 (3.7). In the latter case no pdf is generated. On comparing the tex files, you will observe that squares of components of vectors are represented differently. Then, when you run the ‘spacetimePython3. tex’ file, it got stuck precisely when it reaches the corresponding latex code. I don’t know if this is relevant, though. Also, I forgot to tell you that I am on Windows 7. Many thanks for your help. Kind regards, FB

### FreddyBaudine commented Feb 27, 2019

 I am awfully sorry, I closed the issue inadvertently. I trust it is now reopened. Regards, FB

### FreddyBaudine commented Feb 27, 2019

 Dear Utensil, In despair, I reactivated my good old XP computer equipped with an old version of MikTex and tried to run Galgebra new version on the same file, viz., spacetimePython3. In this instance, I had to run MikTex manually. Of course MikTex complained about missing packages which I was refused adamantly to install. None the less I ignored the complaints and issued a bunch of return to eventually reach the result in the zip file enclosed. If you examine the pdf file, you will notice that the formulae obtained are correct but that the squares are not enclosed in parentheses as I suspected initially. Now, this is not quite right as the numbers could be confused with indices. Well, I hope this will help you somehow to sort this issue out. Many thanks again for your help. Kind regards, Freddy Baudine WinXPPython3.4.zip

### utensil commented Feb 27, 2019 • edited

 Thanks for the detailed report. The problem is closely related to the way galgebra handles subscripts and superscripts and the bug seems to be caused by trying to fix some other bugs. Still investigating the ramifications.
added a commit that referenced this issue Feb 28, 2019
 #15 Seems to be fixed now 
 a18cc52 
Will rework the git history and send PR later.

### utensil commented Feb 28, 2019 • edited

 @FreddyBaudine Sorry for the trouble, this bug was introduced by me at d81364b and I have a fix for it at https://github.com/pygae/galgebra/blob/15-self-product/galgebra/printer.py#L682
added a commit that referenced this issue Mar 1, 2019
 Further reproduce #15 
 4916160 
added a commit that referenced this issue Mar 1, 2019
 Fix #15 
 5767e0b 
added a commit that referenced this issue Mar 1, 2019
 Fix #15 
 479b8c8 
added a commit that referenced this issue Mar 1, 2019
 Add and modify tests for #15 
 4f82e01 
mentioned this issue Mar 1, 2019
Merged

### FreddyBaudine commented Mar 1, 2019

 Dear Utensil, I tried your corrected version of printer.py with Python 3.4 and Python 3.7. Everything went smoothly in this case. Then I did the same with Python 2.7 and here I got the following error message at compile time: " C:\Users\Freddy\Desktop\Python\programs>C:\anaconda2\python "spacetimePython2.7.py" Traceback (most recent call last): File "spacetimePython2.7.py", line 20, in print r'\mbox{Python version = }', sys.version TypeError: unicode argument expected, got 'str' " Finally, I tried IPython (notebook), i.e. Jupyter (with both browsers, viz., Firefox and Chrome) making use of Python 2.7, 3.4 and 3.7 without any problem. The latter result tend to show that the “print” instruction is at fault here, please advise. Many thanks again for your help. Kind regards, Freddy Baudine

### utensil commented Mar 2, 2019

 Then I did the same with Python 2.7 and here I got the following error message at compile time: " C:\Users\Freddy\Desktop\Python\programs>C:\anaconda2\python "spacetimePython2.7.py" Traceback (most recent call last): File "spacetimePython2.7.py", line 20, in print r'\mbox{Python version = }', sys.version TypeError: unicode argument expected, got 'str' " This seems to be caused by the usage of StringIO ( by printer.py ) which is only meant for unicode text. Some googling gives the following solution: from io import BytesIO as StringIO # or just replace all the usage to BytesIO  I'll open a issue to track this issue. Some verifications are in order. Thank you for this report.
added the label Mar 2, 2019
This was referenced Mar 2, 2019

### utensil commented Mar 4, 2019 • edited

 The first, spacetimePython2.7, running the old version of Galgebra, Python 2.7. No problem here. Dear @FreddyBaudine, there's one thing I really can't understand, you can run spacetimePython2.7.py using brombo/galgebra and Python 2.7 and having no problem, but I can't get it to work. When it runs to (a*a).Fmt(1,r'\bm{a} \bm{a}'), it always complains something like: /home/gitpod/.pyenv/versions/2.7.15/lib/python2.7/site-packages/sympy-1.3-py2.7.egg/sympy/printing/printer.pyc in _print(self, expr, **kwargs) 285 printmethod = '_print_' + cls.__name__ 286 if hasattr(self, printmethod): --> 287 return getattr(self, printmethod)(expr, **kwargs) 288 # Unknown object, fall back to the emptyPrinter. 289 return self.emptyPrinter(expr) /workspace/galgebra/galgebra/printer.pyc in _print_Pow(self, expr) 674 else: 675 if expr.base.is_Function: --> 676 return self._print(expr.base, self._print(expr.exp)) 677 else: 678 if expr.is_commutative and expr.exp == -1: TypeError: _print() takes exactly 2 arguments (3 given)  Which version of sympy are you using? How did you install galgebra( python setgapth.py )?

### FreddyBaudine commented Mar 5, 2019 • edited by unfurl-links bot

 Dear Utensil, I found a way to determine the Sympy version in my Anaconda 2 through the command 'pip show sympy'. Here's a screenshot of the terminal. " Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Anaconda2>pip show sympy Name: sympy Version: 1.0 Summary: Computer algebra system (CAS) in Python Home-page: http://sympy.org Author: SymPy development team Author-email: sympy@googlegroups.com License: BSD Location: c:\anaconda2\lib\site-packages Requires: You are using pip version 9.0.1, however version 19.0.3 is available. You should consider upgrading via the 'python -m pip install --upgrade pip' command. C:\Anaconda2> " Hope this help. Kind regards, Freddy

### FreddyBaudine commented Mar 5, 2019 • edited by unfurl-links bot

 Dear Utensil, I upgraded my pip version as suggested in the preceding message. As you can read below, Python 2.7 will be over by January 2020! Here's the screenshot: C:\Anaconda2>pip show sympy DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. Name: sympy Version: 1.0 Summary: Computer algebra system (CAS) in Python Home-page: http://sympy.org Author: SymPy development team Author-email: sympy@googlegroups.com License: BSD Location: c:\anaconda2\lib\site-packages Requires: Required-by: galgebra C:\Anaconda2> Kind regards, Freddy

### utensil commented Mar 14, 2019

 As you can read below, Python 2.7 will be over by January 2020! Yes, Python 2.7 will no longer be maintained after that date, but its usage won't vanish for quite a while. I intend to not drop 2.7 support since the support for 3 (by pygae/galgebra) is still young and maintaining 2.7 compatibility is not a burden for now.
added a commit that referenced this issue Mar 16, 2019
 Fix #15 
 cf3fd6d 
added a commit that referenced this issue Mar 16, 2019
 Add and modify tests for #15 
 2518bfd 

### utensil commented Mar 16, 2019 • edited

 The cause of the bug was first described in #17 and moved here: A bug was introduced by me at d81364b which caused failure to render self products and inverses of multivectors, namely, pdflatex complains: ! Double superscript. \mathsup l.54 ...{equation*} \bm{A} \cdot \bm{A} = A^{x} ^2 + A^{y} ^2 + A^{z} ^2 \en...  Although it took me quite some time to recall the place and figure how to fix it, the fix itself is trivial and straightforward. I've also added tests ( reusing the code by @FreddyBaudine, please let me know if it's not OK) and fixed other broken tests ( because they expect exactly same LaTeX outputs which is changed now although visually identical ). The original implementation by @brombe is:  if expr.base.is_Function: return self._print(expr.base, self._print(expr.exp)) It would not work because the following error:  680 else: 681 if expr.base.is_Function: --> 682 return self._print(expr.base, self._print(expr.exp)) 683 else: 684 if expr.is_commutative and expr.exp == -1: TypeError: _print() takes 2 positional arguments but 3 were given  I have no idea why this worked in the past, but the fix was obvious to me except I forgot to consider the base itself might include superscripts too which lead us to the bug and the fix. I still wonder if there's a better fix by utilize something in the base printer class from sympy.

### utensil commented Mar 16, 2019

 @FreddyBaudine What's your email? We would like to invite you to join our Slack workspace so we can discuss GA in a more IM-ish fashion and there're some people working on GA related projects (symbolic, numeric, visualization etc. in Python, Julia and C++).
added and removed labels Mar 16, 2019
added this to the 0.4.4 milestone Apr 3, 2019
closed this in #17 Jul 7, 2019