ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 23 Nov 2016 13:44:53 -0600problems with symbolic integrationhttp://ask.sagemath.org/question/35702/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!carstenWed, 23 Nov 2016 13:44:53 -0600http://ask.sagemath.org/question/35702/max_symbolic and distributive law with multiplicationhttp://ask.sagemath.org/question/26214/max_symbolic-and-distributive-law-with-multiplication/Minimum and maximum are distributive over multiplication of non-negative numbers, i.e., if a,b,c >= 0 then
a * max{ b, c } = max { ab, ac }
and the same works for min{}. How can I exploit this in sagemath? Consider the followiing:
n=5
x=var(['x_'+str(i+1) for i in range(n)])
# (x_1, x_2, x_3, x_4, x_5)
assume([x[i] >= 0 for i in range(n)])
assumptions()
# [x_1 >= 0, x_2 >= 0, x_3 >= 0, x_4 >= 0, x_5 >= 0]
This does **not** work as expected:
y = max_symbolic( x[4] * max_symbolic(x[0],x[1]), x[0] * max_symbolic(x[2],x[3]) )
# y == max(x_5*max(x_1, x_2), x_1*max(x_3, x_4))
simplify(y)
# max(x_1*max(x_3, x_4), x_5*max(x_1, x_2))
Simplify does not do the simplification I want it to do, which should yield
## max(max(x_1*x_3, x_1*x_4), max(x_5*x_1, x_5*x_2))
or even better
## max(x_1*x_3, x_1*x_4, x_5*x_1, x_5*x_2)
Needless to say, I have also tried `expand` and `full_simplify`. None of them does the trick.
So, I wonder, am I missing out on some other fancy function here, or is there a (hopefully easy) way to add a distributive law-feature to the max_symbolic function?BjornTue, 17 Mar 2015 00:12:56 -0500http://ask.sagemath.org/question/26214/