RootedLambdaPool

Struct RootedLambdaPool 

Source
pub struct RootedLambdaPool<'src, T: LambdaLanguageOfThought> { /* private fields */ }
Expand description

A lambda expression with its root defined.

Implementations§

Source§

impl<'src, T: LambdaLanguageOfThought> RootedLambdaPool<'src, T>

Source

pub fn new_free_variable( index: usize, t: LambdaType, ) -> RootedLambdaPool<'src, T>

Creates an anonymous free variable with [index] of type [t]

Source

pub fn free_variables( &self, ) -> impl Iterator<Item = (&FreeVar<'src>, &LambdaType)>

Gets all free variables that must be bound in order to evaluate this lambda expression

Source

pub fn len(&self) -> usize

Get the length of a lambda tree

Source§

impl<'src, T: LambdaLanguageOfThought + Clone> RootedLambdaPool<'src, T>

Source

pub fn cleanup(&mut self)

Clean up dangling references.

Source

pub fn get_type(&self) -> Result<LambdaType, TypeError>

The type of the lambda expression

§Errors

Returns a TypeError if the underlying pool is malformed leading to no possible type being extractible.

Source

pub fn merge(self, other: Self) -> Option<Self>

Combine two lambda expressions by applying one to the other. Returns None if that is impossible.

§Panics

Will panic if either pool is malformed such that no type can be found.

Source

pub fn apply(self, other: Self) -> Option<Self>

Applies other to self and returns None if the types do not correspond.

§Panics

Will panic if either pool is malformed such that no type can be found.

Source

pub fn reduce(&mut self) -> Result<(), ReductionError>

Reduce a lambda expression

§Errors

Will throw a ReductionError if there is something makes the reduction improper.

Source

pub fn into_pool(self) -> Result<T::Pool, T::ConversionError>

Convert a lambda expression to its executable version (should only be done if there are only LambdaExpr::LanguageOfThoughtExpr expressions.

§Errors

Will throw a [T::ConversionError] if there are any lambda terms left in the pool

Source

pub fn bind_free_variable( &mut self, fvar: FreeVar<'src>, replacement: RootedLambdaPool<'src, T>, ) -> Result<(), LambdaError>

Replace a free variable with a value.

§Errors

Will return an error if a FreeVar with the same name but different type already exists

Source

pub fn lambda_abstract_free_variable( &mut self, fvar: FreeVar<'src>, lambda_type: LambdaType, always_abstract: bool, ) -> Result<(), LambdaError>

Replace a free variable by lambda abstracting it. (e.g. $P(x_{free})$ to $\lambda x P(x)$).

§Errors

Will throw an error if the free variable has the wrong type.

Source

pub fn apply_new_free_variable( &mut self, fvar: FreeVar<'src>, ) -> Result<LambdaType, LambdaError>

Apply a free variable to a function.

§Errors

Will throw an error if there is an issue with the reduction

Source§

impl<T: LambdaLanguageOfThought + Clone + Debug> RootedLambdaPool<'_, T>

Source

pub fn lift(&mut self) -> Result<(), TypeError>

Convert an expression phi of type x and convert it to lambda <x,t> P P(phi)

§Errors

Will return a type error if the type of the lambda expression is malformed

Source

pub fn stats(&self) -> LambdaSummaryStats

Get LambdaSummaryStats for an expression, e.g. how many context functions, size, etc.

Source§

impl<'a> RootedLambdaPool<'a, Expr<'a>>

Source

pub fn conjoin(self, other: Self) -> Result<Self, ConjoiningError>

Takes two lambda expressions, phi and psi of type <x, t> where x is any type and returns phi AND psi.

§Errors

Returns a ConjoiningError if self and other are not of the right types such that a

Source

pub fn raised_conjoin(self, other: Self) -> Result<Self, ConjoiningError>

Takes two lambda expressions, phi <x, <y,t>> and psi of type <y, t> where x and y is any type and returns phi AND psi.

This is a generalized kind of Event Identification from Kratzer (1996)

  • Kratzer, A. (1996). Severing the External Argument from its Verb. In J. Rooryck & L. Zaring (Eds.), Phrase Structure and the Lexicon (pp. 109–137). Springer Netherlands. https://doi.org/10.1007/978-94-015-8617-7_5
§Errors

Returns a ConjoiningError if self and other are not of the right types such that a

Source

pub fn parse(s: &'a str) -> Result<Self, LambdaParseError>

Create a RootedLambdaPool<Expr> from a string.

§Errors

Returns a LambdaParseError if the input string is malformed and not a LOT expression.

Source§

impl<'src, T: LambdaLanguageOfThought + Clone> RootedLambdaPool<'src, T>

Source

pub fn typeless_sampler( possible_expressions: PossibleExpressions<'src, T>, max_expr: usize, max_types: usize, ) -> TypeAgnosticSampler<'src, T>

Create a sampler which can sample arbitrary types.

§Panics

Will panic if max_types == 0 or max_expr == 0

Source§

impl<'src> RootedLambdaPool<'src, Expr<'src>>

Source

pub fn resample_from_expr<'a>( &mut self, possible_expressions: &'a PossibleExpressions<'src, Expr<'src>>, helpers: Option<&HashMap<LambdaType, Vec<RootedLambdaPool<'src, Expr<'src>>>>>, rng: &mut impl Rng, ) -> Result<(), LambdaError>

Create a LambdaSampler of a given type.

§Errors

Will return a LambdaError if the tree is malformed

§Panics

Will panic if the size of the tree is greater than u32::MAX.

Source

pub fn enumerator_filter<'a, F: Fn(&Context) -> bool>( t: &LambdaType, filter: F, possible_expressions: &'a PossibleExpressions<'src, Expr<'src>>, ) -> LambdaEnumerator<'a, 'src, Expr<'src>, F>

Create a LambdaSampler of a given type with a filter

Source

pub fn enumerator<'a>( t: &LambdaType, possible_expressions: &'a PossibleExpressions<'src, Expr<'src>>, ) -> LambdaEnumerator<'a, 'src, Expr<'src>, impl Fn(&Context) -> bool>

Create a LambdaSampler of a given type.

Source

pub fn sampler( t: &LambdaType, possible_expressions: &PossibleExpressions<'src, Expr<'src>>, max_expr: usize, ) -> LambdaSampler<'src, Expr<'src>>

Creates a reusable random sampler by enumerating over the first max_expr expressions

Source

pub fn random_expr( t: &LambdaType, possible_expressions: &PossibleExpressions<'src, Expr<'src>>, rng: &mut impl Rng, ) -> RootedLambdaPool<'src, Expr<'src>>

Randomly generate a RootedLambdaPool of type t.

§Panics

Will panic if no such type can be generated.

Source

pub fn random_expr_no_constant( t: &LambdaType, possible_expressions: &PossibleExpressions<'src, Expr<'src>>, rng: &mut impl Rng, ) -> Option<RootedLambdaPool<'src, Expr<'src>>>

Randomly generate a RootedLambdaPool of type t without constant functions.

Source§

impl<'src> RootedLambdaPool<'src, Expr<'src>>

Source

pub fn prune_quantifiers(&mut self)

Remove quantifiers which do not use their variable in their body.

Source

pub fn swap_expr( &mut self, possible_expressions: &PossibleExpressions<'src, Expr<'src>>, rng: &mut impl Rng, ) -> Result<(), TypeError>

Replace a random expression with something else of the same type.

§Errors

Will return a TypeError if there is no compatible type to replace

§Panics

Will panic if the size of the tree is greater than u32::MAX.

Source

pub fn swap_subtree(&mut self, rng: &mut impl Rng) -> Result<(), TypeError>

Replace a random expression with something else of the same type from within the same expression.

§Errors

Will return TypeError if a compatible subtree can’t be found.

§Panics

Will panic if the size of the tree is greater than u32::MAX.

Source§

impl<'src> RootedLambdaPool<'src, Expr<'src>>

Source

pub fn for_document(&self) -> MathModeExpression<'_>

Get a [MathModeExpression] to be serialized for documents.

Trait Implementations§

Source§

impl<'src, T: Clone + LambdaLanguageOfThought> Clone for RootedLambdaPool<'src, T>

Source§

fn clone(&self) -> RootedLambdaPool<'src, T>

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<'src, T: Debug + LambdaLanguageOfThought> Debug for RootedLambdaPool<'src, T>

Source§

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

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

impl<'de, 'a> Deserialize<'de> for RootedLambdaPool<'a, Expr<'a>>
where 'de: 'a,

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<'a> Display for RootedLambdaPool<'a, Expr<'a>>

Source§

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

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

impl<'src, T: LambdaLanguageOfThought + Clone> Distribution<RootedLambdaPool<'src, T>> for LambdaSampler<'src, T>

Source§

fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> RootedLambdaPool<'src, T>

Generate a random value of T, using rng as the source of randomness.
§

fn sample_iter<R>(self, rng: R) -> Iter<Self, R, T>
where R: Rng, Self: Sized,

Create an iterator that generates random values of T, using rng as the source of randomness. Read more
§

fn map<F, S>(self, func: F) -> Map<Self, F, T, S>
where F: Fn(T) -> S, Self: Sized,

Map sampled values to type S Read more
Source§

impl<'a> From<LanguageExpression<'a>> for RootedLambdaPool<'a, Expr<'a>>

Source§

fn from(value: LanguageExpression<'a>) -> Self

Converts to this type from the input type.
Source§

impl<T: LambdaLanguageOfThought + HashLambda> Hash for RootedLambdaPool<'_, T>

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<T: LambdaLanguageOfThought + PartialEq + Eq> Ord for RootedLambdaPool<'_, T>

Source§

fn cmp(&self, other: &Self) -> 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<T: PartialEq + LambdaLanguageOfThought> PartialEq for RootedLambdaPool<'_, T>

Source§

fn eq(&self, other: &Self) -> 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<T: LambdaLanguageOfThought + PartialEq + Eq> PartialOrd for RootedLambdaPool<'_, T>

Source§

fn partial_cmp(&self, other: &Self) -> 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<'src> Serialize for RootedLambdaPool<'src, Expr<'src>>

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T: PartialEq + LambdaLanguageOfThought> Eq for RootedLambdaPool<'_, T>

Auto Trait Implementations§

§

impl<'src, T> Freeze for RootedLambdaPool<'src, T>

§

impl<'src, T> RefUnwindSafe for RootedLambdaPool<'src, T>
where T: RefUnwindSafe,

§

impl<'src, T> Send for RootedLambdaPool<'src, T>
where T: Send,

§

impl<'src, T> Sync for RootedLambdaPool<'src, T>
where T: Sync,

§

impl<'src, T> Unpin for RootedLambdaPool<'src, T>
where T: Unpin,

§

impl<'src, T> UnwindSafe for RootedLambdaPool<'src, T>
where T: UnwindSafe,

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
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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
§

impl<'src, T> IntoMaybe<'src, T> for T
where T: 'src,

§

type Proj<U: 'src> = U

§

fn map_maybe<R>( self, _f: impl FnOnce(&'src T) -> &'src R, g: impl FnOnce(T) -> R, ) -> <T as IntoMaybe<'src, T>>::Proj<R>
where R: 'src,

§

impl<'p, T> Seq<'p, T> for T
where T: Clone,

§

type Item<'a> = &'a T where T: 'a

The item yielded by the iterator.
§

type Iter<'a> = Once<&'a T> where T: 'a

An iterator over the items within this container, by reference.
§

fn seq_iter(&self) -> <T as Seq<'p, T>>::Iter<'_>

Iterate over the elements of the container.
§

fn contains(&self, val: &T) -> bool
where T: PartialEq,

Check whether an item is contained within this sequence.
§

fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>
where 'p: 'b,

Convert an item of the sequence into a [MaybeRef].
§

impl<T, S> SpanWrap<S> for T
where S: WrappingSpan<T>,

§

fn with_span(self, span: S) -> <S as WrappingSpan<Self>>::Spanned

Invokes [WrappingSpan::make_wrapped] to wrap an AST node in a span.
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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> OrderedSeq<'_, T> for T
where T: Clone,