<commit_before>---
layout: single
category: command
author_profile: false
excerpt: ""
title: iff
tags: [Logic programming]
comments: true
date: '2016-09-17'
sidebar:
  nav: "commands"
---

[iff] is used to create equivalence constraints between logic cases

### Syntax

````matlab
F = iff(A,B)
````

### Examples

[iff] is used to define logic equivalence. As an example, the following code will ensure that a variable **x** satisfies a set of inequalities if and only if a binary variable **d** is true (value 1), and vice versa.
````matlabb
d = binvar(1);
F = iff(d,A*x <= b);
````

[iff] is mainly intended for (BINARY <-> BINARY), although it can be used also for more general constructions as above (bearing in mind that these models typically are numerically sensitive and may require a lot of binary variables to be modeled).

The following code constrains a variable **y** if and only if a set of constraints on **x** hold.
````matlabb
F = iff(A*x <= b, A*y <=y);
````

The following code is equivalent
````matlabb
d = binvar(1,1);
F = iff(A*x <= b, d);
F = iff(A*y <= b, d);
````

[iff] is overloaded as == on constraints, hence the following code gives the same model.

````matlab
F = [(A*x <= b) == (A*y <= b)];
````

and so does the following model

````matlab
binvar d
F = [d == (A*x <= b), d == (A*y <= b)];
````

For more examples, see the [logic programming tutorial](/tutorial/logicprogramming).

### Comments
Since [iff] is implemented using a [tutorials.Big-M big-M] approach, it is crucial that all involved variables have explicit bound constraints.

[iff] is very sensitive to modelling choices (is \\(10^{-5}\\) really a positive number in practice?), so it should be avoided as much as possible. If you can rewrite your model to simple (BINARY-> Linear) using [implies], do so!
<commit_msg>Update 2017-09-17-iff.md<commit_after>---
layout: single
category: command
author_profile: false
excerpt: ""
title: iff
tags: [Logic programming]
comments: true
date: '2016-09-17'
sidebar:
  nav: "commands"
---

[iff] is used to create equivalence constraints between logic cases

### Syntax

````matlab
F = iff(A,B)
````

### Examples

[iff] is used to define logic equivalence. As an example, the following code will ensure that a variable **x** satisfies a set of inequalities if and only if a binary variable **d** is true (value 1), and vice versa.

````matlab
d = binvar(1);
F = iff(d,A*x <= b);
````

[iff] is mainly intended for (BINARY <-> BINARY), although it can be used also for more general constructions as above (bearing in mind that these models typically are numerically sensitive and may require a lot of binary variables to be modeled).

The following code constrains a variable **y** if and only if a set of constraints on **x** hold.
````matlabb
F = iff(A*x <= b, A*y <=y);
````

The following code is equivalent
````matlabb
d = binvar(1,1);
F = iff(A*x <= b, d);
F = iff(A*y <= b, d);
````

[iff] is overloaded as == on constraints, hence the following code gives the same model.

````matlab
F = [(A*x <= b) == (A*y <= b)];
````

and so does the following model

````matlab
binvar d
F = [d == (A*x <= b), d == (A*y <= b)];
````

For more examples, see the [logic programming tutorial](/tutorial/logicprogramming).

### Comments
Since [iff] is implemented using a [tutorials.Big-M big-M] approach, it is crucial that all involved variables have explicit bound constraints.

[iff] is very sensitive to modelling choices (is \\(10^{-5}\\) really a positive number in practice?), so it should be avoided as much as possible. If you can rewrite your model to simple (BINARY-> Linear) using [implies], do so!

{'fraction_non_alphanumeric': 0.14124759549326737, 'fraction_numerical': 0.010442429238801869, 'mean_word_length': 4.283018867924528, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2210161', 'n_tokens_mistral': 1200, 'n_tokens_neox': 1101, 'n_words': 527}