lambda_calc parses, reduces and compares alpha-equivalence of lambda calculus expressions.
See lambda_calc.core/parser and tests
There are several files in lambda_calc:
ast.py: Contains the dataclassesVar,Fun,Apprepl.py: A simple lambda calculus repl in the terminalparser.py: Contains the structure for a lambda expression- Note that the parser allows for variables like
x,x`and evenx`` - So lambda expressions like :
λx'.x',λx.xandλx''.x''will be accepted by the parser
- Note that the parser allows for variables like
core.py: Contains the functions used for alpha reduction and beta reductionwrapper.py: Contains the functioncheck_candidate_str(candidate_str: str, initial_expr: str) -> List[str]that can be called to parse a candidate string\
The python code below shows how check_candidate_str can be used:
candidate_str = """
(λx.x)(λz.yz)(z)
b-> ((λz.yz)z)
a-> ((λx.yx)z)
b-> (y z)
"""
errors = check_candidate_str(candidate_string = candidate_str, initial_expr = '(λx.x)(λz.yz)(z)')line 0: Contains the lambda expression to parse:(λx.x)(λz.yz)(z)- A beta reduction can be initiated in a line starting with
b ->like inline 1:b-> ((λz.yz)z) - An alpha reduction can be initiated in a starting with
a->like inline 2:a-> ((λx.yx)z) check_candidate_strreturns a list of errors detected in the candidate string\
List of Errors:
Cannot parse initial lambda expression: The lambda expression inline 0cannot be parsedLine x could not be parsed: The reduction inline xcannot be parsedLine x: Invalid reduction type: The reduction inline xdoes not start witha->orb->Line x: Alpha reduction is not valid: The reduction inline xis not alpha equivalent toline x-1Line x: Alpha reduction not necessary: The alpha reduction inline xis not neededLine x: Invalid beta reduction: The reduction inline xis invalid and is not alpha equivalent toline x-1Last expression is not a simple expression: The last line in the candidate string is not a simple expression