30
1
Challenge
Write code that outputs TeX (LaTeX) math-equation code (given below) that will typeset Sierpinski Triangle Fractal of 5 levels. Shortest code wins.
Details
TeX (and friends like LaTeX, etc.) is a sophisticated typesetting system. It can render arbitrary nested complex expressions for mathematical formulas. Coincidentally this "nested complex" is also descriptive of fractals. The following is rendered with MathJaX
$${{{{{x^x_x}^{x^x_x}_{x^x_x}}^{{x^x_x}^{x^x_x}_{x^x_x}}_{{x^x_x}^{x^x_x}_{x^x_x}}}^{{{x^x_x}^{x^x_x}_{x^x_x}}^{{x^x_x}^{x^x_x}_{x^x_x}}_{{x^x_x}^{x^x_x}_{x^x_x}}}_{{{x^x_x}^{x^x_x}_{x^x_x}}^{{x^x_x}^{x^x_x}_{x^x_x}}_{{x^x_x}^{x^x_x}_{x^x_x}}}}^{{{{x^x_x}^{x^x_x}_{x^x_x}}^{{x^x_x}^{x^x_x}_{x^x_x}}_{{x^x_x}^{x^x_x}_{x^x_x}}}^{{{x^x_x}^{x^x_x}_{x^x_x}}^{{x^x_x}^{x^x_x}_{x^x_x}}_{{x^x_x}^{x^x_x}_{x^x_x}}}_{{{x^x_x}^{x^x_x}_{x^x_x}}^{{x^x_x}^{x^x_x}_{x^x_x}}_{{x^x_x}^{x^x_x}_{x^x_x}}}}_{{{{x^x_x}^{x^x_x}_{x^x_x}}^{{x^x_x}^{x^x_x}_{x^x_x}}_{{x^x_x}^{x^x_x}_{x^x_x}}}^{{{x^x_x}^{x^x_x}_{x^x_x}}^{{x^x_x}^{x^x_x}_{x^x_x}}_{{x^x_x}^{x^x_x}_{x^x_x}}}_{{{x^x_x}^{x^x_x}_{x^x_x}}^{{x^x_x}^{x^x_x}_{x^x_x}}_{{x^x_x}^{x^x_x}_{x^x_x}}}}}$$
by the following plain-text math-equation code consisting of nested super- and sub-scripts:
{{{{{x^x_x}^{x^x_x}_{x^x_x}}^{{x^x_x}^{x^x_x}_{x^x_x}}_{{x^x_x}^{x^x_x}_{x^x_x}}}^{{{x^x_x}^{x^x_x}_{x^x_x}}^{{x^x_x}^{x^x_x}_{x^x_x}}_{{x^x_x}^{x^x_x}_{x^x_x}}}_{{{x^x_x}^{x^x_x}_{x^x_x}}^{{x^x_x}^{x^x_x}_{x^x_x}}_{{x^x_x}^{x^x_x}_{x^x_x}}}}^{{{{x^x_x}^{x^x_x}_{x^x_x}}^{{x^x_x}^{x^x_x}_{x^x_x}}_{{x^x_x}^{x^x_x}_{x^x_x}}}^{{{x^x_x}^{x^x_x}_{x^x_x}}^{{x^x_x}^{x^x_x}_{x^x_x}}_{{x^x_x}^{x^x_x}_{x^x_x}}}_{{{x^x_x}^{x^x_x}_{x^x_x}}^{{x^x_x}^{x^x_x}_{x^x_x}}_{{x^x_x}^{x^x_x}_{x^x_x}}}}_{{{{x^x_x}^{x^x_x}_{x^x_x}}^{{x^x_x}^{x^x_x}_{x^x_x}}_{{x^x_x}^{x^x_x}_{x^x_x}}}^{{{x^x_x}^{x^x_x}_{x^x_x}}^{{x^x_x}^{x^x_x}_{x^x_x}}_{{x^x_x}^{x^x_x}_{x^x_x}}}_{{{x^x_x}^{x^x_x}_{x^x_x}}^{{x^x_x}^{x^x_x}_{x^x_x}}_{{x^x_x}^{x^x_x}_{x^x_x}}}}}
Note this is just a 5-level nesting. You do not need to generate $...$
or $$...$$
or other markup required to start/end a math equation in TeX & Co. You can preview generated TeX in many online editors, for instance: http://www.hostmath.com but you can find many others too. This question was inspired by a discussion with friends.
Update
There is a similar question but it much more general and will produce different solutions. I wanted to see really kolmogorov-complexity for a very fixed simple code that in one system (TeX) is completely explicit while in another compressed. This also address the n
instead of 5 levels comment.
Why exactly 5 levels? It would be interesting (and probably easier) to implement arbitrary number of levels and to take level number as a parameter. – None – 2017-09-20T13:00:29.850
@ThePirateBay yes, sure, but i did not want to generalize, see my update. – Vitaliy Kaurov – 2017-09-20T13:18:50.623
2Hello; I closed your question as a duplicate because I believe that answers can be too trivially modified from the other question to answer this question. However, I like the idea and I think it looks pretty cool! :) – HyperNeutrino – 2017-09-20T13:20:25.220
2For what it's worth, I reopened this question as I do not see the code as being trivially modifiable to translate from one to the other. – AdmBorkBork – 2017-09-20T13:36:46.993
4That's far too quick to be accepting a solution! – Shaggy – 2017-09-20T13:38:10.497
@HyperNeutrino was the question open again? – Vitaliy Kaurov – 2017-09-20T13:44:56.487
@Shaggy I removed acceptance for now because there is some confusion with opening and closing the question. Sorry. – Vitaliy Kaurov – 2017-09-20T13:45:41.237
@VitaliyKaurov Yes, AdmBorkBork hammered it: For what it's worth, I reopened this question as I do not see the code as being trivially modifiable to translate from one to the other.. – Mr. Xcoder – 2017-09-20T13:45:54.780
@AdmBorkBork thank you for your consideration – Vitaliy Kaurov – 2017-09-20T13:46:59.070
3
Relevant Meta: https://codegolf.meta.stackexchange.com/q/5056/32352
– Sanchises – 2017-09-20T14:09:54.9472
When I saw this challenge, this answer came to my mind... https://codegolf.stackexchange.com/a/6830/67961 and... it was yours
– J42161217 – 2017-09-20T21:26:11.237@Jenny_mathy yeah guilty as charged ;-) – Vitaliy Kaurov – 2017-09-20T21:31:58.373
Is the challenge just to generate that TeX string, or to generate any TeX string which will have the same output? – TRiG – 2017-09-21T10:46:35.080
@TRiG "any TeX string which will have the same output" – Vitaliy Kaurov – 2017-09-21T10:49:02.803