precedences.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. from .factors import expand_double, expand_single
  2. from .sort import move_constant
  3. from .numerics import reduce_fraction_constants, raise_numerics
  4. from .logarithmic import factor_in_exponent_multiplicant, \
  5. factor_out_exponent, raised_base, factor_out_exponent_important
  6. from .derivatives import chain_rule
  7. from .negation import double_negation, negated_factor, negated_nominator, \
  8. negated_denominator
  9. # Functions to move to the beginning of the possibilities list. Pairs of within
  10. # the list itself are compared by their position in the list: lower in the list
  11. # means lower priority
  12. HIGH = [
  13. raised_base,
  14. ]
  15. # Functions to move to the end of the possibilities list. Pairs of within the
  16. # list itself are compared by their position in the list: lower in the list
  17. # means lower priority
  18. LOW = [
  19. move_constant,
  20. reduce_fraction_constants,
  21. factor_in_exponent_multiplicant,
  22. ]
  23. # Fucntion precedences relative to eachother. Tuple (A, B) means that A has a
  24. # higer priority than B. This list ignores occurences in the HIGH or LOW lists
  25. # above
  26. RELATIVE = [
  27. # Precedences needed for 'power rule'
  28. (chain_rule, raised_base),
  29. (raised_base, factor_out_exponent),
  30. # Expand 'single' before 'double' to avoid unnessecary complexity
  31. (expand_single, expand_double),
  32. (factor_out_exponent_important, raise_numerics),
  33. ]
  34. # Convert to dictionaries for efficient lookup
  35. HIGH = dict([(h, i) for i, h in enumerate(HIGH)])
  36. LOW = dict([(h, i) for i, h in enumerate(LOW)])
  37. # List of implicit rules. Implicit rules are condidererd trivial and are
  38. # therefore not printed in verbose rewrite_all mode
  39. IMPLICIT_RULES = [
  40. negated_factor,
  41. double_negation,
  42. negated_nominator,
  43. negated_denominator,
  44. ]