1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
//! A collection of mathematical properties for random testing.
//!
//! It's based on [dicetest](https://github.com/jakoschiko/dicetest).
//!
//! # Status of this crate
//!
//! The author does not consider this crate as stable yet. Changes will be documented in the
//! [changelog](https://github.com/jakoschiko/diceprop/blob/master/CHANGELOG.md).
//!
//! # Examples
//!
//! ## Associative binary operation
//!
//! ```
//! use diceprop::{props, Fun2, Set};
//! use dicetest::prelude::*;
//!
//! #[test]
//! fn add_is_associative_for_small_f32() {
//!     Dicetest::repeatedly().run(|mut fate| {
//!         let set = Set::new("f32 ∩ [-100,100]", dice::f32(-100.0..=100.0));
//!         let vars = fate.roll(set.vars(["x", "y", "z"]));
//!         let add = Fun2::infix("+", |x, y| x + y);
//!         props::binop::associative(vars, add);
//!     })
//! }
//! ```
//!
//! The test fails with the following output:
//!
//! ```text
//! The test failed after 12 passes.
//!
//! # Config
//! - seed: 14859458141222391139
//! - start limit: 0
//! - end limit: 100
//! - passes: 200
//!
//! # Counterexample
//! - run code: "2pYRCj9fj8sV52fB5iyFhxCISGY3nKlMzlzIKq0NKLwGAAAAAAAAAA=="
//! - limit: 6
//! - hints:
//!         - Is `+` associative?
//!                 - x, y, z of f32 ∩ [-100,100]
//!                 - x = 96.621735
//!                 - y = -90.97134
//!                 - z = -8.10239
//!                 - (x + y) = 5.6503983
//!                 - ((x + y) + z) = -2.451992
//!                 - (y + z) = -99.07373
//!                 - (x + (y + z)) = -2.4519958
//!                 - (((x + y) + z) == (x + (y + z))) = false
//! - error: assertion failed: (((x + y) + z) == (x + (y + z)))
//! ```
//!
//! ## Left inverse function
//!
//! ```
//! use diceprop::{props, Fun1, Set};
//! use dicetest::prelude::*;
//!
//! #[test]
//! fn sqrt_is_left_inverse_of_sq_for_non_negative_f32() {
//!     Dicetest::repeatedly().run(|mut fate| {
//!         let set = Set::new("f32 ∩ [0,+∞]", dice::f32(0.0..));
//!         let vars = fate.roll(set.vars(["x"]));
//!         let sq = Fun1::postfix("²", |x| x * x);
//!         let sqrt = Fun1::new("√", |x: f32| x.sqrt());
//!         props::fun::left_inverse(vars, sq, sqrt);
//!     })
//! }
//! ```
//!
//! The test fails with the following output:
//!
//! ```text
//! The test failed after 0 passes.
//!
//! # Config
//! - seed: 7632522237817347676
//! - start limit: 0
//! - end limit: 100
//! - passes: 200
//!
//! # Counterexample
//! - run code: "F2/nnlbX6qyCOm5MU7P8BSXdnJ4XNXJdihgwhtWxlzMAAAAAAAAAAA=="
//! - limit: 0
//! - hints:
//!         - Is `√` left inverse of `²`?
//!                 - x of f32 ∩ [0,+∞]
//!                 - x = 305770290000000000000000000000000000000.0
//!                 - (x)² = inf
//!                 - √((x)²) = inf
//!                 - (√((x)²) == x) = false
//! - error: assertion failed: (√((x)²) == x)
//! ```
//!
//! ## Partial order
//!
//! ```
//! use diceprop::{props, Fun2, Set};
//! use dicetest::prelude::*;
//!
//! #[test]
//! fn gt_is_partial_order_for_any_f32() {
//!     Dicetest::repeatedly().run(|mut fate| {
//!         let set = Set::new("f32", dice::any_f32());
//!         let vars = fate.roll(set.vars(["x", "y", "z"]));
//!         let gt = Fun2::infix("≤", |x, y| x <= y);
//!         props::binrel::partial_order(vars, gt);
//!     })
//! }
//! ```
//!
//! The test fails with the following output:
//!
//! ```text
//! The test failed after 3 passes.
//!
//! # Config
//! - seed: 18374838706510982620
//! - start limit: 0
//! - end limit: 100
//! - passes: 200
//!
//! # Counterexample
//! - run code: "h6jQMNr6fi/j9OZOXmklXYAUATM96EpE6+DENMhSZHkBAAAAAAAAAA=="
//! - limit: 1
//! - hints:
//!         - Is `≤` a partial order?
//!                 - Is `≤` reflexive?
//!                         - x of f32
//!                         - x = NaN
//!                         - (x ≤ x) = false
//! - error: assertion failed: (x ≤ x)
//! ```

#[macro_use]
mod eval;
pub use eval::Eval;

mod elem;
pub use elem::Elem;

mod vars;
pub use vars::Vars;

mod set;
pub use set::Set;

mod fun;
pub use fun::{Fun1, Fun1Label, Fun2, Fun2Label, Fun3, Fun3Label};

pub mod ops;

pub mod props;