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] -
But
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 usereduce_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 inexpform (it’s fine). But then fraction and solving equation for it’s parts makes more number ofexp. If we have more number ofexpthen we get more number ofimageset, Since we_invertfor eachexpfactors. -
It retuns
ConditionSetwhen it can’t solve, but its expression is in ` expform mostly withI` and in complicated form. -
some times
_solve_as_polycan solve Trig equations, but it is not using it.
New implemention :
-
I added
reduce_imagesetinsolveset.pyto reduce the number of union returned by_solve_trigmethod. As Harsh said it is no specific tosolveset, so I moved the method tosets/sets.py. I added the doctests and test-cases intest_sets.py. -
Now solving the
expform directly usingsolveset. This makes the less number ofImageSetin many cases. But to solve equation havingtanin it, will be complicated, for that I changed thesolve_rationalmethod, so that it can handleexpwithI. in denominator. -
Now using
_solve_as_polywhensolvesetcan’t solve it usingexpform. If this also can’t solve then retuns theConditionSethaving simple trig functions, which is understandable.
reduce_imageset :
-
reduce_imagesettake theImageSetor Union ofImageSetand returns the minimum number ofImageSet. -
First we extract the
Lambdaexpression from the eachImageSetand take principle values. Separate the positive and negative principle values and sort them. -
+ve and -ve values are passed into
interpolatemethod defined inpolys/polyfuncs.pyto get the general function in terms of Dummyn. -
If only one
Imagesetor value in +ve or -ve value list then return that as it is. Here we need to note that Dummyndefined here is different then original lambda expression, so need to return originalimageset. So I am storing originalImageSetin 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.
Problems :
- In this PR
solveset_real(tan(x), x)returnsimageset(Lambda(n, pi*(n - 1)), S.Integers)but I wantimageset(Lambda(n, n*pi), S.Integers).
Issues :
- Meanwhile I found a issue in
solveset. issues/11194.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 triedfactor,expand(Trig + True),expand_trig,rewrite(sin).
Follow @shekharrajak