Commit 7e9c9993 authored by Taddeus Kroes's avatar Taddeus Kroes

Relative precedences in strategy now support more than 2 functions in the same list.

parent 08c982bb
...@@ -7,12 +7,13 @@ from .logarithmic import factor_in_exponent_multiplicant, \ ...@@ -7,12 +7,13 @@ from .logarithmic import factor_in_exponent_multiplicant, \
from .derivatives import chain_rule from .derivatives import chain_rule
from .negation import double_negation, negated_factor, negated_nominator, \ from .negation import double_negation, negated_factor, negated_nominator, \
negated_denominator, negated_zero negated_denominator, negated_zero
from .factors import expand_double, expand_single
from .fractions import multiply_with_fraction, extract_fraction_terms, \ from .fractions import multiply_with_fraction, extract_fraction_terms, \
add_nominators add_nominators
from .integrals import factor_out_constant, integrate_variable_root from .integrals import factor_out_constant, integrate_variable_root
from .powers import remove_power_of_one from .powers import remove_power_of_one
from .sqrt import quadrant_sqrt, extract_sqrt_mult_priority from .sqrt import quadrant_sqrt, extract_sqrt_mult_priority
from .lineq import substitute_variable, swap_sides from .lineq import substitute_variable, swap_sides, divide_term, multiply_term
# Functions to move to the beginning of the possibilities list. Pairs of within # Functions to move to the beginning of the possibilities list. Pairs of within
...@@ -32,6 +33,9 @@ HIGH = [ ...@@ -32,6 +33,9 @@ HIGH = [
LOW = [ LOW = [
factor_in_exponent_multiplicant, factor_in_exponent_multiplicant,
reduce_fraction_constants, reduce_fraction_constants,
# Sorting expression terms has a low priority because it is assumed to
# be handled by the user
move_constant, move_constant,
] ]
...@@ -68,6 +72,10 @@ RELATIVE = [ ...@@ -68,6 +72,10 @@ RELATIVE = [
# Prevent useless swapping when solving multiple equations # Prevent useless swapping when solving multiple equations
(substitute_variable, swap_sides), (substitute_variable, swap_sides),
# When solving of an equation with constants, expanding an equation has
# a lower priority
(divide_term, multiply_term, swap_sides, expand_double, expand_single),
] ]
......
...@@ -18,11 +18,9 @@ def compare_possibilities(a, b): ...@@ -18,11 +18,9 @@ def compare_possibilities(a, b):
return 0 return 0
# Check if A and B have a precedence relative to eachother # Check if A and B have a precedence relative to eachother
if (ha, hb) in RELATIVE: for rel in RELATIVE:
return -1 if ha in rel and hb in rel:
return cmp(rel.index(ha), rel.index(hb))
if (hb, ha) in RELATIVE:
return 1
# If A has a high priority, it might be moved to the start of the list # If A has a high priority, it might be moved to the start of the list
if ha in HIGH: if ha in HIGH:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment