Message Boards Message Boards

Visualizing Euler's Number

Posted 7 years ago

Happy e day! As with pi, e is an irrational number (as well as transcendental), and repeats forever in a seemingly bizarre pattern of digits. It shows up in tons of places inside and outside of mathematics.

I've always been a sucker for strange patterns, and love investigating them. The Wolfram Language has some of the best pattern matching capabilities available, so I wanted to make use of them to visualize the digits of e. I'm no number theorist or visualization expert by any means—just an enthusiastic user who likes puzzles—but was still able to come across some cool observations.

Partitioning Digits of e

The first thing that needed to be done to visualize how the digits of e behave is to essentially pick out those digits up to a certain placement. I chose the first 200 digits because, well, why not? First, I generated the digits:

e = N[E,200]
(*2.71828182845904523536028747135266249775724709369995957496696762772407663035354759457138217852516642742746639193200309921817413596629043572 9003342952605956307381323286279434907632338298807531952510190*)

Next, I figured the easiest way to split the digits into single elements of a list was to turn the whole thing into a string, then split it, then turn it back into an expression:

ToString[e] //
    StringSplit[#, ""] & //
   Drop[#, 2] & (*drops both the 2 and the decimal point so I just get digits after the decimal*)//
  ToExpression[#] & //
 (eList = #) &

Finally, I decided to do a ListLinePlot just to see what I was working with:

ListLinePlot[eList]

enter image description here

So first thing I thought was, "huh, that looks like a time series", which informed the rest of what I did; I decided to do a Fourier transform as well, just to check out what the power spectrum would look like:

fourierList = Rest[Abs@Fourier[eList]];
ListLinePlot[fourierList]

enter image description here

Filtering and Comparison

This thing definitely required some smoothing, so I used a basic LowpassFilter and varied the parameters a bit until my eyeballs thought it looked roughly ok. I did this both for the original sequence of digits:

fit = LowpassFilter[eList, 0.1];
ListPlot[{eList, fit}, Joined -> True]

enter image description here

As well as the transformed sequence of digits:

fourierFit = LowpassFilter[fourierList, 0.1];
ListPlot[{fourierList, fourierFit}, Joined -> True]

enter image description here

Finally, I wanted to get a sense of how well their relative "smoothness" compared, and if there was something more to investigate:

ListLinePlot[{fit, fourierFit}, Filling -> Axis, 
 PlotLegends -> {"Original", "Transformed"}]

enter image description here

So to me, it looks like there's a pretty clear and consistent gap between digits of e before and after transformation. Could this distance be visualized? I wanted to try it; if nothing special came out of it, then, well, might at least look pretty.

Distance Visualization

First, I wanted to get a idea of the distance between consecutive digits of e—both the original sequence:

MatrixPlot[DistanceMatrix[eList],
 PlotLabel -> "Distance matrix for first 200 digits of e", 
 FrameTicks -> {Automatic, Automatic}]

enter image description here

and the transformed sequence:

MatrixPlot[DistanceMatrix[fourierList],
 PlotLabel -> "Distance matrix for first 200 transformed digits of e",
  FrameTicks -> {Automatic, Automatic}]

enter image description here

Ok, those are pretty neat looking, and compared to the MatrixPlot of the first 200 digits in the PrimePi function, it is way less smooth (I'll leave it to y'all to explore that reference visual).

Going back to my earlier desire of wanting to investigate the distance between the original sequence of digits and its corresponding transformed sequence, I was able to do that just as easily as these other two plots:

DistanceMatrix[eList, fourierList] // 
 MatrixPlot[#, PlotLabel -> "Distance matrix between sequences", 
   FrameTicks -> {Automatic, Automatic}] &

enter image description here

Interpreting this MatrixPlot is not something I know how to do, but as a visualization within the digit space of e, it's pretty cool to examine. Some other cool visuals for distance metrics I'd like to investigate for these sequences are force-directed graphs or a Voronoi diagram; maybe y'all can discuss those visualization techniques in this thread; would definitely be interested to see what gets produced! Enjoy this transcendental occasion!

POSTED BY: Jesse Dohmann
6 Replies

enter image description here - Congratulations! This post is now a Staff Pick as distinguished by a badge on your profile! Thank you, keep it coming!

POSTED BY: EDITORIAL BOARD
Posted 7 years ago

This is more convenient, at least for me.

Rest@Flatten@RealDigits[E, 10, 200]
POSTED BY: Okkes Dulgerci
Posted 7 years ago

Hah! I always seem to forget about those unique Wolfram Language functions that would make my life easier...iterating over strings is only intuitive and easy for me because it's a pretty standard technique across languages (probably for performance purposes).

Below is a small performance comparison between methods on my machine. The one using RealDigits is slightly faster (also gave me one extra digit for a full 200 i.e. has better precision); gotta work harder at changing my perspective!

ToExpression[Drop[StringSplit[ToString[N[E, 200]], ""], 2]] // Timing
(*{0.000937, {7, 1, 8, 2, 8, 1, 8, 2, 8, 4, 5, 9, 0, 4, 5, 2, 3, 5, 3, 6, 0, 2, 8, 7, 4, 7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 3, 0, 7, 3, 8, 1, 3, 2, 3, 2, 8, 6, 2, 7, 9, 4, 3, 4, 9, 0, 7, 6, 3, 2, 3, 3, 8, 2, 9, 8, 8, 0, 7, 5, 3, 1, 9, 5, 2, 5, 1, 0, 1, 9, 0, 1}}*)
POSTED BY: Jesse Dohmann

The easiest way to get the digits of a real number as a list is to use RealDigits. You could also use the built in time series tools.

POSTED BY: Paul Abbott
Posted 7 years ago

That's pretty interesting! I don't know exactly how to interpret DistanceMatrix wrt eigenvalues (was reading that it can be interpreted as a connectivity measure for graphs, which gives merit to trying to approach visualization as a graph), but it looks very similar to a dampened harmonic oscillator. Unfortunately, I could not get FindFit to get me parameter values that fulfilled the model of one such oscillator a*(E^(-b*t))*Sin[c*t+d] in a way that looked similar.

POSTED BY: Jesse Dohmann

Cool !

It just occured to me: look at this

dm = DistanceMatrix[eList] // N;
evdm = Eigenvalues[dm];
ListLinePlot[evdm]

Whatever that means?

POSTED BY: Hans Dolhaine
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract