# Error invalid subscript

**URL:** <https://discuss.ampl.com/t/error-invalid-subscript/967>\
**Category:** Support\
**Tags:** errors-and-messages\
**Created:** [February 26, 2024, 9:32pm UTC](https://discuss.ampl.com/t/error-invalid-subscript/967 "2024-02-26T21:32:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steph](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/steph/32/671_2.png) [@Steph](https://discuss.ampl.com/u/Steph)\
**Post date:** [February 26, 2024, 9:32pm UTC](https://discuss.ampl.com/t/error-invalid-subscript/967/1 "2024-02-26T21:32:36Z")

</div>

I am declaring the following restriction:

```auto
subject to Siembra_Cult_perm1 {j in PERM, k in U, t in T}:
   z[j,k,t+fen[j]] <= 1 + M * (z[j,k,t]-1);

```

However, t + fen[j] is greater than T, because in this point fen[j] is 3…so I get the following: Error executing “solve” command:  
error processing constraint Siembra\_Cult\_perm1[12,1,10]:  
invalid subscript z[12,1,13]

How Can I rewrite this restriction, if I want only t+fen[j] less than 12 in the z subscript, before the equal?

---

<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:** [February 27, 2024, 2:45am UTC](https://discuss.ampl.com/t/error-invalid-subscript/967/2 "2024-02-27T02:45:17Z")

</div>

If you do not want any constraint to be generated when t+fen[j] is greater than 12, then you can add that condition to the constraint’s indexing expression:

```auto
subject to Siembra_Cult_perm1
      {j in PERM, k in U, t in T: t+fen[j] <= 12}:
   z[j,k,t+fen[j]] <= 1 + M * (z[j,k,t]-1);

```

This is OK if the last member of set T will always be 12. Otherwise, you may want to replace the explicit “12” by a parameter of the model (or an expression involving parameters).
