substitution with a condition

10 visualizações
Pular para a primeira mensagem não lida

Philippe Piot

não lida,
23 de mar. de 2020, 11:36:5523/03/2020
para sympy
Dear All, 
  I cannot figure out how to impose a condition. I have a function that is defined as a piecewise function. When it returns its results with several Min(x,y). I would like to substitute Min(x,X) with "x" since x<X. I have tried something like (here simplified as my function output as several terms). 
with assuming (x<X):
    print (Min(x,X))
but it does not work [i.e. it does not simplify Min(x,X) with x]. Thanks for any suggestions. 
  Best,  -- Philippe. 

Oscar Benjamin

não lida,
23 de mar. de 2020, 15:02:1023/03/2020
para sympy
Hi Philippe,

There isn't any way to do this properly right now.

We can't use inequalities like `x < X` but we can say that X = x+delta
where delta is positive:
```
In [3]: x, X = symbols('x X', real=True)

In [4]: e = Min(x, X)

In [5]: e
Out[5]: Min(X, x)

In [6]: delta = Symbol('delta', positive=True)

In [7]: e.subs(X, x+delta)
Out[7]: x
```

There is also the direct approach:
```
In [8]: e.subs(Min(x, X), x)
Out[8]: x
```

--
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 sympy+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/bdf779d5-e435-4985-bd76-7155914e1c6d%40googlegroups.com.
Responder a todos
Responder ao autor
Encaminhar
0 nova mensagem