Ask Your Question

sssageeee's profile - activity

2019-08-08 17:31:25 +0200 received badge  Famous Question (source)
2018-05-24 20:08:35 +0200 received badge  Notable Question (source)
2017-12-13 22:02:36 +0200 received badge  Popular Question (source)
2017-04-24 03:20:31 +0200 commented answer Recurrence, for-loop and zero.

Thank you so much nbruin. Hope you have a good day!

2017-04-24 00:09:35 +0200 asked a question Recurrence, for-loop and zero.

Hello guys! Hope you guys are having a nice day.

I have some problem as follows: I setup some recurrence as follows

def f(j,k):
if k==0:
    m=j
elif j==0:
    m=k
else:
    m=j/k*(f(j-1,k)+1/k*(f(j-1,k)))+k/j*(f(j,k-1)+1/j*(f(j,k-1)))
return m

And if we calculate

f(1,1), f(2,1), f(1,2), f(2,2)

in sage, then what we get are

4, 35/2, 35/2, 105/2.

However, if we do the for loop as in the below, I found the above results to be zero!!:

for k in range(3):
    for j in range(3):
        (j,k), expVal(j,k)

And the calculation result from the sage is:

((0, 0), 0)

((1, 0), 1)

((2, 0), 2)

((0, 1), 1)

((1, 1), 0)

((2, 1), 0)

((0, 2), 2)

((1, 2), 0)

((2, 2), 0)

And observe the bolded result above... it is weird that the result is zero... Can anyone help me fix this please...

Thank you for any help! Hope you have a nice rest of the day!

2017-03-19 22:26:09 +0200 commented answer Priniting Horizontally??

Thank you tmonteil. Your answer is also very helpful! I hope you have a nice day! and wish you the best luck for your future!

2017-03-19 22:26:09 +0200 commented answer Priniting Horizontally??

Thank you soooo much ndomes! This answer is very awesomeeeee! You helped me very much a lot. Thank you very much again! I hope you have a great day! And wish you the best luck for your future!

2017-03-19 20:33:25 +0200 received badge  Scholar (source)
2017-03-18 21:50:13 +0200 asked a question Priniting Horizontally??

Hello, guys! hope you are having a good day. First of all, I'm very new to sage and this forum, so would you please be generous to my question,, please?..

So, I was trying to do some recursive/iterative calculations as follows:

def calculator(L1,L2):
    c=0
    m=len(L1)
    n=len(L2)
    print '('
    if m==0:
        c=c+0
        print '+'
        print c
        print ')'
    elif m==1:
        l1=L1[0]
        l2=L2[0]
        if l1<l2:
            c=c+l1
            print '+'
            print c
            print ')'
        else:
            c=c+0
            print '+'
            print c
            print ')'
    else:
        for i in range(m):
            l1=L1[i]
            l2=L2[i]
            if l1<l2:
                c=c+l2
                print '+'
                print c
                print ')'
            else:
                L3=[L1[j] for j in range(i)]+[L1[j] for j in range(i+1,m)]
                L4=[L2[j] for j in range(i)]+[L2[j] for j in range(i+1,n)]
                c=c+(-1)^m*calculator(L3,L4)
                print '+'
                print c
                print ')'
    return c

And, if we calculate, for example,

L1=[5,7,3]; L2=[7,5,2]; calculator(L1,L2)

then we get: (I've intentionally wrote vertically in the below, because that is exactly the sage gives us as a result)

(

+

7

)

(

+

7

)

(

+

5

)

+

12

)

+

-5

)

(

+

7

)

(

+

5

)

+

12

)

+

-17

)

-17

BUT!, if we actually, calculate by hand, then we get:

calculator([5,7,3],[7,5,2])

=7-calculator([5,3],[7,2])-calculator([5,7],[7,5]

=7-(7+calculator([5],[7]))-(7+calculator([5],[7])

=7-(7+(5))-(7+(5))=-17

And I actually want 7-(7+(5))-(7+(5))=-17 as a result... Can any body help me how to solve this kind of problem,, please...

And, moreover, if it is possible to get the result like

"calculator([5,7,3],[7,5,2])

=7-calculator([5,3],[7,2])-calculator([5,7],[7,5]

=7-(7+calculator([5],[7]))-(7+calculator([5],[7])

=7-(7+(5))-(7+(5))=-17"

then, it would be much greater...!

Oh one last thing to note is that even though we get the vertical result as above, if we write down horizontally that result, we get

( + 7 ) ( + 7 ) ( + 5 ) + 12 ) + -5 ) ( + 7 ) ( + 5 ) + 12 ) + -17 ) -17

which shows us that there are some redundancy in the result and some parentheses are showing weirdly...

Can any body,, please help me how to solve this kind of problem... Thank you for help! and I hope you have a great day!!! I wish you the best luck for your future! Thank you!

2017-03-07 02:44:30 +0200 asked a question Overwriting...?

Hello, guys! ... First of all, I'm very new to sage and this forum, so please be generous for my question, please...

So, I've wrote in sage (between @@@@@'s):

@@@@@

p=[3,2,1];

q=p;

temporary=q[0];

q[0]=q[1];

q[1]=temporary;

@@@@@

Then, the result for p and q was

p=[2,3,1] and q=[2,3,1].

But, what I actually want is that p doesn't change; so I want to have

p=[3,2,1] and q=[2,3,1]

so that p doesn't get changed when we set 'q=p', while q is defined to be p when we set 'q=p' and then q get changed via the codes followed by 'q=p' above... In other words, is there a way to 'overwrite' q to be p, and not changing p? Thank you!!!

2017-03-05 09:47:39 +0200 received badge  Student (source)
2017-03-04 23:31:44 +0200 asked a question Finding intersection of two lists?

Hello, guys. First of all, I'm very new to Sage and also to this forum, so please be generous for my question...

So, suppose we have

c=[[0, 1, 2, 3], [0, 1, 2, 4], [0, 1, 3, 4], [0, 2, 3, 4], [1, 2, 3, 4]],

d=[[0, 1, 2, 3], [0, 1, 3, 4], [0, 2, 3, 4], [9, 8, 7, 6]]

I would like to get

[[0, 1, 2, 3], [0, 1, 3, 4], [0, 2, 3, 4]]

which is intersection of c and d. Is there a way to do this?

Thank you for any help.

2017-03-04 23:31:44 +0200 asked a question Changing a 1-line permutation to a string 'blablabla'

Hello, guys. First of all I'm very new to Sage, and also this forum, so please be generous to my question..

So, I was wondering given a permutation, say

Permutation([1,2,3,4])

how can I change to a string of the form

'1234'

??

Thank you for any help.