System of Inequalities
Right now solve uses
reduce_inequalities to solve system of equations. But it is not designed for more than one variable.
ex: system =
[2*x - 3*y <= 12, x+5*y <=20, x>0] symbols = [x,y])you will get :
NotImplementedError: inequality has more than one symbol of interest We know answer is
[0 < x <120/13 and 2(x-6)/3 <= y <= (20-x)/5]
[x = 120/13 and y = 28/13]
SymPyalready have project on this Cylindrical algebraic decomposition to Provide an interface for solving systems of polynomial inequalities.
If we want to feature like old
solvethen just need to pass system of inequalities having one variable to solve for one variable. After checking this use
reduce_inequalitie(system, symbol)it will return solution. It is easy to implement.
General solution for Trigonometric equations
Problems in old method :
_solve_trigchanges the trig equation in
expform (it’s fine). But then fraction and solving equation for it’s parts makes more number of
exp. If we have more number of
expthen we get more number of
imageset, Since we
ConditionSetwhen it can’t solve, but its expression is in ` exp
form mostly withI` and in complicated form.
_solve_as_polycan solve Trig equations, but it is not using it.
New implemention :
solveset.pyto reduce the number of union returned by
_solve_trigmethod. As Harsh said it is no specific to
solveset, so I moved the method to
sets/sets.py. I added the doctests and test-cases in
Now solving the
expform directly using
solveset. This makes the less number of
ImageSetin many cases. But to solve equation having
tanin it, will be complicated, for that I changed the
solve_rationalmethod, so that it can handle
I. in denominator.
solvesetcan’t solve it using
expform. If this also can’t solve then retuns the
ConditionSethaving simple trig functions, which is understandable.
ImageSetor Union of
ImageSetand returns the minimum number of
First we extract the
Lambdaexpression from the each
ImageSetand take principle values. Separate the positive and negative principle values and sort them.
+ve and -ve values are passed into
interpolatemethod defined in
polys/polyfuncs.pyto get the general function in terms of Dummy
If only one
Imagesetor value in +ve or -ve value list then return that as it is. Here we need to note that Dummy
ndefined here is different then original lambda expression, so need to return original
imageset. So I am storing original
ImageSetin dict with its principle vales.
If more than one +ve/-ve values are there then interpolate expression will be
ImageSetexpression and return.
Here I separe the -ve and +ve values because interpolate returns complicated expressions if we both types of values.
Also I sorted the +ve and -ve list, to get simplified expression from interpolate.
- In this PR
imageset(Lambda(n, pi*(n - 1)), S.Integers)but I want
imageset(Lambda(n, n*pi), S.Integers).
- Meanwhile I found a issue in
2*sin(x) - 2*sqrt(3)*cos(x) - sqrt(3)*tan(x) +3 = 0can be easily solved if we factorize it correctly. But I haven’t found a good way to get its factor. I tried
expand(Trig + True),