OutputSelection

Struct OutputSelection 

Source
pub struct OutputSelection<'a, T, TermId> { /* private fields */ }
Expand description

Wrap a multi-output Boolean function by selecting a single output.

§Example

use libreda_logic::traits::*;
use libreda_logic::native_boolean_functions::*;
use libreda_logic::adaptors::*;

fn f([a]: [bool; 1]) -> [bool; 2] {
    [a, !a]   
}

// Wrap the native Rust function such that it implements the traits of Boolean functions.
let f2 = NativeBooleanFunction::new(f);

// Select the first output.
let f_0 = OutputSelection::new(&f2, 0);

// Select the second output.
let f_1 = OutputSelection::new(&f2, 1);

assert_eq!(f_0.eval(&[false]), false);
assert_eq!(f_0.eval(&[true]), true);

assert_eq!(f_1.eval(&[false]), true);
assert_eq!(f_1.eval(&[true]), false);

Implementations§

Source§

impl<'a, T: BooleanSystem> OutputSelection<'a, T, T::TermId>

Source

pub fn new(boolean_system: &'a T, output: T::TermId) -> Self

Create a boolean function by selecting a single output.

Trait Implementations§

Source§

impl<'a, T: BooleanSystem> BooleanFunction for OutputSelection<'a, T, T::TermId>

Source§

fn eval(&self, input_values: &[bool]) -> bool

Evaluate the boolean function with the given input values.
Source§

impl<'a, T: BooleanSystem> BooleanSystem for OutputSelection<'a, T, T::TermId>

Source§

fn evaluate_term(&self, _term: &Self::TermId, input_values: &[bool]) -> bool

Compute the value of the term. The values of all needed literals must be defined by the input_values function.
Source§

impl<'a, T: NumInputs, TermId> NumInputs for OutputSelection<'a, T, TermId>

Source§

fn num_inputs(&self) -> usize

Get the number of inputs of the boolean function.
Source§

impl<'a, T: NumOutputs, TermId> NumOutputs for OutputSelection<'a, T, TermId>

Source§

fn num_outputs(&self) -> usize

Get the number of outputs of the boolean function.
Source§

impl<'a, T: PartialBooleanSystem> PartialBooleanFunction for OutputSelection<'a, T, T::TermId>

Source§

fn partial_eval(&self, input_values: &[bool]) -> Option<bool>

Evaluate the boolean function with the given input values.
Source§

impl<'a, T: PartialBooleanSystem> PartialBooleanSystem for OutputSelection<'a, T, T::TermId>

Source§

type LiteralId = <T as PartialBooleanSystem>::LiteralId

An identifier for an input of the boolean formula.
Source§

type TermId = ()

An identifier of an intermediate value or output.
Source§

fn evaluate_term_partial( &self, _term: &Self::TermId, input_values: &[bool], ) -> Option<bool>

Compute the value of the term. The values of all needed literals must be defined by the input_values function. Returns None if the value is not specified for the given inputs.
Source§

impl<'a, T, TermId> StaticNumOutputs<1> for OutputSelection<'a, T, TermId>

Auto Trait Implementations§

§

impl<'a, T, TermId> Freeze for OutputSelection<'a, T, TermId>
where TermId: Freeze,

§

impl<'a, T, TermId> RefUnwindSafe for OutputSelection<'a, T, TermId>
where TermId: RefUnwindSafe, T: RefUnwindSafe,

§

impl<'a, T, TermId> Send for OutputSelection<'a, T, TermId>
where TermId: Send, T: Sync,

§

impl<'a, T, TermId> Sync for OutputSelection<'a, T, TermId>
where TermId: Sync, T: Sync,

§

impl<'a, T, TermId> Unpin for OutputSelection<'a, T, TermId>
where TermId: Unpin,

§

impl<'a, T, TermId> UnwindSafe for OutputSelection<'a, T, TermId>
where TermId: UnwindSafe, T: RefUnwindSafe,

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