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

Update pynac to 0.7.27 to fix wrong result on symbolic exponentiation #30446

Closed
dkrenn opened this issue Aug 26, 2020 · 49 comments
Closed

Update pynac to 0.7.27 to fix wrong result on symbolic exponentiation #30446

dkrenn opened this issue Aug 26, 2020 · 49 comments

Comments

@dkrenn
Copy link
Contributor

dkrenn commented Aug 26, 2020

Before this ticket:

sage: n((24*sqrt(3))^(100/50))
3.80392047155301e5927962146
sage: n((24*sqrt(3))^(2))
1728.00000000000

Clearly, both should be the same, namely the second.

This was on SageMath 9.1 on openSUSE Leap 15.2 (64bit) (reported by a colleague to me).

I've tried to reproduce, but my SageMath, as well as on CoCalc crashes. The error message on my machine was

Traceback (most recent call last):
  File "<string>", line 25, in <module>
ModuleNotFoundError: No module named 'Cython'
Error while executing Python code.
Saved trace to /home/dakrenn/.sage/crash_logs/crash_lqkqgydq.log
------------------------------------------------------------------------
Unhandled SIGABRT: An abort() occurred.
This probably occurred because a *compiled* module has a bug
in it and is not properly wrapped with sig_on(), sig_off().
Python will now terminate.
------------------------------------------------------------------------
Aborted (core dumped)

However, my SageMath seems to be fine otherwise, make ptestlong passes.
Same on current 9.2.beta9.

Depends on #31118

Upstream: None of the above - read trac for reasoning.

CC: @zimmermann6

Component: symbolics

Author: Ben Livingston, Dima Pasechnik

Branch: ccdf77c

Reviewer: Dima Pasechnik, Matthias Koeppe

Issue created by migration from https://trac.sagemath.org/ticket/30446

@dkrenn dkrenn added this to the sage-9.2 milestone Aug 26, 2020
@DaveWitteMorris
Copy link
Member

comment:1

I confirm the error. I get exactly the same answers as in the original report. I am using Mac OS 10.15.5, and tested both 9.1 and 9.2b10. (The version with 100/2 is slow -- takes about 50 seconds.)

When I tried CoCalc, it failed because it ran out of memory. (The memory gauge was over 3GB before it aborted.)

@bmlivin bmlivin mannequin self-assigned this Sep 21, 2020
@DaveWitteMorris
Copy link
Member

comment:3

There is no need to use big numbers, so the situation is even worse than it first appeared:

sage: n((2*sqrt(2))^(2/1))                                                      
1.24131221754531e1292913987
sage: n((2*sqrt(2))^2)                                                          
8.00000000000000

This only takes a few seconds with 9.1 on CoCalc (but needs more than 1GB of memory) or with 9.2b13 on MacOS 10.15.6.

@mantepse
Copy link
Collaborator

mantepse commented Oct 1, 2020

comment:4

I can confirm this on Ubuntu 18 with SageMath version 9.2.beta13, using Python 3.8.5.

@bmlivin
Copy link
Mannequin

bmlivin mannequin commented Oct 3, 2020

comment:5

Okay, I believe I've tracked this down. It is a pynac bug. Here's what's happening:

Sage eventually calls pynac's pow from sage.symbolic.expression:Expression._pow_, but before that happens, it simplifies the exponent. Specifically, it simplifies the exponent so that pynac thinks it is an integer, but its type is still MPQ.

None of that should matter, except that what pynac calls to evaluate the expression is numeric::pow_intexp. Here is the content of that function:

if (not exponent.is_integer())
    throw std::runtime_error("nueric::pow_intexp: exponent not integer");
if (exponent.t == MPZ) {
    if (not mpz_fits_sint_p(exponent.v._bigint))
        throw std::runtime_error("size of exponent exceeds signed long size");
    return power(mpz_get_si(exponent.v._bigint));
}
return power(exponent.v._long);

In this function, exponent.is_integer() is True and exponent.t is MPQ. So both of the if statements are false, and power(exponent.v._long) is called. The problem is that v._long contains junk (very large junk!). Evaluating that statement takes a long time, and it won't give you the answer you want.

If, on the other hand, the second if statement were true, the result would have been exactly what you want. So simply checking whether exponent.t == MPQ or exponent.t == MPZ should fix this. I haven't tried this, but it's what I would at least try.

I think it may be possible as well to fix this by getting Sage to change the type of the exponent when it's cancelled out. I haven't looked into this and I think it sounds like a bad idea.

I'm unassigning this because I can't currently report it upstream.

@bmlivin
Copy link
Mannequin

bmlivin mannequin commented Oct 3, 2020

Upstream: Not yet reported upstream; Will do shortly.

@bmlivin bmlivin mannequin removed their assignment Oct 3, 2020
@bmlivin
Copy link
Mannequin

bmlivin mannequin commented Oct 12, 2020

Author: Ben Livingston

@bmlivin
Copy link
Mannequin

bmlivin mannequin commented Oct 12, 2020

Changed upstream from Not yet reported upstream; Will do shortly. to Fixed upstream, in a later stable release.

@bmlivin
Copy link
Mannequin

bmlivin mannequin commented Oct 12, 2020

comment:6

I've fixed this upstream and submitted a pull request: pynac/pynac#355. The pull request also includes additions to the doctest for sage.symbolic.expression.Expression::_pow_.

@bmlivin bmlivin mannequin added the s: needs review label Oct 12, 2020
@mkoeppe mkoeppe modified the milestones: sage-9.2, sage-9.3 Oct 24, 2020
@dimpase
Copy link
Member

dimpase commented Jan 10, 2021

comment:8

OK, trying https://patch-diff.githubusercontent.com/raw/pynac/pynac/pull/355.patch now.

But where are "additions to the doctest for sage.symbolic.expression.Expression::_pow_"?

I presume they should be here, on this ticket.

@dimpase
Copy link
Member

dimpase commented Jan 10, 2021

comment:9

OK, with that patch,

sage: QQ((24*sqrt(3))^(100/50))==1728                                                                                                                                
True

works. I'll add this as a doctest somewhere.

@dimpase
Copy link
Member

dimpase commented Jan 10, 2021

Branch: u/dimpase/packages/pynac/30446

@dimpase
Copy link
Member

dimpase commented Jan 10, 2021

Reviewer: Dima Pasechnik

@dimpase
Copy link
Member

dimpase commented Jan 10, 2021

Commit: dc073df

@dimpase
Copy link
Member

dimpase commented Jan 10, 2021

comment:10

patches from pynac PRs to be removed at the next pynac update.


New commits:

dc073dffixes for trac #30446

@DaveWitteMorris
Copy link
Member

comment:11

This patch to pynac also fixes #28620, #30304, and #30786. The PR at #30786 adds doctests for all 3 of these tickets (and also moves the doctest of this ticket from the _latex_ method to the _pow_ method, which seems like a more appropriate place).

@DaveWitteMorris
Copy link
Member

comment:12

fyi: Patchbot Linux/74-Ubuntu_SMP_Tue_Sep_17_17%3A06%3A04_UTC_2019/x86_64/4.15.0-65-generic/pc72 seems to have failed to build pynac at ticket #30786. ("Error installing package pynac-0.7.26.sage-2020-04-03.p1") If there is a genuine problem, I think it must be because of this ticket.

@DaveWitteMorris
Copy link
Member

comment:13

This patch also seems to fix #31137. I added a doctest there.

@DaveWitteMorris
Copy link
Member

comment:14

fyi: Another ubuntu patchbot failed to build pynac (on ticket #31137 this time). Both failures say WARNING: 'aclocal-1.16' is missing on your system. ... Makefile:432: recipe for target 'aclocal.m4' failed.

@vbraun
Copy link
Member

vbraun commented Jan 17, 2021

comment:15

Patch touches configure stuff which triggers automake run (which is not a Sage dependency)

Building pynac-0.7.26.sage-2020-04-03.p1
CDPATH="${ZSH_VERSION+.}:" && cd . && /bin/bash /var/lib/buildbot/slave/sage_git/build/local/var/tmp/sage/build/pynac-0.7.26.sage-2020-04-03.p1/src/missing aclocal-1.16 -I m4
/var/lib/buildbot/slave/sage_git/build/local/var/tmp/sage/build/pynac-0.7.26.sage-2020-04-03.p1/src/missing: line 81: aclocal-1.16: command not found
WARNING: 'aclocal-1.16' is missing on your system.
         You should only need it if you modified 'acinclude.m4' or
         'configure.ac' or m4 files included by 'configure.ac'.
         The 'aclocal' program is part of the GNU Automake package:
         <https://www.gnu.org/software/automake>
         It also requires GNU Autoconf, GNU m4 and Perl in order to run:
         <https://www.gnu.org/software/autoconf>
         <https://www.gnu.org/software/m4/>
         <https://www.perl.org/>
Makefile:432: recipe for target 'aclocal.m4' failed
make[5]: *** [aclocal.m4] Error 127
make[5]: Failed to remake makefile 'Makefile'.
make[5]: Target 'all' not remade because of errors.

@mkoeppe
Copy link
Contributor

mkoeppe commented Jan 24, 2021

comment:29

build/pkgs/pynac/SPKG.rst could use an update. In particular "Special Update/Build Instructions" should be removed

@mkoeppe
Copy link
Contributor

mkoeppe commented Jan 24, 2021

Changed reviewer from Dima Pasechnik to Dima Pasechnik, Matthias Koeppe

@mkoeppe mkoeppe changed the title wrong result on symbolic exponentiation Update pynac to 0.7.27 to fix wrong result on symbolic exponentiation Jan 24, 2021
@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 24, 2021

Changed commit from 214712d to ccdf77c

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 24, 2021

Branch pushed to git repo; I updated commit sha1 and set ticket back to needs_review. New commits:

ccdf77cupdate SPKG.rst

@dimpase
Copy link
Member

dimpase commented Jan 24, 2021

comment:34

ok, done

@vbraun
Copy link
Member

vbraun commented Feb 8, 2021

comment:36
[dochtml] [calculus ] docstring of sage.symbolic.expression.Expression.subs:135: WARNING: Literal block expected; none found.
[dochtml] [calculus ] docstring of sage.symbolic.expression.Expression.substitute:135: WARNING: Literal block expected; none found.
[dochtml] [manifolds] The inventory files are in local/share/doc/sage/inventory/en/reference/manifolds.
[dochtml] Build finished. The built documents can be found in /home/release/Sage/local/share/doc/sage/inventory/en/reference/manifolds
[dochtml] [calculus ] The inventory files are in local/share/doc/sage/inventory/en/reference/calculus.
[dochtml] Error building the documentation.
[dochtml] Traceback (most recent call last):
[dochtml]   File "/usr/lib64/python3.9/runpy.py", line 197, in _run_module_as_main
[dochtml]     return _run_code(code, main_globals, None,
[dochtml]   File "/usr/lib64/python3.9/runpy.py", line 87, in _run_code
[dochtml]     exec(code, run_globals)
[dochtml]   File "/home/release/Sage/local/lib64/python3.9/site-packages/sage_setup/docbuild/__main__.py", line 2, in <module>
[dochtml]     main()
[dochtml]   File "/home/release/Sage/local/lib64/python3.9/site-packages/sage_setup/docbuild/__init__.py", line 1730, in main
[dochtml]     builder()
[dochtml]   File "/home/release/Sage/local/lib64/python3.9/site-packages/sage_setup/docbuild/__init__.py", line 343, in _wrapper
[dochtml]     getattr(get_builder(document), 'inventory')(*args, **kwds)
[dochtml]   File "/home/release/Sage/local/lib64/python3.9/site-packages/sage_setup/docbuild/__init__.py", line 569, in _wrapper
[dochtml]     self._build_everything_except_bibliography(lang, format, *args, **kwds)
[dochtml]   File "/home/release/Sage/local/lib64/python3.9/site-packages/sage_setup/docbuild/__init__.py", line 555, in _build_everything_except_bibliography
[dochtml]     build_many(build_ref_doc, non_references)
[dochtml]   File "/home/release/Sage/local/lib64/python3.9/site-packages/sage_setup/docbuild/__init__.py", line 295, in build_many
[dochtml]     _build_many(target, args, processes=NUM_THREADS)
[dochtml]   File "/home/release/Sage/local/lib64/python3.9/site-packages/sage_setup/docbuild/utils.py", line 289, in build_many
[dochtml]     raise worker_exc.original_exception
[dochtml] OSError: docstring of sage.symbolic.expression.Expression.subs:135: WARNING: Literal block expected; none found.
[dochtml] 
[dochtml]     Note: incremental documentation builds sometimes cause spurious
[dochtml]     error messages. To be certain that these are real errors, run
[dochtml]     "make doc-clean" first and try again.

@mkoeppe
Copy link
Contributor

mkoeppe commented Feb 20, 2021

comment:37

Could someone fix up the documentation markup please?

@DaveWitteMorris
Copy link
Member

comment:38

I can't find any mistake, the patchbots are green, and the html documentation builds for me.

I wonder if maybe this error was posted to the wrong ticket? It is exactly the same error that was reported by a patchbot on ticket #30378 because I goofed up the WARNING block there:

[dochtml] OSError: docstring of sage.symbolic.expression.Expression.subs:135: WARNING: Literal block expected; none found.

@mkoeppe
Copy link
Contributor

mkoeppe commented Feb 21, 2021

comment:39

Thanks for checking! Works for me too (tested on top of 31344)

@vbraun
Copy link
Member

vbraun commented Mar 7, 2021

Changed branch from u/dimpase/packages/pynac/0727 to ccdf77c

@slel
Copy link
Member

slel commented Mar 7, 2021

Changed commit from ccdf77c to none

@slel

This comment has been minimized.

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

No branches or pull requests

8 participants