# Why does AMPL treat my linear program as nonlinear?

**URL:** <https://discuss.ampl.com/t/why-does-ampl-treat-my-linear-program-as-nonlinear/57>\
**Category:** FAQs\
**Tags:** variables\
**Created:** [December 15, 2021, 5:31pm UTC](https://discuss.ampl.com/t/why-does-ampl-treat-my-linear-program-as-nonlinear/57 "2021-12-15T17:31:29Z")\
**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:31pm UTC](https://discuss.ampl.com/t/why-does-ampl-treat-my-linear-program-as-nonlinear/57/1 "2021-12-15T17:31:29Z")

</div>

Symptoms of this problem are an `option show_stats 1` listing that refers to nonlinear variables and constraints, and rejection by the solver with a “contains nonlinear constraints” message. The cure may be (a) to reformulate the model so that certain unintended nonlinearities are made linear, or (b) set `option linelim 1` so that substituted linear variables do not become nonlinear.

Case (a) can occur because you have overlooked a simple nonlinearity, such as a variable multiplying or dividing another variable. AMPL’s built-in arithmetic functions, including simple ones such as `abs` and `max` , are treated as nonlinear when applied to variables; `if ... then ... else ...` expressions are also nonlinear if variables appear in the expression following the `if` . You may be able to convert these kinds of “nonlinearities” to equivalent linear expressions, but AMPL cannot do the conversion automatically. (The only such conversions currently built into AMPL are for the piecewise-linear functions described in [Chapter 17](https://ampl.com/BOOK/CHAPTERS/20-piecewise.pdf) of the AMPL book.)

Case (b) occurs when AMPL’s defined variable feature is invoked to substitute an expression for a variable — either by using the `=` operator in declarations of variables, or by setting `option substout 1` to infer substitutions from the constraints. Under `option linelim 0` , AMPL does not substitute explicitly in the constraints, but instead records the substitution as an additional piece of information in the file sent to the solver. This affords very efficient handling of sub-expressions that appear at many places in a problem, but it has the side-effect of causing all variables in a substituted expression to be treated as nonlinear. To request explicit substitution, so that linearity is preserved, leave the `linelim` option at its default setting of `1` .
