joshuabowers / graphca

A graphing calculator and analytic calculus engine
MIT License
0 stars 0 forks source link

Provisionally complete Complex #2

Closed joshuabowers closed 3 years ago

joshuabowers commented 3 years ago

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 binomial a + 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 abstract Field; 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 require Complex to likely define its component parts in terms of Field, with a new sub-class representing variables introduced; conversely, the return type of Field 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.

joshuabowers commented 3 years ago
joshuabowers commented 3 years ago

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:

joshuabowers commented 3 years ago

Done, as of aeada1c3b31762e6639595e537711def26fbe21b. While further refinement is likely warranted at some point, Complex numbers are firmly integrated into the app.