luna-complex

This manual documents the code of Luna-Flow/luna-complex at version 0.2.0 (the version in moon.mod) on MoonBit 0.10, including the unreleased changes listed in CHANGELOG.md.

Overview

Luna-Flow/luna-complex provides complex numbers for Luna Flow. The root package defines the generic type Complex[T], the ring T[i]/(i2+1)T[i]/(i^2 + 1) over any scalar T, with its arithmetic and luna-generic structure instances. The float_backend package adds the analytic functions of Complex[Double] (roots, logarithms, powers, trigonometric and hyperbolic functions and their inverses) with numerically stable formulas, and the capability traits for floating-point scalars.

Install

moon add Luna-Flow/luna-complex@0.3.2

Then import the packages you need in your moon.pkg. The examples in this manual use these aliases:

import {
  "Luna-Flow/luna-complex" @complex,
  "Luna-Flow/luna-complex/float_backend" @fb,
}

The packages need the MoonBit toolchain 0.10.20 or later (moonc ≥ 0.10.20) with moon.mod / moon.pkg manifests; the tests run on wasm-gc, wasm, js and native. They depend on Luna-Flow/luna-generic 0.4.0, Luna-Flow/arithmetic 0.5.0 and Kaida-Amethyst/math.

Pages

The root package is documented under the name core. float_backend replaces the former double_ext package.

PartTutorialAPIDesign
core (Luna-Flow/luna-complex): generic Complex[T], arithmetic, structure instancestutorialAPIdesign
float_backend (Luna-Flow/luna-complex/float_backend): analytic functions of Complex[Double], floating-point capability traitstutorialAPIdesign

The contribution guide collects the rules for changing the code and the manual.

Exported items

  • core: the type Complex[T] with new, set, set_re, set_im, zero, one, add, sub, neg, mul, div, conjugate, inv, equal and to_string
  • core instances: Add, Sub, Neg, Mul, Div, Show, and the luna-generic traits Zero, One, AddMonoid, AddGroup, MulMonoid, Semiring, Ring, Inverse, MulGroup, Field and Conjugate
  • float_backend modulus and argument: abs, abs_sqr, abs_log, arg, polar
  • float_backend arithmetic: div, sqrt, sqrt_real, exp, log, log_10, log_b, pow, pow_real, op_bin_re, op_bin_im
  • float_backend trigonometric and hyperbolic functions: sin, cos, tan, sec, csc, cot, sinh, cosh, tanh, sech, csch, coth
  • float_backend inverse functions: asin, acos, atan, asec, acsc, acot, asinh, acosh, atanh, asech, acsch, acoth, and the real-argument forms asin_real, acos_real, asec_real, acsc_real, acosh_real, atanh_real
  • float_backend storage: pack, native_pack
  • float_backend traits: FloatingAnalyticScalar, FloatingSpecialValues, FloatingBackendScalar, and the re-exported type Complex

The core tutorial computes with Complex[T], and the float_backend tutorial adds roots, logarithms and trigonometry. The API pages state the branch, special-value and abort behaviour of every item, and the design pages derive the algebra and the stable formulas.

Validation

Recommended release checks:

moon check --target all
moon test
moon info