Ask Your Question

Jesus Martinez Garcia's profile - activity

2020-01-22 10:44:58 -0500 received badge  Popular Question (source)
2020-01-15 07:00:13 -0500 received badge  Nice Question (source)
2020-01-10 05:20:04 -0500 received badge  Popular Question (source)
2020-01-01 17:09:44 -0500 received badge  Notable Question (source)
2020-01-01 17:09:44 -0500 received badge  Popular Question (source)
2019-06-26 00:39:11 -0500 commented answer wrapping vector class

@john-palmieri it is all clear now. Thank you for your patience.

2019-06-25 16:25:30 -0500 commented answer wrapping vector class

@John_Palmieri Actually, (disregard original comment, there was mistake), it doesn't work. I do MWE:

from sage.structure.element import Vector
class test(Vector):
  def __init__(self,value):
      Vector.__init__(self, value)
xi2=test([2,2,1])

Get error:

  File "test.sage.py", line 23, in <module>
    xi2=test([_sage_const_2 ,_sage_const_2 ,_sage_const_1 ])
  File "<string>", line 4, in __init__
  File "sage/structure/element.pyx", line 388, in sage.structure.element.Element.__init__ (build/cythonized/sage/structure/element.c:4248)
TypeError: Cannot convert list to sage.structure.parent.Parent
2019-06-25 16:13:21 -0500 commented answer subclass from a sage vector
2019-06-25 16:09:11 -0500 received badge  Commentator
2019-06-25 16:09:11 -0500 commented answer wrapping vector class

@John_Palmieri I guess I want rational vectors (to keep it safe). Should I use from sage.structure.element import Vector_rational_dense?

2019-06-25 16:05:32 -0500 commented answer wrapping vector class

@John_Palmieri Thank you thank you, you can't believe how long I've been struggling with this. How did you know where to import it from? And when I do w=OneParamSubgroup([1,2]), if it is just the empty wrapper calling Vector.__init__, will it have the same effect as doing vecctor([1,2])?

2019-06-25 15:15:51 -0500 commented question Is it possible to subclass a sage class?

Hi, @done_with_fish did you manage to do this? I have no trouble doing it with Python classes, but struggle with Sage classes, see here: https://ask.sagemath.org/question/469...

2019-06-25 12:42:38 -0500 received badge  Editor (source)
2019-06-25 12:40:19 -0500 asked a 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 <module>
    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 "<string>", line 3, in <module>
ImportError: cannot import name vector

and the following on the Notebook

TypeError                                 Traceback (most recent call last)
<ipython-input-1-ec2394617192> in <module>()
      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 12:27:38 -0500 asked a question Creating a module in Sage

I am new to Sage, being used to Python and I am having some trouble with adapting.

In particular, I am trying to create a 'module' in the Python sense, i.e. some set of classes that I can call with 'import'.

When I did this in python in the past, I would create a directory (say /my_module/ in my home) and include a file __'__init____.sage' in that file with a line

__all__ = ['Submodule1', 'Submodule2']

Then I would have a file 'Submodule1' and 'Submodule2'. In the file 'Submodule 1' I would define 'Class1'

and then from a file 'run.py' in home I would write

import my_module
from my_module.Submodule1 import Class1

and then I would be able to write

c=Class1()

to create an object.

I find that this is not working in Sage and the only thing I seem to be able to do is write in run.py

load("my_module/Submodule1.sage")

for each class I want to load. This has many disadvantages, for instance hiding classes from potential users so that they only exist internally.

Any suggestions on how to create and import modules in sage? What is the sage way?

2019-06-24 19:37:32 -0500 commented question Updating Sage in Windows 10

@vdelecroix It is not there. I tell you, I have done a search for cygwin and there is not such directory in the whole disk.

2019-06-24 10:15:05 -0500 commented question Updating Sage in Windows 10

@vdelecroix I don't think that is correct. I downloaded bin files here http://www.mirrorservice.org/sites/ww... and then simply ran the installation file. I do not have cygwin installed on my computer. If sagemath installs cygwin and runs over it, it does it in a completely transparent way. I cannot even find a cygwin folder in my computer.

2019-06-23 08:21:58 -0500 commented answer Testing if the entries of a matrix of rational vectors are actually integers

@john_Palimieri all clear, thanks. I got confused by the line "This seems to be a little faster than[...]".

2019-06-20 10:24:07 -0500 asked a question Updating Sage in Windows 10

The Sage Installation Guide Release 8.7 seems to assume that one installs Sage in Windows using Cygwin, in particular regarding upgrading. However, I installed Sage on Windows 10 from the bin files without installing Cygwin at all. How should I update both Sage and the packages?

I favour an easy way that does not make me uninstall-reinstall.

2019-06-20 10:20:00 -0500 commented answer Testing if the entries of a matrix of rational vectors are actually integers

From your last comparison it seems to me that all(a in ZZ for a in random_matrix(QQ, 200, 200).list()) is the fastest as it takes less ms. Am I missing something?

2019-06-18 07:39:31 -0500 commented answer Testing if the entries of a matrix of rational vectors are actually integers

@Juanjo Yes, of course that works, but I was interested in seeing if there was a method of the class matrix to deal with this, just as there is for the class Rational (or its parent, wherever is_rational is). Anyway, it is neat, so I vote up. If nobody replies in a few days I will accept the answer.

2019-06-18 06:29:39 -0500 commented answer Testing if the entries of a matrix of rational vectors are actually integers

@FrédéricC If I do that and the matrix has denominators it will give an error 'matrix has denominators so can't change to ZZ.'

2019-06-18 05:00:50 -0500 received badge  Autobiographer
2019-06-18 04:58:39 -0500 asked a question Testing if the entries of a matrix of rational vectors are actually integers

I moved from Python to SageMath because it allows me to deal with natural operations in mathematics without having to reinvent the wheel through typing obvious classes and methods. I also suppose the built-in classes and methods do things in more efficient ways that I could do myself.

However, sometimes I find hard to find the right function or class for what I want to do.

I have created several matrices using 'matrix' which may have rational or integer numbers (so I use QQ to define them). I want to check which matrices actually have all entries as integers. I know how to do this by looping through all entries of each matrix and calling 'is_integer', but is there an existing method in 'matrix' doing this for me? I could not find one.

2019-06-04 18:51:34 -0500 received badge  Scholar (source)
2019-06-04 18:51:32 -0500 commented answer Adding elements to a set

Thank you. Incidentally, I think that suggest an answer for my last question ('Is there a natural reason to explain why 'add' is not a method of 'Set'?'): if one wants a mathematical notion of set, we want to be able to create 'set of sets' naturally. Now I remember having this problem in Python when dealing with sets of sets: because the set is mutable (and hence not hashable), one has to create a frozen set, and then a set of frozen sets. From that point of view the Sage design is more natural.

2019-06-04 13:59:23 -0500 asked a question set add element

I learned Python a long while ago before I decided to get into SageMath for mathematical purposes.

I am a bit puzzled that I don't seem to have a way to add an element to a set when using the SageMath definition 'Set()', but there seems to be no problem when doing this using the Python definition 'set()', namely:

a=2; b=3; c=4
D=Set([a,b])
D.add(c)

gives the error

'Set_object_enumerated_with_category' object has no attribute 'add'

whereas

a=2; b=3; c=4
D=set([a,b])
D.add(c)

gives no problem (notice the difference in capital letter when creating set).

I am using the following workaround

a=2; b=3; c=4
D=Set([a,b])
D=D.union(Set([c]))

but it seems rather artificial. Is there no more natural way to proceed? Is there a natural reason to explain why 'add' is not a method of 'Set'?

2019-06-04 13:58:51 -0500 asked a question Adding elements to a set

I learned Python a long while ago before I decided to get into SageMath for mathematical purposes.

I am a bit puzzled that I don't seem to have a way to add an element to a set when using the SageMath definition 'Set()', but there seems to be no problem when doing this using the Python definition 'set()', namely:

a=2; b=3; c=4
D=Set([a,b])
D.add(c)

gives the error

'Set_object_enumerated_with_category' object has no attribute 'add'

whereas

a=2; b=3; c=4
D=set([a,b])
D.add(c)

gives no problem (notice the difference in capital letter when creating set).

I am using the following workaround

a=2; b=3; c=4
D=Set([a,b])
D=D.union(Set([c]))

but it seems rather artificial. Is there no more natural way to proceed? Is there a natural reason to explain why 'add' is not a method of 'Set'?

2019-05-31 07:33:55 -0500 received badge  Supporter (source)
2019-05-14 08:54:40 -0500 received badge  Famous Question (source)
2019-05-14 08:54:40 -0500 received badge  Notable Question (source)
2018-05-04 20:11:18 -0500 received badge  Popular Question (source)