Trávník's smooth self-referential formula - Renderer Program and Optimization
Go back to main page on Trávník's smooth self-referential formula. Go back to Program and Sources.
How to use Renderer Program
Minimal Java version to use this is Java 8. You can use later versions for this. It should work, but I have not tested it.
There are scripts run.sh and run.bat that assist with running the standalone renderer. They expect one parameter: a filename with job file. The job file describes what should be rendered (output PNG image file name, there are several formulas to choose from, saving interval, pixel width of output image, a view coordinates, a render coordinates, subpixel shifts and the arguments to the rendering formula like the big number N).
There are lot of examples in files ending with "-job.txt". You can run them with run.bat / run.sh scripts. For all of them there is already an output image present so you can just view output image without running the job. If you would like to run the job, delete the output image first. If image is present, the render job will try to complete it (it uses transparent pixels to mark incomplete parts) so if there is completed image it does nothing (even if you change some parameters of job). You can load an incomplete image into a image viewer or some editors (that do not lock the image file) while computation is running but as the image file is being rewritten every minute or so you may run into case where this happens during loading so loading would fail in some way. You may have better chance to load big images with backup file ending ".previous.png" while computation is running.
Details on format of job files are described in text file "renderjob-notes.txt" that is also a part of distribution.
Rendering optimization
In provided sources for rendering formula there are two Java implementations of the formula: SelfFormula and SelfFormulaFast. The SelfFormula is as close as possible to the displayed formula above. The SelfFormulaFast contains several optimizations that significantly improve runtime, however they produce same results.
Optimization in SelfFormulaFast:
- BigInteger type is replaced with String. So division by 10k are implemented by substring operations. About 33 times speedup.
- Additional 2x speed up comes from split in Sr(x, y) = PrintFormula(x, y) + PrintN(x, y, floor(log10(N)), 0, 2, 0) where left and right part are evaluated only in regions where they are needed based on y coordinate.
- Additional up to 2000x speed up (depending on N size). It comes from bounding box on glyphs ("Glyph" function) because glyphs have known bounding box, there is no need to evaluate outside of it. Glyphs might draw something beyond their bounding box if there would be unconnected curve gap close to the side of box, but all the glyphs I produced should have connected outline curves. I even considered adding such bounding box condition to "Glyph" function in the formula, but it would clutter it so I decided against it.
I have tested that both SelfFormula and SelfFormulaFast produce same output. See directory "self-formula-slow" for two outputs (image files are identical byte for byte) produced by two implementations. The slow one was running for a week on my computer, the fast was took about 10 seconds.
Go back to main page on Trávník's smooth self-referential formula. Go back to Program and Sources.
Back to index - Jakub Trávník's resources.