Ask Your Question

carsten's profile - activity

2016-11-24 11:02:28 +0200 received badge  Student (source)
2016-11-24 02:03:14 +0200 asked a question problems with symbolic integration

I have recently asked a question on math.stackexchange concerning how to compute volumes of intersecting hypercubes and hyperspheres to which I got an extremely helpful answer. I would love to link there, but have insufficient karma.

Now, I'm trying to utilize sage to generate some analytic solution for the lowest dimensionalities. With my very naive understanding of sage, the help of google and some trial & error, I came up with the following solution:

from sage.symbolic.integration.integral import integral

R = var("R")
assume(R>0)
x = var("x")

V0(R) = 1
V = [V0]

for i in range(1,3):
    vlast = V[i-1]
    vnew(R) = integral( vlast(R=sqrt(R**2 - x**2)),x,-min_symbolic(R,1),min_symbolic(R,1))
    #,algorithm="fricas")
    V.append(vnew)        

print(V)

However, the output is not quite what I expected:

[R |--> 1, R |--> 2*min(1, R), R |--> 2*integrate(min(1, sqrt(R^2 - x^2)), x, -min(1, R), min(1, R))]

Somehow, the symbolic integrator seems unable to deal with this (relatively simple) function. As you can see from the code, I've already tried using fricas. That however results in

TypeError: sage1 := x=-min(R, 1)..min(R, 1)
   There are 1 exposed and 2 unexposed library operations named min having 2 argument(s) but none was determined to be applicable. Use HyperDoc Browse, or issue
                                                                                                                   )display op min
      to learn more about the available operations. Perhaps package-calling the operation or using coercions on the arguments will allow you to apply the operation.

   Cannot find a definition or applicable library operation named min with argument type(s) 
                                                                                                                     Variable(R)
                                                                                                                   PositiveInteger

      Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.

I'm not sure what to make of this error message. Do I understand correctly that there is no implementation for min available that is capable of dealing with a variable and an integer? That seems a little strange, given that this is such a fundamental functionality - or am I missing out on something here?

Any suggestion how to make it work are greatly appreciated!

2016-11-23 22:23:55 +0200 received badge  Notable Question (source)
2015-01-06 01:41:41 +0200 received badge  Popular Question (source)
2011-11-08 09:55:40 +0200 marked best answer strange behaviour when solving equations symbolically

This is actually pretty normal behavior. Let's compare some examples from the documentation.

      sage: x, y = var('x, y')
      sage: solve([x+y==6, x-y==4], x, y)
      [[x == 5, y == 1]]

So the answers appear in a list; in this case, the answer is two variables equalling something, so it is a list with one element which has two elements in it.

      sage: solve([sin(x)==x,y^2==x],x,y)
      [sin(x) == x, y^2 == x]

Here, Sage/Maxima doesn't know how to solve this, so it just returns a list with the original equations. And that is what is happening in your case too, only your equation is slightly rearranged and is long enough that the brackets appear above and below it because it doesn't fit on one line.

In general I don't know that one can expect all solutions - there is always a place a human will be smarter than the computer.

sage: S = solve(qe,r)[0]
sage: S.lhs()^2==S.rhs()^2
M^2 + r^2 == (u - sqrt(m^2 + r^2))^2
sage: S.lhs()^2==(S.rhs()^2).expand()
M^2 + r^2 == m^2 + r^2 + u^2 - 2*sqrt(m^2 + r^2)*u

But trying to solve the latter for r throws an error because it wants to know if something is positive. Here I intervene.

sage: T = M^2-m^2-u^2==-2*u*sqrt(m^2 + r^2)
sage: T^2
(M^2 - m^2 - u^2)^2 == 4*(m^2 + r^2)*u^2
sage: (T^2).expand()
M^4 - 2*M^2*m^2 - 2*M^2*u^2 + m^4 + 2*m^2*u^2 + u^4 == 4*m^2*u^2 + 4*r^2*u^2
sage: solve((T^2).expand(),r)
[r == -1/2*sqrt(M^4 - 2*M^2*m^2 - 2*M^2*u^2 + m^4 - 2*m^2*u^2 + u^4)/u, r == 1/2*sqrt(M^4 - 2*M^2*m^2 - 2*M^2*u^2 + m^4 - 2*m^2*u^2 + u^4)/u]

I have no idea if spurious solutions were introduced - squaring is dangerous! But the moral is that sometimes you have to do things 'by hand', even with computers.

2011-11-08 09:55:40 +0200 received badge  Scholar (source)
2011-11-08 09:55:30 +0200 received badge  Supporter (source)
2011-11-08 09:14:51 +0200 asked a question strange behaviour when solving equations symbolically

I'm new to sage and wanted to get startet. However, i tried solving equations symbolically and found a strang behaviour i do not understand. Can anybody explain to me this behaviour?

$ sage
----------------------------------------------------------------------
| Sage Version 4.7.1, Release Date: 2011-08-11                       |
| Type notebook() for the GUI, and license() for information.        |
----------------------------------------------------------------------
sage: r, u, m, M = var('r, u, m, M')
sage: qe = (u == sqrt(r^2 + m^2) + sqrt(r^2 + M^2))
sage: qe
u == sqrt(m^2 + r^2) + sqrt(M^2 + r^2)
sage: print solve(qe, r)
[
sqrt(M^2 + r^2) == u - sqrt(m^2 + r^2)
]
sage:

Any suggestions?