Module programinduction::lambda [] [src]

(representation) Polymorphically-typed lambda calculus.

Examples

use programinduction::lambda::{task_by_simple_evaluation, Language};

fn simple_evaluator(name: &str, inps: &[i32]) -> i32 {
    match name {
        "0" => 0,
        "1" => 1,
        "+" => inps[0] + inps[1],
        _ => unreachable!(),
    }
}

let dsl = Language::uniform(vec![
    ("0", tp!(int)),
    ("1", tp!(int)),
    ("+", arrow![tp!(int), tp!(int), tp!(int)]),
]);

// task: sum 1 with two numbers
let tp = arrow![tp!(int), tp!(int), tp!(int)];
let examples = vec![(vec![2, 5], 8), (vec![1, 2], 4)];
let task = task_by_simple_evaluation(&simple_evaluator, tp, &examples);

// solution:
let expr = dsl.parse("(λ (+ (+ 1 $0)))").unwrap();
assert!((task.oracle)(&dsl, &expr).is_finite())

Structs

CompressionParams

Parameters for grammar induction.

Language

(representation) A Language is a registry for primitive and invented expressions in a polymorphically-typed lambda calculus with corresponding production log-probabilities.

LispEvaluator

Execute expressions in a simple lisp interpreter.

ParseError

Enums

Expression

Expressions of lambda calculus, which only make sense with an accompanying Language.

InferenceError
LispError

Functions

task_by_simple_evaluation

Create a task based on evaluating lambda calculus expressions on test input/output pairs.