[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
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

[WIP] Polynomial System Factorization Methods (continued) #27303

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aasim-maverick
Copy link
Contributor
@aasim-maverick aasim-maverick commented Nov 23, 2024

This PR is a continuation of work from here. For context please refer to the discussion in the parent PR.

Release Notes

  • polys
    • Added factor_system() to find factor combinations that satisfy a system of equations
    • Added factor_system_bool() to express solutions as Boolean combinations in disjunctive normal form
    • Added factor_system_cond() to factor systems while preserving parametric conditions

@sympy-bot
Copy link
sympy-bot commented Nov 23, 2024

Hi, I am the SymPy bot. 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
    • Added factor_system() to find factor combinations that satisfy a system of equations (#27303 by @aasim-maverick)

    • Added factor_system_bool() to express solutions as Boolean combinations in disjunctive normal form (#27303 by @aasim-maverick)

    • Added factor_system_cond() to factor systems while preserving parametric conditions (#27303 by @aasim-maverick)

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

Click here to see the pull request description that was parsed.
This PR is a continuation of work from [here](https://github.com/sympy/sympy/pull/27169). For context please refer to the discussion in the parent PR.

#### Release Notes

<!-- Write the release notes for this release below between the BEGIN and END
statements. The basic format is a bulleted list with the name of the subpackage
and the release note for this PR. For example:

* solvers
  * Added a new solver for logarithmic equations.

* functions
  * Fixed a bug with log of integers. Formerly, `log(-x)` incorrectly gave `-log(x)`.

* physics.units
  * Corrected a semantical error in the conversion between volt and statvolt which
    reported the volt as being larger than the statvolt.

or if no release note(s) should be included use:

NO ENTRY

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
    - Added factor_system() to find factor combinations that satisfy a system of equations
     - Added factor_system_bool() to express solutions as Boolean combinations in disjunctive normal form
     - Added factor_system_cond() to factor systems while preserving parametric conditions

<!-- END RELEASE NOTES -->

…tion systems

Added a new function `factor_system` to sympy.polys.polytools that finds all
possible combinations of factors of equations of a polynomial system that could
simultaneously all be zero to satisfy a system of equations.
@aasim-maverick aasim-maverick force-pushed the functionality/sys-factorization-method branch from 305b486 to 171bd1e Compare November 23, 2024 04:35
@aasim-maverick
Copy link
Contributor Author

Alright, continuing where we left off:

The last review suggested the following changes:

  1. We should now get rid of assert_equal_unordered in the tests of factor_system and make the function return ordered outputs(don't return sets at all). See this comment.

  2. We should refactor factor_system_poly to maybe use gcd to eliminate redundant systems with univariate polynomials. See this comment.

>>> eqs = [a * (x - 1) * (y - 1), b * (x - 2) * (y - 1) * (y - 2)]
>>> factor_system_bool(eqs, [x, y])
(Eq(y - 1, 0) | (Eq(a, 0) & Eq(b, 0)) |((Eq(a, 0) | Eq(x - 1, 0)) & (Eq(b, 0) | Eq(x - 2, 0))) | ((Eq(a, 0) | Eq(x - 1, 0)) & (Eq(b, 0) | Eq(y - 2, 0))))

Here it was pointed out that the case a=0,b=0 seems redundant. See comment.

  1. Rewrite docstrings accordingly and also reduce the explanatory part in the docstring of the pivate function _cnf2dnf.

@aasim-maverick
Copy link
Contributor Author

Also, can someone please explain why the CI tests here are failing when for the same code in the parent PR they didn't. It was unexpected for me. How may I fix it ?

@oscarbenjamin
Copy link
Collaborator

I think the failed test is basically the same issue as gh-20456.

@oscarbenjamin
Copy link
Collaborator

I think that all of these functions should be moved to sympy/solvers/polysys.py along with related functions like solve_poly_system.

I also think that factor_system should be renamed factor_poly_system and the other functions renamed similarly. The factor_poly_system function should be added to the top-level sympy/__init__.py but I'm not sure about any of the others.

All of these functions should be added to the docs so we should make sure they are added there somewhere. The docstrings should be simplified with the use of sorted removed.

I don't like the fact that factor_poly_system discards conds but that may mean that it discards the information that the system is generically unsolvable. Maybe it should return a tuple with the second part being a boolean condition for the solvability like the outer And returned by factor_system_bool.

@aasim-maverick
Copy link
Contributor Author

I don't like the fact that factor_poly_system discards conds but that may mean that it discards the information that the system is generically unsolvable. Maybe it should return a tuple with the second part being a boolean condition for the solvability like the outer And returned by factor_system_bool.

Does something like this suffice ? :

def factor_poly_system(eqs, *gens, **kwargs):

   systems, conds = factor_system_cond(eqs, *gens, **kwargs)

   # Converting systems to ordered lists
   ordered_systems = []
   for system in systems:
       # Extracting expresions from (factor, conditions) pairs and sort them here only
       exprs = [f.as_expr() for f, c in system]
       ordered_systems.append(sorted(exprs, key=str))

   # Sort the systems themselves
   ordered_systems.sort(key=lambda x: [str(expr) for expr in x])

   # Make solvability condition
   if not systems:
       solvability = False if conds else True
   else:
       # Base solvability on the constant conditions
       solvability = True if not conds else And(*[Eq(c.as_expr(), 0) for c in conds])

   return ordered_systems, solvability

@oscarbenjamin
Copy link
Collaborator

I think it can just be:

def factor_system(eqs, *gens, **kwargs):
    systems, conds = factor_system_cond(eqs, *gens, **kwargs)
    systems = [{f.as_expr() for f, c in system} for system in systems]
    return systems, And(*conds)

If we are going to sort the output then I would prefer to do it in the base routine factor_system_poly.

We shouldn't use str for anything.

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.

3 participants