ASKSAGE: Sage Q&A Forum - Latest question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 23 Sep 2020 02:48:15 -0500- Incorrect results for comparison expressionhttps://ask.sagemath.org/question/53548/incorrect-results-for-comparison-expression/Sage incorrectly evaluates `bool(1/47749 <= -5564456128*e + 15125759978)` as False.
In more detail, consider this:
sage: x = -5564456128*e + 15125759978
sage: (1/47749).n(digits=6)
0.0000209428
sage: x.n(digits=20)
0.000020943072740919888020
sage: bool(1/47749 <= x)
False
What is going on? Why does the last boolean evaluate to False? This results in the failure of the assertion that `1/ceil(1/x) <= x`, which should be true mathematically.
Is there a way to compare two quantities that will result in a correct answer, using as much precision as necessary?svatWed, 23 Sep 2020 02:48:15 -0500https://ask.sagemath.org/question/53548/
- possible bug in: _cmp_ functionhttps://ask.sagemath.org/question/48658/possible-bug-in-_cmp_-function/Hello,
on a 2019-release of sage, the following behaviour was observed:
After defining:
R = Zp(5)
a = R(5, 6)
b = R(10)
an inconsistent output was given for `a<b` and `b>a`:
a<b
False
b>a
True
Is this a bug, or should the output not be consistent here for some reason?
P.S: The comparison function is implemented in the file: `padic_generic_element.pyx`
Thank you.noaWed, 06 Nov 2019 14:23:41 -0600https://ask.sagemath.org/question/48658/
- comparison of PartitionTupleshttps://ask.sagemath.org/question/47965/comparison-of-partitiontuples/I find this issue with the coercion model for `PartitionTuples` confusing:
<pre><code>sage: P = PartitionTuples(level=2)
sage: P((p,p)) in P
True
sage: (p,p) in P
True
sage: P((p,p)) == (p,p)
False
</code></pre>
However as FrÃ©dericC notes below we have
<pre><code>sage: P((p,p)) == [p,p]
True
</code></pre>
Implementing `_richcmp_` and `__richcmp__` both in the element and in the category does not solve this issue as they are never called. Also in the list case if one tries to compare directly using `_cmp_` or their rich versions we'd get an exception. So I guess the comparison is happening at the Python level as follows:
<pre><code>sage: S = (p,p,p)
sage: T = P(S)
sage: L = [p,p,p]
sage: T.__eq__(S)
False
sage: T.__eq__(L)
True
</code></pre>heluaniWed, 18 Sep 2019 14:00:28 -0500https://ask.sagemath.org/question/47965/
- Automatic expression.maxima_methods().rootscontract() ?https://ask.sagemath.org/question/32705/automatic-expressionmaxima_methodsrootscontract/I have to compare quite a lot expressions and I like to do it with Sage.
Sadly something like
sqrt(x^3)/sqrt(x^2) == sqrt(x)
gives false in default mode sage. Here
expression.maxima_methods().rootscontract()
does help, but is there a automatic way doing that, at least for one notebook? (Btw, why is it not the default?) Shouldn't at least simplify_full be enough to trigger that?
Maybe worth another question:
Are there other pitfalls like this, I should be aware of?metabetaThu, 03 Mar 2016 11:39:50 -0600https://ask.sagemath.org/question/32705/
- Comparing numbers in an algebraic fieldhttps://ask.sagemath.org/question/24841/comparing-numbers-in-an-algebraic-field/I get a very strange results from comparison of number in an algebraic field, see the example:
version()
X = polygen(ZZ)
f = X^3 - 2*X^2 - 2*X - 2
Qb.<b> = QQ.extension(f, embedding=3)
b.N() # b is positive
0 < b # gives False; why?
0 < 1 # gives True; fine
Qb(0) < Qb(1) # gives False; WTF?
---
sage: version()
'Sage Version 6.1.1, Release Date: 2014-02-04'
sage: X = polygen(ZZ)
sage: f = X^3 - 2*X^2 - 2*X - 2
sage: Qb.<b> = QQ.extension(f, embedding=3)
sage:
sage: b.N() # b is positive
2.91963956583942
sage: 0 < b # gives False; why?
False
sage: 0 < 1 # gives True; fine
True
sage: Qb(0) < Qb(1) # gives False; WTF?
False
sage:
Can I do something to obtain the correct results of comparison, or is using the flawed `.N()` the only option?toheczWed, 12 Nov 2014 13:25:40 -0600https://ask.sagemath.org/question/24841/
- Comparing even powers of $i$ with 1https://ask.sagemath.org/question/10612/comparing-even-powers-of-i-with-1/Computing $i^4$ yields $1$, but it's not the same $1$ as when I type $1$. Compare these two evaluations:
sage: I^4 == 1
1 == 1
sage: I^2 == 1
-1 == 1
I would have expected the first to yield `True` and the second to yield `False`. Is Sage's answer a desirable default behavior?
I see that the first $1$ is a `sage.symbolic.expression.Expression` and the other $1$ is a `sage.rings.integer.Integer` (likewise for the $-1$). How can I make the comparison evaluate as one might reasonably expect mathematically?Ed ScheinermanTue, 15 Oct 2013 09:41:10 -0500https://ask.sagemath.org/question/10612/
- Comparaisons between different linux distributionshttps://ask.sagemath.org/question/10190/comparaisons-between-different-linux-distributions/Have you tested and compared the execution speed of different algorithms on different linux distributions?
Are there a faster linux distributions?
And moroplogoTue, 04 Jun 2013 06:58:16 -0500https://ask.sagemath.org/question/10190/
- matrix entry-wise comparison (masking)https://ask.sagemath.org/question/9549/matrix-entry-wise-comparison-masking/Hello,
I've heard that in some programming languages it is possible to "mask" your matrix. That is, I should be able to do something like
sage: M = Matrix([[1,2,3],[0,4,5],[0,0,6]])
sage: Z = zero_matrix(ZZ, 3)
sage: ( M == Z )
[False False False]
[True False False]
[True True False]
Or perhaps the matrix outputted would have 0's and 1's (that would be more convenient). Is there a way to do this in Sage, perhaps using some object other than a matrix?
Thanks!
shacsmugglerTue, 20 Nov 2012 06:43:49 -0600https://ask.sagemath.org/question/9549/
- Comparing objects in Pythonhttps://ask.sagemath.org/question/9475/comparing-objects-in-python/ sage: R = ZZ
sage: S = ZZ
sage: R == S
<False>
No really this comes up as "True", but for my class which I derived from the Ring Class, something like this comes up as False. How can I avoid this?SLOtoSFSat, 27 Oct 2012 22:22:44 -0500https://ask.sagemath.org/question/9475/
- comparing Expressions in pythonhttps://ask.sagemath.org/question/9394/comparing-expressions-in-python/Hi,
I have an Expression I want to compare:
> var('x,y')
> x+y == x+y
But this does not return `True`. Why?
SLOtoSFSun, 28 Oct 2012 11:12:00 -0500https://ask.sagemath.org/question/9394/
- Multiplying an inequality by -1.https://ask.sagemath.org/question/9207/multiplying-an-inequality-by-1/I am new to sage and wondering why it doesn't reverse the terms (or the sign) of an inequality when multiplying by -1. E.g.:
sage: var('x y')
(x, y)
sage: f = x + 3 < y - 2
sage: f*2
2*x + 6 < 2*y - 4 # preserves truth-value of f
sage: f*(-1)
-x - 3 < -y + 2 # reverses truth-value of f
Why?nbitsSun, 05 Aug 2012 00:22:01 -0500https://ask.sagemath.org/question/9207/