# I have declared “set S” and “param b {S}”. How do I write an AMPL expression for the arg min of b\[i\] — that is, the s in S such that b\[s\] equals the minimum of b\[i\] over al

**URL:** <https://discuss.ampl.com/t/i-have-declared-set-s-and-param-b-s-how-do-i-write-an-ampl-expression-for-the-arg-min-of-b-i-that-is-the-s-in-s-such-that-b-s-equals-the-minimum-of-b-i-over-al/62>\
**Category:** FAQs\
**Tags:** sets-and-indexing\
**Created:** [December 15, 2021, 5:44pm UTC](https://discuss.ampl.com/t/i-have-declared-set-s-and-param-b-s-how-do-i-write-an-ampl-expression-for-the-arg-min-of-b-i-that-is-the-s-in-s-such-that-b-s-equals-the-minimum-of-b-i-over-al/62 "2021-12-15T17:44:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![megrobert](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@megrobert](https://discuss.ampl.com/u/megrobert)\
**Post date:** [December 15, 2021, 5:44pm UTC](https://discuss.ampl.com/t/i-have-declared-set-s-and-param-b-s-how-do-i-write-an-ampl-expression-for-the-arg-min-of-b-i-that-is-the-s-in-s-such-that-b-s-equals-the-minimum-of-b-i-over-al/62/1 "2021-12-15T17:44:12Z")

</div>

There’s no specific arg min operator in AMPL. However, proceeding directly from the definition, you can define the arg min explicitly by a set expression like

```auto
{s in S: b[s] = min {i in S} b[i]}

```

This expression gives a subset of `S` , however, containing all of the members of `S` that achieve the minimum. To get just one member representing the arg min, you can define this to be an ordered set,

```auto
set b_argmin ordered := {s in S: b[s] = min {i in S} b[i]};

```

Then `first(b_argmin)` is guaranteed to be one member of `S` that minimizes `b[i]` .

As an alternative, you can use AMPL’s `for` and `if` commands to write a script that loops over `S` to compute the arg min explicitly:

```auto
param bmin; 
param imin symbolic in S; 
let bmin := Infinity; 
for {i in S} { 
   if b[i] < bmin then { 
      let bmin := b[i]; 
      let imin := i; } }

```

In general this is a slower alternative than defining `b_argmin` as above. It admits a greater variety of generalizations in complex cases, however.
