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>
The type of the lambda expression
Sourcepub fn merge(self, other: Self) -> Option<Self>
pub fn merge(self, other: Self) -> Option<Self>
Combine two lambda expressions by applying one to the other. Returns None if that is
impossible.
Sourcepub fn reduce(&mut self) -> Result<(), ReductionError>
pub fn reduce(&mut self) -> Result<(), ReductionError>
Reduce a lambda expression
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.
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>
Replace a free variable with a value.
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)$).
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.
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)
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.
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
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.
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.
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.
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.
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>
Replace a random expression with something else of the same type.
Sourcepub fn swap_subtree(&mut self, rng: &mut impl Rng) -> Result<(), TypeError>
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.
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: PartialEq + LambdaLanguageOfThought> PartialEq for RootedLambdaPool<'_, T>
impl<T: PartialEq + LambdaLanguageOfThought> PartialEq for RootedLambdaPool<'_, T>
Source§impl<'src> Serialize for RootedLambdaPool<'src, Expr<'src>>
impl<'src> Serialize for RootedLambdaPool<'src, Expr<'src>>
impl<T: PartialEq + Eq + 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
§impl<T> CallHasher for T
impl<T> CallHasher for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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].