Skip to content

Instantly share code, notes, and snippets.

View Shekharrajak's full-sized avatar
📚
Being Geek!

Shekhar Prasad Rajak Shekharrajak

📚
Being Geek!
View GitHub Profile
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.
##############################################################################
# ------------------------------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.
# 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
##############################################################################
# ------------------------------nonlinsolve ---------------------------------#
##############################################################################
def substitution(system, symbols=None, result=[{}], known_symbols=[],
exclude=[], all_symbols=None):
r""" Solves the `system` using substitution method.
##############################################################################
# ------------------------------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.
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)
@Shekharrajak
Shekharrajak / reduce_imageset_v2.py
Created June 10, 2016 19:36
Secod attempt for reduce_imageset methoid
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.
# 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))
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
In [ ]: solveset(2*sin(x) - 1<0,x, S.Reals)
Out[ ]:
⎛ π⎞ ⎛5⋅π ⎞
⎜-∞, ─⎟ ∪ ⎜───, ∞⎟
⎝ 6⎠ ⎝ 6 ⎠