問題文
$5.4 \lt \log_4 2022 \lt 5.5$ であることを示せ。ただし、 $0.301 \lt \log_{10} 2 \lt 0.3011$ であることは用いてよい。
(2022 京都大学 理系第1問 文系第1問)
コード
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as ani
from matplotlib.colors import ListedColormap

#紙の準備よし
fig = plt.figure()
fig.canvas.draw()
fig.suptitle("2022京大数学 理系第1問 文系第1問",
             color="0.5",ha="right",x=0.95,y=0.95,zorder=-1)
width = 12
height = 4
ax = fig.add_subplot(111)
ax.set_xlim(0,width)
ax.set_ylim(0,height)
ax.set_aspect("equal")
ax.axis("off")

#フォントの準備よし
plt.rcParams["mathtext.fontset"] = 'cm'
fdic={
"clip_on" : True,
"animated" : True,
"fontsize"  : 19,
"fontfamily" : "Meiryo",
"verticalalignment" : "baseline",
}

#台本
comment01='''\
ところで
'''
comment02='''\
$\\log_4\\,2022$
'''
comment1='''\
お前はどうして 5.5 よりも小さいの?
'''
lines11=[
r"$<\log_4 2048$",
]
lines12=[
r"$=\log_4 (4\times512)$",
r"$=\log_4 (4^2\times128)$",
r"$=\log_4 (4^3\times32)$",
r"$=\log_4 (4^4\times8)$",
r"$=\log_4 (4^5\times2)$",
r"$=\log_4 (4^5\times4^{0.5})$",
r"$=\log_4 \, 4^{5.5}$",
r"$=5.5$",
]
comment2='''\
お前はどうして 5.4 よりも大きいの?
'''
lines21=[
r"$>\log_4 2000$",
]
lines22=[
r"$=\dfrac{\log_{10} \, 2000}{\log_{10} \, 4}$",
r"$=\dfrac{\log_{10} (2\times1000)}{\log_{10} \, 2^2}$",
r"$=\dfrac{\log_{10} \, 2 + \log_{10} \, 1000}{2 \, \log_{10} \, 2}$",
r"$=\dfrac{\log_{10} \, 2 + 3}{2 \, \log_{10} \, 2}$",
r"$>\dfrac{0.301 + 3}{2 \times 0.3011}$",
]
lines23=[
r"$=\dfrac{3.301}{0.6022}$",
r"$=5.48\ldots$",
r"$>5.4$"
]
comment3='''\
Q.E.D.

(*・ω・*)ゞ!!
'''

#定数のセッティング
base = height/5
delta = 0.1
colors = [(1,1,1,alpha) for alpha in np.arange(0,11)/10]
cmap = ListedColormap(colors)

#数式が現れる関数
def appearing(i,X,Y):
    
    C = np.zeros(len(X)-1)
    C[2*i+1:2*i+20] = np.arange(0.05,1.00,0.05)
    C[2*i+20:] = 1
    C = np.reshape(C,(len(X)-1,1))
    img = ax.pcolormesh(X,Y,C,cmap=cmap,zorder=10)
    return img

#最初の1行目を表示する関数
def show_first_line_with_left(imgs,left,Ltext,lines):
    
    text = ax.text(left,base+height/2,lines[0],fontdict=fdic)
    bbox = text.get_window_extent().transformed(ax.transData.inverted())
    
    i = 0
    while True:
        img = [ax.text(left,base+height/2,Ltext,fontdict=fdic,
                       ha="right",zorder=10)]
        img += [text]
        X,Y = np.mgrid[left-2:left+bbox.x1+2:delta,height/2:3*height/2:height/2]
        img += [appearing(i,X,Y)]
        imgs.append(img)
        i += 1
        if 2*i+20 > len(X)-1:
            break

#2行目を表示する関数
def show_second_line_with_left(imgs,left,Ltext,lines,k):
    
    text = ax.text(left,base,lines[k+1],fontdict=fdic)
    bbox = text.get_window_extent().transformed(ax.transData.inverted())
    
    i = 0
    while True:
        img = [ax.text(left,base+height/2,Ltext,fontdict=fdic,
                       ha="right",zorder=10)]
        img += [ax.text(left,base+height/2,lines[k],fontdict=fdic)]
        img += [text]
        X,Y = np.mgrid[left-2:left+bbox.x1+2:delta,0:height:height/2]
        img += [appearing(i,X,Y)]
        imgs.append(img)
        i += 1
        if 2*i+20 > len(X)-1:
            break
        
#次の数式へと進む関数
def go_next_line_with_left(imgs,left,Ltext,lines,k):
    
    for i in range(21):
        img = [ax.text(left,base+height/2,Ltext,fontdict=fdic,
                       ha="right",zorder=10)]
        alpha = max((10-i)/10,0)
        img += [ax.text(left,base+height/2+height*i/40,lines[k],fontdict=fdic,alpha=alpha)]
        img += [ax.text(left,base+height*i/40,lines[k+1],fontdict=fdic)]
        imgs.append(img)

#最後の1行目を表示する関数
def show_last_line_with_left(imgs,left,Ltext,lines):
    
    for i in range(21):
        img = [ax.text(left,base+height/2,Ltext,fontdict=fdic,
                       ha="right",zorder=10)]
        text = ax.text(left,base+height/2,lines[-1],fontdict=fdic)
        img += [text]
        imgs.append(img)
    
    bbox = text.get_window_extent().transformed(ax.transData.inverted())
    return bbox.x1,Ltext+lines[-1]

#数式の部分の関数
def load_lines_with_left(imgs,left,Ltext,lines):
    
    show_first_line_with_left(imgs,left,Ltext,lines)
    
    for k in range(len(lines)-1):
        show_second_line_with_left(imgs,left,Ltext,lines,k)
        go_next_line_with_left(imgs,left,Ltext,lines,k)
        
    next_left,next_Ltext = show_last_line_with_left(imgs, left, Ltext, lines)
    return next_left,next_Ltext

#コメントの部分の関数
def interlude(imgs,text,frames):
    
    fdic = {
        "animated" : True,
        "ha" : "center",
        "va" : "center",
        "size" : 24,
        "color" : "white",
        "fontfamily": "Meiryo",
        }
    boxdic = {
        "facecolor" : "black",
        "pad" : 200,
        }
    
    for i in range(frames):
        interlude=ax.text(width/2,height/2,text,
                          fontdict=fdic,bbox=boxdic)
        imgs.append([interlude])

#上演   
imgs=[]
interlude(imgs,comment01,20)
interlude(imgs,comment02,30)
interlude(imgs,comment1,50)
left,Ltext = load_lines_with_left(imgs,width/3.5,r"$\log_4 2022$", lines11)
load_lines_with_left(imgs,left,Ltext,lines12)
interlude(imgs,comment01,20)
interlude(imgs,comment02,30)
interlude(imgs,comment2,50)
left,Ltext = load_lines_with_left(imgs,width/4.5,r"$\log_4 2022$",lines21)
left,Ltext = load_lines_with_left(imgs,left,Ltext,lines22)
load_lines_with_left(imgs,left,Ltext,lines23)
interlude(imgs,comment3,50)

mov=ani.ArtistAnimation(fig, imgs, 100)
plt.show()
解説になっているのか?甚だギモンな動画
「高校数学のエアポケット」に戻る