def prune_expr(lin_op):
 if (lin_op.type is lo.VARIABLE):
  return False
 elif (lin_op.type in [lo.SCALAR_CONST, lo.DENSE_CONST, lo.SPARSE_CONST, lo.PARAM]):
  return True
 pruned_args = []
 is_constant = True
 for arg in lin_op.args:
  arg_constant = prune_expr(arg)
  if (not arg_constant):
   is_constant = False
   pruned_args.append(arg)
 lin_op.args[:] = pruned_args[:]
 return is_constant

def prune_expr ( lin_op ) : if ( lin_op . type is lo . VARIABLE ) : return False elif ( lin_op . type in [ lo . SCALAR_CONST , lo . DENSE_CONST , lo . SPARSE_CONST , lo . PARAM ] ) : return True pruned_args = [ ] is_constant = True for arg in lin_op . args : arg_constant = prune_expr ( arg ) if ( not arg_constant ) : is_constant = False pruned_args . append ( arg ) lin_op . args [ : ] = pruned_args [ : ] return is_constant
prunes constant branches from the expression .