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, 04 Jul 2018 06:32:58 -0500Assumptions and inequalitieshttp://ask.sagemath.org/question/42825/assumptions-and-inequalities/Hello all.
I have some expressions like **sums of ratios of real polynomials in a variable t**. Mathematically, by assuming t real in a specific interval, each such expression is either always positive, or always non-negative.
For Sage, this is **sometimes the case, sometimes not:** as you can see, the first one is correct, the second one not
<pre><code>
var('t')
expr1 = -1 + (t^2 - 1)/t^2 + 1/t^2
expr2 = (t^2 - 1)/(t^2 - 3)
with assuming(t > 0, t < 1/2):
print(bool(expr1 <= 0), bool(expr1 > 0))
print(bool(expr2 <= 0), bool(expr2 > 0))
</code></pre>
**Output:** (True, False) \n (False, False)
**Questions:** Why? How can I avoid this problem?
(An answer to the second question would be enough for me)
Thanks in advance :)yeahWed, 04 Jul 2018 06:32:58 -0500http://ask.sagemath.org/question/42825/Solving an inequality symbolically under constraintshttp://ask.sagemath.org/question/40456/solving-an-inequality-symbolically-under-constraints/Hello,
new to Sage. How would you go about this problem?
Assumptions:
a) e0, e1 are positive real numbers
b) e1 <= e0/2
Define:
A=e0/2-e1; (notice, greater than or equal to zero)
B=e0/2+e1; (equivalently, B=A+2e1)
Solve for e1:
Int(1/B)+2 >= 1/A, where Int(x) is the largest integer less or equal to x
Output:
An expression linking e0 and e1MurèneWed, 03 Jan 2018 22:07:00 -0600http://ask.sagemath.org/question/40456/Sage says equation isn't true while Mathematica says it ishttp://ask.sagemath.org/question/38795/sage-says-equation-isnt-true-while-mathematica-says-it-is/I have the following equation, of which I know that it is true when ```sigma > 0``` and ```mu > 0```.
eq = mu + 0.5*log(2*pi*sigma^2*e) == log(sqrt(2)*sqrt(pi)*sigma*e^(mu + 0.5))
So I set the constraints ```assume(sigma > 0)``` and ```assume(mu > 0)```. When evaluating it with ```bool(eq)```, Sage says ```False``` while Mathematica says that the equation holds. What am I doing wrong?muxamilianTue, 12 Sep 2017 08:22:24 -0500http://ask.sagemath.org/question/38795/a problem with variables in real domainshttp://ask.sagemath.org/question/37766/a-problem-with-variables-in-real-domains/Hi,
I have a problem with setting the domains of definition of variables.
For example, typing
var("y") ; assume(y, "real")
conjugate(y + I)
I get the result `y + I`. The same with `var("y", domain="real")`.
Where I'm wrong?
thanks!danieleFri, 02 Jun 2017 12:12:44 -0500http://ask.sagemath.org/question/37766/Why is assume() so slow?http://ask.sagemath.org/question/37744/why-is-assume-so-slow/Declaring assumptions using `assume()` takes an awful lot of time, e.g.:
var('a b c d e f g h i')
assume([(var1, 'real') for var1 in [a, b, c, d, e, f, g, h, i]])
The same applies to declaring variables with the `domain` option, e.g. `var('a', domain='positive')`.
See also https://cocalc.com/projects/34b4b62a-2621-47c8-9bda-cde3a855f995/files/test_assumptions.ipynb for an example. Does anyone know why this takes so much time and/or how this could be made faster? Thanks a lot!stanTue, 30 May 2017 16:39:08 -0500http://ask.sagemath.org/question/37744/How to save and load assumptions?http://ask.sagemath.org/question/35816/how-to-save-and-load-assumptions/ I use save_session() and load_session() to transfer data between worksheets, but I noticed that among other things, assumptions are not saved. So what I tried to do is save all assumptions in a separate list beforehand:
list_assumptions = assumptions()
save_session('temp/worksheet')
In the receiving worksheet, I tried:
load_session('temp/worksheet.sobj')
assumption1 = list_assumptions[1]
print assumption1
assumption1.assume()
but I get the following error:
a_s is real
TypeError: ECL says: Error executing code in Maxima: activate: no such context _SAGE_VAR_contextsage52
Interestingly, it works if I declare the assumption in the same way explicitly:
decl = sage.symbolic.assumptions.GenericDeclaration(a_s, 'real')
decl.assume()
And, by the way:
assumption1 == decl
True
Is this a bug, or am I doing something wrong? Thanks for your help!
stanWed, 30 Nov 2016 07:38:46 -0600http://ask.sagemath.org/question/35816/declare a variable as *not* an integer for solvehttp://ask.sagemath.org/question/34876/declare-a-variable-as-not-an-integer-for-solve/ I am trying to solve symbolically a simple equation for x:
solve(x^K + d == R, x)
I am declaring these variables and assumptions:
var('K, d, R')
assume(K>0)
assume(K, 'real')
assume(R>0)
assume(R<1)
assumptions()
︡> [K > 0, K is real, R > 0, R < 1]
Yet when I run the solve, I obtain the following error:
> Error in lines 1-1
>
> Traceback (most recent call last):
>
> File
> "/projects/sage/sage-7.3/local/lib/python2.7/site-packages/smc_sagews/sage_server.py",
> line 957, in execute
> exec compile(block+'\n', '', 'single') in namespace, locals
>
> ...
>
> File "/projects/sage/sage-7.3/local/lib/python2.7/site-packages/sage/interfaces/interface.py",
> line 671, in __init__
> raise TypeError(x)
>
> TypeError: Computation failed since Maxima requested additional constraints; using the 'assume' command before evaluation *may* help (example of legal syntax is 'assume(K>0)', see `assume?` for more details)
>
> **Is K an integer?**
Apparently, maxima is asking whether K is an integer? But I explicitly declared it 'real'!
How can I spell out to maxima that it should not assume that K is an integer?
ThanksAntoine-sacWed, 21 Sep 2016 04:11:14 -0500http://ask.sagemath.org/question/34876/Does right_kernel_matrix support assumptions over the symbolic ring?http://ask.sagemath.org/question/34385/does-right_kernel_matrix-support-assumptions-over-the-symbolic-ring/I'm trying to a basis for the kernel of a symbolic matrix. However, exactly quite what the kernel is depends on the assumptions that have been made. It seems that although other matrix functions (e.g. calculating the inverse) respect assumptions the kernel function doesn't. Here is an example:
var('x,y')
M = Matrix(SR, [[x, 0],[0,y]])
print(~M) # Gives expected inverse [[1/x, 0], [0,1/y]]
print(M.right_kernel_matrix()) # Gives [] as expected (if x, y != 0 then M is invertible so has trivial kernel)
assume(x == 0)
# print(~M) # Throws an error (ZeroDivisionError)
print(M.right_kernel_matrix()) # Still gives [], whereas the kernel now has basis [(1, 0)]
Am I missing something here? Is it possible to use this function with assumptions?exodusTue, 09 Aug 2016 09:51:57 -0500http://ask.sagemath.org/question/34385/variable assumptionhttp://ask.sagemath.org/question/33126/variable-assumption/I have an expression in term of an independent variable $q$. Now, I would like to assume that $q$ is an arbitrary $14$-th root of unity (i.e. $q^{14}=1$).
It is not allow to evaluate in any primitive root of unity, say $\eta$, since the coefficients of my expression are in the $7$-th cyclotomic field (i.e. the field is generated by $\xi=e^{2\pi i/7}$), so $\eta$ is in the field.
I also tried with "assume(q^14==1)", but it didn't work.
How can I do?
**Added after Bruno's comment**: Here is an example. I have the expression
exp=q^16*xi^5 + (q^325-12*q^235)*xi^2.
where q is an independent variable and xi is the 7th-root of unity with least argument. In other words, I have an expression in terms of an independent variable q with coefficients in the 7-th cyclotomic field
K.<xi> = CyclotomicField(7)
Now, I want to assume that $q^{14}=1$, thus the resultant expression should be
q^2*xi^5 + (q^3-12*q^11)*xi^2
since $16\equiv 2\pmod {14}$, $325 \equiv 3\pmod {14}$ and $235\equiv 11\pmod {14}$.
How can I do that? Note that it is not sufficient to evaluate the expression in $q=$some primitive $14$-th root of unity, since $q$ can be $+1$ or $-1$.
Please, think that the expression have thousands of terms, so I cannot do it by hand as above.
emiliocbaFri, 15 Apr 2016 18:49:39 -0500http://ask.sagemath.org/question/33126/Extract equalities from a list of assumptionshttp://ask.sagemath.org/question/32008/extract-equalities-from-a-list-of-assumptions/Hi,
how can I recognize an equality from an inequality, in a list of assumptions?
thanks, danieleSun, 03 Jan 2016 07:49:04 -0600http://ask.sagemath.org/question/32008/Substitution of parametershttp://ask.sagemath.org/question/31314/substitution-of-parameters/I would like to understand what is the correct and more efficient way for performing sostitution of parameters in objects of some category.
For example, a typical problem for me is the following. I have a 1-form in an ExteriorAlgebra, whose coefficients depends on some variable, let's say t. I find conditions on such parameters, let's say, t should be zero in order that some property holds. (In general, i will have solutions of linear systems.) I try to use "substitute" for setting the parameter to be 0, but this does not work to me..
E.<x,y> = ExteriorAlgebra(SR)
_=var("t")
theta = 3*x+t*y
print "theta = ", theta
theta2 = theta.substitute({t:0})
print "modified theta = ", theta2
Another solution I tried is the following. I assume t==0 at a certain point. But this seems to me to force the substitution before too.
E.<x,y> = ExteriorAlgebra(SR)
_=var("t")
theta = 3*x+t*y
print "theta = ", theta
assume(t==0)
theta2 = theta
print "modified theta = ", theta2
Thanks in advance for any suggestions!danieleFri, 04 Dec 2015 03:05:49 -0600http://ask.sagemath.org/question/31314/order of assumehttp://ask.sagemath.org/question/31318/order-of-assume/I am working on cloud-sagemath. I have a question on how "assume" works.
I type:
E.<x,y> = ExteriorAlgebra(SR)
_ = var('t')
psi = t*x+y
assume(t==0)
psi
when I check the output the first time with shift+enter, I just get
> t * x + y
The second time, I get the expected answer:
> y
Why? how to force the second answer since the beginning?
thanks in advance!danieleFri, 04 Dec 2015 04:34:49 -0600http://ask.sagemath.org/question/31318/Problem with assumption (in RR)http://ask.sagemath.org/question/26854/problem-with-assumption-in-rr/ Hello,
The following code returns the value "False", and I don't understand why. Does 'assume' and 'in RR' work fine together ?
sage: var('alpha')
sage: assume(alpha,'real')
sage: alpha in RR
False
Thank you by advance
Please excuse me for the mistakes, I'm French.
gblotMon, 18 May 2015 00:55:15 -0500http://ask.sagemath.org/question/26854/Condition in sum() function?http://ask.sagemath.org/question/24946/condition-in-sum-function/ Hello,
I'm trying to use the exponential form of the Fourier series representation of a function to plot an approximation of said function using the first five terms.
The actual function is f(t) = 1/2 + j/(2*pi) * E from (n = -5) to (n = 5) of ((-1)^n - 1)/n * e^(j*2*n*pi*t), where n =/= 0
Here I'm using 'E' to indicate summation notation. I apologize if this deviates from an established standard, but I'm having trouble uploading images right now (which would have made the function clearer).
The code I'm using for this function is
var('n, t')
j = i # imaginary unit
expr = ((-1)^n - 1)/n * exp(2*pi*n*j*t) # I think the problem is the division by 'n' here
assume(n, 'integer'); assume(n != 0)
f(t) = 1/2 + j/(2*pi) * sum(expr, n, -5, 5)
However, when I try this, I get the following exception:
<code>
RuntimeError: ECL says: Error executing code in Maxima: expt: undefined: 0 to a negative exponent.
</code>
This seems to be due to the division by <code>n</code> in <code>expr</code>. Are my assumptions not working here? Thus, my actual question is how can I add the condition <code>n != 0</code> to the <code>sum()</code> function in sage?mpattonSat, 22 Nov 2014 12:50:08 -0600http://ask.sagemath.org/question/24946/symbolic integrationhttp://ask.sagemath.org/question/10724/symbolic-integration/Hi,
I am a sage-noob. To calculate the vortex sheet of a flat plate in potential flow, I have to solve some integrales of such a king:
**Mathematica syntax:** Integrate[Exp[-I * t * 2 * m * k]*((1/t+1)^0.5-1),t,0, Infinity]
And this is the reult:
If[Im[k m] < 0,
((0. + 0.5 I) - (0. + 0.886227 I) HypergeometricU[-0.5, 0, (2 I) k m])/km
My approach in **Sagemath** is:
f(x) = exp(-I*x*2*m*k)*((1/x+1)^0.5-1)
integral(f, x, 0, infinity)
But Sagemath is asking for assumptions regarding m and k. Im[k m] < 0 would be the appropriate assumption. What would be the right syntax? Thank you very much for your answers.
Best wishes, Chris
chris42Mon, 11 Nov 2013 02:24:05 -0600http://ask.sagemath.org/question/10724/Assumptionshttp://ask.sagemath.org/question/9509/assumptions/ var("a b")
assume(b > 0, b < 1, a > 0, a < 1)
bool(a*b < 1)
returns false, why?petresWed, 14 Nov 2012 04:59:18 -0600http://ask.sagemath.org/question/9509/Assumptions in sagehttp://ask.sagemath.org/question/9470/assumptions-in-sage/Hello!
I am a sage beginner and I wish to know that How sage handles assumptions ?
My example is as follows.
a= var('a');
solve((a-1)*x ==3, x);
and sage solves and gives correct solution [x==(3 / (a - 1))].
But here how the assumption (a != 1) is handled ? Because solution is not defined for (a=1).
Best regards
Charmi
sage_learnerThu, 25 Oct 2012 10:04:20 -0500http://ask.sagemath.org/question/9470/Piecewise assumptions (for integration)http://ask.sagemath.org/question/8710/piecewise-assumptions-for-integration/All right, still with these integration problems, and I don't know all the subtleties of passing extra-arguments to Maxima (ok, I reckon that @kcrisman doesn't stop pointing out Maxima flags now and then when some expert uses them but some list would be very handy).
What I want is to integrate a function with the domain of integration broken into pieces. The problem is that the maxima engine requires different assumptions for each piece but an assumption seems to tie a variable globally.
**Example**: In fact, this example is still related to the [double integral thread over there](http://ask.sagemath.org/question/1077/symbolic-expectations-and-double-integrals). After a little but tedious pen and paper work, I could get rid of the absolute value by breaking the domain of integration into pieces but then I'm stuck again. Independently of my own shortcomings and maybe the hard nature of what I tried to compute, in my sense, the remaining problem causes are mainly twofold, we need to talk to Maxima (pass assumptions) and the assumption mechanisms in Sage are somehow weak.
This is what I tried to get around these shortcomings and to answer the above question:
# This could take extra-arguments for the integral function (algorithm, ...) but I don't know all of them, so let's leave this as is for now.
def integral_assumptions(f, var, lbound, ubound, extra_assumptions):
old_assumptions= assumptions() # Keep current assumptions for later restore
assume(extra_assumptions)
result = integral(f, var, lbound, ubound)
forget()
assume(old_assumptions) # Unfortunately, extra assumptions don't stay local
return result
Different problems arise:
1- If the integral call breaks (and this often occurs), the old_assumptions are not restored .. ok, this one should be easy and dealt with some exception handling but I don't know the Sage coding guideline here.
x,y,u,v,p,k,b=var('x,y,u,v,p,k,b') # It seems enough to just say var('x,y,u,v,p,k,b') but I'm not sure
n(x)=1/sqrt(2*pi) * exp(-1/2*x^2) # I would have loved to be able to get this directly from Maxima but okay, it was just a few keystrokes away.
# I need to split at -sqrt(k-1)*v
alpha_neg(v,k,p)=integral_assumptions((u)^p*(u+sqrt(k-1)*v)^p*n(v)*n(u), u, 0, -sqrt(k-1)*v, [k-1 > 0, v < 0])
integral(alpha_neg(v, k, p), v, -oo, 0) # Error
alpha_neg(v,k,2) # Still an error but just to find the culprit
2- One **big** problem is the way Sage handles assumptions: they are global and (but maybe that *feature* is because of the fact that ...) they can't be made more stringent. Namely `assume(x>=0); assume(x>0)` doesn't yield x>0. It would have also been handy to be able to say forget(x>0) and it would give back x>=0 and have a forget_about(x) function which forgets everything about x ..
To be clear, I'm not against global assumptions but I just want some way to enforce extra assumptions locally.
3- Another bonus feature would have been the possibility of attaching a set of assumptions to an expression/function/whatnot. In fact I started with:
#inner_neg as we're on the part where v<0.
inner_neg(v, k, p, i_lo, i_hi)=integral_assumptions((u)^p*(u+sqrt(k-1)*v)^p*n(v)*n(u), u, i_lo, i_hi, v < 0)
g(v,k)=inner_neg(v, k, 1, 0, oo) # -sqrt(k-1)*v) # Ok with oo
If I instead ask with `-sqrt(k-1)*v`, Maxima again complains about vGreen diodSun, 12 Feb 2012 12:29:54 -0600http://ask.sagemath.org/question/8710/