Skip to main content
3 of 3
deleted 124 characters in body
Azzurro94
  • 499
  • 2
  • 10

How to get Sum of array of integers?

This question seems easy but I am struggling with it now, I tried a few ways and check this solution as well but couldn't help me, please check and help if you are able:
So I need to save the sum of array elements in single variable and I tried these approaches, I show you two of them here. (I must have x as variable to store result, and initialize the array as well)

Array [A, 3]
A = {1, 2, 5}
R2 = x == Sum[A[index], {index, i, 3}]  && i == 1
Simplify[Reduce[R2]]

And Also

R2 = x == Sum[A[index], {index, i, 3}] && A[1] == 1 && A[2] == 2 && A[3] == 5 && i == 1
Simplify[Reduce[R2]]

this is part of final answer I get

x == A[1] + A[2] + A[3]

It shows me a simple equation not final answer, but I expect a simple answer x== 8 or x-> 8, but it does not solve the SUM, seems I am missing something.

EDITED: based on @thorimur answer I completed my question. Actually the reason i used Reduce and Sum is: 1- I used reduce because we have more complicated expressions which Sum is part of that. 2- I used sum because not all the time we have initialized array. For some times, i need parametric array which must be shown in Sum. this is the more complete statement.

R2 = x == Sum[A[index], {index, i, 3}]  && i == 1
R3=Simplify[Reduce[
  Exists[{i,x,A},  R2 && // Array initialization // i == 1 ]]]

I know this does not work but this is my intention. we need a statement as R3

Azzurro94
  • 499
  • 2
  • 10