'Confirm that all the variables used in the tree are valid/defined.
Otherwise, raise an UndefinedVariable containing all bad variables.'

def check_variables(self, valid_variables, valid_functions):

    if self.case_sensitive:
        casify = (lambda x: x)
    else:
        casify = (lambda x: x.lower())
    bad_vars = set((var for var in self.variables_used if (casify(var) not in valid_variables)))
    bad_vars.update((func for func in self.functions_used if (casify(func) not in valid_functions)))
    if bad_vars:
        raise UndefinedVariable('    '.join(sorted(bad_vars)))
