AI Skill Report Card

Computing Complex Math

B+78·Sep 5, 2026·Source: Web
13 / 15
Python
import cmath # Basic operations cmath.sqrt(-1) # 1j cmath.exp(1j * cmath.pi) # -1+1.2246e-16j (Euler's identity) cmath.log(1j) # 1.5707963267948966j # Polar conversion z = 3 + 4j r, phi = cmath.polar(z) # (5.0, 0.9272952180016122) z2 = cmath.rect(r, phi) # (3+4j) reconstructed
Recommendation
Add an example showing signal processing use case (mentioned in description but not demonstrated), since that's cited as a trigger scenario
13 / 15

Progress:

  • Identify if input/output involves complex numbers (vs. real-only math module)
  • Choose the right function category (conversion, power/log, trig, hyperbolic, classification)
  • Handle edge cases (infinities, NaN) if inputs may be non-finite
  • Verify results with isclose() instead of == for float comparisons

Function Categories

Conversions to/from polar coordinates:

Python
cmath.phase(z) # argument (angle) of z, range (-pi, pi] cmath.polar(z) # returns (r, phi) tuple cmath.rect(r, phi) # builds complex number from polar coords

Power and logarithmic functions:

Python
cmath.exp(z) # e**z cmath.log(z) # natural log; cmath.log(z, base) for other bases cmath.log10(z) # base-10 log cmath.sqrt(z) # square root, principal branch

Trigonometric functions:

Python
cmath.sin(z), cmath.cos(z), cmath.tan(z) cmath.asin(z), cmath.acos(z), cmath.atan(z)

Hyperbolic functions:

Python
cmath.sinh(z), cmath.cosh(z), cmath.tanh(z) cmath.asinh(z), cmath.acosh(z), cmath.atanh(z)

Classification functions:

Python
cmath.isfinite(z) # True if both real and imag parts finite cmath.isinf(z) # True if either part is infinite cmath.isnan(z) # True if either part is NaN cmath.isclose(a, b, rel_tol=1e-09, abs_tol=0.0) # safe comparison

Constants:

Python
cmath.pi, cmath.e, cmath.tau, cmath.inf, cmath.infj, cmath.nan, cmath.nanj
Recommendation
Include a 'bad output' example, e.g. using math.sqrt on negative input causing ValueError, to explicitly contrast with correct cmath usage
15 / 20

Example 1: Solving a quadratic with negative discriminant Input: Solve x^2 + 2x + 5 = 0 (discriminant = -16) Output:

Python
import cmath a, b, c = 1, 2, 5 disc = b**2 - 4*a*c x1 = (-b + cmath.sqrt(disc)) / (2*a) x2 = (-b - cmath.sqrt(disc)) / (2*a) # x1 = (-1+2j), x2 = (-1-2j)

Example 2: Converting rectangular to polar and back Input: z = 1 + 1j Output:

Python
r, phi = cmath.polar(z) # (1.4142135623730951, 0.7853981633974483) cmath.rect(r, phi) # (1.0000000000000002+0.9999999999999999j)

Example 3: Checking for special values Input: z = complex(cmath.inf, 0) Output: cmath.isinf(z)True; cmath.isfinite(z)False

Recommendation
Workflow checklist is somewhat generic; tie it more concretely to a decision tree (e.g., 'if input contains negative sqrt -> use cmath.sqrt')
  • Use cmath instead of math whenever a value could be negative under a square root/log, or whenever inputs are already typed as complex.
  • Always use cmath.isclose() for equality checks — never compare complex floats with ==.
  • cmath.phase(z) returns radians in (-pi, pi]; convert to degrees with math.degrees() if needed.
  • Prefer cmath.rect(r, phi) over manually computing r * (cos(phi) + 1j*sin(phi)).
  • Remember cmath.sqrt and cmath.log return the principal branch — expect one specific root/value, not all solutions.
  • Don't use math.sqrt() on a value that might be negative — it raises ValueError; use cmath.sqrt() instead.
  • Don't assume cmath.phase(0j) is meaningful — phase of zero is 0.0 but is mathematically undefined; treat with care in downstream logic.
  • Don't forget that cmath functions always return complex type, even when the mathematical result is real (e.g., cmath.sqrt(4) returns (2+0j), not 2.0).
  • Don't use == to compare nan components — cmath.isnan(z) follows IEEE 754 semantics where nan != nan.
0
Grade B+AI Skill Framework
Scorecard
Criteria Breakdown
Quick Start
13/15
Workflow
13/15
Examples
15/20
Completeness
15/20
Format
15/15
Conciseness
14/15