def msubs(expr, *sub_dicts, **kwargs):
 sub_dict = dict_merge(*sub_dicts)
 smart = kwargs.pop('smart', False)
 if smart:
  func = _smart_subs
 elif hasattr(expr, 'msubs'):
  return expr.msubs(sub_dict)
 else:
  func = (lambda expr, sub_dict: _crawl(expr, _sub_func, sub_dict))
 if isinstance(expr, (Matrix, Vector, Dyadic)):
  return expr.applyfunc((lambda x: func(x, sub_dict)))
 else:
  return func(expr, sub_dict)

def msubs ( expr , * sub_dicts , ** kwargs ) : sub_dict = dict_merge ( * sub_dicts ) smart = kwargs . pop ( 'smart' , False ) if smart : func = _smart_subs elif hasattr ( expr , 'msubs' ) : return expr . msubs ( sub_dict ) else : func = ( lambda expr , sub_dict : _crawl ( expr , _sub_func , sub_dict ) ) if isinstance ( expr , ( Matrix , Vector , Dyadic ) ) : return expr . applyfunc ( ( lambda x : func ( x , sub_dict ) ) ) else : return func ( expr , sub_dict )
a custom subs for use on expressions derived in physics .