Std. Refine
(Cure Standard Library v0.37.2)
View Source
Refinement-oriented proof helpers for numeric predicates. Prefer ordinary indexed data and explicit propositions for new APIs; this module remains for compatibility with existing refinement clients.
Examples
use Std.Bool
use Std.Proof.Math
use Std.Proof.IntMath
type Positive = {x: Int | x > 0}
type PositiveNat = {value: Nat | IsPositive(value)}
fn one() -> PositiveNat = %[S(Z()), successor_is_positive(Z())]
Summary
Types
Strictly negative integer.
Non-negative integer (zero or positive).
Non-positive integer (zero or negative).
Non-zero integer (Int minus zero).
Integer between 0 and 100 inclusive (a percentage).
Strictly positive integer.
Strictly positive float (e.g. probability density, weight).
Natural numbers known to be strictly positive.
Float in [0.0, 1.0] inclusive (a probability).
Functions
Adding two positive natural numbers preserves positivity.
Multiplying two positive natural numbers preserves positivity.
true when n is non-negative.
true when p is a valid percentage (0..100 inclusive).
true when n is strictly positive.
Construct a positive natural number from any successor.
true when p is a valid probability (0.0..1.0 inclusive).
A value paired with kernel-checked evidence that it satisfies a proposition.
Recover the underlying value from a proof-backed refinement.
Recover the checked evidence carried by a refinement.
Types
type Negative
Strictly negative integer.
type NonNegative
Non-negative integer (zero or positive).
type NonPositive
Non-positive integer (zero or negative).
type NonZero
Non-zero integer (Int minus zero).
type Percentage
Integer between 0 and 100 inclusive (a percentage).
type Positive
Strictly positive integer.
type PositiveFloat
Strictly positive float (e.g. probability density, weight).
type PositiveNatural
Natural numbers known to be strictly positive.
type Probability
Float in [0.0, 1.0] inclusive (a probability).
Functions
fn add_positive_natural_numbers(left: PositiveNatural, right: PositiveNatural) -> PositiveNatural
Adding two positive natural numbers preserves positivity.
fn multiply_positive_natural_numbers(left: PositiveNatural, right: PositiveNatural) -> PositiveNatural
Multiplying two positive natural numbers preserves positivity.
The proof is left as a hole: multiplying_positive_numbers_is_positive is
@lemma-tagged in Std.Proof.Math, so the auto proof-search discharges it
from the two refinement projections without the author naming the lemma.
fn non_negative?(n: Int) -> Bool
true when n is non-negative.
fn percentage?(p: Int) -> Bool
true when p is a valid percentage (0..100 inclusive).
fn positive?(n: Int) -> Bool
true when n is strictly positive.
fn positive_natural_from_successor(predecessor: Nat) -> PositiveNatural
Construct a positive natural number from any successor.
fn probability?(p: Float) -> Bool
true when p is a valid probability (0.0..1.0 inclusive).
fn refine(a: Type, predicate: Function(a, Type), value: a, proof: predicate(value)) -> Sigma(refined_value: a, predicate(refined_value))
A value paired with kernel-checked evidence that it satisfies a proposition.
The surface {value: a | predicate(value)} is an ordinary dependent pair.
It contains no solver result and gives no new authority to the compiler:
constructing one requires evidence the kernel checks like every other proof.
Pair a value with evidence that it satisfies the refinement proposition.
fn refined_value(a: Type, predicate: Function(a, Type), refined: Sigma(refined_value: a, predicate(refined_value))) -> a
Recover the underlying value from a proof-backed refinement.
fn refinement_proof(a: Type, predicate: Function(a, Type), refined: Sigma(value: a, predicate(value))) -> predicate(refined_value(refined))
Recover the checked evidence carried by a refinement.