Hello everyone!
As part of my final project in my computer science degree I would like to develop a class for linear inequalities simplifying. The class's main algorithm is that for given a set of linear inequalities in m variables, it returns a simplified set. "Simplified" may mean an equivalent set with a smallest number of inequalities. As an example, given the inequalities:
x+y≥1
x+y≤0
the algorithm should return the empty set. Given the inequalities:
x+y≥1
2x+2y≥3
the algorithm should return e.g.
2x+2y≥3
The class will also implement operator overloading for + (adding one set to another) and – (removing a subset from original set) and more.
For this project to work I need to fully understand the implemented inequality classes in SymPy which are in sympy.core.relational, so I would know how to manipulate SymPy's inequalities.
The problem is that when I am trying to go through the code of those classes I get lost. There are so many subclasses there and every subclass is inheriting from some other base class.
Is there a way to see a class diagram of those classes so it would be more clear what the purpose of each class is? Does anyone have another idea for understanding those classes?
Hey Oscar,
sorry for the late reply, I was overloaded with exams.
For your first question, I intend to create a new function that when given a set of linear inequalities and a target inequality it would output True if the target is implied by this set, False if it is not, and Unknown otherwise. I wrote doctests to make it all more clear.
You can see it here –
https://github.com/orielmalihi/Final-Project/blob/main/iset%20tests.py
(the main function there is called 'is_implied_by')
For your second question, I intended to use Scipy LP solver, but as far as I can tell it only works with floats. I could convert every coefficient to float using the 'evalf()' function but then we would get 99.9% accurate results and not 100%.
Other option is to use the LP solver suggested by Lee (above), but it is unclear for me how it works, since it has no documentation of input/output. Moreover, I ran the example mentioned there with Scipy LP solver and got different results somehow. (if I understood right, Matric A is the lhs of the constraints, matric B is the rhs, matric c is the objective, and D is the lower bounds. if I am wrong I would be happy if you could tell me why)
--
You received this message because you are subscribed to a topic in the Google Groups "sympy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sympy/udUZ_U-mAh4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sympy+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/a69bc5a0-abf6-401a-9004-7c7eedbfdf8dn%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/311732de-ed2f-4d62-9a3e-5efd757b1d1en%40googlegroups.com.
I understand.
So I would use the LP solver implemented by Lee which should work with symbolic coefficients.
--
You received this message because you are subscribed to a topic in the Google Groups "sympy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sympy/udUZ_U-mAh4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sympy+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAHVvXxQb4TEb7tPov6df5Vv2P-d4XYSKpi3xqUHY5w%2BuTCx2pQ%40mail.gmail.com.
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAMEnX6gOMEDJ1qf8ga1sQG8ggTBpG6spP1jRfywsDtWZRcvWKA%40mail.gmail.com.
On Thu, 18 Feb 2021 at 11:32, Oscar Gustafsson
<oscar.gu...@gmail.com> wrote:
>
> After currently using Mathematica for similar things, I would just like to encourage you to provide some nice method to simplify constraints of piecewise functions using your simplifier, including additional constraints on the range of variables (as SymPy doesn't have a way to put ranges on variables). That doesn't really exist in Mathematica (Assuming[..., Simplify[piecewise]) doesn't always seems to simplify as far as possible).
>
> Something like
> simplify_piecewise_range(piecewisefunction, common_constraints)
> That adds the common_constraints to each region constraint and applies your method. (Possibly, optionally, removing the common_constraints from the final regions if feasible.)
I imagined that this would be something that the new assumptions could
handle in refine. Something like:
p = Piecewise((x, x < 1), (x**2, True))
p = refine(p, abs(x) < 1)
The idea would then be that e.g. when you have Integral(f, (x, a, b))
then the integration routine can do
f = refine(f, (a < x) & (x < b))
> There is an old PR which may be useful to revive in relation to this: https://github.com/sympy/sympy/pull/17443 although sort of independent.
>
> It will also be useful to have a function that can replace Min/Max expressions with linear inequalities (and possibly back again). Right now there is some logic to convert from linear inequalites to Min/Max, but not back. As far as I recall. (There may be a PR doing the Min/Max to linear as well, but not really sure.)
Is this what you mean?
In [1]: Min(x, y).rewrite(Piecewise)
Out[1]:
⎧x for x ≤ y
⎨
⎩y otherwise
Perhaps there could be a rewrite(Max) for Piecewise.
Hello everyone!
I finally completed implementing these functions.
Quick reminder:
The main function is called is_implied_by and it gets a set of linear inequalities and
a target linear inequality and return whether the target is implied by the set
or not.
Two other functions are find_values_interval and simplify_linear_inequalities.
find_values_interval gets a set of linear inequalities and a target expression (expr) and returns an interval of [min possible value for expr, max possible value for expr].
simplify_linear_inequalities gets a set of linear inequalities and returns a simplified set (redundant inequalities are removed).
Now I would like to know what are the
next steps for me to do in order to get my implementation into sympy. This is my
first time contributing so detailed explanation would be really helpful.
--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/07668755-217b-4487-805d-1faefd70191bn%40googlegroups.com.