SphericalHarmonicExpansions.jl icon indicating copy to clipboard operation
SphericalHarmonicExpansions.jl copied to clipboard

Rational result

Open Lightup1 opened this issue 3 years ago • 3 comments

I noticed that the Polyvar expression of Spherical Harmonics generated from rlylm uses float numbers as coefficients. Is there possible to add support for using rational number as expression coeffient to get accurate symbolic result?

3//5  # Rational
0.6   # Float64

Lightup1 avatar Aug 24 '22 03:08 Lightup1

The coefficients in the polynomial are inherently irrational (require sqrt for calculation) so simply using Rational would not do the trick. What are you trying to achieve?

hofmannmartin avatar Aug 24 '22 07:08 hofmannmartin

Dear @hofmannmartin Sorry for the ambiguous description. What I mean is whether it is possible to give accurate symbolic return of spherical harmonics. In that way, one can get accurate ratianal result when dividing polyvar coeffients.

For example:

julia> p4
0.31735664074561293x⁴ + 0.6347132814912259x²y² - 2.5388531259649034x²z² + 0.31735664074561293y⁴ - 2.5388531259649034y²z² + 0.8462843753216343z⁴

julia> p4.terms[1].coefficient/p4.terms[end].coefficient
0.3750000000000001

If the coefficients are symbolic, one can get accurate $3//8$

Lightup1 avatar Aug 24 '22 07:08 Lightup1

In principle one could make different normalizations possible (#6), which would yield the polynomials you desire. However, this refactoring of the package would require some time, which I currently do not have.

Important is to use BigInt and Rational{BigInt}, respectively to avoid overflow. So the generation of the polynomials would be much slower.

hofmannmartin avatar Aug 24 '22 10:08 hofmannmartin