Ask Your Question

John Palmieri's profile - activity

2020-02-13 10:28:25 -0600 commented question looping of equality function

It was clear what answers you were hoping for, but you said it wasn't giving the desired answer. So again: what answers was it giving?

2020-02-13 00:11:35 -0600 commented question looping of equality function

First, use if. Second, what answer are you getting? If you are using this code in a Python file (as opposed to a Sage file), then the ^symbol will be interpreted as in Python as bitwise exclusive or (https://docs.python.org/3/reference/e...). In a Sage file, ^ is converted to **.

2020-02-05 00:47:36 -0600 commented answer how do i plot a parabola in the x=2 plane?

Note that the command var('u') defines u: you should be able to use var('u') rather than u = var('u'). Unfortunately many of the examples in the Sage documentation needlessly use the longer version.

2020-02-04 18:28:50 -0600 commented question how do i plot a parabola in the x=2 plane?

You can use var('y') to define y as a variable, and similarly for z.

2020-02-03 18:37:33 -0600 commented question Generate >2D Matrix

I agree that vectors of matrices don't work, but matrices of matrices do.

2020-02-03 18:37:00 -0600 answered a question Generate >2D Matrix

To construct a matrix of matrices:

sage: a = random_matrix(QQ, 2, 2)
sage: b = random_matrix(QQ, 2, 2)
sage: c = random_matrix(QQ, 2, 2)
sage: d = random_matrix(QQ, 2, 2)
sage: v = matrix([[a,b,c,d]])

It prints horribly (but view(v) looks good).

sage: a
[  2   0]
[  1 1/2]
sage: b
[  0  -1]
[1/2   2]
sage: c
[ 2  1]
[ 2 -2]
sage: d
[ -1 1/2]
[1/2   1]
sage: v
[[  2   0]
[  1 1/2] [  0  -1]
[1/2   2]     [ 2  1]
[ 2 -2] [ -1 1/2]
[1/2   1]]

sage: v.nrows()
1
sage: v.ncols()
4
sage: v.base_ring()
Full MatrixSpace of 2 by 2 dense matrices over Rational Field
2020-02-03 13:37:19 -0600 commented question Generate >2D Matrix

You can also make a 1 x n matrix whose entries are matrices.

2020-02-03 13:34:10 -0600 commented question Generate >2D Matrix

Is a list of matrices, or a tuple of matrices, insufficient? If so, why?

2020-01-17 11:52:10 -0600 commented question Missing 1 required positional argument

As it's written, the indentation is bad: the four lines after def Check(n): should be indented four more spaces.

2020-01-16 18:17:56 -0600 received badge  Nice Answer (source)
2020-01-14 11:02:12 -0600 answered a question finite simplicial complexes, projective spaces, facets, giving strange output

If you want vertices to be given as integers rather than (in the case of RP^5) tuples, you can create a dictionary to translate vertices to integers:

RP5 = simplicial_complexes.RealProjectiveSpace(5)
d = {y:x for x,y in enumerate(RP5.vertices())}

(By the way, Sage constructs such a dictionary already for its own uses, so you can replace the second line with d = RP5._vertex_to_index. This is not an advertised feature, so knowing how to construct your own dictionary for this translation is useful.)

Then you can use that dictionary to translate the actual facets to tuples of integers:

[tuple(d[v] for v in f) for f in RP5.facets()]

As I noted in a comment, this will get unwieldy pretty quickly, as the dimension goes up.

2020-01-14 10:50:04 -0600 commented question finite simplicial complexes, projective spaces, facets, giving strange output

"I would like to obtain only the facets of the first 10 projective spaces." Please look at the documentation. When n is at least 5, there will be (n+2)!/2 facets in Sage's triangulation of n-dimensional real projective space. When n=10, this will produce over 200 million facets.

2020-01-13 22:46:40 -0600 answered a question Unable to convert string to rational when plus sign is added

As far as I can tell, Sage uses gmp(https://gmplib.org) to construct its rational numbers, and the gmp function mpq_set_strdoesn't handle the leading plus sign. In any case, I would call it a lack of a feature rather than a bug. I've opened https://trac.sagemath.org/ticket/29006.

2020-01-10 17:15:35 -0600 commented question Running Sage in Bash

@slcoleman: it's best if sage is in your PATH, and then the first line should be #!/usr/bin/env sage.

2020-01-10 10:57:56 -0600 commented question How to find the sum weight on a vertex

Also, random.sample takes a list as the first argument, and G.num_edges() is a number, not a list.

2020-01-10 10:57:20 -0600 commented question How to find the sum weight on a vertex

The code you posted has an indentation error on the last line: n.append(x) is indented an extra space compared to the previous line. There is no such error on the line for i in ....

2020-01-09 13:02:30 -0600 commented question How to find the sum weight on a vertex

What is q? What sorts of errors do you get? What is a sample graph that we can work with?

2020-01-08 13:17:39 -0600 commented answer Should I avoid using unicode in names of variables?

@Iguananaut: you might want to edit your comment on Nils' answer which says that this is a feature of Python 3 rather than IPython.

2020-01-08 13:14:25 -0600 commented question Running Sage in Bash

Find where Sage is installed, and do /path/to/sage Documents/test.py. Or add the directory containing sage to your PATH, and then do sage Documents/test.py, just like with Python.

2020-01-07 12:52:23 -0600 commented answer Should I avoid using unicode in names of variables?

I just tried out the tab-completion on "\pi". It works for me in IPython but not in plain Python. (This is with Python 3.7.3, built via Sage 9.0.)

2020-01-02 07:24:53 -0600 received badge  Nice Answer (source)
2019-12-31 22:32:10 -0600 commented answer Add commas after matrix-elements in matrix()

Sorry, I forgot to add import re. I will edit the answer.

2019-12-30 23:24:09 -0600 answered a question Add commas after matrix-elements in matrix()

I think you should continue to manipulate m.str(), but using regular expressions, since m.str() already has the correct spacing. The following will work if you know that the matrix entries will be numbers (plus a possible decimal point and/or minus sign), no letters:

import re
m = matrix([[2222,333,44444], [1,0,0]])
no_brackets =  m.str().replace('[', '').replace(']', '') # replace [, ]
add_commas = re.sub("([-.0-9]+) ", "\\1, ", no_brackets)
print(add_commas)

Output:

 2222,   333, 44444
    1,     0,     0
2019-12-20 16:28:04 -0600 edited question Evaluation of triangle inequality

I wrote the following code:

x = var('x')
assume(x,'real')
y = var('y')
assume(y,'real')
z = var('z')
assume(z,'real')

expr = abs(x-y)+abs(y-z) >= abs(x-z)

The I run it:

sage: bool(expr)
False

The expression is obviously mathematically correct. How come Sage returns "False"?

2019-12-18 16:27:01 -0600 answered a question Default algorithm for cardinality

The reference manual describes cardinality as

cardinality(algorithm=None, extension_degree=1)

which means that the default value for the argument is None. The code says

    if algorithm is None:
        # Check for j in subfield
        jpol = self.j_invariant().minimal_polynomial()
        if jpol.degree() < self.base_field().degree():
            algorithm = "subfield"
        else:
            algorithm = "pari"

So if you are working over a prime field, for example, the algorithm is "pari": "use the PARI C-library function ellcard", according to the reference manual. This pari function is documented here. (Click on "Elliptic curves" in the menu on the left, then "ellcard" at the top. I don't see how to give a precise link to the page.)

By the way, to see the source code, you can do

sage: E = EllipticCurve(GF(10007), [1,2,3,4,5])
sage: E.cardinality??
2019-12-18 11:44:28 -0600 commented question factorize symbolic expression

Looks like a bug to me, since (2*a*x + 2*b*x).factor() returns 2*(a + b)*x.

2019-12-18 11:43:43 -0600 commented answer factorize symbolic expression

The notion of factorization is algebraic and depends on the ring in which you are working. For example x^2+1 factors over the complex numbers but not the reals, and x^2-2 factors over the reals but not the rationals. So when you're dealing with factorization, it's a good idea to precisely specify the ring.

2019-12-17 15:04:43 -0600 answered a question factorize symbolic expression

You can work with elements of a polynomial ring instead of with symbolic expressions:

sage: R.<a,b,c> = ZZ[] # polynomials with integer coefficients, variables a, b, c
sage: (a*2+b*2).factor()
2 * (a + b)
sage: (a*c+b*c).factor()
c * (a + b)
2019-12-16 12:36:24 -0600 commented answer import error on debian

You say "This used to work before." Before what? What has changed? Your version of Sage? Some system software? By the way, how was Sage installed — built from scratch or a binary distribution?

2019-12-16 08:13:47 -0600 received badge  Great Answer (source)
2019-12-16 08:13:47 -0600 received badge  Guru (source)
2019-12-15 11:24:11 -0600 commented question How can I calculate only the imaginary part of a complex number?

Note that x.imag() is a real number, so (x.imag()*-i) is purely imaginary. Its square will be negative, so your function may certainly end up computing the square root of a negative number.

2019-12-15 11:22:13 -0600 commented question How can I calculate only the imaginary part of a complex number?

I think we need more information: what are a and b, and what are you expecting for your output?

2019-12-13 23:55:50 -0600 commented question How can I calculate only the imaginary part of a complex number?

What goes wrong if you do n(complexDis(b-a).imag()), or the same with real()?

2019-12-12 00:48:39 -0600 commented question How to install SageMath on CentOS?

Why not build from scratch? Visit http://doc.sagemath.org/html/en/insta... for details.

2019-12-08 00:35:03 -0600 commented answer can't import sage into python

If pylint is using the system's Python, that could explain it, since Sage is (typically) not installed as a module for the system's Python, only Sage's own Python installation. You could try installing pylint in Sage (sage --pip install pylint, I think).

2019-12-07 20:15:11 -0600 commented answer can't import sage into python

Did you delete the old file "sage.py"?

2019-12-07 20:02:59 -0600 received badge  Good Answer (source)
2019-12-07 13:21:17 -0600 received badge  Nice Answer (source)
2019-12-07 10:31:34 -0600 answered a question can't import sage into python

The problem is that your script is called "sage.py", so when you try from sage.all import *, it tries to import it from this file. Rename your script to something else.

2019-12-03 15:34:27 -0600 commented question Mistake in SageMathCell code, finding integral points on elliptic curves
2019-12-01 21:17:33 -0600 commented answer Standard use of underscores in numerals

I would remove the word "precise" from your answer.

2019-11-19 17:12:52 -0600 received badge  Good Answer (source)
2019-11-18 17:17:40 -0600 received badge  Nice Answer (source)