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

Fix PrintHilbertSeries to also work in Python 2.x #93

Open
fingolfin opened this issue Dec 7, 2019 · 4 comments
Open

Fix PrintHilbertSeries to also work in Python 2.x #93

fingolfin opened this issue Dec 7, 2019 · 4 comments

Comments

@fingolfin
Copy link
Member

It raises an exception right now:

Exception raised:
    Traceback (most recent call last):
      File "/opt/python/2.7.15/lib/python2.7/doctest.py", line 1315, in __run
        compileflags, 1) in test.globs
      File "<doctest rational.txt[6]>", line 1, in <module>
        cone.PrintHilbertSeries()
      File "/home/travis/build/Normaliz/PyNormaliz/PyNormaliz.py", line 242, in PrintHilbertSeries
        print(self.PrintPrettyHilbertSeries(numerator,denominator))
      File "/home/travis/build/Normaliz/PyNormaliz/PyNormaliz.py", line 231, in PrintPrettyHilbertSeries
        num, den = self.PrettyPolynomialTuple(numCoefficients, denCoefficients)
      File "/home/travis/build/Normaliz/PyNormaliz/PyNormaliz.py", line 197, in PrettyPolynomialTuple
        num = getNumerator(numCoefficients)
      File "/home/travis/build/Normaliz/PyNormaliz/PyNormaliz.py", line 186, in getNumerator
        coefficient) else '- ', abs(coefficient), to_sup(exp))
    UnicodeEncodeError: 'ascii' codec can't encode character u'\xb2' in position 0: ordinal not in range(128)
@w-bruns
Copy link
Collaborator

w-bruns commented Dec 11, 2019

I think it is impossible to write the exponent as a superscript in Python2, at least it does not work as in the code.

Way out: make to_up dependent on the Python version (if possible) and use ^x in Python2.

@fingolfin
Copy link
Member Author

I have a hard time believing that it would be impossible to do it in Python 2. It might require different code, and it might be very difficult to impossible to write code which works simultaneously in Python 2 and 3 (at least w/o sacrificing code readability seriously; after all, one could always write out byte arrays with the required byte sequences).

That said, I am also highly sceptical how useful this whole function is overall. It's a nice gimmick, but does it really belong into PyNormaliz? What about users whose terminal is not set to UTF (admittedly, that number might be small today, but I am just guessing here).

@w-bruns
Copy link
Collaborator

w-bruns commented Dec 11, 2019

No doubt, it is kind of a gimmick, but the data in the raw output format are often difficult to read. And I think there could be more such functions.

We can of course replace the true exponents by numbers following ^. Then the problem is solved.

@w-bruns
Copy link
Collaborator

w-bruns commented Sep 10, 2020

Now also available in Python 2 with ^ instead of proper superscript.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants