precedences.py 1.9 KB

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