Struct Lit

Source
pub struct Lit { /* private fields */ }
Expand description

Type representing literals, possibly negated boolean variables.

§Representation in Memory

Literal representation is idx << 1 with the last bit representing whether the literal is negated or not. This way the literal can directly be used to index data structures with the two literals of a variable being close together.

Implementations§

Source§

impl Lit

Source

pub const fn new(idx: u32, negated: bool) -> Lit

Creates a new (negated or not) literal with a given index.

§Panics

If idx > Var::MAX_IDX.

Source

pub fn new_with_error(idx: u32, negated: bool) -> Result<Lit, TypeError>

Creates a new (negated or not) literal with a given index.

§Errors

TypeError::IdxTooHigh(idx, Var::MAX_IDX) if idx > Var::MAX_IDX.

Source

pub const unsafe fn new_unchecked(idx: u32, negated: bool) -> Lit

Creates a new (negated or not) literal with a given index. Does not perform any check on the index, therefore might produce an inconsistent variable. Only use this for performance reasons if you are sure that idx <= Var::MAX_IDX.

§Safety

idx must be guaranteed to be not higher than Var::MAX_IDX

Source

pub const fn positive(idx: u32) -> Lit

Creates a new positive literal with a given index. Panics if idx > Var::MAX_IDX.

Source

pub const fn negative(idx: u32) -> Lit

Creates a new negated literal with a given index. Panics if idx > Var::MAX_IDX.

Source

pub fn positive_with_error(idx: u32) -> Result<Lit, TypeError>

Creates a new positive literal with a given index.

§Errors

If idx > Var::MAX_IDX.

Source

pub fn negative_with_error(idx: u32) -> Result<Lit, TypeError>

Creates a new negated literal with a given index.

§Errors

If idx > Var::MAX_IDX.

Source

pub const unsafe fn positive_unchecked(idx: u32) -> Lit

Creates a new positive literal with a given index. Does not perform any check on the index, therefore might produce an inconsistent variable. Only use this for performance reasons if you are sure that idx <= Var::MAX_IDX.

§Safety

idx must be guaranteed to be not higher than Var::MAX_IDX

Source

pub const unsafe fn negative_unchecked(idx: u32) -> Lit

Creates a new negated literal with a given index. Does not perform any check on the index, therefore might produce an inconsistent variable. Only use this for performance reasons if you are sure that idx <= Var::MAX_IDX.

§Safety

idx must be guaranteed to be not higher than Var::MAX_IDX

Source

pub fn from_ipasir(val: c_int) -> Result<Lit, TypeError>

Create a literal from an IPASIR/DIMACS integer value.

§Errors

If the value is zero or the index too high.

Source

pub fn vidx(self) -> usize

Gets the variable index of the literal

Source

pub fn vidx32(self) -> u32

Gets the 32-bit variable index of the literal

Source

pub fn lidx(self) -> usize

Gets a literal representation for indexing data structures

Source

pub fn var(self) -> Var

Gets the variables that the literal corresponds to.

§Examples
let var = Var::new(5);
let lit = Lit::negative(5);
assert_eq!(var, lit.var());
Examples found in repository?
examples/profiling.rs (line 72)
68fn build_full_ub<PBE: BoundUpper + FromIterator<(Lit, usize)>>(lits: &[(Lit, usize)]) {
69    let mut enc = PBE::from_iter(lits.iter().copied());
70    let max_var = lits
71        .iter()
72        .fold(Var::new(0), |mv, (lit, _)| std::cmp::max(lit.var(), mv));
73    let mut var_manager = BasicVarManager::default();
74    var_manager.increase_next_free(max_var + 1);
75    let mut collector = Cnf::new();
76    enc.encode_ub(.., &mut collector, &mut var_manager).unwrap();
77}
Source

pub fn is_pos(self) -> bool

True if the literal is positive.

Source

pub fn is_neg(self) -> bool

True if the literal is negated.

Source

pub fn to_ipasir(self) -> c_int

Converts the literal to an integer as accepted by IPASIR and the DIMACS file format. The IPASIR literal will have idx+1 and be negative if the literal is negated. Panics if the literal does not fit into a c_int.

§Panics

If the variable index does not fit in c_int. As c_int will almost always be i32, this is only the case on very esoteric platforms.

Source

pub fn to_ipasir_with_error(self) -> Result<c_int, TypeError>

Converts the literal to an integer as accepted by IPASIR and the DIMACS file format. The IPASIR literal will have idx+1 and be negative if the literal is negated.

§Errors

TypeError::IdxTooHigh(_, _) if the literal does not fit into a c_int. As c_int will almost always be i32, it is mostly safe to simply use Self::to_ipasir instead.

Trait Implementations§

Source§

impl Add<u32> for Lit

Incrementing literals. This preserves the sign of the literal.

Source§

type Output = Lit

The resulting type after applying the + operator.
Source§

fn add(self, rhs: u32) -> Self::Output

Performs the + operation. Read more
Source§

impl Clone for Lit

Source§

fn clone(&self) -> Lit

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Lit

Literals can be printed with the Debug trait

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Lit

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Lit

Literals can be printed with the Display trait

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N: usize, Sub> Extend<Lit> for Bimander<N, Sub>

Source§

fn extend<T: IntoIterator<Item = Lit>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl Extend<Lit> for Bitwise

Source§

fn extend<T: IntoIterator<Item = Lit>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl Extend<Lit> for Clause

Source§

fn extend<T: IntoIterator<Item = Lit>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<const N: usize, Sub> Extend<Lit> for Commander<N, Sub>

Source§

fn extend<T: IntoIterator<Item = Lit>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<UBE, LBE> Extend<Lit> for Double<UBE, LBE>
where UBE: BoundUpper + Extend<Lit> + 'static, LBE: BoundLower + Extend<Lit> + 'static,

Source§

fn extend<T: IntoIterator<Item = Lit>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<CE> Extend<Lit> for Inverted<CE>
where CE: Encode + Extend<Lit> + 'static,

Source§

fn extend<T: IntoIterator<Item = Lit>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl Extend<Lit> for Ladder

Source§

fn extend<T: IntoIterator<Item = Lit>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl Extend<Lit> for Pairwise

Source§

fn extend<T: IntoIterator<Item = Lit>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl Extend<Lit> for Totalizer

Source§

fn extend<T: IntoIterator<Item = Lit>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl From<Lit> for Axiom<Var>

Available on crate feature proof-logging only.
Source§

fn from(value: Lit) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<Lit> for Assignment

Source§

fn from_iter<T: IntoIterator<Item = Lit>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl<const N: usize, Sub> FromIterator<Lit> for Bimander<N, Sub>

Source§

fn from_iter<T: IntoIterator<Item = Lit>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl FromIterator<Lit> for Bitwise

Source§

fn from_iter<T: IntoIterator<Item = Lit>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl FromIterator<Lit> for Clause

Source§

fn from_iter<T: IntoIterator<Item = Lit>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl<const N: usize, Sub> FromIterator<Lit> for Commander<N, Sub>

Source§

fn from_iter<T: IntoIterator<Item = Lit>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl<UBE, LBE> FromIterator<Lit> for Double<UBE, LBE>
where UBE: BoundUpper + From<Vec<Lit>> + 'static, LBE: BoundLower + From<Vec<Lit>> + 'static,

Source§

fn from_iter<T: IntoIterator<Item = Lit>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl<CE> FromIterator<Lit> for Inverted<CE>
where CE: Encode + From<Vec<Lit>> + 'static,

Source§

fn from_iter<T: IntoIterator<Item = Lit>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl FromIterator<Lit> for Ladder

Source§

fn from_iter<T: IntoIterator<Item = Lit>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl FromIterator<Lit> for Pairwise

Source§

fn from_iter<T: IntoIterator<Item = Lit>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl FromIterator<Lit> for Totalizer

Source§

fn from_iter<T: IntoIterator<Item = Lit>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl Hash for Lit

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Neg for Lit

Trait implementation allowing for negating literals with the unary - operator.

Source§

type Output = Lit

The resulting type after applying the - operator.
Source§

fn neg(self) -> Lit

Performs the unary - operation. Read more
Source§

impl Not for Lit

Trait implementation allowing for negating literals with the ! operator.

Source§

type Output = Lit

The resulting type after applying the ! operator.
Source§

fn not(self) -> Lit

Performs the unary ! operation. Read more
Source§

impl Ord for Lit

Source§

fn cmp(&self, other: &Lit) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Lit

Source§

fn eq(&self, other: &Lit) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Lit

Source§

fn partial_cmp(&self, other: &Lit) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Lit

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Sub<u32> for Lit

Decrementing literals. This preserves the sign of the literal.

Source§

type Output = Lit

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: u32) -> Self::Output

Performs the - operation. Read more
Source§

impl Copy for Lit

Source§

impl Eq for Lit

Source§

impl StructuralPartialEq for Lit

Auto Trait Implementations§

§

impl Freeze for Lit

§

impl RefUnwindSafe for Lit

§

impl Send for Lit

§

impl Sync for Lit

§

impl Unpin for Lit

§

impl UnwindSafe for Lit

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,