I am trying to write a function which operates on an array with subscripted elements.
As an example i have the array a={$1_3$,$2_2$,$4_1$}, which means i have 3 amounts of value 1, 2 amounts of value 2 and 1 amount of value 4. If the subscripted amount reaches 0, then the element has to be dropped from the array.
Now i need a function
edit[a_,lower_,raise_]:=...
with lower_ being an array of elements which shall be decreased by 1 and raise_ being the array of elements which should be increased by 1. These two arrays have to contain the value and not the position of the element which should be changed.
So if i would call the function with
edit[{Subscript[1, 3], Subscript[2, 2], Subscript[4, 1]}, {1, 1, 4}, {2, 5}]
the output should be
{Subscript[1, 1],Subscript[2, 3], Subscript[5, 1]}
because
- the value 1 has to be decreased 2 times, leaving it with the amount 1
- the value 4 has to be decreased once, thus the amount reaches 0 and it has to be dropped
- the value 2 has to be increased once, increasing the amount to a total of 3
- the value 5 has to be increased once, and since its not in the list yet, it has to be added
I want to use subscript because it makes it easy to read and seems to behave like a normal 2 dimensional array, but i am open to good alternatives.