### 2 releases

0.5.2 | Jul 6, 2023 |
---|---|

0.5.1 | May 11, 2023 |

#**648** in Math

**MPL-2.0**license

39KB

649 lines

# predicate-checker

Predicate-checker is a small library written Rust whose only purpose is to check that the validity of a given predicate

implies the validity of a predicate `A`

.`B`

For example, given the predicates

and `A : x > 5`

`B``:` x `>` `6`

, the library can (using the `Predicate``::`implies`(``)`

function) verify that for every value of `x`

where `A`

is true, `B`

is also true (in this example, it is; so the `A``.``implies``(`B`)`

function would return `Implication``::`Total

).

Note: this library was not made by a mathematician, nor a good programmer, nor a good gardener. The results are not 100% truthful and should not be used for anything more important than a small project. Sorry!

## Usage

The

enum represents a boolean expression. You can build one "manually" by assembling other `Predicate`

(`Predicate <T>`

`T`

being a numerical type), or using the builtin parser:`use` `predicatechecker``::`Predicate`;`
`let` predicate `=` `Predicate``::`from`(``"`(x > 2) && (y == 4) && (z < 10)`"``)``.``unwrap``(``)``;` `//` returns a Predicate<f64>

Now, you can check if a predicate "implies" another:

`use` `predicatechecker``::`Predicate`;`
`fn` `main``(``)`` ``{`
`let` a `=` `Predicate``::`from`(``"`(x > 2) && (y == 4) && (z < 10)`"``)``.``unwrap``(``)``;`
`let` b `=` `Predicate``::`from`(``"`(x > 0) && (y > 2)`"``)``.``unwrap``(``)``;`
`assert_eq!``(`a`.``implies``(``&`b`)``,` `Implication``::`Total`)``;`
`}`

The

function can return 3 different values: `implies`

, `Implication ::`Total

`Implication``::`Partial

or `Implication``::`Inexistant

:- A

implication means that any value that verifies A will verify B.`Total` - A

implication means that only a subset of the values that verify A will verify B. This can happen with`Partial`

predicates, for which only one of the two predicates implies B.`Or` - An

implication means that the verification of A by a value x is not enough to know that x also verifies B.`Inexistant`

## Installation

The easiest way to add it to your projects is by using cargo. Add it to your

file:`Cargo .toml`

`[``dependencies``]`
`predicatechecker ``=` `"`0.5.1`"`

You can also clone this repository and use it in your own projects (see Specifying Dependencies from The Cargo Book).

## License

This project is licensed under **Mozilla Public License 2.0**. See

.`LICENSE``.`txt

#### Dependencies

~465KB