Skip to main content

Lambda

Enum Lambda 

Source
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

Source

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().

Source

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.

Source

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.

Source

pub fn from_u16(n: u16) -> Lambda

Lambda from u16 with church encoding

Source

pub fn as_u16(self: Lambda) -> Option<u16>

u16 from Lambda with church encoding

Source

pub fn succ() -> Lambda

Add one to numbers with church encoding

Source

pub fn add() -> Lambda

Add numbers together with church encoding

Trait Implementations§

Source§

impl Clone for Lambda

Source§

fn clone(&self) -> Lambda

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 Debug for Lambda

Source§

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

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

impl Display for Lambda

Source§

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

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

impl PartialEq for Lambda

Source§

fn eq(&self, other: &Lambda) -> 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 StructuralPartialEq for Lambda

Auto Trait Implementations§

§

impl Freeze for Lambda

§

impl RefUnwindSafe for Lambda

§

impl Send for Lambda

§

impl Sync for Lambda

§

impl Unpin for Lambda

§

impl UnwindSafe for Lambda

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
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> 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.