pub enum Lambda {
Func((Box<Lambda>, Box<Lambda>)),
Variable(String),
Reducible((Box<Lambda>, Box<Lambda>)),
AlphaMark(Box<Lambda>),
StVec(Vec<String>),
Brack(Vec<Lambda>),
TFunc(Vec<String>),
Container(Box<Lambda>),
AttPl(()),
}Expand description
Lambda data type
Variants§
Func((Box<Lambda>, Box<Lambda>))
Function
Variable(String)
Variable
Reducible((Box<Lambda>, Box<Lambda>))
Marks a lambda being applied into a function
AlphaMark(Box<Lambda>)
Marks a lambda for alpha reduction
StVec(Vec<String>)
Vector of strings to be converted into a lambda
Brack(Vec<Lambda>)
Token for brackets
TFunc(Vec<String>)
Token for shorthand functions
Container(Box<Lambda>)
Token to contain a lambda inputted through formatting
AttPl(())
Token to mark where to put reducibles
Implementations§
Source§impl Lambda
impl Lambda
Sourcepub fn reduce(self) -> Lambda
pub fn reduce(self) -> Lambda
A single step of beta reduction
use easy_lambda_calculus::*;
println!("{}", lambda!("(%x.(x x)) (%y|z.z)").reduce());
//outputs (λy|z.z) (λy|z.z)§Reduction order:
Outer brackets are beta reduced first. eg: ((λx.(x x)) ((λy.(y y)) (λz.z))) will reduce to (((λy.(y y)) (λz.z)) ((λy.(y y)) (λz.z))) and not (λx.(x x)) ((λz.z) (λz.z))
If the left side is an application into a function rather then a function, it will be beta reduced first. eg: (((λx.x) (λy.(y y))) (λz.z)) will reduce to ((λy.(y y)) (λz.z))
For reduction with functions marked for alpha reduction, see Lambda.alpha_reduce().
Sourcepub fn alpha_reduce(self) -> Lambda
pub fn alpha_reduce(self) -> Lambda
Alpha reduce any sections marked for alpha reduction
use easy_lambda_calculus::*;
println!("{}", lambda!("(%z.(z z)) &(%z.z)").alpha_reduce());
//outputs ((λx.(x x)) (λy.y))§Alpha reduction properties:
Alpha reduction will rename every variable based on when they show up in the lambda. They are renamed with the naming scheme: x, y, z, w, a, b … u, v, xx, xy…
The renamed variables in any section marked for alpha reduction will be different from any other one.
The alpha reduction function can also be used when there are no sections marked for alpha reduction, to rename the variables in the lambda based on the naming scheme.
The sections marked for alpha reduction cannot be reduced, however can be reduced into other functions Note that reducing them into other functions does not remove that they are marked for alpha reduction, and can cause unwanted effects. For example if multiple variables are substituted with the section marked for alpha reduction, when alpha reduced, every copy will have different variable names.
Sourcepub fn evaluate(self) -> Lambda
pub fn evaluate(self) -> Lambda
Evaluate a lambda
use easy_lambda_calculus::*;
println!("{}", lambda!("(%x.&(%x.&(%x.x))) &(%x.x)").evaluate());
//outputs (λx|y.y)§Evaluation method:
Evaluation will first alpha reduce the lambda. It will then automatically beta reduce the lambda until it cannot be reduced anymore. Lastly it will alpha reduce the lambda again, to output it with predictable names.