Article 6WK14 Logarithmic sawtooth

Logarithmic sawtooth

by
John
from John D. Cook on (#6WK14)

Here's a strange integral I ran across recently [1].

logmod2.svg

It's a little surprising that the integral even exists, and more surprising that its value has a simple expression.

Here's a plot of the integrand.

logmod21.png

The plot doesn't do justice to all the activity on the left end. There are an infinite number of increasingly vertical segments piled up on the left end asx goes to 0.

If you were to plot the integrand on a log scale, you'd get a sawtooth wave, stretching back to negative infinity.

logmod22.png

I would expect the integral to be difficult to evaluate numerically without some special handling, but SciPy's quod function does a decent job by default.

 from numpy import log, tanh from scipy.integrate import quad print(quad(lambda x: log(x)%2, 0, 1)) print(1/tanh(1))

This evaluates the integral as 1.313042... while the exact value is 1.313035...

To the integrator's credit, it warns of difficulties before producing the result:

IntegrationWarning: The maximum number of subdivisions (50) has been achieved.

If increasing the limit yields no improvement it is advised to analyze the integrand in order to determine the difficulties. If the position of a local difficulty can be determined (singularity, discontinuity) one will probably gain from splitting up the interval and calling the integrator on the subranges. Perhaps a special-purpose integrator should be used.

Related posts

[1] Matthew A. Niemiro. The Natural Logarithm Modulo 2. The American Mathematical Monthly, Vol. 128, No. 2 (FEBRUARY 2021), p. 177.

The post Logarithmic sawtooth first appeared on John D. Cook.
External Content
Source RSS or Atom Feed
Feed Location http://feeds.feedburner.com/TheEndeavour?format=xml
Feed Title John D. Cook
Feed Link https://www.johndcook.com/blog
Reply 0 comments