Ask Your Question

abu safa's profile - activity

2021-10-24 20:38:31 +0200 received badge  Student (source)
2021-10-24 20:31:29 +0200 received badge  Popular Question (source)
2019-07-04 16:29:35 +0200 commented question Need help converting python code to sage compatible

anyone please ????

2019-07-02 20:42:37 +0200 commented question Need help converting python code to sage compatible

is it possible to convert above code and use it in sage? does sage do iterations fast?

2019-07-02 19:50:34 +0200 commented question Need help converting python code to sage compatible

i am not solving anything, but generating a result from elements. elements are in shape of list - tuple (000000000, 000000001, ........ 333333332, 333333333) i need to multiply each element with all elements to get the result for single element with respect to all elements. you can say, i am making a grid of element as row and columns and their results in do_calculations, i am solving an algebric like equation. I hope you understand what i am doing

2019-07-02 14:14:18 +0200 asked a question Need help converting python code to sage compatible

I have a list of 262144 elements in a list created through "itertools.product". Now I have to loop over these elements and multiply it with all other elements, which is taking too much time. (I don't have any issue of memory / cpu)

elements = []
for e in itertools.product(range(4), repeat=9):
    elements.append(e)

for row in elements:
   for col in elements:
      do_calculations(row, col)

def do_calculations(ro, co):
    t = {}
    t[0] = [multiply(c=ro[0], r=co[0])]
    for i in range(1, len(ro)):
        _t = []
        for j in range(i+1):
            _t.append(multiply(c=ro[j], r=co[i-j]))
        t[i] = _t

        for vals in t.values():
            nx = len(vals)
            _co = ro[nx:]
            _ro = co[nx:]
            for k in range(len(_ro)):
                vals.append(multiply(c=_co[k], r=_ro[k]))

        _t = []
        for k in t.values():
            s = k[0]
            for j in range(1, len(k)):
                s = addition(c=s, r=k[j])
            _t.append(s)
    return _t

def addition(c, r) -> int:
    __a = [[0, 3, 1, 2],
           [3, 2, 0, 1],
           [0, 3, 2, 1],
           [1, 0, 2, 3]]

    return __a[c][r]


def multiply(c, r) -> int:
    __m = [[0, 0, 0, 0],
           [0, 1, 2, 3],
           [0, 3, 1, 2],
           [0, 2, 3, 1]]

    return __m[c][r]

it is taking too much time to process single col with rows.... can any one help me in this? regards