Complex Number Multiplication - Problem
Complex numbers are mathematical objects that extend real numbers by introducing the imaginary unit i, where i² = -1. They're widely used in engineering, physics, and computer graphics for representing rotations and oscillations.
In this problem, you're given two complex numbers as strings in the format "a+bi" or "a-bi", where:
ais the real part (integer between -100 and 100)bis the imaginary part (integer between -100 and 100)irepresents the imaginary unit
Your task is to multiply these two complex numbers and return the result as a string in the same format.
Mathematical Formula: (a + bi) × (c + di) = (ac - bd) + (ad + bc)i
For example: "1+1i" × "1+1i" = "0+2i" because (1×1 - 1×1) + (1×1 + 1×1)i = 0 + 2i
Input & Output
example_1.py — Basic Multiplication
$
Input:
num1 = "1+1i", num2 = "1+1i"
›
Output:
"0+2i"
💡 Note:
Using formula (a+bi)×(c+di) = (ac-bd)+(ad+bc)i: (1+1i)×(1+1i) = (1×1-1×1)+(1×1+1×1)i = 0+2i
example_2.py — Negative Result
$
Input:
num1 = "1+-1i", num2 = "1+-1i"
›
Output:
"0+-2i"
💡 Note:
With negative imaginary parts: (1-1i)×(1-1i) = (1×1-(-1)×(-1))+(1×(-1)+(-1)×1)i = (1-1)+(-1-1)i = 0-2i
example_3.py — Pure Real Numbers
$
Input:
num1 = "2+0i", num2 = "3+0i"
›
Output:
"6+0i"
💡 Note:
When imaginary parts are zero, it behaves like regular multiplication: (2+0i)×(3+0i) = (2×3-0×0)+(2×0+0×3)i = 6+0i
Constraints
- The real and imaginary parts are integers in the range [-100, 100]
-
The input strings will always be in the format
"a+bi"or"a-bi" - The imaginary part will always end with the character 'i'
- Both input strings represent valid complex numbers
Visualization
Tap to expand
Understanding the Visualization
1
Input Representation
Plot both complex numbers as points on the complex plane (real axis = x, imaginary axis = y)
2
Component Extraction
Identify the real and imaginary parts of each complex number
3
Formula Application
Apply the multiplication formula: real_result = ac-bd, imag_result = ad+bc
4
Result Plotting
Plot the resulting complex number and format as string output
Key Takeaway
🎯 Key Insight: Complex number multiplication is essentially a combination of algebraic expansion and the fundamental property that i² = -1, which transforms what could be a complex geometric operation into straightforward arithmetic.
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code