Std. Proof. Math
(Cure Standard Library v0.37.2)
View Source
Proof-carrying mathematics used by refinements and ordinary Cure programs.
This module deliberately contains no trusted arithmetic oracle. Operations are total Cure functions and every law is an ordinary dependent proof term checked by the kernel. Future refinement automation may search for these theorems, but it does not get to bypass them.
Examples
use Std.Nat
use Std.Proof.Math
multiply(S(S(Z())), S(S(S(Z()))))
decide_is_less_than(Z(), S(Z()))
Summary
Types
Evidence that one natural number is strictly less than another.
Evidence that one natural number is less than or equal to another.
Evidence that a natural number is strictly positive.
Functions
Adding a positive right operand to any natural number remains positive.
Adding the same number to both sides preserves strict less-than.
Adding the same number to both sides preserves less-than-or-equal.
Adding anything to a positive left operand remains positive.
Soundness direction for < reflection: inductive IsLessThan evidence
implies natural_is_less_than(left, right) is True.
Soundness direction for <= reflection: inductive IsLessThanOrEqual
evidence implies natural_is_less_than_or_equal(left, right) is True.
Soundness direction for positivity reflection: IsPositive(value) implies
natural_is_positive(value) is True.
Decide strict less-than with checked evidence in either branch.
Decide less-than-or-equal with checked evidence in either branch.
Decide positivity while carrying either a proof or a disproof.
Reflect IsTrue(natural_is_less_than(left, right)) into IsLessThan(left, right).
Reflection: the boolean comparison being true carries the same information as
the inductive relation. Proved by induction, mirroring the boolean function's
own match structure; uninhabited arms discharge by empty match on evidence.
Every natural number is less than or equal to itself.
Less-than-or-equal evidence composes transitively.
Natural-number multiplication, defined structurally on the left operand.
Associativity of multiplication, (a * b) * c = a * (b * c).
Commutativity of multiplication, m * n = n * m.
Binary congruence for Nat multiplication.
Left-commutativity of multiplication, a * (b * c) = b * (a * c).
Left distributivity, a * (b + c) = a * b + a * c.
Right distributivity, (a + b) * c = a * c + b * c.
m * S(n) = m + m * n.
The product of two positive natural numbers is positive.
Boolean-valued strict "less than".
Boolean-valued "less than or equal", structural on both operands.
Boolean-valued positivity.
Reflect IsTrue(natural_is_positive(value)) into IsPositive(value).
Positivity is the same proposition as zero being strictly less than a value.
No successor natural number is less than or equal to zero.
No successor natural number is strictly less than zero.
Every successor natural number is positive.
Lift a disproof of left < right to a disproof of S(left) < S(right).
Lift a disproof of left <= right to a disproof of S(left) <= S(right).
Strictly exceeding zero is evidence of positivity.
Zero is not strictly less than zero.
Zero cannot carry evidence of strict positivity.
Types
type IsLessThan indices (left: Nat, right: Nat)
ZeroIsLessThanSuccessor : IsLessThan(Z, S(right))
SuccessorsAreLessThan : IsLessThan(left, right) -> IsLessThan(S(left), S(right))
Evidence that one natural number is strictly less than another.
type IsLessThanOrEqual indices (left: Nat, right: Nat)
ZeroIsLessThanOrEqual : IsLessThanOrEqual(Z, right)
SuccessorsAreLessThanOrEqual : IsLessThanOrEqual(left, right) -> IsLessThanOrEqual(S(left), S(right))
Evidence that one natural number is less than or equal to another.
type IsPositive indices (value: Nat)
PositiveSuccessor : IsPositive(S(predecessor))
Evidence that a natural number is strictly positive.
Functions
fn adding_a_positive_number_is_positive(natural: Nat, positive: Nat, proof: IsPositive(positive)) -> IsPositive(plus(natural, positive))
Adding a positive right operand to any natural number remains positive.
fn adding_the_same_number_preserves_less_than(addend: Nat, left: Nat, right: Nat, proof: IsLessThan(left, right)) -> IsLessThan(plus(addend, left), plus(addend, right))
Adding the same number to both sides preserves strict less-than.
fn adding_the_same_number_preserves_less_than_or_equal(addend: Nat, left: Nat, right: Nat, proof: IsLessThanOrEqual(left, right)) -> IsLessThanOrEqual(plus(addend, left), plus(addend, right))
Adding the same number to both sides preserves less-than-or-equal.
fn adding_to_a_positive_number_is_positive(positive: Nat, other: Nat, proof: IsPositive(positive)) -> IsPositive(plus(positive, other))
Adding anything to a positive left operand remains positive.
fn boolean_comparison_is_true_when_less_than_holds(left: Nat, right: Nat, proof: IsLessThan(left, right)) -> IsTrue(natural_is_less_than(left, right))
Soundness direction for < reflection: inductive IsLessThan evidence
implies natural_is_less_than(left, right) is True.
fn boolean_comparison_is_true_when_less_than_or_equal_holds(left: Nat, right: Nat, proof: IsLessThanOrEqual(left, right)) -> IsTrue(natural_is_less_than_or_equal(left, right))
Soundness direction for <= reflection: inductive IsLessThanOrEqual
evidence implies natural_is_less_than_or_equal(left, right) is True.
fn boolean_comparison_is_true_when_positive_holds(value: Nat, proof: IsPositive(value)) -> IsTrue(natural_is_positive(value))
Soundness direction for positivity reflection: IsPositive(value) implies
natural_is_positive(value) is True.
fn decide_is_less_than(left: Nat, right: Nat) -> Decision(IsLessThan(left, right))
Decide strict less-than with checked evidence in either branch.
fn decide_is_less_than_or_equal(left: Nat, right: Nat) -> Decision(IsLessThanOrEqual(left, right))
Decide less-than-or-equal with checked evidence in either branch.
fn decide_is_positive(value: Nat) -> Decision(IsPositive(value))
Decide positivity while carrying either a proof or a disproof.
fn less_than_holds_when_boolean_comparison_is_true(left: Nat, right: Nat, evidence: IsTrue(natural_is_less_than(left, right))) -> IsLessThan(left, right)
Reflect IsTrue(natural_is_less_than(left, right)) into IsLessThan(left, right).
fn less_than_or_equal_holds_when_boolean_comparison_is_true(left: Nat, right: Nat, evidence: IsTrue(natural_is_less_than_or_equal(left, right))) -> IsLessThanOrEqual(left, right)
Reflection: the boolean comparison being true carries the same information as
the inductive relation. Proved by induction, mirroring the boolean function's
own match structure; uninhabited arms discharge by empty match on evidence.
fn less_than_or_equal_is_reflexive(value: Nat) -> IsLessThanOrEqual(value, value)
Every natural number is less than or equal to itself.
fn less_than_or_equal_is_transitive(left: Nat, middle: Nat, right: Nat, left_to_middle: IsLessThanOrEqual(left, middle), middle_to_right: IsLessThanOrEqual(middle, right)) -> IsLessThanOrEqual(left, right)
Less-than-or-equal evidence composes transitively.
fn multiply(left: Nat, right: Nat) -> Nat
Natural-number multiplication, defined structurally on the left operand.
fn multiply_assoc(a: Nat, b: Nat, c: Nat) -> Equivalent(Nat, multiply(multiply(a, b), c), multiply(a, multiply(b, c)))
Associativity of multiplication, (a * b) * c = a * (b * c).
fn multiply_comm(m: Nat, n: Nat) -> Equivalent(Nat, multiply(m, n), multiply(n, m))
Commutativity of multiplication, m * n = n * m.
fn multiply_cong(a1: Nat, a2: Nat, b1: Nat, b2: Nat, p: Equivalent(Nat, a1, a2), q: Equivalent(Nat, b1, b2)) -> Equivalent(Nat, multiply(a1, b1), multiply(a2, b2))
Binary congruence for Nat multiplication.
fn multiply_left_comm(a: Nat, b: Nat, c: Nat) -> Equivalent(Nat, multiply(a, multiply(b, c)), multiply(b, multiply(a, c)))
Left-commutativity of multiplication, a * (b * c) = b * (a * c).
fn multiply_one_right(n: Nat) -> Equivalent(Nat, multiply(n, S(Z)), n)
n * 1 = n.
fn multiply_plus_left(a: Nat, b: Nat, c: Nat) -> Equivalent(Nat, multiply(a, plus(b, c)), plus(multiply(a, b), multiply(a, c)))
Left distributivity, a * (b + c) = a * b + a * c.
fn multiply_plus_right(a: Nat, b: Nat, c: Nat) -> Equivalent(Nat, multiply(plus(a, b), c), plus(multiply(a, c), multiply(b, c)))
Right distributivity, (a + b) * c = a * c + b * c.
fn multiply_succ_right(m: Nat, n: Nat) -> Equivalent(Nat, multiply(m, S(n)), plus(m, multiply(m, n)))
m * S(n) = m + m * n.
fn multiply_zero_right(n: Nat) -> Equivalent(Nat, multiply(n, Z), Z)
n * 0 = 0.
fn multiplying_positive_numbers_is_positive(left: Nat, right: Nat, left_is_positive: IsPositive(left), right_is_positive: IsPositive(right)) -> IsPositive(multiply(left, right))
The product of two positive natural numbers is positive.
Matching the left proof refines left to a successor. Multiplication then
reduces to right + multiply(predecessor, right), whose positivity follows
directly from the proof that right is positive.
fn natural_is_less_than(left: Nat, right: Nat) -> Bool
Boolean-valued strict "less than".
fn natural_is_less_than_or_equal(left: Nat, right: Nat) -> Bool
Boolean-valued "less than or equal", structural on both operands.
fn natural_is_positive(value: Nat) -> Bool
Boolean-valued positivity.
fn positive_holds_when_boolean_comparison_is_true(value: Nat, evidence: IsTrue(natural_is_positive(value))) -> IsPositive(value)
Reflect IsTrue(natural_is_positive(value)) into IsPositive(value).
fn positive_means_zero_is_less_than(value: Nat, proof: IsPositive(value)) -> IsLessThan(Z, value)
Positivity is the same proposition as zero being strictly less than a value.
fn successor_is_not_less_than_or_equal_to_zero(predecessor: Nat, proof: IsLessThanOrEqual(S(predecessor), Z)) -> Empty
No successor natural number is less than or equal to zero.
fn successor_is_not_less_than_zero(predecessor: Nat, proof: IsLessThan(S(predecessor), Z)) -> Empty
No successor natural number is strictly less than zero.
fn successor_is_positive(predecessor: Nat) -> IsPositive(S(predecessor))
Every successor natural number is positive.
fn successors_preserve_less_than_disproof(left: Nat, right: Nat, disproof: Function(IsLessThan(left, right), Empty), proof: IsLessThan(S(left), S(right))) -> Empty
Lift a disproof of left < right to a disproof of S(left) < S(right).
fn successors_preserve_less_than_or_equal_disproof(left: Nat, right: Nat, disproof: Function(IsLessThanOrEqual(left, right), Empty), proof: IsLessThanOrEqual(S(left), S(right))) -> Empty
Lift a disproof of left <= right to a disproof of S(left) <= S(right).
fn zero_is_less_than_means_positive(value: Nat, proof: IsLessThan(Z, value)) -> IsPositive(value)
Strictly exceeding zero is evidence of positivity.
fn zero_is_not_less_than_zero(proof: IsLessThan(Z, Z)) -> Empty
Zero is not strictly less than zero.
fn zero_is_not_positive(proof: IsPositive(Z)) -> Empty
Zero cannot carry evidence of strict positivity.