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

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).

Types

type Negative

 type Negative

Strictly negative integer.

type NonNegative

 type NonNegative

Non-negative integer (zero or positive).

type NonPositive

 type NonPositive

Non-positive integer (zero or negative).

type NonZero

 type NonZero

Non-zero integer (Int minus zero).

type Percentage

 type Percentage

Integer between 0 and 100 inclusive (a percentage).

type Positive

 type Positive

Strictly positive integer.

type PositiveFloat

 type PositiveFloat

Strictly positive float (e.g. probability density, weight).

type PositiveNatural

 type PositiveNatural

Natural numbers known to be strictly positive.

type Probability

 type Probability

Float in [0.0, 1.0] inclusive (a probability).

Functions

add_positive_natural_numbers(left: PositiveNatural, right: PositiveNatural) -> PositiveNatural

 fn add_positive_natural_numbers(left: PositiveNatural, right: PositiveNatural) -> PositiveNatural

Adding two positive natural numbers preserves positivity.

multiply_positive_natural_numbers(left: PositiveNatural, right: PositiveNatural) -> PositiveNatural

 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.

non_negative?(n: Int) -> Bool

 fn non_negative?(n: Int) -> Bool

true when n is non-negative.

percentage?(p: Int) -> Bool

 fn percentage?(p: Int) -> Bool

true when p is a valid percentage (0..100 inclusive).

positive?(n: Int) -> Bool

 fn positive?(n: Int) -> Bool

true when n is strictly positive.

positive_natural_from_successor(predecessor: Nat) -> PositiveNatural

 fn positive_natural_from_successor(predecessor: Nat) -> PositiveNatural

Construct a positive natural number from any successor.

probability?(p: Float) -> Bool

 fn probability?(p: Float) -> Bool

true when p is a valid probability (0.0..1.0 inclusive).

refine(a: Type, predicate: Function(a, Type), value: a, proof: predicate(value)) -> Sigma(refined_value: a, predicate(refined_value))

 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.

refined_value(a: Type, predicate: Function(a, Type), refined: Sigma(refined_value: a, predicate(refined_value))) -> a

 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.

refinement_proof(a: Type, predicate: Function(a, Type), refined: Sigma(value: a, predicate(value))) -> predicate(refined_value(refined))

 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.