Ask Your Question

# John Palmieri's profile - activity

 2019-08-14 05:38:59 -0500 received badge ● Good Answer (source) 2019-08-11 18:23:42 -0500 commented question Submitting code to Sage The Sage Developer's Guide is the first step. 2019-08-09 08:09:06 -0500 received badge ● Nice Answer (source) 2019-08-08 10:54:34 -0500 commented question The shortest string containing all given substrings If you want a Sagemath solution, there is http://doc.sagemath.org/html/en/refer.... You would have to translate the numbers 1, 2, ..., 7 to the letters a, c, d, ... h, but that should be easy. 2019-08-08 01:13:10 -0500 received badge ● Nice Answer (source) 2019-08-07 13:47:18 -0500 answered a question tree ordering in sage The documentation in the reference manual says that it is using the algorithm from this paper. 2019-08-05 22:25:22 -0500 commented answer How to draw a graph whose vertices are elements of permuation group d[x] is supposed to be a list consisting of the elements y which do not commute with x. If that list hasn't been created yet (because no such elements y have been found), then if x in d will return False, so you set d[x] to be the list containing y. Otherwise d[x] exists, so append y to the end of the list. 2019-08-05 13:23:17 -0500 answered a question Why GF(256) matrix only have zero and one number? If you want to work mod 256, you should work with Integers(256), not GF(256). (The first of these is the ring Z/256, the second is the field with 256 elements.) sage: matrix(Integers(256), [1,2,3,4]) [1 2 3 4] sage: matrix(Integers(256), [254, 255, 256, 257]) [254 255 0 1]  (edited to add the second example) IntegerModRing(256) is a synonym for Integers(256), by the way. 2019-08-05 11:52:47 -0500 answered a question How to draw a graph whose vertices are elements of permuation group For #1: sage: G = groups.permutation.Symmetric(3) sage: for x in G: ....: (do stuff with x)  For example: sage: G = groups.permutation.Symmetric(3) sage: d = {} sage: for x in G: ....: for y in G: ....: if x*y != y*x: ....: if x in d: ....: d[x].append(y) ....: else: ....: d[x] = [y] ....:  At this point, d is a dictionary. The keys are the non-identity elements of G, and the value corresponding to x is the list of elements y that do not commute with x. So for #2: sage: gr = Graph(d) sage: view(gr) 2019-08-05 10:17:05 -0500 received badge ● Good Answer (source) 2019-08-04 08:35:26 -0500 received badge ● Good Answer (source) 2019-08-04 03:44:52 -0500 received badge ● Nice Answer (source) 2019-08-02 14:25:56 -0500 commented question I just built a Sage system. What files may I delete with impunity? Why version 7.6? That's pretty old. Did more recent versions fail for you? 2019-08-02 14:25:30 -0500 answered a question I just built a Sage system. What files may I delete with impunity? make clean and make misc-clean are safe, although the second of these will remove log files. make micro_release should also be safe, although it will remove all of the built documentation. Removing everything in local/share/doc/sage/ except for html and (if present) pdf should be safe. Removing upstream will still allow Sage to run, but you would then need to download a lot of tar files if you ever wanted to rebuild it. 2019-08-01 20:19:54 -0500 commented answer Trying to get the divided differences of a list of points @Macacroso: I wasn't trying to criticize, rather trying to help in the future. For me, once I know how to really use the documentation, it helps me whenever I use the software. 2019-08-01 11:38:07 -0500 received badge ● Nice Answer (source) 2019-07-30 23:05:18 -0500 answered a question Docstring docs and html docs are different This function is here in the reference manual. This is one of the many listings when you search for "factor" in the reference manual, but it's nowhere near the first one. You can find it by looking at the end of the output for factor?: it says "File: .../site-packages/sage/arith/misc.py", and then you can search the listings for "arith.misc". 2019-07-29 18:31:08 -0500 commented answer How can I assign different degrees to the variables of a polynomial ring? A mistake. I was going to give the links in the other order and then decided that I preferred this order instead. 2019-07-29 13:20:21 -0500 received badge ● Nice Answer (source) 2019-07-29 12:26:04 -0500 answered a question How can I assign different degrees to the variables of a polynomial ring? You can use "weights": sage: P. = PolynomialRing(QQ, 3, order=TermOrder('wdeglex',(1,2,3))) sage: x.degree() 1 sage: z.degree() 3  I think this is not documented very well, or at least I didn't discover it easily. See http://doc.sagemath.org/html/en/refer... and http://doc.sagemath.org/html/en/refer.... 2019-07-29 12:13:25 -0500 commented answer How can I assign different degrees to the variables of a polynomial ring? This unfortunately is not a polynomial ring, since b*b=0. 2019-07-29 08:07:05 -0500 received badge ● Nice Answer (source) 2019-07-28 17:25:01 -0500 received badge ● Nice Answer (source) 2019-07-28 15:09:25 -0500 commented answer Is there a function to render latex or html in a notebook from a string ? The answer is over 8 years old, so it would be a little surprising if it did still work. Sage has changed, the notebook has changed, etc. 2019-07-27 15:25:58 -0500 commented answer Trying to get the divided differences of a list of points For future use, if you find something like this in the Sage reference manual (like http://doc.sagemath.org/html/en/refer... or http://doc.sagemath.org/html/en/refer...), there will probably be examples showing exactly how to use it. 2019-07-26 17:36:07 -0500 answered a question Is there any way to have a cell tell you how long it took to run in the Jupyter notebook? You can put %%time as a line at the start of the cell. Does that do what you want? 2019-07-26 16:20:19 -0500 commented question Is there a binary version of SageMath .app.dmg compatible with Mac OS X ver. 10.14.6 I posted this on sage-support, but the .app.dmg file works for me with OS X 10.14.6 on an iMac Pro. 2019-07-23 09:36:07 -0500 received badge ● Good Answer (source) 2019-07-21 09:34:02 -0500 received badge ● Nice Answer (source) 2019-07-19 22:32:18 -0500 answered a question Why does .remove() seem to take every element out of a list? When you evaluate list1.remove(2), it modifies list1 and always returns None. It does not return the modified list. So: sage: list1 = [1,2,3] sage: list1.remove(2) sage: list1 [1, 3]  Note that there is no output from the second line: it returns nothing. This in contrast to something like the sorted function which does not modify the original list but instead returns a new sorted list: sage: list1 = [3,2,1] sage: sorted(list1) [1, 2, 3] sage: list1 [3, 2, 1]  2019-07-02 21:25:32 -0500 received badge ● Nice Answer (source) 2019-06-25 19:02:23 -0500 commented answer wrapping vector class Oh, also, as @slelievre said in answer to a separate question of yours, using .py files, not .sage files for this kind of work. 2019-06-25 18:59:00 -0500 commented answer wrapping vector class First, use Vector_rational_dense instead of Vector. Or if you use Vector, be prepared to implement lots of things from scratch, since this class is pretty general purpose and doesn't even have an __init__ method. Next, it seems that Vector_rational_dense requires two arguments, the vector space and then the data; furthermore, for any class that inherits from it, it intercepts the arguments, so your __init__ method should have those same arguments. (Vector_rational_denseis defined using Cython; see https://cython.readthedocs.io/en/late....) See my edited answer. 2019-06-25 16:14:49 -0500 commented answer wrapping vector class To find where to import, use import_statements('Vector_rational_dense'). Also, calling Vector.__init__(self, data, ...) should have the same effect as Vector(data, ...). As far as vector([1,2]), you need to read the source code to see exactly what that does. It looks like it tries to determine the base ring, then creates a free module M of the appropriate rank over that ring, then does M(data). I think that in turn calls the _element_constructor_ method for the free module. 2019-06-25 16:00:54 -0500 edited question wrapping vector class I am trying to wrap the vector class to add some extra cases, but I am having trouble doing so. This is the code I have: def lower_triangular_entries(dim,x,y): return upper_triangular_entries(dim,y,x) def upper_triangular_entries(dim,x,y): if y<=x: return 1 else: return 0 class OneParamSubgroup(vector): #TO DO: define scalar multiplication def __init__(self, data, type_A=False): if type_A: BasisChange=matrix(ZZ, len(data)-1, len(data)-1, lambda x,y: lower_triangular(len(data)-1,x,y)) v=vector(data[0:len(data)-1]) v=tuple(BasisChange*v) #data given in terms of basis T else: v=data vector.__init__(self, v) def __repr__(self): return self  However, I get the following error when running on terminal Traceback (most recent call last): File "test.sage.py", line 7, in load("GIT/Group.sage") File "sage/structure/sage_object.pyx", line 1057, in sage.structure.sage_object.load (build/cythonized/sage/structure/sage_object.c:12915) File "/opt/sagemath-8.1/local/lib/python2.7/site-packages/sage/repl/load.py", line 247, in load exec(preparse_file(open(fpath).read()) + "\n", globals) File "", line 3, in ImportError: cannot import name vector  and the following on the Notebook TypeError Traceback (most recent call last) in () 8 return Integer(0) 9 ---> 10 class OneParamSubgroup(vector): 11 #TO DO: define scalar multiplication 12 def __init__(self, data, type_A=False): TypeError: Error when calling the metaclass bases cannot create 'builtin_function_or_method' instances  Any idea of what I am doing wrong? 2019-06-25 15:50:19 -0500 answered a question wrapping vector class In Sage, vector is a function, not a class, so you can't inherit from it. You should use Vector instead: from sage.structure.element import Vector class OneParamSubgroup(Vector): ...  I found this by looking at the help for vector (vector?). At the end, it tells me File: ..../sage/local/lib/python2.7/site-packages/sage/modules/free_module_element.pyx Type: builtin_function_or_method  Actually, Vector may not be perfect. What sort of vectors are you working with? Some other classes may provide more methods. Some examples: sage: type(vector([1, 2])).mro() # integer entries [, , , , , , ] sage: type(vector([1., 2])).mro() # real [, , , , , , ] sage: type(vector([1/2, 2])).mro() # rational [, , , , , , ]  So you could instead inherit from Vector_rational_dense, etc. Edit: to use Vector_rational_dense, you could do this: from sage.modules.vector_rational_dense import Vector_rational_dense class test(Vector_rational_dense): def __init__(self, parent, value): Vector_rational_dense.__init__(self, parent, value) xi2 = test(QQ**3, [2,2,1]) # or do this: def vector_constructor(value): return test(QQ**len(value), value) xi3 = vector_constructor([2,2,1])  2019-06-22 17:24:04 -0500 commented question find all matchings in a graph A problem with my suggestion is that I don't know how to get Sage to tell me all maximal matchings. It produces a single one easily enough, but I don't know about all of them. 2019-06-22 17:17:09 -0500 answered a question find all matchings in a graph I don't know how efficient this is, but to find all matchings with a fixed number of edges, you can do this: sage: from itertools import combinations sage: g = graphs.PetersenGraph() sage: E = [e[:2] for e in g.edges()] sage: E # edges without the labels [(0, 1), (0, 4), (0, 5), (1, 2), (1, 6), (2, 3), (2, 7), (3, 4), (3, 8), (4, 9), (5, 7), (5, 8), (6, 8), (6, 9), (7, 9)]  Now look for sets of n edges containing 2n different vertices, for example with n=5: sage: [a for a in combinations(E, 5) if len(set().union(*a)) == 10] [((0, 1), (2, 3), (4, 9), (5, 7), (6, 8)), ((0, 1), (2, 7), (3, 4), (5, 8), (6, 9)), ((0, 4), (1, 2), (3, 8), (5, 7), (6, 9)), ((0, 4), (1, 6), (2, 3), (5, 8), (7, 9)), ((0, 5), (1, 2), (3, 4), (6, 8), (7, 9)), ((0, 5), (1, 6), (2, 7), (3, 8), (4, 9))]  2019-06-22 17:07:44 -0500 commented question find all matchings in a graph I suppose you could work recursively: ask for all maximal matchings in G, and then ask for all maximal matchings in G with a single edge removed, etc. 2019-06-20 13:12:43 -0500 commented answer Testing if the entries of a matrix of rational vectors are actually integers That one takes 16.2 ms per loop, and the others are about 3.5 ms per loop, so the others are faster. 2019-06-20 10:16:22 -0500 received badge ● Nice Answer (source) 2019-06-18 15:18:20 -0500 commented answer how to generate Cayleygraph I don't know. You can look at the documentation for the cayley_graph method: http://doc.sagemath.org/html/en/refer... 2019-06-18 12:13:33 -0500 edited answer Testing if the entries of a matrix of rational vectors are actually integers If you know that you are dealing with 5x4 matrices, for example: sage: A = random_matrix(QQ, 5, 4) sage: A in MatrixSpace(ZZ, 5, 4) False  Or if you don't know the size: sage: A in MatrixSpace(ZZ, A.nrows(), A.ncols()) False  This seems to be a little faster than all(x in ZZ for x in A.list()), especially as the matrices get large. sage: %timeit all(a in ZZ for a in random_matrix(QQ, 200, 200).list()) 100 loops, best of 3: 15.5 ms per loop sage: %timeit random_matrix(QQ, 200, 200) in MatrixSpace(ZZ, 200, 200) 100 loops, best of 3: 3.32 ms per loop  Revised timings to also compare the denominator method (on a different computer, so all of the timings are different): sage: %timeit all(a in ZZ for a in random_matrix(QQ, 200, 200).list()) 100 loops, best of 3: 16.2 ms per loop sage: %timeit random_matrix(QQ, 200, 200) in MatrixSpace(ZZ, 200, 200) 100 loops, best of 3: 3.44 ms per loop sage: %timeit random_matrix(QQ, 200, 200).denominator() == 1 100 loops, best of 3: 3.77 ms per loop