Introduction¶
When developing agents based on DeepSeek Harness (DSH), complex number computation is a frequent but error-prone aspect. Large language models often struggle to guarantee precision and correctness when handling complex-number arithmetic, polar coordinate conversion, branch cuts of inverse trigonometric functions, and solving equations with complex coefficients. The core philosophy of DSH is that “everything is a plugin”; by introducing a deterministic mathematical computation layer, this type of logic can be separated from model reasoning.
Below is an introduction to the dsh-complex plugin, a toolbox that provides complex-number mathematical operation capabilities for DSH, developed and maintained by TYEclipse.
Plugin Introduction¶
dsh-complex provides six pure mathematics tools for parsing, formatting, arithmetic operations, coordinate conversion, function evaluation, n-th root solving, and solving quadratic equations with complex coefficients. The plugin adopts a zero runtime dependency design, performs deterministic calculations based on IEEE double-precision floating-point numbers, returns results with 10 decimal places by default (configurable), and follows the branch conventions of the CPython cmath library.
Core Functionality¶
The plugin includes the following core tools:
- complex_parse: Parses complex numbers. Supports rectangular form (e.g.,
3+4i), polar form (e.g.,5∠53.13°), and exponential form. The parsed result includes complete information such as modulus, argument (radians/degrees), and conjugate. - complex_calc: Performs complex number arithmetic operations. Supports addition, subtraction, multiplication, division, conjugation, reciprocal, integer powers, and general complex exponentiation (e.g.,
i^i). - complex_convert: Performs coordinate conversion. Supports mutual conversion between rectangular and polar coordinates; the output includes modulus, argument, and exponential representation.
- complex_functions: Computes elementary and inverse functions. Supports principal value calculations for complex exponentials, logarithms, trigonometric functions, hyperbolic functions, and their inverse functions. The result includes branch convention information.
- complex_roots: Computes n-th roots. Calculates all n-th roots of a given complex number (n in the range 1-64).
- complex_quadratic: Solves quadratic equations with complex coefficients. Given coefficients a, b, and c, it returns the discriminant, Vieta’s formula results (sum and product), roots, and residual verification values for each root.
Installation and Activation¶
Before installation, ensure that the environment meets the Node.js >= 20 requirement. Install the plugin with the following command:
dsh plugin --profile web add github:TYEplex/dsh-complex
If you need to pin the version, use:
dsh plugin --profile web add github:TYEplex/dsh-complex#v0.2.0
Typical Usage¶
The following examples show how to invoke these tools:
Parsing and Conversion¶
complex_parse("3+4i")
# 返回: 3+4i (rectangular; |z| = 5, arg = 53.1301023542°, conjugate 3-4i)
complex_convert(input="3+4i", operation="to_polar")
# 返回: |z| = 5, arg = 0.927295218 rad = 53.1301023542° (5∠53.1301023542°; exponential 5·e^(i·0.927295218))
Arithmetic and Exponentiation¶
complex_calc(a="3+4i", b="1-2i", operation="multiply")
# 返回: 11-2i
complex_calc(a="i", b="i", operation="pow")
# 返回: 0.2078795764 (i^i = e^(-π/2))
Functions, Roots, and Equations¶
complex_functions(input="-1", operation="log")
# 返回: 3.1415926536i (principal branch)
complex_roots(input="1", n=4)
# 返回: 1, i, -1, -i
complex_quadratic(a="1", b="-2", c="2")
# 返回: discriminant -4, sum 2, product 2; roots 1+1i, 1-1i
Applicable Scenarios and Notes¶
This plugin is suitable for DSH agent scenarios that require complex number mathematical logic, such as signal processing, control theory simulation, or complex engineering calculations.
- Deterministic Output: The plugin internally uses IEEE double-precision floating-point numbers. Results are retained to 10 decimal places by default; precision can be adjusted (1-15 places) via the
plugins.complex.roundPlacesconfiguration. - Input Syntax: Supports
a+biform andr∠θ°polar coordinate input. Supportsjas the imaginary unit. - Branch Conventions: Inverse function calculations (such as
asin,log) strictly follow the branch conventions of CPythoncmath, and the results include branch explanations. - Error Handling: For invalid inputs (such as
log(0), division by zero,0^0, oratan(±i)), the plugin returnsvalid: falseand provides an honest explanation instead of returning an incorrect value.
Summary¶
By providing a rigorous set of complex number calculation tools, dsh-complex fills a gap in DSH when handling complex mathematical operations. It allows agents to obtain high-precision complex number calculation results without deriving formulas themselves. For more details and source code, visit the GitHub repository.