Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

Comments

@FreddyBaudine
Copy link

@FreddyBaudine 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

This comment has been minimized.

Copy link
Member

@utensil utensil commented Feb 26, 2019

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

Sent with GitHawk

@utensil

This comment has been minimized.

Copy link
Member

@utensil utensil commented Feb 27, 2019

@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

This comment has been minimized.

Copy link
Member

@utensil utensil commented Feb 27, 2019

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.
<recently read> \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.

utensil added a commit that referenced this issue Feb 27, 2019
@FreddyBaudine

This comment has been minimized.

Copy link
Author

@FreddyBaudine 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

2.7.zip
3.4.zip

@FreddyBaudine

This comment has been minimized.

Copy link
Author

@FreddyBaudine FreddyBaudine commented Feb 27, 2019

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

@FreddyBaudine

This comment has been minimized.

Copy link
Author

@FreddyBaudine 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

This comment has been minimized.

Copy link
Member

@utensil utensil commented Feb 27, 2019

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.

utensil added a commit that referenced this issue Feb 28, 2019
Will rework the git history and send PR later.
@utensil

This comment has been minimized.

Copy link
Member

@utensil utensil commented Feb 28, 2019

@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

utensil added a commit that referenced this issue Mar 1, 2019
utensil added a commit that referenced this issue Mar 1, 2019
utensil added a commit that referenced this issue Mar 1, 2019
utensil added a commit that referenced this issue Mar 1, 2019
@utensil utensil mentioned this issue Mar 1, 2019
19 of 19 tasks complete
@FreddyBaudine

This comment has been minimized.

Copy link
Author

@FreddyBaudine 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

This comment has been minimized.

Copy link
Member

@utensil 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.

@utensil

This comment has been minimized.

Copy link
Member

@utensil utensil commented Mar 4, 2019

  • 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

This comment has been minimized.

Copy link
Author

@FreddyBaudine FreddyBaudine commented Mar 4, 2019

Dear Utensil,

The version of ‘brombo/Galgebra’ I am using was downloaded from
https://github.com/brombo/galgebra back in mid 2016. Please see below for today's version is not quite OK.

For the installation, I followed the book Galgebra: a Geometric Algebra Module for Sympy (April 13, 2016), Section 1.3. This means that I made use of the file setgapth.py to get the Ga.pth file properly located, see below.

In particular, Galgebra was not installed in the Python subfolder Lib\site-packages as suggested by Prof Alan Macdonald in his GAlgebra Primer (April 27, 2016), Section 1.

I quickly add that quite a few versions were released in the meantime but they were not that stable. For instance, they failed when I tried to run the little code (on submanifolds) enclosed in the zip file.
As a case in point, even today’s version located in https://github.com/brombo/galgebra does not allow me to run the little code in question!

For your edification, when I run my little code with today’s version of brombo/galgebra downloaded from https://github.com/brombo/galgebra a few minutes ago, here is the error I get

C:\Users\Freddy\Desktop\Issue15Tosh\running27>C:\Anaconda2\python "submanifoldsLatex.py"
Traceback (most recent call last):
File "submanifoldsLatex.py", line 16, in
sph2d = sp3d.sm( sph_map , sph_uv ,norm = True)
File "C:\Users\Freddy\Desktop\CliffordAlgebraPython\galgebra-master\galgebra\ga.py", line 527, in sm
SM = Sm(*kargs, **kwargs)
File "C:\Users\Freddy\Desktop\CliffordAlgebraPython\galgebra-master\galgebra\ga.py", line 1818, in init
self.wedge_print = kwargs['wedge']
KeyError: 'wedge'

C:\Users\Freddy\Desktop\Issue15Tosh\running27>pause
Press any key to continue . . .

Because of that I grew disappointed and I decided to stick to the mid 2016 version.

My interest in Alan Bromborsky’s great work was revived when I heard about pygae version running on Python 3, which I installed via the command 'pip install galgebra'.

Details of my Python 2.7 implementation.
galgebra is located in
C:\Users\Freddy\Desktop\CliffordAlgebraPython\galgebra-master
python.exe is part of the Anaconda installation and is located in
C:\Anaconda2
The file Ga.pth generated through the procedure described in Galgebra book Section 1.3 is located in
C:\Anaconda2

Anaconda2 installer: Anaconda2-4.0.0-Windows-x86.exe (March 29, 2016)

As for Sympy it was part of Anaconda. As far as I can remember, I did not do anything about this. As a specialist you may be able to deduce Sympy’s version from the above installer.

For your convenience, I have enclosed the galgebra folder I am using (with Python 2.7) in the zip file as well as the Ga.pth file.

running27.zip

Kind regards,
Freddy

GitHub
Contribute to brombo/galgebra development by creating an account on GitHub.
@FreddyBaudine

This comment has been minimized.

Copy link
Author

@FreddyBaudine FreddyBaudine commented Mar 5, 2019

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

This comment has been minimized.

Copy link
Author

@FreddyBaudine FreddyBaudine commented Mar 5, 2019

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

This comment has been minimized.

Copy link
Member

@utensil 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.

utensil added a commit that referenced this issue Mar 16, 2019
utensil added a commit that referenced this issue Mar 16, 2019
@utensil

This comment has been minimized.

Copy link
Member

@utensil utensil commented Mar 16, 2019

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.
<recently read> \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))

the history traces back to https://github.com/sympy/sympy/blame/4cd9dc4d57a0a2522d9f413e119b5e8718aef1ec/sympy/galgebra/printing.py#L407 .

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

This comment has been minimized.

Copy link
Member

@utensil 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++).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.