Created
June 11, 2025 14:46
-
-
Save Gro-Tsen/5d0f21a076f72dd3970a2f0485caa63a to your computer and use it in GitHub Desktop.
Plot the staircase function (cumulative graph) of a fat Cantor set.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Compute the cumulative measure function of a "fat" Cantor set (aka | |
# Smith-Volterra-Cantor set) with parameter alpha (meaning that | |
# 2^(k-1) intervals of length alpha^k are removed at the k-th stage of | |
# the construction. | |
alpha = 1/4 | |
# Total measure of the fat Cantor set: | |
totmeas = N((1-3*alpha)/(1-2*alpha)) | |
def staircase(x): | |
x = N(x) | |
if x <= 0: return 0 | |
if x >= 1: return 1 | |
# ycumul and yscale are the lower bound and length of the y-axis | |
# interval on which we've determined the value to lie. | |
yscale = N(1) | |
ycumul = N(0) | |
# lbnd and rbnd are the lower and upper bounds of the x-axis | |
# interval on which we've located the input point x. | |
lbnd = N(0) | |
rbnd = N(1) | |
# alphapow = alpha^(i+1) where i is how many steps in the | |
# constuction we've performed (we go up to i=30). | |
alphapow = N(alpha) | |
for i in range(30): | |
# mlbnd and mrbnd are the lower and upper bounds of the x-axis | |
# interval removed in the middle ofthe interval from lbnd to | |
# rbnd. | |
mlbnd = (lbnd+rbnd-alphapow)/2 | |
mrbnd = (lbnd+rbnd+alphapow)/2 | |
if x<mlbnd: | |
# We are left of the removed interval | |
rbnd = mlbnd | |
yscale /= 2 | |
elif x>mrbnd: | |
# We are right of the removed interval | |
lbnd = mrbnd | |
yscale /= 2 | |
ycumul += yscale | |
else: | |
# We are in the removed interval | |
return ycumul + yscale/2 | |
alphapow *= alpha | |
return ycumul + yscale*(x-lbnd)/(rbnd-lbnd) | |
# For alpha=1/3 (standard Cantor set), of course, totmeas=0 so if you | |
# wish to plot this case, remove *totmeas below. | |
g = plot(lambda x: staircase(x)*totmeas, (0,1), plot_points=960) | |
g.save(filename="plot.png", dpi=300, aspect_ratio=1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See https://mathoverflow.net/questions/495986/on-the-set-of-differentiability-of-a-fat-cantor-staircase and https://bsky.app/profile/gro-tsen.bsky.social/post/3lrb4fmst2c2v for what this is all about