Linear Inequality

A linear inequality has the form ax + by + c < 0 (or ≤, ≥, >). It describes a half-plane region that satisfies the inequality. Linear inequalities are used to model constraints in optimization problems.

Some examples:

  • Budget constraint: 3x + 5y ≤ 15
  • Capacity constraint: x + 2y < 18
  • Nonnegativity constraint: 2x - y ≥ 0

Java - Check if point satisfies inequalities:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
boolean satisfies(double x, double y, double[][] inequalities) {
  for (double[] row : inequalities) {
    double a = row[0]; 
    double b = row[1];
    double c = row[2];
    if (a*x + b*y + c >= 0) {
      return false;
    }
  }
  return true;
}

C++ - Model linear program constraint:

1
2
3
4
5
6
struct Constraint {
  double a, b, c;
  bool operator<(double x, double y) {
    return a*x + b*y < c; 
  }
};

Python - Find feasible region:

1
2
3
4
5
6
7
8
import numpy as np

def find_feasible_region(A, b):
  # Generate grid of points
  X, Y = np.meshgrid(range(-5, 5), range(-5, 5))

  # Check which satisfy constraints
  return (A @ np.c_[X.ravel(), Y.ravel()] + b) <= 0 

Linear inequalities are fundamental to mathematical optimization and modeling problems with linear constraints.

Concept of Linear Inequality

A linear inequality is a mathematical expression that relates two linear functions using inequality symbols, such as (<), (>), (\leq), or (\geq). In its simplest form, a linear inequality in one variable (x) could look like (ax + b < c), where (a), (b), and (c) are constants.

Linear inequalities can be used in various applications like optimizing functions, solving resource allocation problems, and many other real-world scenarios. One common way to solve a linear inequality is to isolate the variable on one side of the inequality.


Example Code

Java

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
public class LinearInequality {
  public static boolean checkInequality(int a, int x, int b, int c) {
    return a * x + b < c;
  }

  public static void main(String[] args) {
    int a = 2, x = 3, b = 4, c = 11;
    System.out.println("Is the inequality satisfied? " + checkInequality(a, x, b, c));
  }
}

C++

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#include <iostream>

bool checkInequality(int a, int x, int b, int c) {
  return a * x + b < c;
}

int main() {
  int a = 2, x = 3, b = 4, c = 11;
  std::cout << "Is the inequality satisfied? " << std::boolalpha << checkInequality(a, x, b, c) << std::endl;
  return 0;
}

Python

1
2
3
4
5
def check_inequality(a, x, b, c):
  return a * x + b < c

a, x, b, c = 2, 3, 4, 11
print("Is the inequality satisfied?", check_inequality(a, x, b, c))

Key Takeaways

  1. Simple Relation: Linear inequalities express a simple relationship between variables and constants, often used to model constraints in real-world problems.

  2. Check Mechanism: Code can be written to verify if certain values satisfy the inequality, which can be part of larger algorithms in, for instance, optimization problems.

  3. Broad Application: Linear inequalities are foundational to areas like linear programming and are often encountered in algorithms and data structures for constraint checking.

  4. Isolation of Variable: The code simply evaluates the inequality by plugging the variable into it. In more complex scenarios, algorithms may need to isolate variables to solve inequalities.

The concept of linear inequalities is straightforward, yet powerful, serving as the building block for many complex mathematical and computational models.