reasoning under uncertainty def __init__(self,gm=none)self cache {(frozenset()frozenset()): probsearch __init__(self,gm def prob_search(selfcontextfactorssplit_order)""returns the number \sum_{split_order\prod_{factorsgiven assignments in context context is variable:value dictionary factors is set of factors split_order is list of variables in factors that are not assigned in context returns sum over variable assignments to variables in split_order of the product of factors ""self display( ,"calling rc,",(context,factors)ce (frozenset(context items())frozenset(factors)key for the cache entry if ce in self cacheself display( ,"rc cache lookup",(context,factors)return self cache[ceif not factorsno factorsneeded if you don' have forgetting and caching return elif vars_not_in_factors :{var for var in context if not any(var in fac variables for fac in factors)}forget variables not in any factor self display( ,"rc forgetting variables"vars_not_in_factorsreturn self prob_search({key:val for (key,valin context items(if key not in vars_not_in_factors}factorssplit_orderelif to_eval :{fac for fac in factors if fac can_evaluate(context)}evaluate factors when all variables are assigned self display( ,"rc evaluating factors",to_evalval math prod(fac get_value(contextfor fac in to_evalif val = return elsereturn val self prob_search(context{fac for fac in factors if fac not in to_eval}split_orderelif len(comp :connected_components(contextfactorssplit_order) there are disconnected components self display( ,"splitting into connected components",comp,"in context",contextreturn(math prod(self prob_search(context, ,eofor ( ,eoin comp)version june