This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _solve_using_known_values(result, solver): | |
"""Solves the system using already known solution | |
(result contains the dict <symbol: value>). | |
solver is `solveset_complex` or `solveset_real`. | |
""" | |
# helper functions | |
def _append_new_soln(sol, rnew, newresult, imgset_info): | |
"""If rnew (A dict <symbol: soln> ) contains valid soln | |
append it to newresult list. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################################## | |
# ------------------------------nonlinsolve ---------------------------------# | |
############################################################################## | |
def substitution(system, symbols, result=[{}], known_symbols=[], | |
exclude=[], all_symbols=None): | |
r""" Solves the `system` using substitution method. | |
A helper function for `nonlinsolve`. This will be called from | |
`nonlinsolve` when any equation(s) is non polynomial equation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# used in class Set(Basic):sets.py file | |
def _union_simplify(self, other): | |
""" | |
Try to reduce number of imageset in the args. Helper method for | |
ImageSet `_union `. It helps to get simpler imageset or | |
union of imageset. | |
First extract the expression of imageset and store in separate list | |
(self_expr for self and final_list for other). If there is any expr in | |
self_list have difference of pi or -pi with any final_expr expr. then |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################################## | |
# ------------------------------nonlinsolve ---------------------------------# | |
############################################################################## | |
def substitution(system, symbols=None, result=[{}], known_symbols=[], | |
exclude=[], all_symbols=None): | |
r""" Solves the `system` using substitution method. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################################## | |
# ------------------------------nonlinsolve ---------------------------------# | |
############################################################################## | |
def substitution(system, symbols=None, result=[{}], known_symbols=[], exclude=[], | |
all_symbols=None): | |
r""" Solves the `system` using substitution method. | |
A helper function for `nonlinsolve`. This will be called from | |
`nonlinsolve` when any equation(s) is non polynomial equation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solveset_univariate_trig_inequality(expr, gen, relational=True): | |
"""Solves a real univariate inequality. | |
Examples | |
======== | |
>>> from sympy.solvers.inequalities import solveset_univariate_trig_inequality | |
>>> from sympy.core.symbol import Symbol | |
>>> x = Symbol('x') | |
>>> solveset((2*cos(x)+1)/(2*cos(x)-1) > 0, x, S.Reals) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def reduce_imageset(new_imgset, imgset = S.EmptySet): | |
""" | |
Try to reduce number of imageset in the args. | |
It is mostly helper to _solve_trig method defined in | |
solvers/solveset.py. | |
First extract the expression of imageset and put in list in new_list | |
(for new_imgset expr) and final_list(for imgset expr). If there is any | |
expr in new_list have difference of pi or -pi with any final_list expr. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# examples how we can use factor to reduce number of imageset : | |
# current master branch | |
In [110]: solveset(4*sin(x)**3 + 2*sin(x)**2 - 2*sin(x) - 1) # ------------ eq(1) | |
Out[110]: | |
⎧ 7⋅π ⎫ ⎧ 11⋅π ⎫ ⎧ 5⋅π ⎫ ⎧ 3⋅π ⎫ ⎧ 7⋅π ⎫ ⎧ π ⎫ | |
⎨2⋅n⋅π + ─── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ──── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ─── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ─── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ─── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ─ | n ∊ ℤ⎬ | |
⎩ 6 ⎭ ⎩ 6 ⎭ ⎩ 4 ⎭ ⎩ 4 ⎭ ⎩ 4 ⎭ ⎩ 4 ⎭ | |
In [123]: solveset((4*sin(x)**3 + 2*sin(x)**2 - 2*sin(x) - 1).rewrite(exp)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def reduce_imageset(soln): | |
""" | |
Try to reduce number of imageset in the args. | |
It is mostly helper to _solve_trig method defined in | |
solvers/solveset.py. | |
First extract the expression of imageset and | |
sort the negative and positive expression. | |
and using interpolate defined in polys/polyfuncs.py | |
generates a function in `n`, which can return all the |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In [ ]: solveset(2*sin(x) - 1<0,x, S.Reals) | |
Out[ ]: | |
⎛ π⎞ ⎛5⋅π ⎞ | |
⎜-∞, ─⎟ ∪ ⎜───, ∞⎟ | |
⎝ 6⎠ ⎝ 6 ⎠ |