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

solving type error and Coercion error in algebraicfield.py #18669

Merged
merged 6 commits into from
Feb 18, 2020

Conversation

mohitacecode
Copy link
Contributor

@mohitacecode mohitacecode commented Feb 16, 2020

References to other Issues or PRs

Fixes #18248
Fixes #13230

Brief description of what is fixed or changed

It solves the type error by:

  • Adding a check for type of ext in AlgebraicField.__init__.

It also solves the Coercion error by:

  • adding a AlgebraicField.from_AlgebraicField(K1, a, K0) method.

Other comments

Release Notes

  • polys
    • Fixed initialization of orig_ext and added from_AlgebraicField() to AlgebraicField.

@sympy-bot
Copy link

sympy-bot commented Feb 16, 2020

Hi, I am the SymPy bot (v151). 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:

  • polys
    • Fixed initialization of orig_ext and added from_AlgebraicField() to AlgebraicField. (#18669 by @mohitacecode)

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

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.

<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->

#### References to other Issues or PRs
<!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
format, e.g. "Fixes #1234" (see
https://tinyurl.com/auto-closing for more information). Also, please
write a comment on that issue linking back to this pull request once it is
open. -->

Fixes #18248
Fixes #13230
#### Brief description of what is fixed or changed
It solves the type error by:

- Adding a check for type of `ext` in `AlgebraicField.__init__`.

It also solves the Coercion error by:

- adding a `AlgebraicField.from_AlgebraicField(K1, a, K0)` method.

#### Other comments


#### 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 -->
*   polys
     *  Fixed initialization of `orig_ext` and added `from_AlgebraicField()` to `AlgebraicField`.
<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@@ -26,8 +26,10 @@ def __init__(self, dom, *ext):
raise DomainError("ground domain must be a rational field")

from sympy.polys.numberfields import to_number_field

self.orig_ext = ext
if len(ext) == 1 and type(ext[0]) is tuple:
Copy link
Member

Choose a reason for hiding this comment

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

if len(ext) == 1 and isinstance(ext[0], tuple)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure updating it now.
thanks for pointing it out.

@codecov
Copy link

codecov bot commented Feb 16, 2020

Codecov Report

Merging #18669 into master will decrease coverage by 4.271%.
The diff coverage is 100%.

@@             Coverage Diff              @@
##            master   #18669       +/-   ##
============================================
- Coverage   75.572%    71.3%   -4.272%     
============================================
  Files          644      644               
  Lines       167515   167831      +316     
  Branches     39485    39566       +81     
============================================
- Hits        126595   119665     -6930     
- Misses       35395    42519     +7124     
- Partials      5525     5647      +122

@mohitacecode
Copy link
Contributor Author

I think it is ready @jksuom

@@ -124,3 +126,8 @@ def numer(self, a):
def denom(self, a):
"""Returns denominator of ``a``. """
return self.one

def from_AlgebraicField(K1, a, K0):
"""Convert a polynomial to ``dtype``. """
Copy link
Member

Choose a reason for hiding this comment

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

Technically, a is represented by a polynomial but it is less confusing to say that it is an algebraic field element. So this should say something about converting an element a from one algebraic field to another.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Convert AlgebraicField element 'a' to another AlgebraicField element
Does it seems ok?

def from_AlgebraicField(K1, a, K0):
"""Convert a polynomial to ``dtype``. """
a = K0.to_sympy(a)
return K1.from_sympy(a)
Copy link
Member

Choose a reason for hiding this comment

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

It is not necessary to save K0.to_sympy(a) temporarily to a local variable, K1.from_sympy(K0.to_sympy(a)) should suffice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I agree I will update it.

@jksuom
Copy link
Member

jksuom commented Feb 17, 2020

There are a couple of comments, otherwise this looks good.

@jksuom
Copy link
Member

jksuom commented Feb 17, 2020

What about the intersection of two circles in #13230? It would be good to have a test.

@mohitacecode
Copy link
Contributor Author

mohitacecode commented Feb 17, 2020

Sure that should be checked too I will add it now.

@mohitacecode
Copy link
Contributor Author

What about the intersection of two circles in #13230? It would be good to have a test.

The test for this should be added in test_ellipse.py. Is it okay to add here?

@jksuom
Copy link
Member

jksuom commented Feb 17, 2020

Both of these issues run solvers but, actually, they are related to algebraic fields. Perhaps they should be added to test_numberfields.py.

@mohitacecode
Copy link
Contributor Author

I just noticed this:
The o/p seems bit absurd to me. what do you think?

>>> c1 = Circle(Point2D(180 + 24*sqrt(210), 168), 231)
>>> c2 = Circle(Point2D(889, 89 + 2*sqrt(9879)), 174)
>>> intersection(c1, c2)
[Point2D((-1418*sqrt(9879)/381721 - 144*sqrt(230510)/381721 + 1896*sqrt(210)/381721 + 56011/381721)*(-38811853369687970538*sqrt(210)/507642891246375390197 + 5572625558444725932*sqrt(230510)/507642891246375390197 + sqrt(5)*sqrt(-2477733817168523132880172154355338155165662648305 + 94596782533875822530882841399346430904131232*sqrt(230510) + 680989928789592059191366739742910325258787060*sqrt(9879) + 169190923751886106340201853200012760065401726272*sqrt(210))/10152857824927507803940 + 544540497818290517582*sqrt(9879)/507642891246375390197 + 257193210521585085426053/2030571564985501560788) + 144*sqrt(230510)/4289 + 1418*sqrt(9879)/4289 + 5088228*sqrt(210)/381721 + 438049031/763442, -38811853369687970538*sqrt(210)/507642891246375390197 + 5572625558444725932*sqrt(230510)/507642891246375390197 + sqrt(5)*sqrt(-2477733817168523132880172154355338155165662648305 + 94596782533875822530882841399346430904131232*sqrt(230510) + 680989928789592059191366739742910325258787060*sqrt(9879) + 169190923751886106340201853200012760065401726272*sqrt(210))/10152857824927507803940 + 544540497818290517582*sqrt(9879)/507642891246375390197 + 257193210521585085426053/2030571564985501560788), Point2D((-1418*sqrt(9879)/381721 - 144*sqrt(230510)/381721 + 1896*sqrt(210)/381721 + 56011/381721)*(-sqrt(5)*sqrt(-2477733817168523132880172154355338155165662648305 + 94596782533875822530882841399346430904131232*sqrt(230510) + 680989928789592059191366739742910325258787060*sqrt(9879) + 169190923751886106340201853200012760065401726272*sqrt(210))/10152857824927507803940 - 38811853369687970538*sqrt(210)/507642891246375390197 + 5572625558444725932*sqrt(230510)/507642891246375390197 + 544540497818290517582*sqrt(9879)/507642891246375390197 + 257193210521585085426053/2030571564985501560788) + 144*sqrt(230510)/4289 + 1418*sqrt(9879)/4289 + 5088228*sqrt(210)/381721 + 438049031/763442, -sqrt(5)*sqrt(-2477733817168523132880172154355338155165662648305 + 94596782533875822530882841399346430904131232*sqrt(230510) + 680989928789592059191366739742910325258787060*sqrt(9879) + 169190923751886106340201853200012760065401726272*sqrt(210))/10152857824927507803940 - 38811853369687970538*sqrt(210)/507642891246375390197 + 5572625558444725932*sqrt(230510)/507642891246375390197 + 544540497818290517582*sqrt(9879)/507642891246375390197 + 257193210521585085426053/2030571564985501560788)

@jksuom
Copy link
Member

jksuom commented Feb 17, 2020

There seems to be only one (real) point in the intersection. Can you check that by computing the distance between the center points? (That should be the sum or difference of the radii.)

@mohitacecode
Copy link
Contributor Author

the distance between their center is around ~458.

@mohitacecode
Copy link
Contributor Author

The answer (o/p in current branch) is giving two points so I think that circles are not only touching externally so the property (distance between the center points should be the sum or difference of the radii.) will not work here.

The reason I find it absurd because the answer seems too unsimplified and long to mee but now I think that answer can be unsimplified and long because of the ugly circles equation we have used here.

@jksuom
Copy link
Member

jksuom commented Feb 17, 2020

The distance I get is 380.55 which is less than 231 + 174 = 405. So there should be two points.

@mohitacecode
Copy link
Contributor Author

Yes distance between centre is 380.55 I had just by mistake took the points
(180+24sqft(210),6) instead of (180+24sqft(210),168).

@mohitacecode
Copy link
Contributor Author

So the answer seems right I will add the test.

def test_issue_13230():
c1 = Circle(Point2D(3, sqrt(5)), 5)
c2 = Circle(Point2D(4, sqrt(7)), 6)
assert intersection(c1, c2) == [Point2D(-1 + (-sqrt(7) + sqrt(5))*(-2*sqrt(7)/29 + 9*sqrt(5)/29 + sqrt(196*sqrt(35) + 1941)/29), -2*sqrt(7)/29 + 9*sqrt(5)/29 + sqrt(196*sqrt(35) + 1941)/29), Point2D(-1 + (-sqrt(7) + sqrt(5))*(-sqrt(196*sqrt(35) + 1941)/29 - 2*sqrt(7)/29 + 9*sqrt(5)/29), -sqrt(196*sqrt(35) + 1941)/29 - 2*sqrt(7)/29 + 9*sqrt(5)/29)]
Copy link
Member

Choose a reason for hiding this comment

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

This should be split onto several lines of length at most 72

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure I will update it.

@mohitacecode
Copy link
Contributor Author

I have done the changes please see if seems ok to you.

@jksuom
Copy link
Member

jksuom commented Feb 18, 2020

Thanks, looks good.

@jksuom jksuom merged commit 72e0994 into sympy:master Feb 18, 2020
@mohitacecode
Copy link
Contributor Author

Thanks :)

@Iqrar99
Copy link

Iqrar99 commented Feb 23, 2020

Hello @mohitacecode , I just want to know. How are you testing the test files? are you using coverage python or what? thanks.

@mohitacecode
Copy link
Contributor Author

Hello @mohitacecode , I just want to know. How are you testing the test files? are you using coverage python or what? thanks.

You can see how to run all type of test here:
https://github.com/sympy/sympy/wiki/Running-tests

@Iqrar99
Copy link

Iqrar99 commented Feb 23, 2020

Thank you so much! 😄

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

Successfully merging this pull request may close these issues.

nonlinsolve raises TypeError Intersection of two circles can lead to a crash
5 participants