a field-theory motivated approach to computer algebra

# cdb.core.manip

Manipulating equations, inequalities and similar expressions
This package contains various helper functions to manipulate expressions in elementary ways, e.g. moving terms around or multiplying sides of an expression by a factor. In order to use this package, import it with the standard Python import statement: if you do import cdb.core.manip as manip then e.g. the isolate function is available as manip.isolate.

## eq_to_subrule(ex: Ex) -> Ex

Create substitution rule from an equation.
Creates a substitution rule from an equation Ex.
eq_to_subrule($a = b + c + d$);
$$\displaystyle{}b+c+d \rightarrow a$$
b + c + d → a

## multiply_through(ex: Ex, factor: Ex, auto_distribute=False) -> Ex

Multiply all terms by the same factor.
Multiplies all terms in ex by factor. If auto_distribute is True, distribute is called on the resulting expression.
multiply_through($a+b < c$, $k$);
$$\displaystyle{}k \left(a+b\right) < k c$$
\less(k (a + b) , k c)

## get_lhs(ex: Ex) -> Ex

Return left-hand side of an expression
Returns the left hand side of an equation, inequality or expression whose top node contains two children.
get_lhs($a=b$);
$$\displaystyle{}a$$
a

## get_rhs(ex: Ex) -> Ex

Return right-hand side of an expression
Returns the right-hand side of an equation, inequality or expression whose top node contains two children.
get_rhs($a=b$);
$$\displaystyle{}b$$
b

## swap_sides(ex: Ex) -> Ex

Swap the left and right-hand sides of an expression.
Swaps the two sides of an equation, inequality or expression whose top node contains two children. Inequalities will flip as appropriate.

## get_factor(node: ExNode, term: Ex) -> Ex

Get all multiplicative factors of term in node

## to_rhs(ex: Ex, part: Ex, exact: bool = False) -> Ex

Move the indicated term of the expression to the right-hand side.
If ex is an equation or inequality which contains part on its left hand side, then moves part to the right hand side. If exact is True then part must contain the multiplier of the term to be moved, including minus signs.
to_rhs($2a+b+j*b+k*b = c+d$);
$$\displaystyle{}0 = c+d-2a-b-j b-k b$$
0 = c + d-2a-b-j b-k b
to_rhs($a-b = c$);
$$\displaystyle{}0 = c-a+b$$
0 = c-a + b

## to_lhs(ex: Ex, part: Ex) -> Ex

Move the indicated term of the expression to the left-hand side.
Complement of to_rhs.

## isolate()

Isolates a term on the left hand side of an equation or inequality
ex := 2a + a * k - b = c * a + b * k + a - 4; isolate(ex, $a$);
$$\displaystyle{}2a+a k-b = c a+b k+a-4$$
2a + a k-b = c a + b k + a-4
$$\displaystyle{}a = \left(b k-4+b\right) {\left(k+1-c\right)}^{-1}$$
a = (b k-4 + b) (k + 1-c)**(-1)