Ask Your Question

John Palmieri's profile - activity

2020-10-30 04:58:44 -0500 received badge  Nice Answer (source)
2020-10-29 12:44:44 -0500 commented answer Generators of simplicial homology

This problem is being tracked at https://trac.sagemath.org/ticket/30838.

2020-10-29 12:36:40 -0500 commented answer Generators of simplicial homology

I don't think it's perfect — it should be fixed — but I'm glad it's helpful.

2020-10-29 12:05:03 -0500 answered a question Generators of simplicial homology

This looks like a missing feature and/or a bug. Note that the documentation for S.homology() says, regarding generators:

Since trac ticket #6100, the result may not be what you expect when not using CHomP since its return is in terms of the chain complex.

The bug is that there is no result at all, but you can recover it by doing:

sage: S.chain_complex().homology(generators=True)
{0: [(Z, Chain(0:(0, 0, 0, 1, 0, 0)))],
 1: [(Z, Chain(1:(0, 1, -1, 0, 0, 0, -1, 1, 0))),
  (Z, Chain(1:(0, 0, 0, 0, 1, -1, -1, 1, 1)))],
 2: []}

To interpret this, you need to know how the simplicial complex is turned into a chain complex. The simplices in each dimension are sorted in order to construct the matrices representing the boundary maps, so to get the first generator in dimension 1, for example, you would look at

sage: S._n_cells_sorted(1)                                                                
[(0, 3), (0, 4), (0, 5), (1, 2), (1, 3), (1, 5), (2, 4), (2, 5), (3, 4)]

The first generator is given by (0, 1, -1, 0, 0, 0, -1, 1, 0), which means the sum of 1 x (item 1 in list), -1 x (item 2), etc.:

(0, 4) - (0, 5) - (2, 4) + (2, 5)
2020-10-28 14:03:25 -0500 answered a question Unbrackable blanck

Here is a screenshot of what your code produces for me (using Sage 9.2):

image description

If I change '' to '/', it adds an extra column to the header row, so that the column "b" has nothing beneath it. Is that really what you want?

2020-10-28 13:56:39 -0500 commented question Unbrackable blanck

What happens if you use ' ' rather than ''?

2020-10-26 16:47:33 -0500 commented question Unbrackable blanck

Can you clarify? It is not clear what you are asking. In Python, ' ' is a blank string. In LaTeX, '~' is a blank.

2020-10-26 11:39:07 -0500 commented question Cohomology ring of a Lie algebra

chain_complex().homology(...) uses the order on the chains as given when constructing the chain complex, which in this case is taken care of by chevalley_eilenberg_complex. So you can look at that code to see what order is chosen.

2020-10-20 08:41:26 -0500 received badge  Nice Answer (source)
2020-10-19 23:21:20 -0500 answered a question what does the .<...> notation mean?

As you probably know, Sage is built on top of Python, but then it extends Python's syntax. If you're not sure what some non-Python thing does, use the preparse command:

sage: preparse("ratpoly.<t> = PolynomialRing(QQ)")
"ratpoly = PolynomialRing(QQ, names=('t',)); (t,) = ratpoly._first_ngens(1)"

So ratpoly.<t> = PolynomialRing(QQ) creates a polynomial ring with coefficients in the rationals (QQ). The ring itself is called ratpoly, and the generator is called t.

2020-10-16 11:39:33 -0500 edited question 'builtin_function_or_method' object has no attribute 'split'

Code:

import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
file = 'IV meas -1.50E+0 V to 1.50E+0 V PHY 364 Practical_Dark_temp_25.57oC_Intensity_0.000suns -light OFF- 0 sec wait at 0 Volt.txt'
f=open(file,'r')
delimiter = ','

line=f.readline()
while (line != ''):
    data=line.split(delimiter)
    V1L.append(float(data[0]))
    I1L.append(float(data[1]))
    line=f.readline

each line in the txt file is of the form

-1.50000E+0,-3.22013E-3
2020-10-15 17:16:42 -0500 commented answer Can attributes of sage classes be changed?

I added an alternative in the edit.

2020-10-15 07:08:44 -0500 received badge  Good Answer (source)
2020-10-15 02:41:50 -0500 received badge  Nice Answer (source)
2020-10-14 18:17:19 -0500 answered a question Can attributes of sage classes be changed?

I haven't tried this in sagetex, but it works in a Sage session:

sage: v = vector([1,2,3])
sage: latex(v)
\left(1,\,2,\,3\right)

That's not what you want, so use latex.vector_delimiters to change the parentheses to what you want:

sage: latex.vector_delimiters("[", "]^{\\intercal}")
sage: latex(v)
\left[1,\,2,\,3\right]^{\intercal}

Edit: An alternative is to modify your sagetex.sty file: change the line

\newcommand{\sage}[1]{\ST@sage{latex(#1)}}

to

\newcommand{\sage}[1]{\ST@sage{my_print(#1)}}

Or maybe better, create an .sty file with this change, with a new name and use that instead of sagetex.sty.

Then the first thing in your LaTeX file (after "\begin{document}") should be

\begin{sagesilent}
def my_print(v):
    if isinstance(v, sage.modules.free_module_element.FreeModuleElement):
        return matrix(v)._latex_() + r'^\intercal'
    else:
        return latex(v)
\end{sagesilent}

Then you can customize the output for each class, however you want.

2020-10-13 22:15:03 -0500 commented question Can attributes of sage classes be changed?

The problem is that FreeModuleElementis a Cython class, and attributes of those can't be modified, I believe. See https://cython.readthedocs.io/en/late....

2020-10-09 11:36:25 -0500 commented question Refinement between Lists of lists

Surely you care whether each list in L2 is a sublist of a list in L1? Then you also want to know that if you concatenate and sort the two lists, the results are equal. Is that good enough? If not, perhaps the code at the link I provided can be modified to do what you need.

2020-10-08 23:53:03 -0500 commented question Refinement between Lists of lists
2020-10-08 23:49:48 -0500 commented question Refinement between Lists of lists

Does the order matter? Is [[0,1]] a refinement of [[1, 0, 2]]?

2020-10-07 12:43:07 -0500 commented answer Obtaining a simplicial complex associated to a poset with the help of Sage

You can also check S.is_shellable().

2020-10-07 12:12:55 -0500 commented answer Obtaining a simplicial complex associated to a poset with the help of Sage

You can check things like S.is_pseudomanifold() and S.fundamental_group() to see if it has a chance to be a sphere, but I don't know how to definitively check the homeomorphism type of a simplicial complex.

2020-10-07 12:08:35 -0500 commented answer Obtaining a simplicial complex associated to a poset with the help of Sage

Mathematically, how do you check if a simplicial complex is homeomorphic to a sphere?

2020-09-30 11:21:00 -0500 commented answer too many for loops

But if there are only 22 variables (for example), using a for loop for 19 of them and cartesian_product for the rest doesn't add too many useless values.

2020-09-29 10:41:35 -0500 commented answer too many for loops

You could use 15 for loops and then cartesian_product for the remainder, if performance is bad for cartesian_product.

2020-09-29 10:39:54 -0500 commented question too many for loops

You could construct a polyhedron based on the ranges in your for loops, and then iterate over the integral points of that polyhedron. I don't know how fast or slow this is, though.

2020-09-21 10:43:35 -0500 answered a question How to install an spkg (the one for GRDB Fano polytopes)?

This is an "old-style" Sage SPKG, and those are no longer supported.

The way to try to install, which would be unsuccessful, is to download the file from http://coates.ma.ic.ac.uk/grdb_polyto..., then run sage -i /path/to/grdb_polytopes-0.1.spkg. This will fail with the message

Error: package '/Users/palmieri/Downloads/grdb_polytopes-0.1.spkg' not found
Note: if it is an old-style package, installing these is no longer supported

I don't see any easy way to work around this. You can still look at the data: this spkg file is just a compressed tarball, so you can download it and then run tar xf grdb_polytopes-0.1.spkg and then look at the data files in grdb_polytopes-0.1.spkg/src.

2020-09-15 08:59:44 -0500 received badge  Nice Answer (source)
2020-09-14 23:23:30 -0500 answered a question Coefficient of Polynomial Function in a loop

The indentation in your second code block is wrong, but if you fix that (don't indent while, indent all of the lines after it), it works, at least for me. The code can also be rewritten a few ways:

No need for the variable i:

for a in List1: 
    Result = List2[0].coefficient(a) 
    List3.append(Result)

In fact, no need for an explicit loop at all, using list comprehension instead:

List3 = [List2[0].coefficient(a) for a in List1]

By the way, there are other ways to get at the coefficients. For example:

a = x^2 + 2*y^2 + 3*z^2
for b in a:
    print(b)

will print

(1, x^2)
(2, y^2)
(3, z^2)

You can get the same information using list comprehension, [b for b in a], or in fact just list(a).

2020-09-13 16:25:21 -0500 received badge  Good Answer (source)
2020-09-12 21:20:00 -0500 received badge  Nice Answer (source)
2020-09-12 11:18:40 -0500 answered a question Convert sage code from v8.1 to work in v9.1

There is a script 2to3 that converts Python 2 code to Python 3 code, in addition to the tools mentioned by @FrédéricC. Try running that on the file. (It is intended for .py files, but it may also work on a .sage file. Or you can do sage --preparse file.sage to produce file.sage.py, and then run 2to3 on that.)

2020-09-08 12:14:59 -0500 commented answer Having trouble in solving two differential equations using desolve_system

Maybe desolve_odeint can be used the same way?

2020-09-04 10:28:22 -0500 commented question Typo in Sagemanifolds worksheet ?

If it's a mistake, it's worth a ticket.

2020-08-15 11:02:24 -0500 commented question Error when trying to integrate

I think the problem is parentheses, not Sage. 1/3.33 * sqrt(2*pi) is equal to sqrt(2*pi)/3.33, whereas I think you meant to have all of that in the denominator. So you need parentheses: 1/(3.33 * sqrt(2*pi)), as in @eric_g's answer.

2020-08-14 19:40:30 -0500 commented question Error when trying to integrate

Don't use "N": just use 2*pi and exp(...).

2020-08-14 19:15:00 -0500 edited question Error when trying to integrate

This is what I want to do in Sage. It can be done very easily in Desmos. https://www.desmos.com/calculator/7oc...

I am just trying to do this integral in Sage. When I do it the answer I get is

f(x) = (1/3.33sqrt(2pi))exp((-1/2)((x-9.486)/3.33)^2)

N(definite_integral(f(x), x, 6, 23))

5.35572539176154

2020-08-13 11:59:34 -0500 received badge  Good Answer (source)
2020-08-05 13:40:24 -0500 received badge  Nice Answer (source)
2020-08-04 20:10:27 -0500 answered a question Sage fails to recognize `1 + (1/2 + i*sqrt(3)/2)^3` is zero

I did:

a = 1 + ( 1/2 + i*sqrt(3)/2 )^3

Then

bool(a == 0)

returns True, and

a.simpify_full()

returns 0. Try typing a.simplify<TAB> to see the list of possible simplifications.

2020-07-30 16:58:30 -0500 answered a question Creating a matrix from block

I'm not sure what you've tried, but you need to convert the vectors to matrices:

sage: A = matrix([[1, 2, 3, 4],[4, 3, 2, 1],[2, 4, 3, 1]])
sage: II = identity_matrix(3)
sage: b = vector([10, 20, 30])
sage: c = vector([1, -2, 3, -1])
sage: z = zero_vector(3) # use a vector with 3 entries, for consistency with the size of II

sage: m = block_matrix(2, [[A, II, matrix(b).transpose()], [matrix(c), matrix(z), zero_matrix(1, 1)]])
sage: m
[ 1  2  3  4| 1  0  0|10]
[ 4  3  2  1| 0  1  0|20]
[ 2  4  3  1| 0  0  1|30]
[-----------+--------+--]
[ 1 -2  3 -1| 0  0  0| 0]

Now you can modify the subdivisions, if you don't like the current ones. For example:

sage: m.subdivisions()  # current subdivision
([3], [4, 7])
sage: m.subdivide([3], [7])
sage: m
[ 1  2  3  4  1  0  0|10]
[ 4  3  2  1  0  1  0|20]
[ 2  4  3  1  0  0  1|30]
[--------------------+--]
[ 1 -2  3 -1  0  0  0| 0]
2020-07-15 18:04:39 -0500 answered a question Checking what the span is for a vector

Looks like you are trying to solve the matrix equation x Matrix = v1 for x. Use Matrix.solve_left(v1).

sage: m = random_matrix(QQ, 2, 4)
sage: m
[   0    1    0 -1/2]
[  -1    0    0    0]
sage: v = 2*m[0] + m[1]
sage: v
(-1, 2, 0, -1)
sage: m.solve_left(v)
(2, 1)

Of course this need not have any solutions, and if it does have a solution, it may not be unique.