## 5.79. compare_and_count

Origin
Constraint

$\mathrm{𝚌𝚘𝚖𝚙𝚊𝚛𝚎}_\mathrm{𝚊𝚗𝚍}_\mathrm{𝚌𝚘𝚞𝚗𝚝}\left(\mathrm{𝚅𝙰𝚁𝙸𝙰𝙱𝙻𝙴𝚂}\mathtt{1},\mathrm{𝚅𝙰𝚁𝙸𝙰𝙱𝙻𝙴𝚂}\mathtt{2},\mathrm{𝙲𝙾𝙼𝙿𝙰𝚁𝙴},\mathrm{𝙲𝙾𝚄𝙽𝚃},\mathrm{𝙻𝙸𝙼𝙸𝚃}\right)$

Arguments
 $\mathrm{𝚅𝙰𝚁𝙸𝙰𝙱𝙻𝙴𝚂}\mathtt{1}$ $\mathrm{𝚌𝚘𝚕𝚕𝚎𝚌𝚝𝚒𝚘𝚗}\left(\mathrm{𝚟𝚊𝚛}-\mathrm{𝚍𝚟𝚊𝚛}\right)$ $\mathrm{𝚅𝙰𝚁𝙸𝙰𝙱𝙻𝙴𝚂}\mathtt{2}$ $\mathrm{𝚌𝚘𝚕𝚕𝚎𝚌𝚝𝚒𝚘𝚗}\left(\mathrm{𝚟𝚊𝚛}-\mathrm{𝚍𝚟𝚊𝚛}\right)$ $\mathrm{𝙲𝙾𝙼𝙿𝙰𝚁𝙴}$ $\mathrm{𝚊𝚝𝚘𝚖}$ $\mathrm{𝙲𝙾𝚄𝙽𝚃}$ $\mathrm{𝚊𝚝𝚘𝚖}$ $\mathrm{𝙻𝙸𝙼𝙸𝚃}$ $\mathrm{𝚍𝚟𝚊𝚛}$
Restrictions
 $|\mathrm{𝚅𝙰𝚁𝙸𝙰𝙱𝙻𝙴𝚂}\mathtt{1}|=|\mathrm{𝚅𝙰𝚁𝙸𝙰𝙱𝙻𝙴𝚂}\mathtt{2}|$ $\mathrm{𝚛𝚎𝚚𝚞𝚒𝚛𝚎𝚍}$$\left(\mathrm{𝚅𝙰𝚁𝙸𝙰𝙱𝙻𝙴𝚂}\mathtt{1},\mathrm{𝚟𝚊𝚛}\right)$ $\mathrm{𝚛𝚎𝚚𝚞𝚒𝚛𝚎𝚍}$$\left(\mathrm{𝚅𝙰𝚁𝙸𝙰𝙱𝙻𝙴𝚂}\mathtt{2},\mathrm{𝚟𝚊𝚛}\right)$ $\mathrm{𝙲𝙾𝙼𝙿𝙰𝚁𝙴}\in \left[=,\ne ,<,\ge ,>,\le \right]$ $\mathrm{𝙲𝙾𝚄𝙽𝚃}\in \left[=,\ne ,<,\ge ,>,\le \right]$ $\mathrm{𝙻𝙸𝙼𝙸𝚃}\ge 0$
Purpose

Enforce the condition

$\left({\sum }_{i=1}^{|\mathrm{𝚅𝙰𝚁𝙸𝙰𝙱𝙻𝙴𝚂}\mathtt{1}|}\mathrm{𝚅𝙰𝚁𝙸𝙰𝙱𝙻𝙴𝚂}\mathtt{1}\left[i\right].\mathrm{𝚟𝚊𝚛}\mathrm{𝙲𝙾𝙼𝙿𝙰𝚁𝙴}\mathrm{𝚅𝙰𝚁𝙸𝙰𝙱𝙻𝙴𝚂}\mathtt{2}\left[i\right].\mathrm{𝚟𝚊𝚛}\right)\mathrm{𝙲𝙾𝚄𝙽𝚃}\mathrm{𝙻𝙸𝙼𝙸𝚃}$.

Example
$\left(〈4,5,5,4,5〉,〈4,2,5,1,5〉,=,\le ,3\right)$

The $\mathrm{𝚌𝚘𝚖𝚙𝚊𝚛𝚎}_\mathrm{𝚊𝚗𝚍}_\mathrm{𝚌𝚘𝚞𝚗𝚝}$ constraint holds since no more than $\mathrm{𝙻𝙸𝙼𝙸𝚃}=3$ pairs of variables are equal, i.e., the first, third and fifth pairs.

Typical
 $|\mathrm{𝚅𝙰𝚁𝙸𝙰𝙱𝙻𝙴𝚂}\mathtt{1}|>1$ $\mathrm{𝚛𝚊𝚗𝚐𝚎}$$\left(\mathrm{𝚅𝙰𝚁𝙸𝙰𝙱𝙻𝙴𝚂}\mathtt{1}.\mathrm{𝚟𝚊𝚛}\right)>1$ $\mathrm{𝚛𝚊𝚗𝚐𝚎}$$\left(\mathrm{𝚅𝙰𝚁𝙸𝙰𝙱𝙻𝙴𝚂}\mathtt{2}.\mathrm{𝚟𝚊𝚛}\right)>1$ $\mathrm{𝙲𝙾𝙼𝙿𝙰𝚁𝙴}\in \left[=\right]$ $\mathrm{𝙲𝙾𝚄𝙽𝚃}\in \left[=,<,\ge ,>,\le \right]$ $\mathrm{𝙻𝙸𝙼𝙸𝚃}>0$ $\mathrm{𝙻𝙸𝙼𝙸𝚃}<|\mathrm{𝚅𝙰𝚁𝙸𝙰𝙱𝙻𝙴𝚂}\mathtt{1}|$
Arg. properties
• Contractible wrt. $\mathrm{𝚅𝙰𝚁𝙸𝙰𝙱𝙻𝙴𝚂}\mathtt{1}$ and $\mathrm{𝚅𝙰𝚁𝙸𝙰𝙱𝙻𝙴𝚂}\mathtt{2}$ (remove items from same position) when $\mathrm{𝙲𝙾𝚄𝙽𝚃}\in \left[<,\le \right]$.

• Extensible wrt. $\mathrm{𝚅𝙰𝚁𝙸𝙰𝙱𝙻𝙴𝚂}\mathtt{1}$ and $\mathrm{𝚅𝙰𝚁𝙸𝙰𝙱𝙻𝙴𝚂}\mathtt{2}$ (add items at same position) when $\mathrm{𝙲𝙾𝚄𝙽𝚃}\in \left[\ge ,>\right]$.