Exemple #1
0
def evalapp_bind_evidence_partial(app_expr, evidence, env={}):

    # First check for failure: if the environment is already inconsistent

    if inconsistent(env, evidence):
        return Fail(env)

    # Propagate failed computations without running small-step evaluator

    answers = map(lambda a: evalapp_bind_evidence_partial(a, evidence, env),
                  app_expr.args)
    for a in answers:
        if type(a) == Fail:
            return a

    result = store_bind_answer(
        env,
        app_expr,
        answers,
        inner_interp=evalDExpr,
        answer_interp=lambda sym, *args: sym.func(*args),
        is_bind=lambda sym: type(sym) == Bind)

    # Second check for failure: if the environment after calculating app_expr
    # is inconsistent

    if inconsistent(env, evidence):
        return Fail(env)

    return result
Exemple #2
0
def evalapp_bind_evidence_partial(app_expr, evidence, env={}):

    # First check for failure: if the environment is already inconsistent

    if inconsistent(env, evidence):
        return Fail(env)

    # Propagate failed computations without running small-step evaluator

    answers = map(lambda a: evalapp_bind_evidence_partial(a, evidence, env), app_expr.args)
    for a in answers:
        if type(a) == Fail:
            return a

    result = store_bind_answer(
                env,
                app_expr,
                answers,
                inner_interp = evalDExpr,
                answer_interp = lambda sym, *args: sym.func(*args),
                is_bind = lambda sym: type(sym) == Bind)

    # Second check for failure: if the environment after calculating app_expr
    # is inconsistent

    if inconsistent(env, evidence):
        return Fail(env)

    return result
Exemple #3
0
def evalapp_bind(app_expr, env={}):
    return store_bind_answer(env,
                             app_expr,
                             map(lambda a: evalapp_bind(a, env),
                                 app_expr.args),
                             inner_interp=lambda e: evalapp_memo(evalDExpr(e)),
                             answer_interp=lambda sym, *args: sym.func(*args),
                             is_bind=lambda sym: type(sym) == Bind)
Exemple #4
0
def evalapp_memo(app_expr, env={}):
    return store_bind_answer(env,
                             app_expr,
                             map(lambda a: evalapp_bind(a, env),
                                 app_expr.args),
                             inner_interp=None,
                             answer_interp=lambda sym, *args: sym.func(*args),
                             is_bind=lambda sym: False)
Exemple #5
0
def evalapp_bind_discrete(app_expr, env={}):
    return store_bind_answer(env,
                             app_expr,
                             map(lambda a: evalapp_bind_discrete(a, env),
                                 app_expr.args),
                             inner_interp=flatten_cpt,
                             answer_interp=gen_cpt_strict,
                             is_bind=lambda sym: type(sym) == Bind)
Exemple #6
0
def evalapp_bind(app_expr, env={}):
    return store_bind_answer(
            env,
            app_expr,
            map(lambda a: evalapp_bind(a, env), app_expr.args),
            inner_interp = lambda e: evalapp_memo(evalDExpr(e)),
            answer_interp = lambda sym, *args: sym.func(*args),
            is_bind = lambda sym: type(sym) == Bind)
Exemple #7
0
def evalapp_memo(app_expr, env={}):
    return store_bind_answer(
            env,
            app_expr,
            map(lambda a: evalapp_bind(a, env), app_expr.args),
            inner_interp = None,
            answer_interp = lambda sym, *args: sym.func(*args),
            is_bind = lambda sym: False)
Exemple #8
0
def evalapp_bind_discrete(app_expr, env={}):
    return store_bind_answer(
            env,
            app_expr,
            map(lambda a: evalapp_bind_discrete(a, env), app_expr.args),
            inner_interp = flatten_cpt,
            answer_interp = gen_cpt_strict,
            is_bind = lambda sym: type(sym) == Bind)