'Return self._expr with all variables rebound to the indices implied by
new_inputs.'

def _rebind_variables(self, new_inputs):

    expr = self._expr
    for (idx, input_) in reversed(list(enumerate(self.inputs))):
        old_varname = ('x_%d' % idx)
        temp_new_varname = ('x_temp_%d' % new_inputs.index(input_))
        expr = expr.replace(old_varname, temp_new_varname)
    return expr.replace('_temp_', '_')
