get_precedence_lhs

sherpa.models.op.get_precedence_lhs(lstr: str, lp: int, p: int, a: bool) str[source] [edit on github]

Return the string to use for the left side of a binary operator.

This is only needed when the operator (represented by the p value) is written in infix form - such as ‘a + b’- rather than prefix form like ‘np.add(a, b)’.

Parameters:
  • lstr (str) – The term to the left of the operator.

  • lp (int) – Precedences of any operator in lstr.

  • p (int) – Precedences of the current operator.

  • a (bool) – Do we care about power-like terms.

Returns:

term – Either lstr or (lstr).

Return type:

str

Examples

>>> get_precedence_lhs("a", NO_PRECEDENCE, lprec[np.divide], False)
'a'
>>> get_precedence_lhs("a + b", lprec[np.add], lprec[np.divide], False)
'(a + b)'
>>> get_precedence_lhs("a * b", lprec[np.multiply], lprec[np.add], False)
'a * b'