# \[AMPL 25038\] Which is more computationally efficient??

**URL:** <https://discuss.ampl.com/t/ampl-25038-which-is-more-computationally-efficient/1080>\
**Category:** Google Group Mirror\
**Created:** [April 30, 2024, 10:17am UTC](https://discuss.ampl.com/t/ampl-25038-which-is-more-computationally-efficient/1080 "2024-04-30T10:17:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa1](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/rafa1/32/868_2.png) [@Rafa1](https://discuss.ampl.com/u/Rafa1)\
**Post date:** [April 30, 2024, 10:17am UTC](https://discuss.ampl.com/t/ampl-25038-which-is-more-computationally-efficient/1080/1 "2024-04-30T10:17:59Z")

</div>

Dear all,  
I have a question:  
Which is more computationally efficient:  
using computed variables  
or  
including the equivalent constraint in the formulation?

`var A: B+C`  
vs  
`subject to A==B+C`

Thank you!!  
R

---

<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:** [May 1, 2024, 12:47pm UTC](https://discuss.ampl.com/t/ampl-25038-which-is-more-computationally-efficient/1080/2 "2024-05-01T12:47:23Z")

</div>

Usually it is preferred to write

```auto
var A = B + C;

```

because then the expression “B + C” is substituted for A; the solver does not see the variable A or the constraint “A = B + C”. However, there can be exceptions where the number of “defined variables” like A is very large. So if you are finding that AMPL is taking an especially long time to generate the problem, you may want to try the alternative,

```auto
var A;
subject to Adefn: A = B + C;

```

to see whether it is faster.

---

<div class="post-metadata">

**Author:** ![AMPL\_Google\_Group1](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@AMPL\_Google\_Group1](https://discuss.ampl.com/u/AMPL_Google_Group1)\
**Post date:** [May 1, 2024, 12:48pm UTC](https://discuss.ampl.com/t/ampl-25038-which-is-more-computationally-efficient/1080/3 "2024-05-01T12:48:56Z")

</div>

Your question has been moved to our new user forum at [discuss.ampl.com](http://discuss.ampl.com), and a response has been posted there. To see the response, use this link:

[https://discuss.ampl.com/t/ampl-25038-which-is-more-computationally-efficient/1080/2](https://discuss.ampl.com/t/ampl-25038-which-is-more-computationally-efficient/1080/2)

To reply, click the red “Reply” button that follows the response. (Do not send an email reply to this message.)

---

<div class="post-metadata">

**Author:** ![Rafa1](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/rafa1/32/868_2.png) [@Rafa1](https://discuss.ampl.com/u/Rafa1)\
**Post date:** [May 2, 2024, 11:38am UTC](https://discuss.ampl.com/t/ampl-25038-which-is-more-computationally-efficient/1080/4 "2024-05-02T11:38:45Z")

</div>

Thanks !!

El El mié, 1 may 2024 a las 14:50, AMPL Google Group via AMPL Discourse \<[notifications@ampl.discoursemail.com](mailto:notifications@ampl.discoursemail.com)\> escribió:
