def _get_index_of_monomial(self, element, enablesubstitution=True,<EOL>daggered=False):
result = []<EOL>processed_element, coeff1 = separate_scalar_factor(element)<EOL>if processed_element in self.moment_substitutions:<EOL><INDENT>r = self._get_index_of_monomial(self.moment_substitutions[processed_element], enablesubstitution)<EOL>return [(k, coeff*coeff1) for k, coeff in r]<EOL><DEDENT>if enablesubstitution:<EOL><INDENT>processed_element =apply_substitutions(processed_element, self.substitutions,<EOL>self.pure_substitution_rules)<EOL><DEDENT>if is_number_type(processed_element):<EOL><INDENT>return [(<NUM_LIT:0>, coeff1)]<EOL><DEDENT>elif processed_element.is_Add:<EOL><INDENT>monomials = processed_element.args<EOL><DEDENT>else:<EOL><INDENT>monomials = [processed_element]<EOL><DEDENT>for monomial in monomials:<EOL><INDENT>monomial, coeff2 = separate_scalar_factor(monomial)<EOL>coeff = coeff1*coeff2<EOL>if is_number_type(monomial):<EOL><INDENT>result.append((<NUM_LIT:0>, coeff))<EOL>continue<EOL><DEDENT>k = -<NUM_LIT:1><EOL>if monomial != <NUM_LIT:0>:<EOL><INDENT>if monomial.as_coeff_Mul()[<NUM_LIT:0>] < <NUM_LIT:0>:<EOL><INDENT>monomial = -monomial<EOL>coeff = -<NUM_LIT:1.0> * coeff<EOL><DEDENT><DEDENT>try:<EOL><INDENT>new_element = self.moment_substitutions[monomial]<EOL>r = self._get_index_of_monomial(self.moment_substitutions[new_element], enablesubstitution)<EOL>result += [(k, coeff*coeff3) for k, coeff3 in r]<EOL><DEDENT>except KeyError:<EOL><INDENT>try:<EOL><INDENT>k = self.monomial_index[monomial]<EOL>result.append((k, coeff))<EOL><DEDENT>except KeyError:<EOL><INDENT>if not daggered:<EOL><INDENT>dag_result = self._get_index_of_monomial(monomial.adjoint(),<EOL>daggered=True)<EOL>result += [(k, coeff0*coeff) for k, coeff0 in dag_result]<EOL><DEDENT>else:<EOL><INDENT>raise RuntimeError("<STR_LIT>" +<EOL>str(monomial) + "<STR_LIT>")<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return result<EOL>
Returns the index of a monomial.