Skip to content

Releases: Hegelim/solveminmax

v0.1.4

05 Jul 09:21
ff5a6cb
Compare
Choose a tag to compare

New Features in v0.1.4:

  • Bring in everyone's favorite matplotlib, so now besides pure computation, you can visualize your results.
  • Incorporate OOP ideas and improved readability.
  • Add basic error-handling.
  • Now able to handle negative numbers.

v0.1.0

03 Jul 11:41
Compare
Choose a tag to compare

Github All Releases
Github All Releases
Github All Releases
Github All Releases
About:
solve-sum-minmax is a Python module that allows you to solve a sum of min/max equations
by taking advantage of the powerful sympy library. For instance, say you want to
solve this equation: min(400, 500x) + min(200, 500x) + min(0, 500x) = 700
with the assumption that x is within range (0, 1).
In Math, the rigorous way would
require you to set up all possible conditions, which
might result in huge computation.
Currently, there aren't any available packages in Python
that allows you to solve this kind of equation fastly and efficiently. Thus,
this package is developed to fill the void and hopefully be of use to the broad
population.


Quick Start:
Let's say you want to solve the equation
min(500, 600a) + max(400, 500a) = 500. However, solving it in Math means you
would have to set up the conditions, then solve the check for each one of them,
which sounds like a lot of work, especially for smart people like you
who know how to take advantage of existing tools. So you ask yourself,
"What if there is a library that lets me solve it like a piece of cake?" Well,
there is a library for you now! First off, you need to install it via pip
in your terminal like below:

pip install solve-sum-minmax

Then to solve your problem, simply type in these
codes in your Python console:

>>> from solve-sum-minmax import solver
>>> eq = "min(500, 600*a) + max(400, 500*a) = 500"
>>> solver.auto_solve(eq, "a")
FiniteSet(1/6)

Whola! In fact, this is a pretty complex problem, but
you just solved it with 3 lines of code. But hold on, what does it mean?
Let's break it down: the core function
auto_solve takes in two required parameters
equation and var_name. equation takes in a string of the equation you want to solve
and var_name lets you define your variable with flexibility, such as "a"
or "x", although currently, it only supports "a".
You can also pass in "low", "high", which lets you specify the range
of your variable. Further details are included in the docstring
if you are interested.


Perks:

  • Fast: the module solves a set of complex min and max equations usually
    under 100 ms, depending on your hardware.
    For example, for an equation as complex as below, it takes 7 ms on average to
    give you a solution:
>>> from solve-sum-minmax import solver 
>>> eq = "max(600*a, 400) + min(200*a, 500) + min(100, 300*a) + 50*a = 600"
>>> %timeit solver.auto_solve(eq, "a")
FiniteSet(4/11)
7.1 ms ± 225 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
  • Accurate: it handles exact Rational numbers and intervals.
  • Flexible:you have a lot of flexibility in defining your equation,
    see below.

Format guide:
Because the module depends heavily on regular expressions, please follow
the guide on how to define your equations carefully, or the module might break.
In a nutshell, wrap the equation you want to solve in a string with the format
similar to the example:

>>> eq = "20 + max(600*a, 400) + min(200*a, 500) + min(100, 300*a) + 50*a = 600"

Before we delve into explanations in details, let's define a few terms:

  • value_term: the value you want to solve your equation for, here it's 600.
  • minmax_term: it is what it means in English, for example, max(600*a, 400).
  • cons_var_term: terms with constants times variables, such as 50*a.

In brief, what you can do include:

  • put the variable either in the 1st or 2nd place inside the parenthesis, for
    example, either min(200, 300*a) or min(300*a, 200) is fine.
  • use min and max together in one equation.
  • use + and/or -.
  • have constants in front of min or max, such as 2*min(400, 400a).
  • have any space between each component.
  • have leading 0s before variable, such as min(0*a, 200).
  • have constants inside min or max, such as min(20, 30).

What you can't do include:

  • use == instead of =.
  • for the cons_var_term, have variables before constants, such as a*50
    instead of 50*a.
  • missing any parenthesis.
  • use other operators instead of + or -.
  • missing any necessary * operator for each variable.
  • put any constants on the left-hand side of the equation. Do me a favor, if
    you have any constants, subtract it from the right-hand side and
    rearrange your terms before using the module.

Limitations:

  • Currently, the module only supports "a" as the variable.
  • Because the module heavily depends on regular expressions,
    the user needs to follow the format of the
    equation carefully, or the module might break.
  • The equation must be uni-variate, i.e., there can only be one independent
    variable.

Version history:

Version Core Ideas Return Rationals Return Intervals Error Handling
v0.0.1 numerical methods No No No
v0.0.2 numerical methods No No No
v0.0.3 combinations Yes No No
v0.0.4 intervals Yes Yes No
v0.1.0 intervals Yes Yes Yes

Contact:

  • Email: [email protected]
  • Collaboration: collaborations are welcomed, please email me if you
    are interested.

v0.0.4

02 Jul 10:12
f438e67
Compare
Choose a tag to compare

About:
solve-sum-minmax is a Python module that allows you to solve a sum of min/max equations
by taking advantage of the powerful sympy library. For instance, say you want to
solve this equation: min(400, 500x) + min(200, 500x) + min(0, 500x) = 700
with the assumption that x is within range (0, 1).
In Math, the rigorous way would
require you to set up all possible conditions, which
might result in huge computation.
Currently, there aren't any available packages in Python
that allows you to solve this kind of equation fastly and efficiently. Thus,
this package is developed to fill the void and hopefully be of use to the broad
population.


Quick Start:
Let's say you want to solve the equation
min(500, 600a) + max(400, 500a) = 500. However, solving it in Math means you
would have to set up the conditions, then solve the check for each one of them,
which sounds like a lot of work, especially for smart people like you
who know how to take advantage of existing tools. So you ask yourself,
"What if there is a library that lets me solve it like a piece of cake?" Well,
there is a library for you now! First off, you need to install it via pip
in your terminal like below:

pip install solve-sum-minmax

Then to solve your problem, simply type in these
codes in your Python console:

>>> from solve-sum-minmax import solver
>>> eq = "min(500, 600*a) + max(400, 500*a) = 500"
>>> solver.auto_solve(eq, "a")
FiniteSet(1/6)

Whola! In fact, this is a pretty complex problem, but
you just solved it with 3 lines of code. But hold on, what does it mean?
Let's break it down: the core function
auto_solve takes in two required parameters
equation and var_name. equation takes in a string of the equation you want to solve
and var_name lets you define your variable with flexibility, such as "a"
or "x", although currently, it only supports "a".
You can also pass in "low", "high", which lets you specify the range
of your variable. Further details are included in the docstring
if you are interested.


Perks:

  • Fast: the module solves a set of complex min and max equations usually
    under 100 ms, depending on your hardware.
    For example, for an equation as complex as below, it takes 7 ms on average to
    give you a solution:
>>> from solve-sum-minmax import solver 
>>> eq = "max(600*a, 400) + min(200*a, 500) + min(100, 300*a) + 50*a = 600"
>>> %timeit solver.auto_solve(eq, "a")
FiniteSet(4/11)
7.1 ms ± 225 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
  • Accurate: it handles exact Rational numbers and intervals.
  • Flexible:you have a lot of flexibility in defining your equation,
    see below.

Format guide:
Because the module depends heavily on regular expressions, please follow
the guide on how to define your equations carefully, or the module might break.
In a nutshell, wrap the equation you want to solve in a string with the format
similar to the example:

>>> eq = "20 + max(600*a, 400) + min(200*a, 500) + min(100, 300*a) + 50*a = 600"

Before we delve into explanations in details, let's define a few terms:

  • value_term: the value you want to solve your equation for, here it's 600.
  • minmax_term: it is what it means in English, for example, max(600*a, 400).
  • cons_var_term: terms with constants times variables, such as 50*a.

In brief, what you can do include:

  • put the variable either in the 1st or 2nd place inside the parenthesis, for
    example, either min(200, 300*a) or min(300*a, 200) is fine.
  • use min and max together in one equation.
  • use + and/or -.
  • have constants in front of min or max, such as 2*min(400, 400a).
  • have any space between each component.
  • have leading 0s before variable, such as min(0*a, 200).
  • have constants inside min or max, such as min(20, 30).

What you can't do include:

  • use == instead of =.
  • for the cons_var_term, have variables before constants, such as a*50
    instead of 50*a.
  • missing any parenthesis.
  • use other operators instead of + or -.
  • missing any necessary * operator for each variable.
  • put any constants on the left-hand side of the equation. Do me a favor, if
    you have any constants, subtract it from the right-hand side and
    rearrange your terms before using the module.

Limitations:

  • Currently, the module only supports "a" as the variable.
  • Because the module heavily depends on regular expressions,
    the user needs to follow the format of the
    equation carefully, or the module might break.
  • The equation must be uni-variate, i.e., there can only be one independent
    variable.

Version history:

Version Core Ideas Return Rationals Return Intervals
v0.0.1 numerical methods No No
v0.0.2 numerical methods No No
v0.0.3 combinations Yes No
v0.0.4 intervals Yes Yes

Contact:

  • Email: [email protected]
  • Collaboration: collaborations are welcomed, please email me if you
    are interested.

v0.0.3

25 Jun 08:11
f7c9612
Compare
Choose a tag to compare

About:
solve-sum-minmax is used to solve a sum of min/max equations in python by
taking advantage of the powerful sympy library. For instance, say you want to solve this equation:
min(400, 500x) + min(200, 500x) + min(0, 500x) = 700
with the assumption that
x is within range (0, 1).
In Math, the rigorous way would
require you to set up all possible conditions, which
might result in huge computation.
Currently, there aren't any available packages in Python
that allows you to solve this kind of equation fastly and efficiently. Thus,
this package is developed to fill the void and hopefully be of use to the broad population.


Quick Start:
Let's say you want to solve the equation
min(500, 600a) + max(400, 500a) = 500. However, solving it in Math means you
would have to set up the conditions, then solve the check for each one of them,
which sounds like a lot of work, especially for smart people like you
who knows how to take advantage of existing tools. So you ask yourself,
"What if there is a library that lets me solve it like a piece of cake?" Well,
there is a library for you now! To solve your problem, simply type in these
codes below:

from solve-sum-minmax import solver
>>> eq = "min(500, 600*a) + max(400, 500*a) = 500"
>>> solver.solve_sum_minmax(eq, "a")
1/6

Dang, that's so cool😆😆! In fact, this is a pretty complex problem, but
you just solved it with 3 lines of code. But wait, what does it mean?
Let's break it down: the core function
solve_sum_minmax takes in two required parameters
equation and var_name. equation takes in a string of the equation you want to solve
and var_name lets you define your variable with flexibility, such as "a"
or "x" or any other characters in the alphabet except "m".
Optionally, you can also pass in "low", "high", which
lets you specify the range of your variable, and "decimal",
with details left out in the docstring if you are interested.


Features in 0.0.3:

  • Now the module is able to return exact values as fractions, such as 1/6.
  • When there isn't a solution, the function would return None.
  • you can put the variable either in the first place inside the parenthesis
    or in the second place.
  • you can use any characters in the alphabet except "m" for the variable.
  • you can use min and max together in one equation.
  • you can use + or -.
  • you can have constants in front of min or max, such as 2*min(400, 400a).

Limitations:

  • One of the biggest limitations now is when there are infinitely many solutions,
    the module cannot handle it well and would only return a single real number.
  • Because the module is written in a way that it heavily depends on regular
    expressions, it currently doesn't support "m" as user-defined variable name.
  • With the reason same as above, the user needs to follow the format of the
    equation carefully, or the module might break.
  • The equation must be univariate, i.e., there can only be one independent
    variable.

Contact:

  • Email: [email protected]
  • Collaboration: collaborations are welcomed, please send me an email if you
    are interested.