Module programinduction::lambda
source · Expand description
(representation) Polymorphically-typed lambda calculus.
Examples
use polytype::{ptp, tp};
use programinduction::{Task, lambda::{task_by_evaluation, Language, SimpleEvaluator}};
fn evaluate(name: &str, inps: &[i32]) -> Result<i32, ()> {
match name {
"0" => Ok(0),
"1" => Ok(1),
"+" => Ok(inps[0] + inps[1]),
_ => unreachable!(),
}
}
let dsl = Language::uniform(vec![
("0", ptp!(int)),
("1", ptp!(int)),
("+", ptp!(@arrow[tp!(int), tp!(int), tp!(int)])),
]);
// task: sum 1 with two numbers
let tp = ptp!(@arrow[tp!(int), tp!(int), tp!(int)]);
let examples = vec![(vec![2, 5], 8), (vec![1, 2], 4)];
let task = task_by_evaluation(SimpleEvaluator::from(evaluate), tp, &examples);
// solution:
let expr = dsl.parse("(λ (+ (+ 1 $0)))").unwrap();
assert!(task.oracle(&dsl, &expr).is_finite())
Structs
- Parameters for grammar induction.
- (representation) A Language is a registry for primitive and invented expressions in a polymorphically-typed lambda calculus with corresponding production log-probabilities.
- A function object for evaluation in domains with first-class functions.
- Like
LiftedFunction
, but for lazy evaluation with aLazyEvaluator
. - An
Evaluator
defined solely by a function.
Enums
- Expressions of lambda calculus, which only make sense with an accompanying
Language
.
Traits
- A specification for evaluating lambda calculus expressions in a domain.
- Like
Evaluator
, but you get to decide whether certain arguments should be evaluated.
Functions
- This function makes it easier to write your own compression scheme. It takes the role of a single compression step, separating it into sub-steps that are decent to implement in isolation.
- Create a task based on evaluating lambda calculus expressions on test input/output pairs.
- Like
task_by_evaluation
, but for use with aLazyEvaluator
.
Type Aliases
- A convenient frontier representation.