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

2302 Canonical powers and fix to perfect_power #267

Closed
wants to merge 12 commits into from

Conversation

smichr
Copy link
Member

@smichr smichr commented Apr 28, 2011

2302: gcd of multiplied integer bases are extracted

    When a sequence of integer-based powers is multiplied,
    a canonical representation can be obtained by attempting
    to separate all relatively prime bases with different powers.
    So for 2**(1/3)*3**(1/4)*6**(1/5) the 2 (and 3) are extracted
    from the 6 and the powers combined to give 2**(8/15)*3**(9, 20)

2302: canonical integer-base powers

    When a power of a prime factor of a power's base shares a gcd with
    the denominator of the base's exponent, e.g. in (2**4*3)**(1/6) the
    4 shares a gcd of 2 with 6, then that prime will be factored out of
    the base: e.g. to give 2**(2/3)*3**(1/6).

2321: Fix perfect_factor

    A number like 2**5*3**3 was coming back incorrectly as being a perfect power with exponent of 1. It should have returned None.

See issue 2302 and issue 2321.

@smichr
Copy link
Member Author

smichr commented Apr 28, 2011

TODO: wait for review

@certik
Copy link
Member

certik commented Apr 28, 2011

Test results: http://pastebin.com/1tMs9kV3

Automatic review by sympy-bot.

@smichr
Copy link
Member Author

smichr commented Apr 29, 2011

@asmeurer, can you give this a review?

@asmeurer
Copy link
Member

By the way, the commit from issue 415 was 7b87b62.

num_rat.extend(grow)
num_exp.append((bi, num_rat[i][1]))
i += 1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this code to be correct it is important that igcd always returns a positive number. (This seems to be the case but I don't see where that guarantee on igcd is documented).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this code to be correct it is important that igcd always returns
a positive number. (This seems to be the case but I don't see
where that guarantee on igcd is documented).

This is part of the igcd tests in test_numbers. But I added it to the docstring, too.

/c

@ness01
Copy link
Contributor

ness01 commented Apr 29, 2011

This looks good to me. Perhaps some tests with negative bases might be a good idea.

@smichr
Copy link
Member Author

smichr commented May 2, 2011

o perfect_power now returns False rather than None
o the gcd extraction has been reformulated as an addition commit
o a test has been added for issues 1095 so that issue can be closed
o the failing doctest of the deprecated block_diag has been gutted so the doctest no longer tests the deprecated function;
the diag method provides the documentation and comprable tests
o flatten treated 1.0 different than all other reals and this should not be done. 1 and 1.0 are no more similar than 2.0 and 2.
o a SKIP directive was removed form a matrix test with no adverse reaction under W32
o code from Mul.flatten that handled combination of bases was copied to powsimp so it, too, will follow power rules
o a force option was given to powsimp to allow ignoring of base-combination rules
o some dubious code (issue 2333) was refactored and a general tidyup of powsimp was done.

@ness01
Copy link
Contributor

ness01 commented May 4, 2011

Test results html report: http://pastehtml.com/view/1ed2zqy.html

Automatic review by sympy-bot.

@ness01
Copy link
Contributor

ness01 commented May 4, 2011

There seems to be a test failure in concrete/summations.

@smichr
Copy link
Member Author

smichr commented May 4, 2011

What can be wrong? Nothing fails here.

============================= test process starts ==============================

executable:   C:\Python26\python.exe  (2.6.4-final-0)
ground types: python

sympy\mpmath\tests\test_summation.py[5] .....                               [OK]


================== tests finished: 5 passed, in 0.61 seconds ===================


============================= test process starts ==============================

executable:   C:\Python26\python.exe  (2.6.4-final-0)
ground types: python

sympy\core\evalf.py[2] ..                                                   [OK]


================== tests finished: 2 passed, in 0.57 seconds ===================

============================== txt doctests start ==============================


doc\src\modules\evalf.txt [74]                                              [OK]

============================= test process starts ==============================

executable:   C:\Python26\python.exe  (2.6.4-final-0)
ground types: python

sympy\matrices\matrices.py[40] ........................................     [OK]


================== tests finished: 40 passed, in 1.52 seconds ==================

============================== txt doctests start ==============================


doc\src\modules\matrices.txt [98]                                           [OK]

C:\Documents and Settings\chris\sympy>\s\doc wester

C:\Documents and Settings\chris\sympy>\Python26\python.exe "C:\documents and set
tings\chris\sympy\bin\doctest"  wester
============================== txt doctests start ==============================


doc\src\modules\polys\wester.txt [60]                                       [OK]

Can anybody else confirm these failures? Is something strange going on?

@ness01
Copy link
Contributor

ness01 commented May 5, 2011

Well the failure in summation is actually a doctest, but I cannot reproduce it independently either. It only happens when I run setup.py test... I suppose it's some weird caching issue. Not that I know what to do about it ^^

@certik
Copy link
Member

certik commented May 5, 2011

Test results html report: http://pastehtml.com/view/1edeyx6.html

Automatic review by sympy-bot.

@certik
Copy link
Member

certik commented May 5, 2011

I get a few failures too in doctests. There seem to be some problem (e.g. wrong numbers returned), e.g. it's not just some hashing issue.

smichr added 12 commits May 5, 2011 23:55
    A number like 2**5*3**3 was coming back as being a perfect power with
    exponent of 1, i.e. (2**5*3**3, 1). It should be False to indicate that
    it is not a perfect power.
    When a power of a prime factor of a power's base shares a gcd with
    the denominator of the base's exponent, e.g. in (2**4*3)**(1/6) the
    4 shares a gcd of 2 with 6, then that prime will be factored out of
    the base: e.g. to give 2**(2/3)*3**(1/6).
    When a sequence of integer-based powers is multiplied,
    a canonical representation can be obtained by attempting
    to separate all relatively prime bases with different powers.
    So for 2**(1/3)*3**(1/4)*6**(1/5) the 2 (and 3) are extracted
    from the 6 and the powers combined to give 2**(8/15)*3**(9, 20)
    Now the gcd work is done after doing all the base and exponent combining.
    This leads to fewer terms to process.

    In addition, -1 is pulled out of every Number-based power with a Rational
    exponent and either stands alone or is re-inserted into a power with a
    matching exponent.
    Some Rationals are protected from making changes to p and q. Others
    are not. When you change the p and q values you are modifying that
    object in place and if that is a cached object then that object will
    no longer have the same value when it is recalled later.
    Real(1.0) was being changed to S.One by flatten. This was removed
    since no other Real was being treated that way, e.g. -1.0 is retained.

    A couple of test were changed.
    Bases having a common exponent should not combine unless the
    bases are positive or the exponents are integers. The exception
    being that a negative base or a base with an unknown sign
    can join non-negative bases.
    Some condensation of code was done and the portion where
    c_exp was traversed while being deleted and reconstructed
    was re-written.
@smichr
Copy link
Member Author

smichr commented May 5, 2011

I think I found the problem and left the commit (don't modify .p and .q) next to the offending commit so as not to forget this nasty little error. Can you guys confirm that there are now no failures?

@ness01
Copy link
Contributor

ness01 commented May 5, 2011

Test results html report: http://pastehtml.com/view/1edn0kz.html

Automatic review by sympy-bot.

@ness01
Copy link
Contributor

ness01 commented May 5, 2011

So the tests look good now [wester is not your fault].

@smichr
Copy link
Member Author

smichr commented May 5, 2011

OK, if there are no other objections this will be pushed in about 8 hours.

@smichr
Copy link
Member Author

smichr commented May 6, 2011

it's in.

@smichr smichr closed this May 6, 2011
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

Successfully merging this pull request may close these issues.

None yet

4 participants