[−][src]Struct term_rewriting::Signature
Records a universe of symbols.
Use Signature::default
for a blank Signature
, or Signature::new
to initialize a
Signature
with given Operator
s.
Examples
// Constructing a Signature using the default let mut sig1 = Signature::default(); let a = sig1.new_op(2, Some("A".to_string())); let b = sig1.new_op(0, Some("B".to_string())); let c = sig1.new_op(0, Some("C".to_string())); // Constructing a Signature using Signature::new let mut sig2 = Signature::new(vec![ (2, Some("A".to_string())), (0, Some("B".to_string())), (0, Some("C".to_string())), ]); assert_eq!(sig1, sig2);
Methods
impl Signature
[src]
pub fn new(operator_spec: Vec<(u32, Option<String>)>) -> Signature
[src]
Construct a Signature
with the given Operator
s.
Each Operator
is specified in the form of (arity, Some(name))
or
(arity, None)
, where arity
is the number of arguments a Term
takes
(for example, an arity
of 0 gives a "constant" Operator
). A name
for
the Operator
is unnecessary, but may be supplied for more readable
formatting.
The returned vector of Operator
s corresponds to the supplied spec.
Examples
let mut sig = Signature::new(vec![ (2, Some(".".to_string())), (0, Some("S".to_string())), (0, Some("K".to_string())), ]); let ops = sig.operators(); let op_names: Vec<String> = ops.iter().map(|op| op.display()).collect(); assert_eq!(op_names, vec![".", "S", "K"]); let mut sig2 = Signature::default(); let p = sig2.new_op(2, Some(".".to_string())); let s = sig2.new_op(0, Some("S".to_string())); let k = sig2.new_op(0, Some("K".to_string())); assert_eq!(sig, sig2); let mut sig = Signature::new(vec![]); let mut sig2 = Signature::default(); assert_eq!(sig, sig2);
pub fn operators(&self) -> Vec<Operator>
[src]
Returns every Operator
known to the Signature
, in the order they were created.
Examples
let mut sig = Signature:: new(vec![ (2, Some(".".to_string())), (0, Some("S".to_string())), (0, Some("K".to_string())), ]); let ops: Vec<String> = sig.operators().iter().map(|op| op.display()).collect();; assert_eq!(ops, vec![".", "S", "K"]);
pub fn variables(&self) -> Vec<Variable>
[src]
Returns every Variable
known to the Signature
, in the order they were created.
Examples
let mut sig = Signature:: new(vec![ (2, Some(".".to_string())), (0, Some("S".to_string())), (0, Some("K".to_string())), ]); parse_term(&mut sig, "A(x_ y_)").expect("parse of A(x_ y_)"); let vars: Vec<String> = sig.variables().iter().map(|v| v.display()).collect(); assert_eq!(vars, vec!["x_", "y_"]);
pub fn atoms(&self) -> Vec<Atom>
[src]
Returns every Atom
known to the Signature
.
Examples
let mut sig = Signature::default(); parse_term(&mut sig, "A(x_ B(y_))").expect("parse of A(x_ B(y_))"); let atoms: Vec<String> = sig.atoms().iter().map(|a| a.display()).collect(); assert_eq!(atoms, vec!["x_", "y_", "B", "A"]);
pub fn new_op(&mut self, arity: u32, name: Option<String>) -> Operator
[src]
Create a new Operator
distinct from all existing Operator
s.
Examples
let mut sig = Signature::default(); let a = sig.new_op(1, Some(".".to_string())); let s = sig.new_op(2, Some("S".to_string())); let s2 = sig.new_op(2, Some("S".to_string())); assert_ne!(a, s); assert_ne!(a, s2); assert_ne!(s, s2);
pub fn new_var(&mut self, name: Option<String>) -> Variable
[src]
Create a new Variable
distinct from all existing Variable
s.
Examples
let mut sig = Signature::default(); let z = sig.new_var(Some("z".to_string())); let z2 = sig.new_var(Some("z".to_string())); assert_ne!(z, z2);
pub fn merge(
&self,
other: &Signature,
strategy: MergeStrategy
) -> Result<SignatureChange, ()>
[src]
&self,
other: &Signature,
strategy: MergeStrategy
) -> Result<SignatureChange, ()>
Merge two Signature
s. All Term
s, Context
s, Rule
s, and TRS
s associated
with the other
Signature
should be reified
using methods provided
by the returned SignatureChange
.
Examples
// Merging 2 signatures by assuming all operators in the second are distinct from the first. let mut sig1 = Signature::new(vec![ (2, Some(".".to_string())), (0, Some("S".to_string())), (0, Some("K".to_string())), ]); let mut sig2 = Signature::new(vec![ (2, Some("A".to_string())), (1, Some("B".to_string())), (0, Some("C".to_string())), ]); sig1.merge(&sig2, MergeStrategy::DistinctOperators); let ops: Vec<String> = sig1.operators().iter().map(|op| op.display()).collect(); assert_eq!(ops, vec![".", "S", "K", "A", "B", "C"]); // Merging 2 signatures by assuming all operators in the second are the same from the first. let mut sig1 = Signature::new(vec![ (2, Some(".".to_string())), (0, Some("S".to_string())), (0, Some("K".to_string())), ]); let mut sig2 = Signature::new(vec![ (2, Some(".".to_string())), (0, Some("S".to_string())), (0, Some("K".to_string())), ]); sig1.merge(&sig2, MergeStrategy::SameOperators); let ops: Vec<String> = sig1.operators().iter().map(|op| op.display()).collect(); assert_eq!(ops, vec![".", "S", "K"]); // Merging 2 signatures by SameOperators should fail if all operators in both signatures are not the same. let mut sig1 = Signature::new(vec![ (2, Some(".".to_string())), (0, Some("S".to_string())), (0, Some("K".to_string())), ]); let mut sig2 = Signature::new(vec![ (2, Some(".".to_string())), (1, Some("S".to_string())), (0, Some("K".to_string())), ]); assert!(sig1.merge(&sig2, MergeStrategy::SameOperators).is_err()); // Merging 2 signatures assuming any operators with the same name and arity are the same. let mut sig1 = Signature::new(vec![ (2, Some(".".to_string())), (0, Some("S".to_string())), (0, Some("K".to_string())), ]); let mut sig2 = Signature::new(vec![ (2, Some("A".to_string())), (1, Some("B".to_string())), (0, Some("K".to_string())), ]); sig1.merge(&sig2, MergeStrategy::OperatorsByArityAndName); let ops: Vec<String> = sig1.operators().iter().map(|op| op.display()).collect(); assert_eq!(ops, vec![".", "S", "K", "A", "B"]);
Trait Implementations
impl Default for Signature
[src]
impl Clone for Signature
[src]
fn clone(&self) -> Signature
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl PartialEq<Signature> for Signature
[src]
fn eq(&self, other: &Signature) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl Eq for Signature
[src]
impl Hash for Signature
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl Debug for Signature
[src]
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,