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>
impl<'src, T: LambdaLanguageOfThought> RootedLambdaPool<'src, T>
Sourcepub fn new_free_variable(
index: usize,
t: LambdaType,
) -> RootedLambdaPool<'src, T>
pub fn new_free_variable( index: usize, t: LambdaType, ) -> RootedLambdaPool<'src, T>
Creates an anonymous free variable with [index] of type [t]
Sourcepub fn free_variables(
&self,
) -> impl Iterator<Item = (&FreeVar<'src>, &LambdaType)>
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§impl<'src, T: LambdaLanguageOfThought + Clone> RootedLambdaPool<'src, T>
impl<'src, T: LambdaLanguageOfThought + Clone> RootedLambdaPool<'src, T>
Sourcepub fn get_type(&self) -> Result<LambdaType, TypeError>
pub fn get_type(&self) -> Result<LambdaType, TypeError>
Sourcepub fn apply(self, other: Self) -> Option<Self>
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.
Sourcepub fn reduce(&mut self) -> Result<(), ReductionError>
pub fn reduce(&mut self) -> Result<(), ReductionError>
Reduce a lambda expression
§Errors
Will throw a ReductionError if there is something makes the reduction improper.
Sourcepub fn into_pool(self) -> Result<T::Pool, T::ConversionError>
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
Sourcepub fn bind_free_variable(
&mut self,
fvar: FreeVar<'src>,
replacement: RootedLambdaPool<'src, T>,
) -> Result<(), LambdaError>
pub fn bind_free_variable( &mut self, fvar: FreeVar<'src>, replacement: RootedLambdaPool<'src, T>, ) -> Result<(), LambdaError>
Sourcepub fn lambda_abstract_free_variable(
&mut self,
fvar: FreeVar<'src>,
lambda_type: LambdaType,
always_abstract: bool,
) -> Result<(), LambdaError>
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.
Sourcepub fn apply_new_free_variable(
&mut self,
fvar: FreeVar<'src>,
) -> Result<LambdaType, LambdaError>
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>
impl<T: LambdaLanguageOfThought + Clone + Debug> RootedLambdaPool<'_, T>
Sourcepub fn lift(&mut self) -> Result<(), TypeError>
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
Sourcepub fn stats(&self) -> LambdaSummaryStats
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>>
impl<'a> RootedLambdaPool<'a, Expr<'a>>
Sourcepub fn conjoin(self, other: Self) -> Result<Self, ConjoiningError>
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
Sourcepub fn raised_conjoin(self, other: Self) -> Result<Self, ConjoiningError>
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
Sourcepub fn parse(s: &'a str) -> Result<Self, LambdaParseError>
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>
impl<'src, T: LambdaLanguageOfThought + Clone> RootedLambdaPool<'src, T>
Sourcepub fn typeless_sampler(
possible_expressions: PossibleExpressions<'src, T>,
max_expr: usize,
max_types: usize,
) -> TypeAgnosticSampler<'src, T>
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>>
impl<'src> RootedLambdaPool<'src, Expr<'src>>
Sourcepub 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>
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.
Sourcepub 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> ⓘ
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
Sourcepub fn enumerator<'a>(
t: &LambdaType,
possible_expressions: &'a PossibleExpressions<'src, Expr<'src>>,
) -> LambdaEnumerator<'a, 'src, Expr<'src>, impl Fn(&Context) -> bool> ⓘ
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.
Sourcepub fn sampler(
t: &LambdaType,
possible_expressions: &PossibleExpressions<'src, Expr<'src>>,
max_expr: usize,
) -> LambdaSampler<'src, Expr<'src>>
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
Sourcepub fn random_expr(
t: &LambdaType,
possible_expressions: &PossibleExpressions<'src, Expr<'src>>,
rng: &mut impl Rng,
) -> RootedLambdaPool<'src, Expr<'src>>
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.
Sourcepub fn random_expr_no_constant(
t: &LambdaType,
possible_expressions: &PossibleExpressions<'src, Expr<'src>>,
rng: &mut impl Rng,
) -> Option<RootedLambdaPool<'src, Expr<'src>>>
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>>
impl<'src> RootedLambdaPool<'src, Expr<'src>>
Sourcepub fn prune_quantifiers(&mut self)
pub fn prune_quantifiers(&mut self)
Remove quantifiers which do not use their variable in their body.
Sourcepub fn swap_expr(
&mut self,
possible_expressions: &PossibleExpressions<'src, Expr<'src>>,
rng: &mut impl Rng,
) -> Result<(), TypeError>
pub fn swap_expr( &mut self, possible_expressions: &PossibleExpressions<'src, Expr<'src>>, rng: &mut impl Rng, ) -> Result<(), TypeError>
Sourcepub fn swap_subtree(&mut self, rng: &mut impl Rng) -> Result<(), TypeError>
pub fn swap_subtree(&mut self, rng: &mut impl Rng) -> Result<(), TypeError>
Source§impl<'src> RootedLambdaPool<'src, Expr<'src>>
impl<'src> RootedLambdaPool<'src, Expr<'src>>
Sourcepub fn for_document(&self) -> MathModeExpression<'_>
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>
impl<'src, T: Clone + LambdaLanguageOfThought> Clone for RootedLambdaPool<'src, T>
Source§fn clone(&self) -> RootedLambdaPool<'src, T>
fn clone(&self) -> RootedLambdaPool<'src, T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'src, T: Debug + LambdaLanguageOfThought> Debug for RootedLambdaPool<'src, T>
impl<'src, T: Debug + LambdaLanguageOfThought> Debug for RootedLambdaPool<'src, T>
Source§impl<'de, 'a> Deserialize<'de> for RootedLambdaPool<'a, Expr<'a>>where
'de: 'a,
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>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<'a> Display for RootedLambdaPool<'a, Expr<'a>>
impl<'a> Display for RootedLambdaPool<'a, Expr<'a>>
Source§impl<'src, T: LambdaLanguageOfThought + Clone> Distribution<RootedLambdaPool<'src, T>> for LambdaSampler<'src, T>
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>
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> RootedLambdaPool<'src, T>
T, using rng as the source of randomness.§fn sample_iter<R>(self, rng: R) -> Iter<Self, R, T>where
R: Rng,
Self: Sized,
fn sample_iter<R>(self, rng: R) -> Iter<Self, R, T>where
R: Rng,
Self: Sized,
T, using rng as
the source of randomness. Read moreSource§impl<'a> From<LanguageExpression<'a>> for RootedLambdaPool<'a, Expr<'a>>
impl<'a> From<LanguageExpression<'a>> for RootedLambdaPool<'a, Expr<'a>>
Source§fn from(value: LanguageExpression<'a>) -> Self
fn from(value: LanguageExpression<'a>) -> Self
Source§impl<T: LambdaLanguageOfThought + HashLambda> Hash for RootedLambdaPool<'_, T>
impl<T: LambdaLanguageOfThought + HashLambda> Hash for RootedLambdaPool<'_, T>
Source§impl<T: LambdaLanguageOfThought + PartialEq + Eq> Ord for RootedLambdaPool<'_, T>
impl<T: LambdaLanguageOfThought + PartialEq + Eq> Ord for RootedLambdaPool<'_, T>
Source§impl<T: PartialEq + LambdaLanguageOfThought> PartialEq for RootedLambdaPool<'_, T>
impl<T: PartialEq + LambdaLanguageOfThought> PartialEq for RootedLambdaPool<'_, T>
Source§impl<T: LambdaLanguageOfThought + PartialEq + Eq> PartialOrd for RootedLambdaPool<'_, T>
impl<T: LambdaLanguageOfThought + PartialEq + Eq> PartialOrd for RootedLambdaPool<'_, T>
Source§impl<'src> Serialize for RootedLambdaPool<'src, Expr<'src>>
impl<'src> Serialize for RootedLambdaPool<'src, Expr<'src>>
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> 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,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 Twhere
T: 'src,
impl<'src, T> IntoMaybe<'src, T> for Twhere
T: 'src,
§impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
§type Iter<'a> = Once<&'a T>
where
T: 'a
type Iter<'a> = Once<&'a T> where T: 'a
§fn contains(&self, val: &T) -> boolwhere
T: PartialEq,
fn contains(&self, val: &T) -> boolwhere
T: PartialEq,
§fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>where
'p: 'b,
fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>where
'p: 'b,
MaybeRef].