ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 29 Mar 2023 09:43:21 +0200Why does this non-zero integral evaluate to 0?https://ask.sagemath.org/question/67139/why-does-this-non-zero-integral-evaluate-to-0/I want to perform formal computations using SageMath, which involve integrals of trigonometric functions. I noticed some inconsistencies and narrowed my issues down to the following basic problem.
Why does the following source code return 0?
<pre>
var('n t')
assume(n, 'integer')
integrate(cos(2 * pi * n * t), t, 0, 1)
</pre>
While I agree that the integral is zero when `n` is non-zero, mathematically, the integral is worth 1 when `n` is zero. Up to my understanding, I only tell SageMath that `n` is an integer here, so it should handle the case `n = 0` also.
I checked that `integrate(cos(2 * pi * 0 * t), t, 0, 1)` correctly returns 1, so SageMath seems to be aware of this possibility, but somehow misses the fact that `n` could be 0.
What am I missing?cs89Wed, 29 Mar 2023 09:43:21 +0200https://ask.sagemath.org/question/67139/Solve within assumptionshttps://ask.sagemath.org/question/60084/solve-within-assumptions/I am trying to get the solutions of an inequality which has several variables. These variables move within intervals I have defined with `assume`. When I call `solve` the assumptions seem to be ignored. Below is my code:
variables = var('n_s','alpha','n_p','m','omega_p')
for variable in variables:
assume(variable, 'real')
for refractive_index in {n_s, n_p}:
assume(refractive_index > 1)
assume(0 < alpha, alpha < 1)
assume(omega_p > 0)
assume(m > 0)
assume(m < omega_p)
Xi = ((1-alpha)**2-(m/omega_p)**2)**(1/2)
expression = (n_s**2*alpha**2 + n_p**2 - Xi)/(2*n_p*n_s*alpha)
solve([1>expression],[n_p])
and this produces the following output
[[0 < n_p,
0 < n_s,
0 < alpha,
-alpha^2*n_s^2 + 2*alpha*n_p*n_s - n_p^2 + sqrt((alpha^2 - 2*alpha + 1)*omega_p^2 - m^2)/omega_p > 0],
[n_p < 0,
0 < n_s,
alpha < 0,
-alpha^2*n_s^2 + 2*alpha*n_p*n_s - n_p^2 + sqrt((alpha^2 - 2*alpha + 1)*omega_p^2 - m^2)/omega_p > 0],
[0 < n_p,
n_s < 0,
alpha < 0,
-alpha^2*n_s^2 + 2*alpha*n_p*n_s - n_p^2 + sqrt((alpha^2 - 2*alpha + 1)*omega_p^2 - m^2)/omega_p > 0],
[n_p < 0,
n_s < 0,
0 < alpha,
-alpha^2*n_s^2 + 2*alpha*n_p*n_s - n_p^2 + sqrt((alpha^2 - 2*alpha + 1)*omega_p^2 - m^2)/omega_p > 0],
[0 < n_p,
0 < n_s,
alpha < 0,
alpha^2*n_s^2 - 2*alpha*n_p*n_s + n_p^2 - sqrt((alpha^2 - 2*alpha + 1)*omega_p^2 - m^2)/omega_p > 0],
[n_p < 0,
0 < n_s,
0 < alpha,
alpha^2*n_s^2 - 2*alpha*n_p*n_s + n_p^2 - sqrt((alpha^2 - 2*alpha + 1)*omega_p^2 - m^2)/omega_p > 0],
[0 < n_p,
n_s < 0,
0 < alpha,
alpha^2*n_s^2 - 2*alpha*n_p*n_s + n_p^2 - sqrt((alpha^2 - 2*alpha + 1)*omega_p^2 - m^2)/omega_p > 0],
[n_p < 0,
n_s < 0,
alpha < 0,
alpha^2*n_s^2 - 2*alpha*n_p*n_s + n_p^2 - sqrt((alpha^2 - 2*alpha + 1)*omega_p^2 - m^2)/omega_p > 0]]
This is clearly ignoring the assumptions, for example the second solution has `alpha < 0`. Is it possible to somehow check for my assumptions automatically?
iovcrerufTCRRYSat, 04 Dec 2021 18:23:16 +0100https://ask.sagemath.org/question/60084/max_symbolic, polynomial expressions, assumptionshttps://ask.sagemath.org/question/56120/max_symbolic-polynomial-expressions-assumptions/ The following works as expected:
var('b')
with assuming(b>1):
v = max_symbolic(7*b-5,0).full_simplify()
print(v)
yields 7*b - 5
The following does not (maybe my expectations are unrealistic)
with assuming(b>1):
v = max_symbolic(b^2-b+1,0).full_simplify()
print(v)
yields max(0, b^2 - b + 1), even though the latter expression is always > 3/4
I have a bunch of expressions such as the one below, that I want to analyze, to get a piecewise-defined function:
print(myexpr,"\n\n")
print(myexpr.full_simplify(),"\n\n")
with assuming(a>2):
print(myexpr.full_simplify(),"\n\n")
max(max(3, a + 1) + 2*max(2*max(3, a + 1) + 1, a + max(3, a + 1)), a*max(3, a + 1) + max(2*max(3, a + 1) + 1, a + max(3, a + 1)))
max(max(3, a + 1) + 2*max(2*max(3, a + 1) + 1, a + max(3, a + 1)), a*max(3, a + 1) + max(2*max(3, a + 1) + 1, a + max(3, a + 1)))
max(5*a + 7, a^2 + 3*a + 3)
This is good, however:
with assuming(a>2000):
print(myexpr.full_simplify())
yields max(5*a + 7, a^2 + 3*a + 3)
Can such expressions, as above, in max_symbolic be converted into piecewise defined functions? (I would also be interested in having
more than one parameter, and having SAGE partition the parameter space appropriately and automatically).
JTSThu, 11 Mar 2021 13:39:33 +0100https://ask.sagemath.org/question/56120/