Struct term_rewriting::Signature[][src]

pub struct Signature { /* fields omitted */ }

Records a universe of symbols.

Use Signature::default for a blank signature, or Signature::new to initialize a signature with given operators.

Methods

impl Signature
[src]

Construct a signature with the given operators.

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 Operators corresponds to the supplied spec.

Examples

// Constructs a new signature with the operators ".","S","K' from the vector
let (mut sig,ops) = Signature:: new(vec![
    (2, Some(".".to_string())),
    (0, Some("S".to_string())),
    (0, Some("K".to_string())),
]);
let (mut sig2,ops2) = Signature:: new(vec![
    (2, Some(".".to_string())),
    (0, Some("S".to_string())),
    (0, Some("K".to_string())),
]);
let (mut sig3,ops3) = Signature:: new(vec![
    (2, Some(".".to_string())),
    (0, Some("S".to_string())),
]);

assert_eq!(sig,sig2);
assert_ne!(sig,sig3);

Returns every Operator known to the signature, in the order they were created.

Examples

// Constructs a new signature with the operators ".","S","K' from the vector
let (mut sig,ops) = Signature:: new(vec![
    (2, Some(".".to_string())),
    (0, Some("S".to_string())),
    (0, Some("K".to_string())),
]);
// Returns the operators in the signature above
let example_ops = sig.operators();

assert_eq!(ops,example_ops);

Returns every Variable known to the signature, in the order they were created.

Examples

// Constructs a new signature with the variables ".","S","K' from the vector
let (mut sig,ops) = Signature:: new(vec![
    (2, Some(".".to_string())),
    (0, Some("S".to_string())),
    (0, Some("K".to_string())),
]);

// Returns the variables in the signature above
let vars = sig.variables();
let vars2 = sig.variables();

let newVar = sig.new_var(Some("A".to_string()));
let vars3 = sig.variables();

assert_eq!(vars,vars2);
assert_ne!(vars,vars3);

Returns every Atom known to the signature.

Create a new Operator distinct from all existing operators.

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);

Create a new Variable distinct from all existing variables.

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);

Merge two Signatures. All terms, contexts, rules, and TRSs associated with the other signature should be reified using methods provided by the returned SignatureChange.

Examples

let (mut sig1, _ops) = Signature::new(vec![
    (2, Some(".".to_string())),
    (0, Some("S".to_string())),
    (0, Some("K".to_string())),
]);
let mut sig2 = sig1.clone();

let s1 = "S K K";
let term = parse_term(&mut sig1, s1).unwrap();
let s2 = "S x_ y_ z_ = (x_ z_) (y_ z_);";
let trs = parse_trs(&mut sig2, s2).unwrap();

let sigchange = sig1.merge(sig2, MergeStrategy::SameOperators);
// we only reify terms/rules/TRSs associated with sig2
let trs = sigchange.reify_trs(trs);
// now term and rule both exist with symbols according to sig1.

Trait Implementations

impl Clone for Signature
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for Signature
[src]

Formats the value using the given formatter. Read more

impl Default for Signature
[src]

Creates a new Signature without any Operators or Variables

Usage

let mut sig = Signature::default();
let (mut sig2,ops) = Signature::new(vec![]);
let (mut sig3,ops) = Signature::new(vec![
    (2, Some(".".to_string())),
    (0, Some("S".to_string())),
    (0, Some("K".to_string())),
    ]);
assert_eq!(sig,sig2);
assert_ne!(sig,sig3);

Returns the "default value" for a type. Read more

impl PartialEq for Signature
[src]

Compares two Signatures to test if they should be considered equal

Examples

let mut sig = Signature::default();
let mut sig2 = Signature::default();

assert!(sig.eq(&sig2));

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

impl Send for Signature

impl Sync for Signature