def partial_order(px, fol): """Return `u <= p` and `p <= u`.""" ux = { x: dict(a=stx._prime_like(d['a']), b=stx._prime_like(d['b'])) for x, d in px.items() } varmap = parameter_varmap(ux, px) u_leq_p = subseteq(varmap, fol) varmap = parameter_varmap(px, ux) p_leq_u = subseteq(varmap, fol) return u_leq_p, p_leq_u
def partial_order(px, fol): """Return `u <= p` and `p <= u`.""" ux = { x: dict( a=stx._prime_like(d['a']), b=stx._prime_like(d['b'])) for x, d in px.items()} varmap = parameter_varmap(ux, px) u_leq_p = subseteq(varmap, fol) varmap = parameter_varmap(px, ux) p_leq_u = subseteq(varmap, fol) return u_leq_p, p_leq_u
def test_add_prime_like_too(): table = dict(x=(-4, 5), y='bool') t = stx._add_prime_like_too(table) assert 'x' in t, t assert 'y' in t, t xp = stx._prime_like('x') yp = stx._prime_like('y') assert xp != 'x', xp assert yp != 'y', yp assert xp in t, (xp, t) assert yp in t, (yp, t) assert t['x'] == table['x'], t assert t['y'] == table['y'], t assert t[xp] == t['x'], t assert t[yp] == t['y'], t with assert_raises(AssertionError): table["x'"] = tuple(table['x']) stx._add_prime_like_too(table)
def setup_aux_vars(f, care, fol): """Add and return auxiliary variables. No BDD operations other than `support` are invoked. Returns: - `x_vars`: set of variable names in `support(f) \/ support(care)` - `px`: map var name to `dict` of indexed parameters - `qx`: similar for var copies - `p_to_q`: `dict` that maps parameters to their copies For example: ``` x_vars = {'x', 'y'} px = dict( x=dict(a='a_x', b='b_x'), y=dict(a='a_y', b='b_y')) qx = dict( x=dict(a='u_x', b='v_x'), y=dict(a='u_y', b='v_y')) p_to_q = dict( a_x='u_x', b_x='v_x', a_y='u_y', b_y='v_y') ``` @return x_vars, px, qx, p_to_q """ assert f != fol.false assert care != fol.false assert not (f == fol.true and care == fol.true) x_vars = joint_support([f, care], fol) assert x_vars, x_vars # aux vars for orthotope representation params = dict(pa='a', pb='b', qa='u', qb='v') p_dom = _parameter_table(x_vars, fol.vars, a_name=params['pa'], b_name=params['pb']) q_dom = _parameter_table(x_vars, fol.vars, a_name=params['qa'], b_name=params['qb']) p_dom = stx._add_prime_like_too(p_dom) q_dom = stx._add_prime_like_too(q_dom) common = x_vars.intersection(p_dom) assert not common, common common = x_vars.intersection(q_dom) assert not common, common # works for primed variables too fol.declare(**p_dom) fol.declare(**q_dom) px = _map_vars_to_parameters(x_vars, a_name=params['pa'], b_name=params['pb']) qx = _map_vars_to_parameters(x_vars, a_name=params['qa'], b_name=params['qb']) assert set(px) == set(qx), (px, qx) p_to_q = _renaming_between_parameters(px, qx) q_to_p = {v: k for k, v in p_to_q.items()} p_to_u = {p: stx._prime_like(p) for p in p_to_q} p_vars = set(p_to_q) q_vars = set(p_to_q.values()) u_vars = set(p_to_u.values()) log.debug('x vars: {x_vars}'.format(x_vars=x_vars)) assert not (p_vars & q_vars), (p_vars, q_vars) assert not (p_vars & u_vars), (p_vars, u_vars) assert not (u_vars & q_vars), (u_vars, q_vars) varmap = parameter_varmap(px, qx) # package prm = Parameters() prm._px = px prm._qx = qx prm._varmap = varmap prm.x_vars = x_vars prm.p_vars = p_vars prm.q_vars = q_vars prm.u_vars = u_vars prm.p_to_q = p_to_q prm.q_to_p = q_to_p prm.p_to_u = p_to_u return prm
def setup_aux_vars(f, care, fol): """Add and return auxiliary variables. No BDD operations other than `support` are invoked. Returns: - `x_vars`: set of variable names in `support(f) \/ support(care)` - `px`: map var name to `dict` of indexed parameters - `qx`: similar for var copies - `p_to_q`: `dict` that maps parameters to their copies For example: ``` x_vars = {'x', 'y'} px = dict( x=dict(a='a_x', b='b_x'), y=dict(a='a_y', b='b_y')) qx = dict( x=dict(a='u_x', b='v_x'), y=dict(a='u_y', b='v_y')) p_to_q = dict( a_x='u_x', b_x='v_x', a_y='u_y', b_y='v_y') ``` @return x_vars, px, qx, p_to_q """ assert f != fol.false assert care != fol.false assert not (f == fol.true and care == fol.true) x_vars = joint_support([f, care], fol) assert x_vars, x_vars # aux vars for orthotope representation params = dict(pa='a', pb='b', qa='u', qb='v') p_dom = _parameter_table( x_vars, fol.vars, a_name=params['pa'], b_name=params['pb']) q_dom = _parameter_table( x_vars, fol.vars, a_name=params['qa'], b_name=params['qb']) p_dom = stx._add_prime_like_too(p_dom) q_dom = stx._add_prime_like_too(q_dom) common = x_vars.intersection(p_dom) assert not common, common common = x_vars.intersection(q_dom) assert not common, common # works for primed variables too fol.declare(**p_dom) fol.declare(**q_dom) px = _map_vars_to_parameters( x_vars, a_name=params['pa'], b_name=params['pb']) qx = _map_vars_to_parameters( x_vars, a_name=params['qa'], b_name=params['qb']) assert set(px) == set(qx), (px, qx) p_to_q = _renaming_between_parameters(px, qx) q_to_p = {v: k for k, v in p_to_q.items()} p_to_u = {p: stx._prime_like(p) for p in p_to_q} p_vars = set(p_to_q) q_vars = set(p_to_q.values()) u_vars = set(p_to_u.values()) log.debug('x vars: {x_vars}'.format(x_vars=x_vars)) assert not (p_vars & q_vars), (p_vars, q_vars) assert not (p_vars & u_vars), (p_vars, u_vars) assert not (u_vars & q_vars), (u_vars, q_vars) varmap = parameter_varmap(px, qx) # package prm = Parameters() prm._px = px prm._qx = qx prm._varmap = varmap prm.x_vars = x_vars prm.p_vars = p_vars prm.q_vars = q_vars prm.u_vars = u_vars prm.p_to_q = p_to_q prm.q_to_p = q_to_p prm.p_to_u = p_to_u return prm
def test_prime_like(): var = 'x' pvar = stx._prime_like(var) assert pvar != var, (pvar, var) assert pvar == 'x_cp', pvar