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 Literal
s
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
impl Literal
Sourcepub const MAX_INPUT: usize = 4_611_686_018_427_387_901usize
pub const MAX_INPUT: usize = 4_611_686_018_427_387_901usize
Maximum input number representable as literal
Sourcepub const MAX_GATE: usize = 4_611_686_018_427_387_903usize
pub const MAX_GATE: usize = 4_611_686_018_427_387_903usize
Maximum gate number representable as literal
Sourcepub const FALSE: Self
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);
Sourcepub const TRUE: Self
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));
Sourcepub const UNDEF: Self
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));
Sourcepub const fn from_input(negative: bool, input: Var) -> Self
pub const fn from_input(negative: bool, input: Var) -> Self
Create a new literal from an input variable
Sourcepub const fn from_gate(negative: bool, gate: Var) -> Self
pub const fn from_gate(negative: bool, gate: Var) -> Self
Create a new literal from a gate number
Sourcepub const fn is_positive(self) -> bool
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());
Sourcepub const fn is_negative(self) -> bool
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());
Sourcepub const fn positive(self) -> Self
pub const fn positive(self) -> Self
Get the positive variant of this literal
assert!(Literal::from_input(true, 42).positive().is_positive());
Sourcepub const fn negative(self) -> Self
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());
Sourcepub const fn is_input(self) -> bool
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());
Sourcepub const fn is_gate(self) -> bool
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());
Sourcepub const fn get_input(self) -> Option<Var>
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);
Sourcepub const fn get_gate_no(self) -> Option<Var>
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()
Sourcepub fn apply_gate_map(self, gate_map: &[Literal]) -> Self
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 Ord for Literal
impl Ord for Literal
Source§impl PartialOrd for Literal
impl PartialOrd for Literal
impl Copy for Literal
impl Eq for Literal
impl StructuralPartialEq for Literal
Auto Trait Implementations§
impl Freeze for Literal
impl RefUnwindSafe for Literal
impl Send for Literal
impl Sync for Literal
impl Unpin for Literal
impl UnwindSafe for Literal
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.