Skip to content

Conversation

@AnimeshSinha1309
Copy link
Contributor

Factors() splits rational factors into its numerator and denominator.
collect_const() can now collect the common dividing factors in an expression.

References to other Issues or PRs

Fixes #16296

Brief description of what is fixed or changed

Breaks down the numerator and denominator of Rational factors in a multiplicative expression, fixing the denominator collection issue that collect_const() was having.

Release Notes

  • core
    • sympy.core.exprtools.Factors() now splits each rational factor into a seaprate numerator and denominator

Fixes sympy#16296. Breaks down the numerator and denominator of Rational factors in a multiplicative expression, fixing the denominator collection issue that collect_const() was having.
@sympy-bot
Copy link

sympy-bot commented Apr 1, 2019

Hi, I am the SymPy bot (v147). I'm here to help you write a release notes entry. Please read the guide on how to write release notes.

Your release notes are in good order.

Here is what the release notes will look like:

  • core
    • sympy.core.exprtools.Factors() now splits each rational factor into a seaprate numerator and denominator (#16527 by @AnimeshSinha1309)

This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.5.

Note: This comment will be updated with the latest check if you edit the pull request. You need to reload the page to see it.

Click here to see the pull request description that was parsed.

`Factors()` splits rational factors into its numerator and denominator.
`collect_const()` can now collect the common dividing factors in an expression.

#### References to other Issues or PRs
Fixes #16296 

#### Brief description of what is fixed or changed
Breaks down the numerator and denominator of Rational factors in a multiplicative expression, fixing the denominator collection issue that collect_const() was having.

#### Release Notes

<!-- Write the release notes for this release below. See
https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more information
on how to write release notes. The bot will check your release notes
automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->
* core
  * sympy.core.exprtools.Factors() now splits each rational factor into a seaprate numerator and denominator
<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

# Handle all rational Coefficients
for f in list(factors.keys()):
if type(f) is Rational or type(f) is Half:
factors[f.p] = (factors[f.p] if f.p in factors else 0) + factors[f]
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps factors.set_default(f.p, 0) could be used.

Copy link
Member

Choose a reason for hiding this comment

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

f.p is a Python int. It should be converted into a SymPy Integer.

@Abdullahjavednesar Abdullahjavednesar added core PR: author's turn The PR has been reviewed and the author needs to submit more changes. labels Apr 1, 2019
@oscarbenjamin
Copy link
Collaborator

The tests seem to be breaking right now so I guess something here isn't working right.

This should have some new tests when it is working.

Converting p, q to Sympy Integer and checking instance of Rational to fix the errors in tests.
All tests working now. Changed condition to Rational and Not integer when breaking up numberator and denominator.
@jksuom
Copy link
Member

jksuom commented Apr 7, 2019

Please add a unit test.

Testing factors directly and checking that collect_const can collect rationals.
Not evaulating Mul allows testing the collect_const function with Rational Factors.
@AnimeshSinha1309 AnimeshSinha1309 force-pushed the issue/collectconst-16296 branch from 6e4c3c2 to 075f29f Compare April 8, 2019 08:23
@AnimeshSinha1309
Copy link
Contributor Author

Hope everything works well now, thanks a lot.

Importing sympy.core.numbers.Half is no longer necessary.
@jksuom
Copy link
Member

jksuom commented Apr 11, 2019

Thanks, looks good.

@jksuom jksuom merged commit 630a1a3 into sympy:master Apr 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core PR: author's turn The PR has been reviewed and the author needs to submit more changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

collect_const() does cannot collect rationals

5 participants