On Sun, 27 Dec 2020 at 10:46, אוריאל מליחי <[email protected]> wrote: > > Hello everyone!
Hi, > As part of my final project in my computer science degree I would like to > develop a class for linear inequalities simplifying. That sounds like an excellent project. To be clear, are you intending for this to be incorporated as part of sympy? Handling systems of inequalities is a feature that is currently missing from sympy but the most useful way to add it would really be as a function or several functions rather than a class (although the function could use a class internally). > 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 Or perhaps: x+y >= 3/2 It would be useful to have a function for making a subset of the symbols in an inequality become the subject. There already is a function for this but it doesn't work for systems of inequalities with multiple unknowns: In [1]: from sympy.solvers.inequalities import reduce_inequalities In [2]: ineq = x + y > 2 In [3]: reduce_inequalities(ineq, [x]) Out[3]: x > 2 - y In [4]: reduce_inequalities(ineq, [y]) Out[4]: y > 2 - x In [5]: reduce_inequalities([x+y > 2, x < 1], [x, y]) --------------------------------------------------------------------------- NotImplementedError inequality has more than one symbol of interest. > The class will also implement operator overloading for + (adding one set to > another) and – (removing a subset from original set) and more. This is already handled by Python's built in set class so it isn't really necessary to make a class for this. We can just put the inequalities in a set. > 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? The codebase for sympy is large which means it takes time to understand. You can see the inheritance scheme for these classes with mro: In [6]: LessThan.mro() Out[6]: [sympy.core.relational.LessThan, sympy.core.relational._Less, sympy.core.relational._Inequality, sympy.core.relational.Relational, sympy.logic.boolalg.Boolean, sympy.core.basic.Basic, sympy.printing.defaults.Printable, sympy.core.evalf.EvalfMixin, object] Here Printable and EvalfMixin are mixins that provide printing support and make it possible to use .evalf() e.g.: In [7]: x < pi Out[7]: x < π In [8]: _.evalf() Out[8]: x < 3.14159265358979 Basic is a fundamental class in sympy. Most sympy objects are instances of Basic. Basic is used to represent mathematical objects as trees and to implement operations like subs working over those trees. You can see an explanation of that here: https://docs.sympy.org/latest/tutorial/manipulation.html (Surprisingly that page doesn't actually mention Basic!) Boolean is a subclass of Basic for objects representing boolean True/False. The Boolean class provides operations like `&` and `|` representing "and" and "or" (as well as many other operations): In [9]: (x < pi) & (y < 3) Out[9]: x < π ∧ y < 3 Relational is a subclass of Boolean and is the common superclass for LessThan, StrictLessThan, Equality, Unequality, GreaterThan and StrictGreaterThan representing the 6 types of relation in sympy (`<=, <, ==, !=, >=, >`). The classes `_Inequality` and `_Less` are used for sharing/dividing code between the different inequality classes. -- Oscar -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAHVvXxRZEBdprrsXHOZPndEgRyv2WAcgjmio6WN-i21hxaOAhg%40mail.gmail.com.
