Literal

Struct Literal 

Source
pub struct Literal(/* private fields */);
Expand description

A possibly negated variable

There are three kinds of variables: constants (Literal::FALSE and Literal::TRUE), circuit inputs, and gates.

Concerning ordering, the following properties hold: Given two Literals a, b, a <= b is equivalent to the lexicographic comparison (a.positive(), a.is_negative()) <= (b.positive(), b.is_negative()). Furthermore, Literal::FALSE <= a holds (and thus Literal::TRUE <= a if a != Literal::FALSE).

Implementations§

Source§

impl Literal

Source

pub const MAX_INPUT: usize = 4_611_686_018_427_387_901usize

Maximum input number representable as literal

Source

pub const MAX_GATE: usize = 4_611_686_018_427_387_903usize

Maximum gate number representable as literal

Source

pub const FALSE: Self

Literal representing the constant

This is literal is considered to be positive (i.e., not negated):

assert!(Literal::FALSE.is_positive());
assert!(Literal::FALSE < Literal::TRUE);
Source

pub const TRUE: Self

Literal representing the constant

This is literal is considered to be negated:

assert!(Literal::TRUE.is_negative());
assert!(Literal::TRUE < Literal::from_input(false, 0));
assert!(Literal::TRUE < Literal::from_gate(false, 0));
Source

pub const UNDEF: Self

Undefined literal

This is considered to be a positive (i.e., not negated) input, but its variable number is larger than Self::MAX_INPUT. Attempting to create this literal using Self::from_input() will trigger a debug assertion.

assert!(Literal::UNDEF.is_positive());
assert!(Literal::UNDEF.is_input());
assert_eq!(Literal::UNDEF.get_input(), Some(Literal::MAX_INPUT + 1));
Source

pub const fn from_input(negative: bool, input: Var) -> Self

Create a new literal from an input variable

Source

pub const fn from_gate(negative: bool, gate: Var) -> Self

Create a new literal from a gate number

Source

pub const fn is_positive(self) -> bool

Is the literal positive?

Same as !self.is_negative()

assert!(Literal::from_input(false, 42).is_positive());
assert!(!Literal::from_input(true, 1337).is_positive());
Source

pub const fn is_negative(self) -> bool

Is the literal negative?

Same as !self.is_positive()

assert!(Literal::from_gate(true, 42).is_negative());
assert!(!Literal::from_gate(false, 1337).is_negative());
Source

pub const fn positive(self) -> Self

Get the positive variant of this literal

assert!(Literal::from_input(true, 42).positive().is_positive());
Source

pub const fn negative(self) -> Self

Get the negative variant of this literal

assert_eq!(Literal::from_input(true, 42), Literal::from_input(false, 42).negative());
assert!(Literal::from_input(false, 42).negative().is_negative());
Source

pub const fn is_input(self) -> bool

Does this literal refer to an input?

assert!(Literal::from_input(false, 42).is_input());
assert!(!Literal::FALSE.is_input());
assert!(!Literal::TRUE.is_input());
assert!(!Literal::from_gate(false, 1337).is_input());
Source

pub const fn is_gate(self) -> bool

Check if this literal refers to a gate

assert!(Literal::from_gate(false, 42).is_gate());
assert!(!Literal::FALSE.is_gate());
assert!(!Literal::TRUE.is_gate());
assert!(!Literal::from_input(false, 1337).is_gate());
Source

pub const fn get_input(self) -> Option<Var>

Get the input number (if this literal refers to an input)

assert_eq!(Literal::from_input(false, 42).get_input(), Some(42));
assert_eq!(Literal::FALSE.get_input(), None);
assert_eq!(Literal::TRUE.get_input(), None);
assert_eq!(Literal::from_gate(false, 42).get_input(), None);
Source

pub const fn get_gate_no(self) -> Option<Var>

Get the gate number (if this literal refers to an input)

assert_eq!(Literal::from_gate(false, 42).get_gate_no(), Some(42));
assert_eq!(Literal::FALSE.get_gate_no(), None);
assert_eq!(Literal::TRUE.get_gate_no(), None);
assert_eq!(Literal::from_input(false, 42).get_gate_no(), None);

See also: Circuit::gate()

Source

pub fn apply_gate_map(self, gate_map: &[Literal]) -> Self

Map this literal based on gate_map

If this literal refers to a gate, the method performs a lookup for the gate number in gate_map. If the gate number is in bounds, the return value is the mapped literal with its sign adjusted, otherwise the return value is Literal::UNDEF. Non-gate literals are returned as they are.

Trait Implementations§

Source§

impl BitXor<bool> for Literal

Source§

type Output = Literal

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: bool) -> Self::Output

Performs the ^ operation. Read more
Source§

impl Clone for Literal

Source§

fn clone(&self) -> Literal

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 Literal

Source§

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

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

impl Display for Literal

Source§

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

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

impl Hash for Literal

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 Not for Literal

Source§

type Output = Literal

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self

Performs the unary ! operation. Read more
Source§

impl Ord for Literal

Source§

fn cmp(&self, other: &Literal) -> 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 Literal

Source§

fn eq(&self, other: &Literal) -> 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 Literal

Source§

fn partial_cmp(&self, other: &Literal) -> 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 Copy for Literal

Source§

impl Eq for Literal

Source§

impl StructuralPartialEq for Literal

Auto Trait Implementations§

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