2022-10-15 13:26:50 +0100 received badge ● Popular Question (source) 2021-02-01 09:49:00 +0100 asked a question how to sum sums I am new to sagemath and I am trying to calculate some formulas using it. I learned how to write a sum such as sage: a = [2, 2, 3, 4] sage: d = [2, 4, 5, 6] sage: def pi(i): ....: var("i") ....: f = sum([a[k]*d[k] for k in range(i + 1)]) ....: return f  However, I am having difficulties to write a sum for pi(i) such as sage: def Z(a, b): ....: var("a b") ....: l = len(d) - 1 ....: def pi(i): ....: var("i") ....: f = sum([a[k]*d[k] for k in range(i + 1)]) ....: return f ....: h = sum([pi(i) for i in range(l - 1)]) ....: return h  but I got error. I tried to use for i in range(l - 1):  also it doesn't work. 2020-12-03 11:01:45 +0100 commented answer counting number of matrices in finite field thank you so much for helping me you are the best :) 2020-12-03 10:59:19 +0100 received badge ● Scholar (source) 2020-12-02 20:21:13 +0100 commented answer counting number of matrices in finite field Thank you for answering my question. I am trying to count them on modules like M=matrix([[x1,x2],[x3,-x1]]) or M=matrix([x1,x2,x3],[x4,x5,x6],[x7,x8,-x1-x5]]) Is there a way where I can put the variables and make sage run them through GF(p) 2020-12-02 20:03:43 +0100 received badge ● Student (source) 2020-12-02 18:30:03 +0100 received badge ● Editor (source) 2020-12-02 17:18:01 +0100 asked a question counting number of matrices in finite field I am new to sage and I want to count the number of matrices per rank in a given finite field. Example: M=matrix([[x1, x2, x3],[ x4,-x1, x5],[x6,x7,x8]]) in Z/3Z