Std.Proof.LinearArithmetic.Semantics (Cure Standard Library v0.37.2)

View Source

Trusted semantic lemmas used by the linear-arithmetic proof modules. The declarations relate coefficient lists and their evaluated sums.

Examples

use Std.Int
use Std.List
use Std.Equivalent
use Std.Proof.IntOrder
use Std.Proof.LinearArithmetic
use Std.Proof.LinearArithmetic.Semantics

fn empty_dot_is_zero() -> Equivalent(Int, dot(Nil(), Nil()), int_zero()) =
  dot_zero_coefficients(ZeroAtEmpty())

Summary

Functions

── Farkas Unsatisfiability & Classical Refutation-to-Proof ──────────────

Refutation-to-proof for integer equality: refuting both right < left and left < right yields Equivalent(Int, left, right).

Refutation-to-proof for ≤: if assuming right < left leads to Empty (for instance via farkas_fold_unsat), then left ≤ right holds.

Refutation-to-proof for <: if assuming right ≤ left leads to Empty, then left < right holds.

Types

type AddedCoefficientsAt indices (left: List(Int), right: List(Int), result: List(Int), valuation: List(Int))

 type AddedCoefficientsAt indices (left: List(Int), right: List(Int), result: List(Int), valuation: List(Int))
   AddedEmpty : AddedCoefficientsAt(Nil(), Nil(), Nil(), Nil())
   AddedCons : {lefts: List(Int)} -> {rights: List(Int)} -> {results: List(Int)} -> {valuation: List(Int)} -> {left: Int} -> {right: Int} -> {value: Int} -> AddedCoefficientsAt(lefts, rights, results, valuation) -> AddedCoefficientsAt(Cons(left, lefts), Cons(right, rights), Cons(add_int(left, right), results), Cons(value, valuation))

type AlignedCoefficients indices (coefficients: List(Int), valuation: List(Int))

 type AlignedCoefficients indices (coefficients: List(Int), valuation: List(Int))
   AlignedEmpty : AlignedCoefficients(Nil(), Nil())
   AlignedCons : {coefficients: List(Int)} -> {valuation: List(Int)} -> {coefficient: Int} -> {value: Int} -> AlignedCoefficients(coefficients, valuation) -> AlignedCoefficients(Cons(coefficient, coefficients), Cons(value, valuation))

type AllAffineFormsHold indices (coefficient_sets: List(List(Int)), constants: List(Int), valuation: List(Int))

 type AllAffineFormsHold indices (coefficient_sets: List(List(Int)), constants: List(Int), valuation: List(Int))
   AllAffineEmpty : AllAffineFormsHold(Nil(), Nil(), valuation)
   AllAffineCons : {coefficients: List(Int)} -> {constant: Int} -> {rest_coefficients: List(List(Int))} -> {rest_constants: List(Int)} -> {valuation: List(Int)} -> IsLessThanOrEqual(dot(coefficients, valuation), constant) -> AllAffineFormsHold(rest_coefficients, rest_constants, valuation) -> AllAffineFormsHold(Cons(coefficients, rest_coefficients), Cons(constant, rest_constants), valuation)

type ScaledCoefficientsAt indices (scalar: Nat, source: List(Int), result: List(Int), valuation: List(Int))

 type ScaledCoefficientsAt indices (scalar: Nat, source: List(Int), result: List(Int), valuation: List(Int))
   ScaledEmpty : {scalar: Nat} -> ScaledCoefficientsAt(scalar, Nil(), Nil(), Nil())
   ScaledCons : {scalar: Nat} -> {source: List(Int)} -> {result: List(Int)} -> {valuation: List(Int)} -> {coefficient: Int} -> {value: Int} -> ScaledCoefficientsAt(scalar, source, result, valuation) -> ScaledCoefficientsAt(scalar, Cons(coefficient, source), Cons(scale_nat_int(scalar, coefficient), result), Cons(value, valuation))

type WeightedAffineFold indices (coefficient_sets: List(List(Int)), constants: List(Int), witness: List(Nat), result_coefficients: List(Int), result_constant: Int, valuation: List(Int))

 type WeightedAffineFold indices (coefficient_sets: List(List(Int)), constants: List(Int), witness: List(Nat), result_coefficients: List(Int), result_constant: Int, valuation: List(Int))
   WeightedAffineEmpty : {result_coefficients: List(Int)} -> {valuation: List(Int)} -> ZeroCoefficientsAt(result_coefficients, valuation) -> WeightedAffineFold(Nil(), Nil(), Nil(), result_coefficients, int_zero(), valuation)
   WeightedAffineCons : {coefficients: List(Int)} -> {constant: Int} -> {scalar: Nat} -> {scaled_coefficients: List(Int)} -> {tail_coefficients: List(List(Int))} -> {tail_constants: List(Int)} -> {tail_witness: List(Nat)} -> {tail_result_coefficients: List(Int)} -> {tail_result_constant: Int} -> {valuation: List(Int)} -> {result_coefficients: List(Int)} -> ScaledCoefficientsAt(scalar, coefficients, scaled_coefficients, valuation) -> WeightedAffineFold(tail_coefficients, tail_constants, tail_witness, tail_result_coefficients, tail_result_constant, valuation) -> AddedCoefficientsAt(scaled_coefficients, tail_result_coefficients, result_coefficients, valuation) -> WeightedAffineFold(Cons(coefficients, tail_coefficients), Cons(constant, tail_constants), Cons(scalar, tail_witness), result_coefficients, add_int(scale_nat_int(scalar, constant), tail_result_constant), valuation)

type ZeroCoefficientsAt indices (coefficients: List(Int), valuation: List(Int))

 type ZeroCoefficientsAt indices (coefficients: List(Int), valuation: List(Int))
   ZeroAtEmpty : ZeroCoefficientsAt(Nil(), Nil())
   ZeroAtCons : {coefficients: List(Int)} -> {valuation: List(Int)} -> {value: Int} -> ZeroCoefficientsAt(coefficients, valuation) -> ZeroCoefficientsAt(Cons(int_zero(), coefficients), Cons(value, valuation))

Functions

adding_holding_affine_forms_preserves_holding(left_coefficients: List(Int), right_coefficients: List(Int), result_coefficients: List(Int), valuation: List(Int), left_constant: Int, right_constant: Int, alignment: AddedCoefficientsAt(left_coefficients, right_coefficients, result_coefficients, valuation), left_holds: IsLessThanOrEqual(dot(left_coefficients, valuation), left_constant), right_holds: IsLessThanOrEqual(dot(right_coefficients, valuation), right_constant)) -> IsLessThanOrEqual(dot(result_coefficients, valuation), add_int(left_constant, right_constant))

 fn adding_holding_affine_forms_preserves_holding(left_coefficients: List(Int), right_coefficients: List(Int), result_coefficients: List(Int), valuation: List(Int), left_constant: Int, right_constant: Int, alignment: AddedCoefficientsAt(left_coefficients, right_coefficients, result_coefficients, valuation), left_holds: IsLessThanOrEqual(dot(left_coefficients, valuation), left_constant), right_holds: IsLessThanOrEqual(dot(right_coefficients, valuation), right_constant)) -> IsLessThanOrEqual(dot(result_coefficients, valuation), add_int(left_constant, right_constant))

Adding two aligned affine inequalities that hold at valuation yields a holding sum.

dot_added_coefficients(left: List(Int), right: List(Int), result: List(Int), valuation: List(Int), alignment: AddedCoefficientsAt(left, right, result, valuation)) -> Equivalent(Int, dot(result, valuation), add_int(dot(left, valuation), dot(right, valuation)))

 fn dot_added_coefficients(left: List(Int), right: List(Int), result: List(Int), valuation: List(Int), alignment: AddedCoefficientsAt(left, right, result, valuation)) -> Equivalent(Int, dot(result, valuation), add_int(dot(left, valuation), dot(right, valuation)))

Pointwise addition of aligned coefficient lists distributes over dot.

dot_scaled_coefficients(scalar: Nat, source: List(Int), result: List(Int), valuation: List(Int), alignment: ScaledCoefficientsAt(scalar, source, result, valuation)) -> Equivalent(Int, dot(result, valuation), scale_nat_int(scalar, dot(source, valuation)))

 fn dot_scaled_coefficients(scalar: Nat, source: List(Int), result: List(Int), valuation: List(Int), alignment: ScaledCoefficientsAt(scalar, source, result, valuation)) -> Equivalent(Int, dot(result, valuation), scale_nat_int(scalar, dot(source, valuation)))

Nonnegative scalar multiplication of an aligned coefficient list commutes with dot.

dot_zero_coefficients(coefficients: List(Int), valuation: Valuation, alignment: ZeroCoefficientsAt(coefficients, valuation)) -> Equivalent(Int, dot(coefficients, valuation), int_zero())

 fn dot_zero_coefficients(coefficients: List(Int), valuation: Valuation, alignment: ZeroCoefficientsAt(coefficients, valuation)) -> Equivalent(Int, dot(coefficients, valuation), int_zero())

The dot product of an all-zero coefficient list with any aligned valuation is zero.

farkas_contradiction_is_empty(constant: Int, zero_le: IsLessThanOrEqual(int_zero(), constant), neg: IsLessThan(constant, int_zero())) -> Empty

 fn farkas_contradiction_is_empty(constant: Int, zero_le: IsLessThanOrEqual(int_zero(), constant), neg: IsLessThan(constant, int_zero())) -> Empty

── Farkas Unsatisfiability & Classical Refutation-to-Proof ──────────────

0 ≤ c and c < 0 cannot hold simultaneously for any integer c.

farkas_fold_unsat(coefficient_sets: List(List(Int)), constants: List(Int), witness: List(Nat), result_coefficients: List(Int), result_constant: Int, valuation: List(Int), fold: WeightedAffineFold(coefficient_sets, constants, witness, result_coefficients, result_constant, valuation), holds: AllAffineFormsHold(coefficient_sets, constants, valuation), result_zero: ZeroCoefficientsAt(result_coefficients, valuation), negative_constant: IsLessThan(result_constant, int_zero())) -> Empty

 fn farkas_fold_unsat(coefficient_sets: List(List(Int)), constants: List(Int), witness: List(Nat), result_coefficients: List(Int), result_constant: Int, valuation: List(Int), fold: WeightedAffineFold(coefficient_sets, constants, witness, result_coefficients, result_constant, valuation), holds: AllAffineFormsHold(coefficient_sets, constants, valuation), result_zero: ZeroCoefficientsAt(result_coefficients, valuation), negative_constant: IsLessThan(result_constant, int_zero())) -> Empty

Farkas Lemma (soundness of nonnegative weighted affine refutation): if every affine inequality in a system holds at valuation and a nonnegative weighted combination produces all-zero coefficients with a strictly negative right-hand constant, the system is contradictory.

farkas_refute_to_eq(left: Int, right: Int, refute_gt: Function(IsLessThan(right, left), Empty), refute_lt: Function(IsLessThan(left, right), Empty)) -> Equivalent(Int, left, right)

 fn farkas_refute_to_eq(left: Int, right: Int, refute_gt: Function(IsLessThan(right, left), Empty), refute_lt: Function(IsLessThan(left, right), Empty)) -> Equivalent(Int, left, right)

Refutation-to-proof for integer equality: refuting both right < left and left < right yields Equivalent(Int, left, right).

farkas_refute_to_le(left: Int, right: Int, refuter: Function(IsLessThan(right, left), Empty)) -> IsLessThanOrEqual(left, right)

 fn farkas_refute_to_le(left: Int, right: Int, refuter: Function(IsLessThan(right, left), Empty)) -> IsLessThanOrEqual(left, right)

Refutation-to-proof for ≤: if assuming right < left leads to Empty (for instance via farkas_fold_unsat), then left ≤ right holds.

farkas_refute_to_lt(left: Int, right: Int, refuter: Function(IsLessThanOrEqual(right, left), Empty)) -> IsLessThan(left, right)

 fn farkas_refute_to_lt(left: Int, right: Int, refuter: Function(IsLessThanOrEqual(right, left), Empty)) -> IsLessThan(left, right)

Refutation-to-proof for <: if assuming right ≤ left leads to Empty, then left < right holds.

folding_aligned_holding_affine_forms_preserves_holding(coefficient_sets: List(List(Int)), constants: List(Int), witness: List(Nat), result_coefficients: List(Int), result_constant: Int, valuation: List(Int), fold: WeightedAffineFold(coefficient_sets, constants, witness, result_coefficients, result_constant, valuation), holds: AllAffineFormsHold(coefficient_sets, constants, valuation)) -> IsLessThanOrEqual(dot(result_coefficients, valuation), result_constant)

 fn folding_aligned_holding_affine_forms_preserves_holding(coefficient_sets: List(List(Int)), constants: List(Int), witness: List(Nat), result_coefficients: List(Int), result_constant: Int, valuation: List(Int), fold: WeightedAffineFold(coefficient_sets, constants, witness, result_coefficients, result_constant, valuation), holds: AllAffineFormsHold(coefficient_sets, constants, valuation)) -> IsLessThanOrEqual(dot(result_coefficients, valuation), result_constant)

Folding a nonnegative weighted linear combination over holding affine inequalities produces a combined affine inequality that also holds at valuation.

is_less_than_to_le_pred(left: Int, right: Int, proof: IsLessThan(left, right)) -> IsLessThanOrEqual(left, pred_int(right))

 fn is_less_than_to_le_pred(left: Int, right: Int, proof: IsLessThan(left, right)) -> IsLessThanOrEqual(left, pred_int(right))

Discrete-integer conversion: left < right implies left ≤ pred_int(right).

le_int_antisymmetric(left: Int, right: Int, lr: IsLessThanOrEqual(left, right), rl: IsLessThanOrEqual(right, left)) -> Equivalent(Int, left, right)

 fn le_int_antisymmetric(left: Int, right: Int, lr: IsLessThanOrEqual(left, right), rl: IsLessThanOrEqual(right, left)) -> Equivalent(Int, left, right)

Antisymmetry of ≤ on Int.

le_nat_antisymmetric(left: Nat, right: Nat, lr: IsTrue(le_nat(left, right)), rl: IsTrue(le_nat(right, left))) -> Equivalent(Nat, left, right)

 fn le_nat_antisymmetric(left: Nat, right: Nat, lr: IsTrue(le_nat(left, right)), rl: IsTrue(le_nat(right, left))) -> Equivalent(Nat, left, right)

Antisymmetry of le_nat: left <= right and right <= left imply left == right.

le_nat_false_implies_lt_nat_swap(a: Nat, b: Nat, not_le: Function(IsTrue(le_nat(a, b)), Empty)) -> IsTrue(lt_nat(b, a))

 fn le_nat_false_implies_lt_nat_swap(a: Nat, b: Nat, not_le: Function(IsTrue(le_nat(a, b)), Empty)) -> IsTrue(lt_nat(b, a))

Refuting le_nat(a, b) yields Boolean evidence of lt_nat(b, a).

lt_nat_false_implies_le_nat_swap(a: Nat, b: Nat, not_lt: Function(IsTrue(lt_nat(a, b)), Empty)) -> IsTrue(le_nat(b, a))

 fn lt_nat_false_implies_le_nat_swap(a: Nat, b: Nat, not_lt: Function(IsTrue(lt_nat(a, b)), Empty)) -> IsTrue(le_nat(b, a))

Refuting lt_nat(a, b) yields Boolean evidence of le_nat(b, a).

normalize_atom_preserves_evaluation(coefficients: List(Int), constant: Int, relation: Relation, valuation: Valuation) -> Equivalent(Bool, evaluate_atom(normalize_atom(linear_atom(coefficients, constant, relation)), valuation), evaluate_atom(linear_atom(coefficients, constant, relation), valuation))

 fn normalize_atom_preserves_evaluation(coefficients: List(Int), constant: Int, relation: Relation, valuation: Valuation) -> Equivalent(Bool, evaluate_atom(normalize_atom(linear_atom(coefficients, constant, relation)), valuation), evaluate_atom(linear_atom(coefficients, constant, relation), valuation))

Normalizing a LinearAtom to <= form preserves its Boolean evaluation at valuation.

not_le_int_implies_gt(left: Int, right: Int, not_le: Function(IsLessThanOrEqual(left, right), Empty)) -> IsLessThan(right, left)

 fn not_le_int_implies_gt(left: Int, right: Int, not_le: Function(IsLessThanOrEqual(left, right), Empty)) -> IsLessThan(right, left)

Negating left ≤ right yields right < left.

not_lt_int_implies_ge(left: Int, right: Int, not_lt: Function(IsLessThan(left, right), Empty)) -> IsLessThanOrEqual(right, left)

 fn not_lt_int_implies_ge(left: Int, right: Int, not_lt: Function(IsLessThan(left, right), Empty)) -> IsLessThanOrEqual(right, left)

Negating left < right yields right ≤ left.