本文整理汇总了Python中pomagma.compiler.expressions.Expression.make方法的典型用法代码示例。如果您正苦于以下问题:Python Expression.make方法的具体用法?Python Expression.make怎么用?Python Expression.make使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pomagma.compiler.expressions.Expression
的用法示例。
在下文中一共展示了Expression.make方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate
# 需要导入模块: from pomagma.compiler.expressions import Expression [as 别名]
# 或者: from pomagma.compiler.expressions.Expression import make [as 别名]
def validate(expr):
assert expr.is_rel(), expr
assert expr.name in ['LESS', 'EQUAL']
if expr.name != 'EQUAL':
print 'WARNING: not validating {0}'.format(expr)
return
while True:
try:
lhs, rhs = expr.args
lhs = head_normalize(lhs)
rhs = head_normalize(rhs)
assert len(lhs) == len(rhs),\
'Failed to validate\n {0}\nbecause\n {1} != {2}'.format(
expr, lhs, rhs)
assert lhs[0] == rhs[0],\
'Failed to validate\n {0}\nbecause \n{1} != {2}'.format(
expr, lhs[0], rhs[0])
for args in zip(lhs[1:], rhs[1:]):
validate(Expression.make(expr.name, *args))
break
except RequireVariable:
lhs, rhs = expr.args
fresh = get_fresh(expr.vars)
lhs = APP(lhs, fresh)
rhs = APP(rhs, fresh)
expr = Expression.make(expr.name, lhs, rhs)
except SkipValidation:
print 'WARNING: not validating {0}'.format(expr)
return
示例2: __call__
# 需要导入模块: from pomagma.compiler.expressions import Expression [as 别名]
# 或者: from pomagma.compiler.expressions.Expression import make [as 别名]
def __call__(self, term):
nargs = len(term.args)
if nargs == 0:
return self._fillings if term is HOLE else ()
elif nargs == 1:
name = term.name
key, = term.args
return tuple(Expression.make(name, f) for f in self(key))
elif nargs == 2:
name = term.name
lhs, rhs = term.args
return tuple(itertools.chain(
(Expression.make(name, f, rhs) for f in self(lhs)),
(Expression.make(name, lhs, f) for f in self(rhs)),
))
示例3: define_a
# 需要导入模块: from pomagma.compiler.expressions import Expression [as 别名]
# 或者: from pomagma.compiler.expressions.Expression import make [as 别名]
def define_a(
max_solutions=15,
max_memory=pomagma.analyst.synthesize.MAX_MEMORY,
verbose=1,
address=pomagma.analyst.ADDRESS):
'''
Search for definition of A = Join {<r, s> | r o s [= I}.
Tip: use pyprofile and snakeviz to profile this function:
$ pyprofile -o define_a.pstats -s time src/examples/synthesize.py define_a
$ snakeviz define_a.pstats
'''
assert max_solutions > 0, max_solutions
assert 0 < max_memory and max_memory < 1, max_memory
facts = parse_facts(A_THEORY)
hole = Expression.make('hole')
initial_sketch = parse_expr('HOLE')
language = {
'APP': 1.0,
# 'COMP': 1.6,
'JOIN': 3.0,
'B': 1.0,
'C': 1.3,
'A': 2.0,
'BOT': 2.0,
'TOP': 2.0,
'I': 2.2,
# 'Y': 2.3,
'K': 2.6,
'S': 2.7,
'J': 2.8,
'DIV': 3.0,
}
with pomagma.analyst.connect(address) as db:
results = synthesize_from_facts(
db=db,
facts=facts,
var=hole,
initial_sketch=initial_sketch,
language=language,
max_solutions=max_solutions,
max_memory=max_memory,
verbose=verbose)
print 'Possible Fillings:'
APP = Expression_2('APP')
f = Expression.make('f')
for complexity, term, filling in results:
print simplify_expr(APP(filling, f))
return results
示例4: unguard_vars
# 需要导入模块: from pomagma.compiler.expressions import Expression [as 别名]
# 或者: from pomagma.compiler.expressions.Expression import make [as 别名]
def unguard_vars(expr):
if expr.name == 'VAR':
return expr.args[0]
elif expr.is_var():
return expr
else:
args = map(unguard_vars, expr.args)
return Expression.make(expr.name, *args)
示例5: guard_vars
# 需要导入模块: from pomagma.compiler.expressions import Expression [as 别名]
# 或者: from pomagma.compiler.expressions.Expression import make [as 别名]
def guard_vars(expr):
"""Whereas pomagma.compiler follows the variable naming convention defined
in pomagma.compiler.signature.is_var(), pomagma.analyst.validate and the
puddle editor require VAR guarded variables."""
if expr.name == 'VAR':
return expr
elif expr.is_var():
return VAR(expr)
else:
args = map(guard_vars, expr.args)
return Expression.make(expr.name, *args)
示例6: test_compile_S
# 需要导入模块: from pomagma.compiler.expressions import Expression [as 别名]
# 或者: from pomagma.compiler.expressions.Expression import make [as 别名]
def test_compile_S():
# Compiling incremental search given: APP APP_x_y APP_y_z
# cost = 2.70067540518
# if S
# for x let APP_S_x
# for y if APP x y let APP_APP_S_x_y
# for z if APP y z let APP_APP_APP_S_x_y_z
# ensure EQUAL APP_APP_APP_S_x_y_z APP_APP_x_z_APP_y_z
S = Expression.make('S')
_test_sequent(
[],
[EQUAL(APP(APP(APP(S, x), y), z), APP(APP(x, z), APP(y, z)))])
示例7: Expression_2
# 需要导入模块: from pomagma.compiler.expressions import Expression [as 别名]
# 或者: from pomagma.compiler.expressions.Expression import make [as 别名]
from parsable import parsable
import pomagma.analyst
from pomagma.analyst.synthesize import synthesize_from_facts
from pomagma.compiler.expressions import Expression, Expression_2
from pomagma.compiler.parser import parse_string_to_expr, parse_theory_string
from pomagma.compiler.simplify import simplify_expr
from pomagma.compiler.sugar import desugar_expr
APP = Expression_2('APP')
K = Expression.make('K')
F = Expression.make('F')
def parse_expr(string):
return desugar_expr(parse_string_to_expr(string))
def parse_facts(string):
facts = parse_theory_string(string)['facts']
facts = map(desugar_expr, facts)
for fact in facts:
for var in fact.vars:
assert len(var.name) > 2, 'unbound variable: {}'.format(var)
return facts
A_THEORY = (
'''
EQUAL conj FUN s FUN r FUN f COMP r COMP f s
EQUAL conj FUN s FUN r FUN f COMP COMP r f s
示例8: test_compile_I
# 需要导入模块: from pomagma.compiler.expressions import Expression [as 别名]
# 或者: from pomagma.compiler.expressions.Expression import make [as 别名]
def test_compile_I():
I = Expression.make('I')
_test_sequent(
[],
[EQUAL(APP(I, x), x)])
示例9: test_compile_ap_quote
# 需要导入模块: from pomagma.compiler.expressions import Expression [as 别名]
# 或者: from pomagma.compiler.expressions.Expression import make [as 别名]
def test_compile_ap_quote():
AP = Expression.make('AP')
_test_sequent(
[],
[EQUAL(APP(APP(AP, QUOTE(x)), QUOTE(y)), QUOTE(APP(x, y)))])
示例10: test_compile_qt_quote
# 需要导入模块: from pomagma.compiler.expressions import Expression [as 别名]
# 或者: from pomagma.compiler.expressions.Expression import make [as 别名]
def test_compile_qt_quote():
QT = Expression.make('QT')
_test_sequent(
[],
[EQUAL(APP(QT, QUOTE(x)), QUOTE(QUOTE(x)))])
示例11: test_compile_eval
# 需要导入模块: from pomagma.compiler.expressions import Expression [as 别名]
# 或者: from pomagma.compiler.expressions.Expression import make [as 别名]
def test_compile_eval():
EVAL = Expression.make('EVAL')
_test_sequent(
[],
[EQUAL(APP(EVAL, QUOTE(x)), x)])
示例12: test_compile_comp_x_x_x
# 需要导入模块: from pomagma.compiler.expressions import Expression [as 别名]
# 或者: from pomagma.compiler.expressions.Expression import make [as 别名]
def test_compile_comp_x_x_x():
U = Expression.make('U')
_test_sequent(
[EQUAL(COMP(x, x), x)],
[EQUAL(x, APP(U, x))])
示例13: test_compile_bot
# 需要导入模块: from pomagma.compiler.expressions import Expression [as 别名]
# 或者: from pomagma.compiler.expressions.Expression import make [as 别名]
def test_compile_bot():
BOT = Expression.make('BOT')
_test_sequent(
[],
[LESS(BOT, x)])
示例14: test_compile_Y
# 需要导入模块: from pomagma.compiler.expressions import Expression [as 别名]
# 或者: from pomagma.compiler.expressions.Expression import make [as 别名]
def test_compile_Y():
Y = Expression.make('Y')
_test_sequent(
[],
[EQUAL(APP(Y, f), APP(f, APP(Y, f)))])
示例15: test_compile_K
# 需要导入模块: from pomagma.compiler.expressions import Expression [as 别名]
# 或者: from pomagma.compiler.expressions.Expression import make [as 别名]
def test_compile_K():
K = Expression.make('K')
_test_sequent(
[],
[EQUAL(APP(APP(K, x), y), x)])