Den tors 18 feb. 2021 kl 14:36 skrev Oscar Benjamin < [email protected]>:
> On Thu, 18 Feb 2021 at 11:32, Oscar Gustafsson > <[email protected]> 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)) > Yes, a different assumption system will also do the trick. But until that is in place, this would be a useful short-cut for a specific use case. > 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. > > I seem to recall that I did something that rewrote/simplified, probably as part of the pattern based logic simplification, And(x <= y, x <= z) to x <= Min(y, z) At some later stage I realized it was sometimes a bad idea (as the logic simplification sometimes worked better without the Min/Max, do not recall exactly) and I sort of regretted introducing that rewrite, but cannot recall if the reverse operation was ever introduced. Piecewise may work though, but I believe that for the linear inequality simplifier it may be better to rewrite x <= Min(y, z) back to And(x <= y, x <= z) . BR 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/CAFjzj-LFb7wK25oVdyF6O2z3obo-qZYxuhRBawV%3DG2E1oGEBRA%40mail.gmail.com.
