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.Thu, 20 Feb 2014 22:49:58 +0100Testing inequalities in sagehttps://ask.sagemath.org/question/10388/testing-inequalities-in-sage/I wanted to show if:
$$ |a+b| \leq |a| + |b|$$
So I wrote this in sage:
var('a','b')
eqn1=abs(a+b)
eqn2=abs(a)+abs(b)
bool(eqn1<=eqn2)
The result is False.
I had expected the result to be True. What is the correct way to test this in sage?
Thank you in advance for any help provided.ensabaFri, 26 Jul 2013 08:22:04 +0200https://ask.sagemath.org/question/10388/Determine rationality of an expression?https://ask.sagemath.org/question/11067/determine-rationality-of-an-expression/I am trying to determine whether an expression is rational or not - and if it rational, to get the numerator and denominator.
To give you some context, I first use "solve" to get a `[ x == ..., y == ... ]` solution, and then I compute `log(solution[x])/log(solution[y])`. In some cases, this expression is a rational. I would like to be able to determine when it is a rational.
Of course it is rational in some very predictable cases - i.e., when the two logarithms are commensurate, and there are ways of checking this on the value of `solution[x]` and `solution[y]` themselves. But I am hoping that sage can do this for me.
I tried to do `Rational((log(...)/log(...)).n())` or `(log(...)/log(...)).n() in QQ`, but of course that does not work, as `.n()` converts the expression to some arbitrary precision float. Doing `(log(...)/log(...)) in QQ` always returns False even, for instance, for the case `(log(100)/log(10)) = 2`.
How can I do this?JeremieThu, 20 Feb 2014 22:49:58 +0100https://ask.sagemath.org/question/11067/Compare symbolic expressionshttps://ask.sagemath.org/question/10185/compare-symbolic-expressions/Following is the problem I am trying to solve:
I have multiple complex symbolic expressions f1(x1,x2,...,xn),f2(x1,x2,...,xn),...,fn(x1,x2,...,xn) which are functions of symbolic variables x1,x2,...,xn. I also have some constraints for the symbolic variables, e.g. 0 is smaller than x1, 2 is smaller than x2, x2 is integer, etc. How can I find out for two selected symbolic expressions which one is larger for given constraints?
I've tried something like:
<code> assume(0<x1,2<x2)
assume(x2,'integer')
bool(f1>f2) </code>
It seems to work for more simple symbolic expressions. For more complex symbolic expressions (where a solution definitely exists) SAGE seems not to be able to compare the expressions. Is there a way to overcome this?
KurtMMon, 03 Jun 2013 11:51:40 +0200https://ask.sagemath.org/question/10185/Compare elements of a recursive defined sequencehttps://ask.sagemath.org/question/10163/compare-elements-of-a-recursive-defined-sequence/I define the recursive sequence as:
A, b, c = var('A, b, c')
def Sequence_rec(k):
x = 0
for i in range(1,k+1):
x = x + (A - x)/((c-i+2)^b)
return x
For the parameters the assumptions are:
assume(A>0,c>0,b>0)
assume(c, 'integer')
I'm interested in the elements of Sequence_rec(k) with k<=c. The following relation has to be true for the defined sequence considering the given assumptions:
assume(c>2)
bool(Sequence_rec(4) > Sequence_rec(3))
But Sage computes it is false! The following plot shows the difference is positive:
plot((Sequence_rec(4) - Sequence_rec(3))(A=1,c=3),b,(0,100))
How can I force Sage to compare the elements of the sequence `bool(Sequence_rec(n+1) > Sequence_rec(n)) = true` for any positive integer n correctly? Thank you for your advice!
Kurt
KurtMWed, 29 May 2013 11:02:26 +0200https://ask.sagemath.org/question/10163/Assumptionshttps://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 11:59:18 +0100https://ask.sagemath.org/question/9509/bool returns false with arcsin(x) and 2*arctan(x/(1+sqrt(1-x^2)))https://ask.sagemath.org/question/7762/bool-returns-false-with-arcsinx-and-2arctanx1sqrt1-x2/The two expression should be equal
but when I write
bool(arcsin(x) == 2*arctan(x/(1+sqrt(1-x^2))))
it returns false.
Any clue - Why it does that? Any get around?ShuFri, 12 Nov 2010 14:40:25 +0100https://ask.sagemath.org/question/7762/