omega — Linear Arithmetic
omega is a decision procedure for linear arithmetic over integers and natural numbers. It automatically solves goals involving <, ≤, =, +, -, and multiplication by constants.
What omega Solves
omega handles linear arithmetic—inequalities and equations where variables are only multiplied by constants:
lean
1-- Simple inequalities2example (n : Nat) : n ≤ n + 1 := by omega3example (a b : Nat) (h : a < b) : a + 1 ≤ b := by omega4example (x : Int) (h : x > 0) : x ≥ 1 := by omega56-- Arithmetic combinations7example (a b c : Nat) : a + b + c = c + b + a := by omega8example (n : Nat) : 2 * n = n + n := by omega9example (x y : Int) : x - y + y = x := by omegaKey Takeaway
Use
omega for any goal that's "obviously true" by arithmetic reasoning. It handles +, -, *, /, %, <, ≤, =, ≠ on Nat and Int.Nat vs Int
lean
1-- omega works on both Nat and Int2example (n : Nat) : n - n = 0 := by omega3example (n : Int) : n - n = 0 := by omega45-- Careful: Nat subtraction is truncated6example (a b : Nat) : a - b ≤ a := by omega7example (a b : Nat) (h : a ≥ b) : a - b + b = a := by omega89-- Int subtraction is normal10example (a b : Int) : a - b + b = a := by omegaUsing Hypotheses
lean
1-- omega uses all relevant hypotheses automatically2example (a b c : Nat) (h1 : a ≤ b) (h2 : b ≤ c) : a ≤ c := by omega34example (x y : Int) (h1 : x < y) (h2 : y < x + 2) : y = x + 1 := by omega56example (n : Nat) (h : n > 0) (h2 : n < 3) : n = 1 ∨ n = 2 := by omegaDivision and Modulo
lean
1-- omega handles div and mod2example (n : Nat) : n / 2 ≤ n := by omega3example (n : Nat) : n % 2 < 2 := by omega4example (n : Nat) : 2 * (n / 2) + n % 2 = n := by omega56-- Useful for proving termination arguments7example (n : Nat) (h : n > 1) : n / 2 < n := by omega8example (n m : Nat) (h : m > 0) : n % m < m := by omegaℹ
omega is complete for linear arithmetic—if a goal is provable using only linear reasoning, omega will find the proof.What omega Cannot Do
lean
1-- Non-linear: omega can't handle x * y where both are variables2-- example (x y : Nat) : x * y = y * x := by omega -- fails3example (x y : Nat) : x * y = y * x := by ring -- use ring instead45-- Symbolic: omega doesn't understand abstract functions6-- example (f : Nat → Nat) (h : f 0 = 0) : f 0 ≤ 1 := by omega -- fails78-- Need specific Nat lemmas sometimes9example (n : Nat) : n * 2 / 2 = n := by 10 exact Nat.mul_div_cancel_left n (by omega : 2 > 0)Combining with Other Tactics
lean
1-- omega after simplification2example (xs : List Nat) : xs.length ≤ xs.length + 1 := by3 omega45-- omega in subgoals6example (n : Nat) : n = 0 ∨ n > 0 := by7 cases n with8 | zero => left; rfl9 | succ m => right; omega1011-- omega with simp12example (a b : Nat) (h : a + b = 10) : a ≤ 10 := by13 omegaDeep Dive: How omega Works
omega implements the Omega test algorithm:
- Convert the goal to a conjunction of linear constraints
- Eliminate variables one by one using Fourier-Motzkin elimination
- Check if the remaining constraints are satisfiable
- If unsatisfiable, the goal is proven
lean
1-- omega proves by contradiction:2-- "The negation of the goal + hypotheses is unsatisfiable"34example (a b : Nat) (h1 : a < b) (h2 : b < a) : False := by5 omega -- Detects a < b ∧ b < a is impossibleCommon Patterns
Termination Arguments
lean
1-- Proving arguments decrease2def myFun (n : Nat) : Nat :=3 if n < 2 then n4 else myFun (n / 2) + myFun (n / 2)5termination_by n6decreasing_by all_goals omegaIndex Bounds
lean
1-- Array and list index bounds2example (arr : Array Nat) (i : Nat) (h : i < arr.size) : i < arr.size + 1 := by3 omega45example (xs : List Nat) (i : Nat) (hi : i < xs.length) (hj : i + 1 < xs.length) 6 : i < xs.length := by omegaRange Proofs
lean
1-- Proving values are in range2example (n : Nat) (h1 : n ≥ 5) (h2 : n ≤ 10) : n > 0 := by omega3example (x : Int) (h1 : x > -10) (h2 : x < 10) : x.natAbs < 10 := by omegaExamples
Triangle Inequality Consequence
lean
1example (a b c : Nat) (h1 : a + b > c) (h2 : b + c > a) (h3 : c + a > b) 2 : a < b + c := by omegaDivision Properties
lean
1example (n : Nat) (h : n ≥ 2) : n / 2 ≥ 1 := by omega2example (n : Nat) (h : n % 2 = 0) : 2 * (n / 2) = n := by omegaChained Inequalities
lean
1example (a b c d e : Nat) 2 (h1 : a ≤ b) (h2 : b ≤ c) (h3 : c ≤ d) (h4 : d ≤ e) 3 : a ≤ e := by omega