# \[AMPL 24601\] Re: Double summation

**URL:** <https://discuss.ampl.com/t/ampl-24601-re-double-summation/470>\
**Category:** Google Group Mirror\
**Created:** [April 3, 2023, 8:27pm UTC](https://discuss.ampl.com/t/ampl-24601-re-double-summation/470 "2023-04-03T20:27:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ruonan\_Zhao](https://avatars.discourse-cdn.com/v4/letter/r/a6a055/32.png) [@Ruonan\_Zhao](https://discuss.ampl.com/u/Ruonan_Zhao)\
**Post date:** [April 3, 2023, 8:27pm UTC](https://discuss.ampl.com/t/ampl-24601-re-double-summation/470/1 "2023-04-03T20:27:53Z")

</div>

Hi all,  
Can anyone please kindly help below. I need to do double summation but index l should not equal to k. Below is what I write but seems wrong. Do you have any suggestions? Thanks!

**sum** {k **in** K,l **in** K **diff** {k}} y[k,l]

Best,  
Ruonan

---

<div class="post-metadata">

**Author:** ![4er](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/4er/32/530_2.png) [@4er](https://discuss.ampl.com/u/4er)\
**Post date:** [April 4, 2023, 6:43pm UTC](https://discuss.ampl.com/t/ampl-24601-re-double-summation/470/2 "2023-04-04T18:43:29Z")

</div>

I did a little test where I set K equal to {1,2,3,4,5} and assigned some random numbers to y. Your sum was evaluated without any errors:

```auto
ampl: set K := 1..5;
ampl: var y {K,K} := Uniform01();

ampl: display sum {k in K, l in K diff {k}} y[k,l];
sum{k in K, l in K diff {k}} y[k,l] = 9.30924

```

However, some other error in your model might be causing an error when you use this expression. To get more help, upload a complete example that we can run to reproduce the error message.

---

<div class="post-metadata">

**Author:** ![AMPL\_Google\_Group](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@AMPL\_Google\_Group](https://discuss.ampl.com/u/AMPL_Google_Group)\
**Post date:** [April 5, 2023, 2:20am UTC](https://discuss.ampl.com/t/ampl-24601-re-double-summation/470/3 "2023-04-05T02:20:54Z")

</div>

I did a little test where I set K equal to {1,2,3,4,5} and assigned some random numbers to y. Your sum was evaluated without any errors:

```auto
ampl: set K := 1..5; 
ampl: var y {K,K} := Uniform01(); 

ampl: display sum {k in K, l in K diff {k}} y[k,l]; 
sum{k in K, l in K diff {k}} y[k,l] = 9.30924 

```

However, some other error in your model might be causing an error when you use this expression. To get more help, reply with a complete example that we can run to reproduce the error message.
