Closed joshuabowers closed 3 years ago
multiply
and the complex trigonometric functions. E.g. cosh(z) === cos(i * z)
, where z is complex, the argument i * z
is the complex multiplication of i
and z
, and cos
is the complex implementation.z ** 0.5
, or using the Field
API: z.raise(new Complex(0.5, 0))
for z complex.)A potential approach to implementing the Gamma function: using the Lanczos Approximation. The python example seems relatively simple to translate, and should be functional on complex numbers.
A few notes about implementing Lanczos:
p
, which each term in the convergent series get multiplied by. Much of this can be pre-computed---indeed, the python source linked above already has those values listed for a given g
. Other sets of coefficients can, for example, be found hereField
so that both Real
and Complex
can utilize the functionality. This might also potentially result in a reimplmentation of Real.prototype.factorial
, so that it would be applicable to the broader set of numbers. z + 1
, which might be weird to represent.Done, as of aeada1c3b31762e6639595e537711def26fbe21b. While further refinement is likely warranted at some point, Complex numbers are firmly integrated into the app.
Complex
implements an imprecise interpretation of the mathematical concept of a field, specifically for representing complex numbers. Currently, it defines the representation of a complex number---i.e. a pair of reals,(a, b)
which represent the real and imaginary parts of the prototypical binomiala + bi
---alongside a series of mathematical operations which may be calculated upon that field. (This is in keeping with it being a sub-class of the abstractField
;Real
is a sibling sub-class which implements a similar structure for reals.)Currently,
Complex
does not yet define any implementation for the following sets of functions:The first two will require the implementation---on
Field
---of the hyperbolic functions. Factorial will likely need to be represented as the gamma function, which currently makes my head hurt. Exponentiation can be implemented in terms of the trigonometric functions via De Moivre's formula.It should be noted that the current implementation of the complex logarithm, and some of the likely solutions suggested above, yield only the principal value of the applied function, ignoring the infinite generalized unbounded solutions, by binding the result to a particular domain. For the logarithm, this constrains the resultant imaginary part to lie within
(-pi, pi]
. A more general approach---which takes into consideration the branch cuts would likely be desirable, but would requireComplex
to likely define its component parts in terms ofField
, with a new sub-class representing variables introduced; conversely, the return type ofField
operations would need to be altered to allow for AST node-structures to be allowed, which would allow methods like logarithm to return new sub-trees.