Ask Your Question

Katika's profile - activity

2018-04-17 02:28:54 -0600 received badge  Popular Question (source)
2018-03-24 03:36:26 -0600 received badge  Notable Question (source)
2018-03-24 03:36:26 -0600 received badge  Popular Question (source)
2016-12-11 06:17:25 -0600 received badge  Notable Question (source)
2015-01-13 14:10:27 -0600 received badge  Notable Question (source)
2014-06-28 20:14:40 -0600 marked best answer Help! I have a problem with lists!

Hello!

I am a real beginner in Sage, I have just started th use it. In fact this is my first programing language, so I have some difficulties with it... Now I needed a command, which determins all the k-element subset of [1,2,...,N]. Since I don't found a command like this, I decided to write a program... :-) And now I simple don't understand while my program doesn't work corrrectly! Could you explain me? It is a bit longish, so sorry for this.

def eve(A,N):
    """
    the largest elem in the list A which can
    be increased by 1, such that the resulting list contains only 
    different elements less than N. Originally
    A should contain different elements in increasing order.
    """         
    ev = len(A)-1
    while A[ev] == ev+N-len(A):
        ev=ev-1    
    return ev        

def rakovetkezo(A,N):
    """
    Increases the eve(A,N)nt element by 1, and all the other elements 
    after this element are succesive natural numbers
    """
    Q=A
    ev=eve(Q,N)
    x=Q[ev]  
    for i in range(ev,len(Q)):
        Q[i]=x+i-ev+1
    return Q   

def reszhalmazok(N,k):
    """
    It should (but it doesn't) return the k-element 
    subset of [1,2,...,N]
    """
    X=range(k)
    B=[range(k)]
    ev=eve(X,N)
    while ev != -1:
        X=rakovetkezo(X,N)
        B.append(X)
        ev = eve(X,N)
    return B

Now reszhalmazok(5,3) should return [[0,1,2], [0,1,3],...] but it returns something completely different, aaand I don't see why, and how could be improve it?

Katika

2013-04-19 05:39:09 -0600 received badge  Popular Question (source)
2013-03-14 02:43:33 -0600 received badge  Popular Question (source)
2012-04-11 16:58:35 -0600 received badge  Taxonomist
2011-04-07 05:51:55 -0600 received badge  Good Question (source)
2011-04-06 06:03:19 -0600 marked best answer notebook questions

Katika, you should be able to save any object in Sage, as well as a whole session. If you click "Help" on the notebook at the top, the page you get should have

Use "save obj1 obj2 ..." and "load obj1 obj2 ...". This allows for easy moving of objects from one worksheet to another, and saving of objects for later use.

toward the bottom. The syntax is wrong, though.This is now Ticket 11124.

This should work.

A = matrix([[2,3],[3,4]])
save(A,'test')

And then a link to the actual .sobj file should be created, and you could use that. The help for the DATA variable should help as well. If you want to use your home directory, then

save(A,os.path.expanduser('~/')+'test')

might help you; it will show up in your home directory, if you use a system which supports the tilde. Maybe that should be in the help as well...

2011-04-05 22:15:55 -0600 commented answer notebook questions

I secretly voted :-) (Or voting is different from marking... ?)

2011-04-05 21:46:36 -0600 received badge  Supporter (source)
2011-04-05 03:29:52 -0600 commented answer notebook questions

I tried this, but it doesn't work if I would like to load "ssum" in another notebook cell... Is there a way to tell the path to the ssum.obj? I think something load('~/sage/ssum.sobj')?

2011-04-04 23:07:11 -0600 answered a question notebook questions

Thank you very much :-)

2011-04-04 12:05:58 -0600 received badge  Nice Question (source)
2011-04-04 04:15:23 -0600 answered a question notebook questions

Hello!

I show you an example. My dictionary is the following:

square_sum={}

for a in range(1000):

   for b in range(1000):

       square_sum[a,b]=a^2+b^2

Now in another notebook worksheet I would like to upload only this dictionary (or is it called vocabulary?) square_sum. So the question is how to save the dictionary and how to upload it in another worksheet?

2011-04-04 03:48:53 -0600 asked a question notebook questions

Hello!

Could you help me? I used notebook and in it I wrote a program in SAGE which generated a huge dictionary. I would like to save only this dictionary because I need to use this dictionary in another SAGE program. Unfortunately, I am not very familiar in using the notebook, so I don't know how to do this... Another (very simple) question when there is a bug in my program in the notebook, the computer wrotes me which line the bug is. But I don't how to find this line with the given number. Is there a line-numerator in the notebook?

2011-01-05 10:30:58 -0600 commented answer A programing question

Thanks! So my next question will have a better form :-)

2011-01-05 10:25:35 -0600 commented answer A programing question

When I need to return with two variables (I use two dictionaries u and v, and I need both later), is there a method which returns with both u and v?

2011-01-05 06:43:31 -0600 commented answer A programing question

Thank you! It will help me :-)

2011-01-05 06:42:36 -0600 commented answer A programing question

Hello! I was in a trouble editing my question, i don't know how to put indentations... Indeed, I write an indentation and it doesn't appear... I am a beginner both in Sage and in programming, and to read python that's something very hard for me :-) But this forum helps me a lot :-)

2011-01-05 02:41:53 -0600 asked a question A programing question

Hello!

I would like to define a procedure, which puts values in a dictionary:

def put:
    u={}
    u[Cathy]=3232556
    u[John]=4256342

Now if I am outside the procedure, I cannot use the values of u's... Is there a method for that outside the procedura I can use these specific u's?

def put:
    u={}
    u[Cathy]=3232556
    u[John]=4256342

put

print u[Cathy]

Traceback (click to the left of this block for traceback)
...
SyntaxError: invalid syntax

Many Thanks!

2010-12-15 04:05:50 -0600 commented answer multidictionaries

Thank you very much! (I also thought a similar thing but with lists in the argument. But I prefer tuples :-) )

2010-12-15 02:59:52 -0600 asked a question multidictionaries

Hello!

I need to store more data, and in order to do so, I would need multi-dimensional version of a dictionary... For example, let m be an object such that if you give the name and the age, such as m [Cathy, 19], then it returns the phone number. (In a dictionary you have one variable, and now I must call the data by more variables...) Do you know such a command?

2010-12-14 07:28:35 -0600 marked best answer Help! I have a problem with lists!

The reason why your program doesn't work is due to the line

Q = A

in rakovetkezo. When you do Q = A, you make Q point to the same object that A is pointing to. Then, when you change Q, you also change A. See the following:

sage: A = [1,2,3]
sage: Q = A
sage: id(Q)
88220880
sage: id(A)
88220880
sage: Q[0] = 100
sage: A
[100, 2, 3]

In order to make a copy of A, you can do something like

Q = A[:]

or

Q = list(A)

or

 from copy import copy
 Q = copy(A)

Then your program will work just fine.

Sage also has a builtin class for working with with combinations which is a bit more fully-featured than itertools.combinations. Here are some examples of this.

sage: S = Combinations(range(5), 3); S
Combinations of [0, 1, 2, 3, 4] of length 3
sage: S.cardinality()
10
sage: S.random_element()
[0, 3, 4]
sage: S.list()
[[0, 1, 2], [0, 1, 3], [0, 1, 4], [0, 2, 3], [0, 2, 4], [0, 3, 4], [1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]]
sage: [x for x in S]
[[0, 1, 2], [0, 1, 3], [0, 1, 4], [0, 2, 3], [0, 2, 4], [0, 3, 4], [1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]]
2010-12-06 01:40:48 -0600 asked a question subfields in finite fields

Hello! I have another problem with finitefields. I create a field, for example, GF(103^2) and later I use an element from it, which will be also an element of the subfield GF(103), i.e. a=99 is an element of both GF(103) and GF(103^2). But then the program doesn't convert "a" to an element of GF(103)... Do you know a method for this?

2010-12-06 01:35:27 -0600 asked a question time in notebook

Hello!

Could you help me? I need to know the time of a sage program written in the notebook, but when I use the timeit command, it doesn't work if I use "for" iterators in the program.

2010-11-08 13:18:40 -0600 received badge  Teacher
2010-11-08 13:18:39 -0600 received badge  Student (source)
2010-11-08 13:18:39 -0600 received badge  Editor (source)
2010-11-08 13:18:39 -0600 received badge  Scholar (source)
2010-10-19 07:49:26 -0600 answered a question Characters and number fields

Hello Niles!

Thank you for your answer! Tomorrow I will read it more carefully, and think the whole business once again, now I am very tired... :-) With my colleague we worked on this very hard and just now we found another solution. But now I am a bit confused, whether it was a good solution or not? Here what we did:

K.<a>=CyclotomicField(6)
R=K.maximal_order()

A=DirichletGroup(7,K)

character=A[1]

print character(3) 

character(3) in R

Here, in A=DirichletGroup(7,K) means that the Dirichlet character must take their value from the integral domain K, and then everything works perfectly... I really hope we didn't make a fault, by not specifying the value of zeta! (I think not, but I will think it over tomorrow...)

Thanks again! :-)

2010-10-19 04:22:52 -0600 asked a question Characters and number fields

Hello!

I have again a question. Could you help me? I defined the Q(6th primitive unity) by

A=DirichletGroup(7)
K.<a>=NumberField(cyclotomic_polynomial(6))
R=K.maximal_order()

Then I take a character, namely

character=A[1]
print character(3)

This character(3) is zeta6, so I would think that the following should be true:

 character(3) in R.fractional_ideal(a)

But it is false, I think because we defined Q(6th primitive unity) without using zeta6. Mathemathically this is true, so could you help me to persuade the computer to recognize such a relation? Thank you! :-)