def resolvent_for(self, other): """ Resolve self to other. >>> f1 = Expr.parse('Foo<item=12.item>').atoms[0] >>> f2 = Expr.parse('Foo<item=Bar>').atoms[0] >>> f3 = Expr.parse('Foo<item=Car>').atoms[0] >>> f2.resolvent_for(f1) <BLANKLINE> >>> f1.resolvent_for(f2) 12.item : [Bar] >>> f2.resolvent_for(f3) <BLANKLINE> >>> f1.resolvent_for(f3 + f2) 12.item : [Bar + Car] """ c = TemplateContext({}) if self.is_built_in: pass elif self.is_var: c[self.id] = other else: for arg1, arg2 in self.join(other): if arg1 and arg2: c.update(arg1.expr.resolvent_for(arg2.expr)) return c
def resolvent_for(self, other): """ Attempts to compute and return minimal resolvent that will make (self % resolvent).is_super(other). If no such resolvent exists a resolvent will still be returned, but (self % resolvent) will not be super to other. >>> f1 = Expr.parse('Foo<item=[@T.a]>') >>> f2 = Expr.parse('Foo<item=[Bar]>') >>> f3 = Expr.parse('Bar<item=[]>') >>> f2.resolvent_for(f1) <BLANKLINE> >>> f1.resolvent_for(f2) @T.a : [Bar] >>> f1 % f1.resolvent_for(f2) [Foo<item=[Bar]>] >>> f1.resolvent_for(f3) <BLANKLINE> >>> f1 % f1.resolvent_for(f3) [Foo<item=[@T.a]>] >>> a = Expr.parse('@T.a') >>> b = Expr.parse('Bar') >>> a.resolvent_for(b) @T.a : [Bar] >>> b.resolvent_for(a) <BLANKLINE> >>> b % b.resolvent_for(a) [Bar] >>> Expr.parse( ... '[A<[email protected]> + B<x=T!> + C<x=D<x=12.foo>> + D]' ... ).resolvent_for(Expr.parse( ... '[A<x=[Q+R]> + C<x=D<x=Q>> + B<x=S!>]' ... )) 12.foo : [Q] @T.pain : [Q + R] """ c = TemplateContext({}) if self.is_var: c[self.atoms[0].id] = other else: for atom1, atom2 in self.join(other): if atom1 and atom2: c.update(atom1.resolvent_for(atom2)) return c