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

Implemented an algorithm to find a rational point on a conic #19807

Merged
merged 6 commits into from
Jul 30, 2020

Conversation

friyaz
Copy link
Member

@friyaz friyaz commented Jul 20, 2020

References to other Issues or PRs

#19320

Brief description of what is fixed or changed

Implemented an algorithm to find a rational point on the conic. To parametrize a monoid of degree d, we need to find a point of multiplicity d - 1. This implies for curves of degree 2, we need to determine a rational point on it. While determining a point of multiplicity >= 2 is easy using sympy's non-linsolve, a separate algorithm needs to be implemented for points of multiplicity 1 or regular points.

The regular_point was based on iterating over a set of points and checking whether they lie on the conic. This PR fixes this for conics. I have not yet implemented the algorithm for quadrics.

Other comments

Release Notes

  • vector
    • Added a function to find a rational point on conic

@sympy-bot
Copy link

sympy-bot commented Jul 20, 2020

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

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

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
#19320 
<!-- 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. -->


#### Brief description of what is fixed or changed
Implemented an algorithm to find a rational point on the conic. To parametrize a monoid of degree d, we need to find a point of multiplicity d - 1. This implies for curves of degree 2, we need to determine a rational point on it. While determining a point of multiplicity >= 2 is easy using sympy's non-linsolve, a separate algorithm needs to be implemented for points of multiplicity 1 or regular points. 

The `regular_point` was based on iterating over a set of points and checking whether they lie on the conic. This PR fixes this for conics. I have not yet implemented the algorithm for [quadrics](https://en.wikipedia.org/wiki/Quadric). 

#### 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 -->
* vector
    * Added a function to find a rational point on conic
<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@friyaz friyaz marked this pull request as draft July 20, 2020 19:15
@friyaz friyaz requested a review from Upabjojr July 20, 2020 19:15
sympy/vector/implicitregion.py Show resolved Hide resolved
sympy/vector/implicitregion.py Outdated Show resolved Hide resolved
sympy/vector/implicitregion.py Outdated Show resolved Hide resolved
@@ -245,6 +374,12 @@ def rational_parametrization(self, parameters=('t', 's'), reg_point=None):
if len(self.singular_points()) != 0:
singular_points = self.singular_points()
for spoint in singular_points:
syms = Tuple(*spoint).free_symbols
Copy link
Contributor

Choose a reason for hiding this comment

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

what about syms = set(spoint) ?

sympy/vector/tests/test_implicitregion.py Outdated Show resolved Hide resolved
sol = list(sol)[0]
syms = Tuple(*sol).free_symbols
rep = {s: 3 for s in syms}

Copy link
Member Author

Choose a reason for hiding this comment

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

There is a bug here. In cases like x*y = 1, the solution of diophantine equation is {(p2 + q2, -2pq, p2 - q2)}. If I substitute p = 3 and q = 3, z turns out to be zero. This leads to the result being nan. The algorithm requires the solution of diophantine equation to be non-trivial.

Copy link
Contributor

Choose a reason for hiding this comment

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

What about pushing the solution of the diophantine equation into the equation solver? For example, in the case {(p2 + q2, -2pq, p2 - q2)}, can it help if you get p as a function of q?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I think this should work. Solving for z != 0, then using one of its solutions.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is how I am trying to get the solutions for z != 0

for sol in solutions:
    syms = Tuple(*sol).free_symbols
    
    z = sol[2]
    
    z_syms = ztemp.free_symbols

    if len(z_syms) == 2:
        print(solveset(Unequality(z, 0), next(iter(z_syms)), S.Integers))

But solveset is too slow for returning an Integer solution.

Copy link
Contributor

Choose a reason for hiding this comment

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

Have you thought about solving the equality and then taking the complement of the solutions? It should be equivalent to solveset(Unequality( ... )).

Copy link
Member Author

Choose a reason for hiding this comment

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

This should work. In the case of two variables p and q, I will iterate p over S.Integers and then solve q for z != 0.

Copy link
Member Author

Choose a reason for hiding this comment

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

ping @Upabjojr.

@friyaz friyaz requested a review from Upabjojr July 21, 2020 12:38
@friyaz friyaz marked this pull request as ready for review July 28, 2020 14:32
@friyaz friyaz requested a review from Upabjojr July 28, 2020 14:33
@codecov
Copy link

codecov bot commented Jul 28, 2020

Codecov Report

Merging #19807 into master will decrease coverage by 0.009%.
The diff coverage is 71.328%.

@@              Coverage Diff              @@
##            master    #19807       +/-   ##
=============================================
- Coverage   75.719%   75.709%   -0.010%     
=============================================
  Files          664       666        +2     
  Lines       172374    172712      +338     
  Branches     40653     40717       +64     
=============================================
+ Hits        130520    130759      +239     
- Misses       36147     36225       +78     
- Partials      5707      5728       +21     

@@ -210,7 +376,8 @@ def rational_parametrization(self, parameters=('t', 's'), reg_point=None):
=========

- Christoph M. Hoffmann, Conversion Methods between Parametric and
Implicit Curves and Surfaces.
Implicit Curves and Surfaces, 1990. Available:
Copy link
Contributor

Choose a reason for hiding this comment

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

Publisher and authors are more important than the title itself. Christoph M. Hoffmann? Perdue e-Pubs?

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, I will add it.

@Upabjojr
Copy link
Contributor

This looks good to me. Please add the authors and publisher of all citations you've added (in the literatura, authors and publishing review company are usually more important than the title of the paper itself).

@friyaz friyaz requested a review from Upabjojr July 30, 2020 10:07
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

5 participants