#variables #statement #linear #reduction #logic #relationships #value

puan-rust

Puan package contain tools for defining logic relationships among linear inequalities and reduction algorithms

9 releases

0.1.9 Jan 10, 2024
0.1.8 Mar 2, 2023
0.1.7 Dec 14, 2022
0.1.6 Nov 28, 2022
0.1.1 Sep 23, 2022

#373 in Algorithms

26 downloads per month

Apache-2.0

200KB
4K SLoC

Puan

Defining logic relationships among linear inequalities and has effective reduction algorithms.

Example

Here defining a relation between id 0, 1 and 2 saying that value of id 0 is dependent on value on id 1 and 2.

use puanrs::Theory;
use puanrs::Statement;
use puanrs::AtLeast;
use puanrs::Variable;
use puanrs::GeLineq;

let theory: Theory = Theory {
    id          : String::from("A"),
    statements  : vec![
        Statement {
            variable    : Variable {
                id      : 0,
                bounds  : (0,1),
            },
            expression  : Some(
                AtLeast {
                    ids     : vec![1,2],
                    bias   : -1,
                }
            )
        },
        Statement {
            variable    : Variable {
                id      : 1,
                bounds  : (0,1),
            },
            expression  : None
        },
        Statement {
            variable    : Variable {
                id      : 2,
                bounds  : (0,1),
            },
            expression  : None
        },
    ]
};

let actual: Vec<GeLineq> = theory.to_lineqs();
assert_eq!(actual.len(), 1);
assert_eq!(actual[0].bias, 0);
assert_eq!(actual[0].coeffs, vec![-1,1,1]);
assert_eq!(actual[0].indices, vec![0,1,2]);

If A=0, x=1, y=2 (with 0, 1, 2 here being variable id's), we could express above as A=x+y>=1.

Dependencies

~425KB