Work with functionsLesson 21 of 48 · 8 min
Respect logarithm branches
Use positivity assumptions when expanding logarithms and identify a complex counterexample.
Maths refresher: Inverse rules have conditions
For positive real numbers, exponentials and logarithms obey familiar inverse rules. Complex logarithms require a branch convention.
For , but the sum of the principal logarithms is . Positivity is doing real work in the identity.
A logarithm reverses exponentiation, but its domain and branch matter. For positive real inputs, . Extending that rule carelessly to complex values can change the answer by multiples of .
- Multiply first
- Then take log
- Take logs first
SymPy uses the principal logarithm for complex inputs. A branch specifies which value to use when several complex numbers have the same exponential. The principal branch uses a particular angle for each nonzero input. A rule for positive reals can give a different value on that branch. State assumptions before expanding a logarithm.
The counterexample uses . The product is one, whose principal log is zero, while each principal log of is . Avoid force=True unless you have separately justified the missing conditions and will preserve them in the result.
Is the real-positive product rule automatically valid for every complex pair?
Write a prediction (optional)
Exact symbolic investigation
Select Run Python with the code unchanged.
Your saved draft is open. To use the published code, select Restore example in Tools. Use Recover draft to bring back your code.
Tools
About Python
Python and the course packages can load while you read. Each run starts with fresh user variables; imported modules stay loaded. Stop replaces the worker. Runtime details ↗
Ctrl+Enter or ⌘+Enter runs Python.
Execution error
Technical error details
Your result
Python text output
Compare with the worked example
Executed from the published Python during the site build. Your own run appears above. Build environment ↗
Worked text output
Positive product expanded: log(a) + log(b) Power inside logarithm: 1/2 Unrestricted input rule: log(z)/2 Positive input rule: log(a)/2 Log of product (-1)(-1): 0 Sum of principal logs: 2*I*pi
Read the starter result
Compare Unrestricted input rule with Positive input rule. The positivity assumption allows the latter expansion. The two principal-log counterexample results show why multiplication alone does not justify a complex rewrite.
Edit and compare
Replace power = sp.Rational(1,2) with power = 2. Select Run Python and compare Unrestricted input rule with Positive input rule. Why can SymPy split off an exponent for a and still keep the log of a power for z?
Scope. Complex branch cuts are a larger topic; this example establishes why forced rewrites need explicit justification.
Try a fresh case
What justifies splitting into in this lesson?
Need a hint?
Hint 1
Test the negative pair in the example.
Hint 2
Identify which assumption rules that pair out.