def _process_monomial(self, monomial, n_vars):
processed_monomial, coeff = separate_scalar_factor(monomial)<EOL>try:<EOL><INDENT>substitute = self.moment_substitutions[processed_monomial]<EOL>if not isinstance(substitute, (int, float, complex)):<EOL><INDENT>result = []<EOL>if not isinstance(substitute, Add):<EOL><INDENT>args = [substitute]<EOL><DEDENT>else:<EOL><INDENT>args = substitute.args<EOL><DEDENT>for arg in args:<EOL><INDENT>if is_number_type(arg):<EOL><INDENT>if iscomplex(arg):<EOL><INDENT>result.append((<NUM_LIT:0>, coeff*complex(arg)))<EOL><DEDENT>else:<EOL><INDENT>result.append((<NUM_LIT:0>, coeff*float(arg)))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>result += [(k, coeff*c2)<EOL>for k, c2 in self._process_monomial(arg,<EOL>n_vars)]<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>result = [(<NUM_LIT:0>, coeff*substitute)]<EOL><DEDENT><DEDENT>except KeyError:<EOL><INDENT>try:<EOL><INDENT>k = self.monomial_index[processed_monomial]<EOL><DEDENT>except KeyError:<EOL><INDENT>if not self.complex_matrix:<EOL><INDENT>try:<EOL><INDENT>processed_monomial_adjoint =apply_substitutions(processed_monomial.adjoint(),<EOL>self.substitutions)<EOL>k = self.monomial_index[processed_monomial_adjoint]<EOL><DEDENT>except KeyError:<EOL><INDENT>k = n_vars + <NUM_LIT:1><EOL>self.monomial_index[processed_monomial] = k<EOL><DEDENT><DEDENT>else:<EOL><INDENT>k = n_vars + <NUM_LIT:1><EOL>self.monomial_index[processed_monomial] = k<EOL><DEDENT><DEDENT>result = [(k, coeff)]<EOL><DEDENT>return result<EOL>
Process a single monomial when building the moment matrix.