LISP on TeX でマンデルブロな話
LuaTeXならマンデルブロ集合も書ける。
いや,e-pLaTeX でもいけるはずだ.もっと言えば,LISP on TeX で記述できるはずだ.
というわけで書いてみた.精度は時間がかかるのでだいぶ抑えているけど.
以下ソース
\documentclass[a3paper,landscape]{jsarticle} \usepackage[dvipdfm,margin=1pt]{geometry} \usepackage{lisp} \lispinterpl{% (\define \maxloop :100) (\define \scale :100) (\define \limitr (\* :2 \scale \scale)) (\define \sq (\lambda (\x) (\/ (\* \x \x) \scale))) (\define \isMandell (\lambda (\a \b \k \x \y) (\lispif (\< \maxloop \k) /t (\lispif (\< \limitr (\+ (\sq \x) (\sq \y))) /f (\isMandell \a \b (\+ \k :1) (\+ \a (\sq \x) (\- (\sq \y))) (\+ \b (\/ (\* :2 \x \y) \scale))))))) (\define \drawMandell (\lambda (\a \b) (\lispif (\isMandell \a \b :0 :0 :0) (\begin (\texprint '*') (\immediatewrite) ) (\begin (\texprint '-') (\immediatewrite) )))) (\define \modulo (\lambda (\n \m) (\- \n (\* \m (\/ \n \m))))) (\define \loopMandell (\lambda (\n) (\lispif (\= \n (\* :4 \scale \scale)) % test (\* :4 \scale \scale) () (\begin (\drawMandell (\- (\modulo \n (\* :2 \scale)) \scale) (\- (\/ \n (\* :2 \scale)) \scale)) (\lispif (\= (\modulo \n (\* :2 \scale)) (\- (\* :2 \scale):1)) (\texprint '\\') ()) (\loopMandell (\+ \n :1)))))) } \begin{document} \fontsize{5pt}{0pt}\selectfont\ttfamily\noindent \lispinterpl{(\loopMandell :0)} \end{document}
LISPじゃねーかw
ソース自体は,リポジトリに置いてある.勇気のあるひとは実行して欲しい.
実行結果はこちら*1.アスキーアート出力なので,アスペクト比がおかしいけど,計算自体はできている.
一応,ログファイルのメモリ使用量もつけてみる.
Here is how much of TeX's memory you used: 1523 strings out of 494059 15752 string characters out of 3159691 112278 words of memory out of 3000000 5008 multiletter control sequences out of 15000+200000 9102 words of font info for 41 fonts, out of 3000000 for 9000 750 hyphenation exceptions out of 8191 39i,4n,80p,192b,229s stack positions out of 5000i,500n,10000p,500000b,50000s
ちなみに,私の実行環境(W32TeX (2012/2/4),Core 2 Quad 2.4GHz,4GB memory)での計算時間は 130 [min] ほどでした.
*1:ページ番号入れっぱなしだったのでトリミングしてある