Ladies and gentlemen… I did it!

I used Fourier analysis and Discrete Fourier Transforms to reverse-engineer the next 75 years of moon phase data. This allowed me to derive a new phase equation that is very compact, *extremely* accurate, and will remain so for… probably the next 1000 years.

This was a long and arduous process. I had to learn some python code and I used Chat GPT to help me learn these unfamiliar concepts, which was essential in helping me fit a new series of sin curves to the moon data.

Here is a comparison between the relative error of @mikeoday’s previous equation (which really is very accurate) and mine (shown in red) from today’s date until the year 2100. You can see that Mike’s equation is pretty stable for the next 20 years or so, but then it starts to become more inaccurate over time.

Here are the equations formatted for both Facer and for Python in case some of you want to run it through your own paces:

```
(((#DNOW#/2551442844-0.228535)
+0.01765sin(#DNOW#/378902233-1.828)
+0.00583sin(#DNOW#/5022682843-3.179)
-0.00383sin(#DNOW#/437445587-4.186)
-0.00057sin(#DNOW#/218722742-2.084))%1)
```

Here’s a 1-line version that is easy to copy into Facer Creator:

```
(((#DNOW#/2551442844-0.228535)+0.01765sin(#DNOW#/378902233-1.828)+0.00583sin(#DNOW#/5022682843-3.179)-0.00383sin(#DNOW#/437445587-4.186)-0.00057sin(#DNOW#/218722742-2.084))%1)
```

Here’s a version that works in Python, which uses Unix time output in seconds (instead of milliseconds like Facer’s “#DNOW#” function does) so we have to adjust our scalars in the formula slightly:

```
import time
import math
def moonPhaseCalc():
cTime = time.time()
mCalc = ( ( cTime / 2551442.844 - 0.228535 )
+ 0.01765 * math.sin( cTime / 378902.233 - 1.828 )
+ 0.00583 * math.sin( cTime / 5022682.843 - 3.179 )
- 0.00383 * math.sin( cTime / 437445.587 - 4.186 )
- 0.00057 * math.sin( cTime / 218722.742 - 2.084 ) )
return mCalc % 1
print(moonPhaseCalc())
```

Now… could I make it even *more* accurate? …Perhaps, but we’re at a point of diminishing returns here. My new equation should be no more than 20 minutes off from the true phase of the moon, and for all practical purposes… this is probably overkill.

That being said, I couldn’t resist the challenge. And frankly, I hope someone else attempts to improve on it! Many thanks to @mikeoday for the original formulation, which was highly instructive and gave me a great starting point — all I’ve done is derive new values for the other terms. I may post again with further refinements, but this is pretty good now!

Cheers!