How to express relations of variables like x > y in a assume context?

127 views
Skip to first unread message

Max Linke

unread,
Oct 26, 2017, 12:13:34 PM10/26/17
to sympy


Hi

I'm trying to solve a integral with sympy.  To get meaningful results I need to tell sympy that the assumptions d1>d2>d3 hold for the variables
in the integral. I tried this unsuccessfully:

```python
with assume.assuming(Q.is_true(d1 > d2), Q.is_true(d2 > d3)):
    integrate(C2, (t, 0, oo)
```

I've attached a image of the function C2 and a here is a notebook with my attempt at solving the integral.

I appreciate help how to define these assumptions in sympy.

With google I haven't found anything helpful on this topic. Only a 4 year old SO post that this is not possible.

A colleague already checked with mathematica for me that given the assumption d1>d2>d3 the integral
converges. So a solution does exist.

best Max
Message has been deleted

Chris Smith

unread,
Oct 29, 2017, 11:36:17 PM10/29/17
to sympy
I get the following when using auxiliary variables to make true your assumptions.

>>> eq
(0.2*exp(t*(4*d1 + 7*d2 + 7*d3)) + 0.2*exp(t*(7*d1 + 4*d2 + 7*d3)) + 0.2*exp(t*(
7*d1 + 7*d2 + 4*d3)) + 0.4*exp(t*(6*d1 + 6*d2 + 6*d3 + 2*sqrt(d1**2 - d1*d2 - d1
*d3 + d2**2 - d2*d3 + d3**2))))*exp(-8*t*(d1 + d2 + d3))
>>> eq = nsimplify(eq)
>>> p,q=var('p,q',positive=True)
>>> factor_terms(nsimplify(eq.subs(d1,d3+p+q).subs(d2,d3+p).expand()))
(1 + 2*exp(-2*p*t)*exp(-q*t)*exp(2*t*sqrt(p**2 + p*q + q**2)) + exp(-3*p*t) + ex
p(-3*p*t)*exp(-3*q*t))*exp(-6*d3*t)*exp(-2*p*t)*exp(-q*t)/5
>>> _.integrate((t,0,oo))
Piecewise((2/(5*(1 + q/(d3*(3 + 2*p/d3)))*(1 - sqrt(p**2 + p*q + q**2)/(d3*(1 +
q/(d3*(3 + 2*p/d3)))*(3 + 2*p/d3)))*(6*d3 + 4*p)) + 1/(5*d3*(1 + 4*q/(d3*(6 + 5*
p/d3)))*(6 + 5*p/d3)) + 1/(5*d3*(1 + q/(d3*(6 + 5*p/d3)))*(6 + 5*p/d3)) + 1/(10*
d3*(1 + q/(2*d3*(3 + p/d3)))*(3 + p/d3)), (Abs(periodic_argument(polar_lift(d3)*
polar_lift(3 + p/d3), oo)) <= pi/2) & (Abs(periodic_argument(polar_lift(d3)*pola
r_lift(6 + 5*p/d3), oo)) <= pi/2) & (Abs(periodic_argument(polar_lift(d3)*polar_
lift(1 + q/(d3*polar_lift(3 + 2*p/d3)))*polar_lift(3 + 2*p/d3), oo)) < pi/2) & N
e(sqrt(p**2 + p*q + q**2)/(d3*(1 + q/(d3*(3 + 2*p/d3)))*(3 + 2*p/d3)), 1) & (-2*
sqrt(p**2 + p*q + q**2) + 2*cos(Abs(periodic_argument(polar_lift(d3)*polar_lift(
1 + q/(d3*polar_lift(3 + 2*p/d3)))*polar_lift(3 + 2*p/d3), oo)))*Abs(d3*(1 + q/(
d3*(3 + 2*p/d3)))*(3 + 2*p/d3)) > 0)), (Integral((1 + 2*exp(-2*p*t)*exp(-q*t)*ex
p(2*t*sqrt(p**2 + p*q + q**2)) + exp(-3*p*t) + exp(-3*p*t)*exp(-3*q*t))*exp(-6*d
3*t)*exp(-2*p*t)*exp(-q*t)/5, (t, 0, oo)), True))

Max Linke

unread,
Oct 30, 2017, 5:55:32 PM10/30/17
to sy...@googlegroups.com
Screenshot from 2017-10-30 22-44-41.png

I can get the same answer. But that result is not that nice to handle. I attached a solution the mathematica produces. It's a good bit more compact.

The additional symbols in the equation are:
D = 1/3(D_1 + D_2 + D_3)
Delta = \sqrt{D_1^2 + D_2^2 + D_3^2 - D_1 D_2 - D_1 D_3 - D_3 D_2}

It would be cool to be able to get the same answer with sympy.

--
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 post to this group, send email to sy...@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/3b675a36-dbe0-45e4-8891-dec9d8bcd99a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages