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.Tue, 03 Dec 2019 10:13:08 -0600Mistake in SageMathCell code, finding integral points on elliptic curveshttps://ask.sagemath.org/question/48933/mistake-in-sagemathcell-code-finding-integral-points-on-elliptic-curves/ I've the following number:
$$12\left(n-2\right)^2x^3+36\left(n-2\right)x^2-12\left(n-5\right)\left(n-2\right)x+9\left(n-4\right)^2\tag1$$
Now I know that $n\in\mathbb{N}^+$ and $n\ge3$ (and $n$ has a given value) besides that $x\in\mathbb{N}^+$ and $x\ge2$.
I want to check if the number is a perfect square, so I can rewrite $(1)$ as follows:
$$y^2=12\left(n-2\right)^2x^3+36\left(n-2\right)x^2-12\left(n-5\right)\left(n-2\right)x+9\left(n-4\right)^2\tag2$$
Where $y\in\mathbb{Z}$.
In this problem I've: $n=71$, the number is equal to;
$$y^2=57132x^3+2484x^2-54648x+40401\tag3$$
So, I used SageMathCell to look for the integral points on the elliptic curve and the code that was used is the following:
E = EllipticCurve([0, β, 0, γ, δ])
P = E.integral_points()
for p in P:
if p[0] % α == 0:
print(p[0] // α, p[1] // α)
I found the coeficients I need to use using equation $(2)$ and $(3)$ (but I do not know if they are corect):
- $$\alpha=12(71-2)^2=57132\tag4$$
- $$\beta=36(71-2)=2484\tag5$$
- $$\gamma=-144(71-5)(71-2)^3=-3122149536\tag6$$
- $$\delta=1296(71-4)^2(71-2)^4=131871507195024\tag7$$
So the final code looks like:
E = EllipticCurve([0, 2484, 0, -3122149536, 131871507195024])
P = E.integral_points()
for p in P:
if p[0] % 57132 == 0:
print(p[0] // 57132, p[1] // 57132)
But I found no solutions and it should give at least one solution at $x=1585$.
>What mistake have I made?Jan123Tue, 03 Dec 2019 10:13:08 -0600https://ask.sagemath.org/question/48933/Sage is not preparsing Python 3 underscored integershttps://ask.sagemath.org/question/47908/sage-is-not-preparsing-python-3-underscored-integers/Hello, Sage community!
With the upcoming migration of Sage from Python 2 to Python 3 (really soon, let us hope!), there are some testings I have been trying, and I have noticed that the "underscored integer literals", like "1_000_000" are not preparsed by Sage. For example,
preparse('1_000_000 + 3')
results in
'1_000_000 + Integer(3)'
However,
preparse('1000000 + 3')
returns
'Integer(1000000) + Integer(3)'
On the other hand, if I write
type(1_000_000 + 3)
the result is
<class 'sage.rings.integer.Integer'>
which is great, but
type(1_000_000 + 3_000)
instead gives me
<class 'int'>
Finally,
type(1000000 + 3000)
gives us
<class 'sage.rings.integer.Integer'>
I know one of the reasons for the `Integer` type was to allow divisions like `3/2` to return the float `1.5` even with Python 2, which would return (very disturbingly) `1`, in other case. However, Python 3 integers already do this. Besides what I mentioned above and this, I haven't found any other difference in behavior.
So I was wondering: Is there any disadvantage in Sage not being preparsing this type of literals?dsejasFri, 13 Sep 2019 15:41:47 -0500https://ask.sagemath.org/question/47908/Request: Have the len function output a Sage Integer instead of a Python inthttps://ask.sagemath.org/question/48141/request-have-the-len-function-output-a-sage-integer-instead-of-a-python-int/In the following code (See https://sagecell.sagemath.org/?q=cctcfj ):
a=[4,5,6]
b=[0,1,2]
for i in zip([0,1,2],a):
print i[0],"divided by",len(a),"is equal to",i[0]/len(a)
a=[4,5,6]
b=range(len(a))
print(b)
for i in zip(b,a):
print i[0],"divided by",len(a),"is equal to",i[0]/len(a)
Gives the following output
0 divided by 3 is equal to 0
1 divided by 3 is equal to 1/3
2 divided by 3 is equal to 2/3
[0, 1, 2]
0 divided by 3 is equal to 0
1 divided by 3 is equal to 0
2 divided by 3 is equal to 0
Greetings
-AAdrian sotoWed, 02 Oct 2019 09:02:50 -0500https://ask.sagemath.org/question/48141/Where is defined __gmpq_cmp_z?https://ask.sagemath.org/question/47314/where-is-defined-__gmpq_cmp_z/I got the following error after launching sage in Debian10.
----> 7 cdef class Integer(EuclideanDomainElement):
global cdef = undefined
global Integer = undefined
global EuclideanDomainElement = undefined
8 # This is really of type mpz_t, but we don't use the mpz_t typedef
9 # to work around Cython bug
11 cdef __mpz_struct value[1]
12
13 cdef int _to_ZZ(self, ZZ_c *z) except -1
14 cdef void set_from_mpz(self, mpz_t value)
15 cdef hash_c(self)
16
17 cpdef __pari__(self)
18
19 cpdef _shift_helper(Integer self, y, int sign)
20 cpdef _add_(self, other)
21 cpdef _mul_(self, other)
22 cpdef _pow_(self, other)
23 cdef _and(Integer self, Integer other)
24 cdef _or(Integer self, Integer other)
25 cdef _xor(Integer self, Integer other)
26
27 cpdef size_t _exact_log_log2_iter(self,Integer m)
28 cpdef size_t _exact_log_mpfi_log(self,m)
29 cpdef RingElement _valuation(Integer self, Integer p)
30 cdef object _val_unit(Integer self, Integer p)
31 cdef Integer _divide_knowing_divisible_by(Integer self, Integer right)
ImportError: /usr/lib/python2.7/dist-packages/sage/rings/integer.x86_64-linux-gnu.so: undefined symbol: __gmpq_cmp_z
Have you any idea to solve this error? Thank you.fylouTue, 30 Jul 2019 12:25:19 -0500https://ask.sagemath.org/question/47314/integer digits range problem (see sage error below) Thanks!!!https://ask.sagemath.org/question/46782/integer-digits-range-problem-see-sage-error-below-thanks/.
sage: for i in [9,10,11]:
....: i.digits(base=3)
....:
[0, 0, 1]
[1, 0, 1]
[2, 0, 1]
sage: for i in range(9,12):
....: i.digits(base=3)
....:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-2-e5aab74726b7> in <module>()
1 for i in range(Integer(9),Integer(12)):
----> 2 i.digits(base=Integer(3))
3
AttributeError: 'int' object has no attribute 'digits'
sage: [9,10,11]==range(9,12)
TrueNewtonMon, 03 Jun 2019 20:07:14 -0500https://ask.sagemath.org/question/46782/Convert real matrix into Integer matrixhttps://ask.sagemath.org/question/45203/convert-real-matrix-into-integer-matrix/Suppose I have a real matrix with integer entries
A = matrix(RR,[[1,2,3],[4,5,6]])
I would like to convert it to an Integer matrix (ZZ). I can do it element by element but is there a function that will do this for the entire matrix. Doing B=ZZ(A) will return an error message
unable to coerce <type 'sage.matrix.matrix_generic_dense.Matrix_generic_dense'> to an integer.
raykanSun, 27 Jan 2019 09:34:47 -0600https://ask.sagemath.org/question/45203/Finding coprime integers near a lattice pointhttps://ask.sagemath.org/question/44435/finding-coprime-integers-near-a-lattice-point/ I have a list $L$ of ordered pairs $(n,m)$ where $n$ and $m$ are integers. I would like to know which elements $(n,m)$ in $L$ satisfy the property that $\gcd(n+i,m+j) \neq 1$ for $i =-1,0,1$ and $j =-1,0,1.$ For example the point $(55,21)$ has this property since $[(55+i,21+j) ] = [(54,20),(54,21),(54,22),(55,20),(55,21),(55,22),(56,20),(56,21),(56,22)].$ I have tried the following :
`for (n,m) in L:
for i in range(-1,2):
for j in range(-1,2):
if gcd(n+i,m+j)!=1:
print(n,m)`
which returns any point with $gcd =1$ which is not what I want.
Thanks very much for your help!
cihanSun, 25 Nov 2018 20:58:03 -0600https://ask.sagemath.org/question/44435/Evaluate from string an equation that has integer divisionhttps://ask.sagemath.org/question/44328/evaluate-from-string-an-equation-that-has-integer-division/ I have the following Python list that contains strings of equations.
L = ['651/349*t + 5382747/9778631000', 't + 57879/196133000', '1000/349*t + 57879/68450417']
You can see that all of the equations have integer division. Because this is obtained by some program, I can not edit the strings.
When I evaluate for `t=1.0` with the following code in SageMath (for example), it does not evaluate as an Euclidean division.
F = function('F')(t)
for k in L:
F(t) = eval(k)
Fc = fast_callable(F, vars=[t])
val2eval = 1.0
print(Fc(val2eval).n(13))
It gives
1.00000000000000
1.00000000000000
2.00000000000000
And should be give
1.86587997307599
1.00029510077345
2.86617507384944
Of course I can solve this by modifying MANUALLY the strings of the equations by indicating that the denominator is a real number and not an integer (I put a decimal point at the end of the integer in the denominator) as following.
L = ['651/349.*t + 5382747/9778631000.', 't + 57879/196133000.', '1000/349.*t + 57879/68450417.']
But this is not the idea, the strings of the equations are generated automatically and one can not modify by editing manually, because it will be implemented in a process where it should be create at least 2000 equations.
Is there some elegant solution for this? --Many thanks!loSuarezBSun, 18 Nov 2018 11:21:18 -0600https://ask.sagemath.org/question/44328/How to compute on Cython mode with 64-bit int?https://ask.sagemath.org/question/43832/how-to-compute-on-cython-mode-with-64-bit-int/The computation is on SageMath 8.3, on a 64-bit computer.
If the integers are less than $2^{31}$ everything is alright:
sage: %time champions(2**30,2**30+10)
CPU times: user 0 ns, sys: 0 ns, total: 0 ns
Wall time: 2.15 ms
But if the integers are greater than $2^{31}$, there is a problem `OverflowError: value too large to convert to int`.
sage: champions(2**31,2**31+10)
---------------------------------------------------------------------------
OverflowError Traceback (most recent call last)
<ipython-input-7-2a762f4cafd8> in <module>()
----> 1 champions(Integer(2)**Integer(31),Integer(2)**Integer(31)+Integer(10))
/home/sage/.sage/temp/LAPTOP-7O5QV19T/9856/spyx/_home_sage_SAGE_EulerRH_spyx/_home_sage_SAGE_EulerRH_spyx_0.pyx in _home_sage_SAGE_EulerRH_spyx_0.champions()
12 return len(list(factor(n)))
13
---> 14 cpdef champions(int m1, int m2):
15 cdef int n,o,s,p,pr
16 cdef float a,c
OverflowError: value too large to convert to int
Here is the code:
from sage.all import *
cpdef g(float x):
return x/(exp(float(euler_gamma))*ln(ln(x)))
cpdef omega(int n):
return len(list(factor(n)))
cpdef champions(int m1, int m2):
cdef int n,o,s,p,pr
cdef float a,c
a=1.7683358; s=2; p=3; pr=6; n=m1
while n<=m2:
if mod(n,10**7)==0:
print(n)
if n>pr:
p=next_prime(p); pr*=p; s+=1
o=omega(n)
if n<>pr:
c=(euler_phi(n)/g(float(n)))**(1/float(s-o))
if c>a:
a=c
print([n,a,factor(Integer(pr)/Integer(n))])
n+=1Sébastien PalcouxFri, 05 Oct 2018 04:52:59 -0500https://ask.sagemath.org/question/43832/NameError: name 'Integer' is not definedhttps://ask.sagemath.org/question/35506/nameerror-name-integer-is-not-defined/ Hi,
all of a sudden, I'm experiencing a strange error and cannot find any solution for it.
Sage itself works fine, but as soon as I try to load any .sage file, the application can't start. Inside sage I can do any calculation/operation as usual, but if I for example load an application that contains:
a=1
b=2
sage returns:
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-1-496f9e9073df> in <module>()
----> 1 load("u.sage")
sage/structure/sage_object.pyx in sage.structure.sage_object.load (/build/sagemath/src/sage-7.4/src/src/build/cythonized/sage/structure/sage_object.c:12333)()
/usr/lib/python2.7/site-packages/sage/repl/load.pyc in load(filename, globals, attach)
245 if attach:
246 add_attached_file(fpath)
--> 247 exec(preparse_file(open(fpath).read()) + "\n", globals)
248 elif ext == '.spyx' or ext == '.pyx':
249 if attach:
/usr/lib/python2.7/site-packages/sage/structure/sage_object.so in <module>()
NameError: name 'Integer' is not defined
Yesterday everything was working fine. I hadn't done any system upgrades and the error appears on programs written and working yesterday and on new written programs.
Does anyone know how to solve this error or where it suddenly comes from? A restart didn't change anything...0x22Thu, 10 Nov 2016 08:25:50 -0600https://ask.sagemath.org/question/35506/simplifying out negative signs in exponentshttps://ask.sagemath.org/question/43132/simplifying-out-negative-signs-in-exponents/Hello all!
I can't for the life of me find a way to force sage to return terms with only positive coefficient variable exponents. For example, if I enter something like
assume(n, 'integer', n>10)
c = 2^(-n)
I would like the output to be something like `1/(2^n)`, but instead I can only get something like `2^(-n)`. Is there a way to force the output to display only positive coefficients in front of the n?
In general I'd like some `magicFunc` function which I could feed some expression `g(x,n)` and have it return a rational expression with no negatives; eg.
var('x,n')
assume(x,'real')
assume(n,'integer',n>10)
g(x,n) = 2^(-n)*x^(-3*n)*3^n
magicFunc(g(x,n))
Would return `3^n/(2^n*x^(3n))`
Is this possible? This seems like it should be an existent simplification method, but nothing I've tried seems to work.
Thanks!Jason021Tue, 24 Jul 2018 16:19:26 -0500https://ask.sagemath.org/question/43132/n-th power of matriceshttps://ask.sagemath.org/question/35155/n-th-power-of-matrices/Is there any way to calculate the n-th power of a (upper unitriangular) matrix in Sage? Here n is an integer variable.
For example, if y=matrix([[1,0,0],[0,1,1],[0,0,1]]), then I want to obtain a formula in n for y^n. In this case this would be y^n=matrix([[1,0,0],[0,1,n],[0,0,1]]).
I tried the following:
sage: y=matrix([[1,0,0],[0,1,1],[0,0,1]]); var('n');
sage: y^n
This resulted in the error: "NotImplementedError: non-integral exponents not supported"
Adding
sage: assume(n, 'integer')
has no effect at all.irisSun, 16 Oct 2016 03:56:39 -0500https://ask.sagemath.org/question/35155/local variable 'Integer' referenced before assignmenthttps://ask.sagemath.org/question/41524/local-variable-integer-referenced-before-assignment/ I'll be honest I have no idea why this error is popping up, and it's really weird! I'm writing code that will generate a closed form solution to the partial sums of integer powers up to n, and this is what I have
def sum_first_n_p_powers(p):
length = p+1
vector = zero_vector(length)
matrix_list = []
for x in xrange(0,length):
copy = vector[:]
for y in xrange(0,length):
copy[y] = binomial(length-y,x-y+1)
matrix_list.append(copy)
M = Matrix(matrix_list)
solution_vector = zero_vector(length)
solution_vector[0] = 1
coeffs = M.solve_right(solution_vector)
n = var('n')
0 = polynomial
for x in xrange(0,len(coeffs)):
polynomial = polynomial + coeffs[x]*n^(length-x)
return polynomial
And when I try to run it I get the most unusual error, it just says to me
UnboundLocalError: local variable 'Integer' referenced before assignment.
I have never run into this before and have no idea what's wrong with the line. Thanks in advance!
JRHalesTue, 13 Mar 2018 20:12:23 -0500https://ask.sagemath.org/question/41524/unable to coerce <type 'sage.rings.real_mpfi.RealIntervalFieldElement'> to an integerhttps://ask.sagemath.org/question/38338/unable-to-coerce-type-sageringsreal_mpfirealintervalfieldelement-to-an-integer/ I am very desperate. I just want to convert a real number to an integer. I have tried int(x), Integer(x), floor(x), ceil(x) but nothing seems to work.davidThu, 20 Jul 2017 16:11:57 -0500https://ask.sagemath.org/question/38338/Matrix conjugacy classes over Z and ideal classeshttps://ask.sagemath.org/question/8244/matrix-conjugacy-classes-over-z-and-ideal-classes/I had a couple questions; the first involves matrix conjugacy classes over the integers and the second involves integral bases. I'm not sure what the algorithms in Sage are for the following procedures.
1) Is it possible to determine if two integer-valued square matrices (which are conjugate over Q) are also conjugate over Z?
2) In a number field K, given an ideal class I, we can find an integral basis for a representative ideal in I by the command:
sage: I.integral_basis()
Is it possible to work in the reverse direction, that is given a set of elements in K which form an integral basis, is it possible to find the corresponding ideal and ideal class for that integral basis?
Thanks in advance for any advice.CCThu, 28 Jul 2011 14:14:45 -0500https://ask.sagemath.org/question/8244/solve x^y == z (for x)https://ask.sagemath.org/question/35105/solve-xy-z-for-x/
I don't understand the behavior:
> var('x','y','z'); assume(x>0, y>0, z>0); assume(x,y,z, 'real')
> solve(x^y==z, x)
generates a traceback error:
"...
Is y an integer?"
I can get the expected answer after adding
> assume(y, 'integer')
but this seems like it should be unnecessary. Anyone know what is going on here?
thanks,
Dustindnlennonpu01Mon, 10 Oct 2016 02:13:03 -0500https://ask.sagemath.org/question/35105/Testing if a result n is an Integer, for large n.https://ask.sagemath.org/question/34406/testing-if-a-result-n-is-an-integer-for-large-n/ I have a number x of size 2^160, and I perform the operation n = x*(x+1.5) and want to test if the result is an integer.
In python I would normally try, n.is_integer() or use an isinstance(), but this doesn't work in sage, I assume due to the fact sage integers are set up quite differently.
Upon scouring this site, I found someone recommend n is in ZZ, but this doesn't work (sage seems to loose accuracy at this level)
Example:
n = 2^160
n in ZZ
Result: False
The only (terribly inefficient) way I can get this to work is to call n.divisors() and if I get the error
"AttributeError: 'sage.rings.real_mpfr.RealNumber' object has no attribute 'divisors' "
I know it was indeed not an integer.
There must be a better way?
jbeatzWed, 10 Aug 2016 07:03:46 -0500https://ask.sagemath.org/question/34406/Assume that n is positive integerhttps://ask.sagemath.org/question/33181/assume-that-n-is-positive-integer/ It seems I cannot make Sage assume that the variable n is a positive integer.
var('n')
assume(n, 'integer')
assume(n>0)
In this code, the "n>0" overwrites the assumption that n is an integer. The command
n.is_integer()
returns false. How do I do this?KofiFri, 22 Apr 2016 04:24:24 -0500https://ask.sagemath.org/question/33181/Possible bug of sum functionhttps://ask.sagemath.org/question/33068/possible-bug-of-sum-function/Consider the following code:
def s(n):
return sum(k/n for k in range(n + 1))
L0 = s(2)
for n in range(2, 3):
L1 = s(n)
The answers are (using sage 7.1):
print L0, L1
(3/2, 1)
In the second case sage is using the usual integer division of python 2.x while in the first one it is using the exact representation of rationals. Is this a known bug?
jllbMon, 11 Apr 2016 12:15:50 -0500https://ask.sagemath.org/question/33068/range and division : unexpected behaviorhttps://ask.sagemath.org/question/32891/range-and-division-unexpected-behavior/Consider the following snippet :
N=5
# code 1
for n in range(N,N+1):
for k in range(0,n):
print k/n
print '-'*10
# code 2
n=N
for k in range(0,n):
print k/n
I was expecting code 1 and code 2 to print the same output. This is not the case :
0
0
0
0
0
----------
0
1/5
2/5
3/5
4/5
In the first case, `k/n` is Python-evaluated as an integer division, in the second case, `k/n` is Sage-evaluated as a fraction. Can someone elaborate please ?
I only notice that substituting `srange(N,N+1)` to `range(N,N+1)` fixes the problem.
candideSun, 27 Mar 2016 04:28:01 -0500https://ask.sagemath.org/question/32891/Integer result for fractionhttps://ask.sagemath.org/question/32347/integer-result-for-fraction/ Hi!
Can somebody explain me this strange behavior of Sage :
for p in range(1,10):
for q in range(1,10):
print p/q
Then `p/q` return the integer division.
However:
for p in range(1,10):
print p/7
give rational results.
A solution is to use `Rational(p)/Rational(q)` instead of `p/q`. But it is not an explanation.
Thanks,
Arnaud
Arnaud1418Wed, 27 Jan 2016 13:12:43 -0600https://ask.sagemath.org/question/32347/'Integer' object is not callable error when it doesn't appear as though I'm calling an integerhttps://ask.sagemath.org/question/29983/integer-object-is-not-callable-error-when-it-doesnt-appear-as-though-im-calling-an-integer/ I have a cell where I'm trying to make a recursive function to shortcut Newton's Method, and it appears to be written properly, but I keep getting the error shown above
%auto
#don't call this, it's an internal function that the main one calls for its recursion step
def newtonsMethodRecursiveCall(func, deri, start, iters):
if iters == 0:
return start - (func(start) / deri(start))
else:
r = newtonsMethodRecursiveCall(start, func, deri, iters-1)
return r - (func(r) / deri(r))
# Recursive function to perform Newton's Method to the nth degree
def newMet(func, vari, start, iters = 10):
deri(vari) = derivative(func, vari, 1)
return (newtonsMethodRecursiveCall(func, deri, start, iters))
when I tested with
tf(x) = x^2 - 2
newMet(tf, x, 1)
it gave me the error.
I don't see anywhere that should indicate that I would be calling an integer, I thought I'd checked all of the names to make sure they were undefined before attempting to call them as a function
as a side note, I don't care if there's already a function for what I'm doing, I wanted to try to write one myself using the definition of newton's methodMFriendTue, 13 Oct 2015 20:49:11 -0500https://ask.sagemath.org/question/29983/How to cast a string with an exponent from sys.argv to an Integer ?https://ask.sagemath.org/question/29597/how-to-cast-a-string-with-an-exponent-from-sysargv-to-an-integer/Hi,
For an exercise, I have written a Python script that takes an integer argument. Of course, the input in sys.argv is of type 'str', so I cast it to an Integer. It works, but I am supposed to accept numbers written like '123^1237' too, with a hat for the exponent. And I cannot find how to do that. In the sage interpreter, I can type "n = Integer(123^1237)" without any problem, but in my script it fails with a "TypeError: unable to convert '123^1237' to an integer". ThanksOnoxSat, 26 Sep 2015 10:00:01 -0500https://ask.sagemath.org/question/29597/Integer types and log()https://ask.sagemath.org/question/28679/integer-types-and-log/I am working with a bunch of lists whose lengths are all powers of 2. I'd like to be able to extract the power by taking the base-2 log of the length. However, Sage wasn't able to simplify an expression like log(len(L),2), because apparently len() returns the wrong kind of integer:
sage: A=list(range(8))
sage: len(A)
8
sage: log(len(A),2)
log(8)/log(2)
sage: log(8,2)
3
sage: type(len(A))
<type 'int'>
sage: type(8)
<type 'sage.rings.integer.Integer'>
sage: log(Integer(len(A)),2)
3
This is the first math function I've come across that seems to care about the distinction between these two kinds of integers, and it would be nice if it didn't, since it took me quite a while to figure out why Sage wouldn't simplify an expression like log(len(A),2).Jeremy MartinTue, 21 Jul 2015 09:57:56 -0500https://ask.sagemath.org/question/28679/How to index lua tables with sage integerhttps://ask.sagemath.org/question/27067/how-to-index-lua-tables-with-sage-integer/ We would like to use [Lua](http://www.lua.org/) integration within Sage.
For this, can use [Python Lupa](https://pypi.python.org/pypi/lupa).
To install it, we first set PYTHONPATH as below:
$ export PYTHONPATH=.../sage-6.4.1-x86_64-Linux/local/
$ python2.7 setup.py install --prefix=.../sage-6.4.1-x86_64-Linux/local/
Everything works as expected, except indexing a table with integers (and maybe floats).
sage: import lupa
sage: from lupa import LuaRuntime
sage: lua = LuaRuntime(unpack_returned_tuples=True)
sage: table = lua.eval('{[1] = "it works"}')
sage: table [1]
(no output)
sage: table [1] is None
True
It seems that the problem comes from Sage integer wrapping.
Lupa performs an automatic conversion between Python integers and Lua integers, but is not aware of Sage integers.
Indeed, we can use strings/booleans in order to index tables:
sage: table2 = lua.eval('{a = "a value"}')
sage: table2 ['a']
u'a value'
sage: table3 = lua.eval('{[true] = "a boolean key"}')
sage: table3 [True]
u'a boolean key'
FurnostTue, 09 Jun 2015 04:25:40 -0500https://ask.sagemath.org/question/27067/Finding Gaussian integer points on elliptic curveshttps://ask.sagemath.org/question/9607/finding-gaussian-integer-points-on-elliptic-curves/How can I find all points whose coordinates are Gaussian integers?
I know that finding all integer points for curves over rationals can be done by:
E.S_integral_points([], both_signs=True)
or
E.integral_points(both_signs=True)
But these do not work with curve defined over "i"-extension of rationals.azerbajdzanTue, 04 Dec 2012 10:57:16 -0600https://ask.sagemath.org/question/9607/Symbolic integer arithmetichttps://ask.sagemath.org/question/23610/symbolic-integer-arithmetic/It's not that hard to find a closed expression for the remainder of the polynomial $x^n$ modulo $x^2-5x-2$. But I don't seem to manage it in SAGE.
n=var('n')
R=PolynomialRing(RationalField(),'x');R
x=R.gen();x
mp=x^2-5*x-2
S=R.quotient(mp,'a')
a=S.gen();a^2
a^5
works as expected, but replacing the last line with a^n gives an error (non-integral exponents not supported). I understand a general variable is not a SAGE integer, but how DO I make clear n is supposed to be an integer?
In the same way, it's not that hard to calculate the symbolic n-the power of a small, say 2x2, matrix, but the straightforward aproach of simplifying A^n gives the same error (non-integral exponents not supported).
I checked wolfram alpha for the symbolic power of a matrix, and immediately got the expected answer for [[1,2],[3,4]]^n .
![Wolfram alpha answer](http://www4b.wolframalpha.com/Calculate/MSP/MSP16951af85fib66538dhg0000648f487198eeg2e8?MSPStoreType=image/gif&s=54&w=1188.&h=58.)
Dirk DanckaertMon, 28 Jul 2014 08:41:10 -0500https://ask.sagemath.org/question/23610/Check that variable is integerhttps://ask.sagemath.org/question/9465/check-that-variable-is-integer/Dear Sage,
I define the following variable
sage: a = var('a')
sage: assume(a, 'integer')
How do I check that is variable is an integer? The following doese not seem to work in sage 5.2.
sage: a in ZZ
False
sage: 2 in ZZ
True
sage: assumptions()
[a is integer]
How should I check the assumption that a is an integer?
Best,
NoudNoudWed, 24 Oct 2012 10:35:45 -0500https://ask.sagemath.org/question/9465/TypeError: 'sage.rings.integer.Integer' object is not callablehttps://ask.sagemath.org/question/11363/typeerror-sageringsintegerinteger-object-is-not-callable/I tried to enter into notebook:
> a=-2
> (-((a-1)^2)-((-a-8)(2(a-1))))/((a-1)^4)
And I obtained error
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "_sage_input_13.py", line 10, in
> <module>
> exec compile(u'open("___code___.py","w").write("#
> -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("KC0oKGEtMSleMiktKCgtYS04KSgyKGEtMSkpKSkvKChhLTEpXjQp"),globals())+"\\n");
> execfile(os.path.abspath("___code___.py"))
> File "", line 1, in <module>
> File "/tmp/tmpF91cWI/___code___.py", line
> 3, in <module>
> exec compile(u'(-((a-_sage_const_1 )**_sage_const_2 )-((-a-_sage_const_8
> )(_sage_const_2 (a-_sage_const_1
> ))))/((a-_sage_const_1
> )**_sage_const_4 ) File "", line 1,
> in <module>
> TypeError: 'sage.rings.integer.Integer' object is
> not callableCaterpillarMon, 28 Apr 2014 05:48:35 -0500https://ask.sagemath.org/question/11363/Cutting unnecessary zeroes in float numbershttps://ask.sagemath.org/question/11051/cutting-unnecessary-zeroes-in-float-numbers/Hello. I have function, which shows a float number with comma instead of dot. But if i use this function on integer it shows float number.
Here is the function
\begin{sagesilent}
def numprint(x):
x = round(x, ndigits=3)
x = latex(x)
x = str(x)
x = x.replace('.', ',\!').replace('\\times','\, \ldotp')
x = sage.misc.latex.LatexExpr(x)
return x
\end{sage}
\newcommand{\sagedot}[1]{\sagestr{numprint(RDF(#1))}}
So, when i use `\sagedot{3}` it shows 3.0 instead of 3. Help me to improve it. Thanks and sorry for dumb english and question :D4uTePMon, 17 Feb 2014 05:49:32 -0600https://ask.sagemath.org/question/11051/