Hello Stack Overflow. I am using sympy summations in python, and I am having a problem where I cannot get a formula that can put my piecewise numbers in order from first to last. I want the numbers to become 1, 2, 3, and lastly 4, because this describes the order I want to use. My code is: import sympy as sp # Define the symbol x = sp.symbols('x') # Define the values using Piecewise f = sp.Piecewise( (3050, sp.Eq(x, 1)), (6020, sp.Eq(x, 2)), (5070, sp.Eq(x, 3)), (7060, sp.Eq(x, 4)), (0, True) # default case ) # Substitute a value for x print(f.subs(x, 3)) # → 5070 # Define summation from 1 to n closed_form_formula = 1 # formula goes here for the variable f n = sp.symbols('n', integer=True, positive=True) summation_expr = sp.summation(f, (x, 1, n)) As you can see in my code, the values are 3050, 6020, 5070, and 7060. I want a mathematical formula that will put the numbers in the order: 3050 5070, 7060, 6020. I want the number 3050 to be 1 and 5070 to be 2 and 7060 to be 3 and 6020 to be 4. I want completely closed form math code that can do this. Can someone help me? Also, it would be good if you guys can do this sequentially so it literally starts at 3050 and puts 1 then the formula adds 1 to when its 5070 since the pattern suggests that 50 is the next number to be used and so on for the pattern in the rest of the numbers. Continue reading...