M → Tip, 4 bytes
Ṅ×ịß
Try it online!
The TIO link adds a footer to call the function with the example Tip program shown on the Esolang page (M's "automatic wrapper" to call functions as though they were programs can't handle rational or fixed-point numbers, or at least I haven't figured out how to tell it how, so I need to make the function into a full program by hand to be able to run it.)
This actually prints useful debug output; the program can't be written in 3 bytes in M because a program consisting of exactly three dyads triggers a special case in the parser, so I had to add an extra command to avoid the special case. Making it Ṅ
(print with newline) at least gives it a useful purpose.
Function submission, taking two arguments: the initial IP on the left, the program on the right. The program is 1-indexed (i.e. command 1 is the first command; M uses 1-indexing by default); goto commands are represented as M rationals, and the halt command as ı
(i.e. the imaginary unit, \$i=\sqrt{-1}\$).
Does not implement I/O (other than halt/no-halt). I/O is an extension to Tip (not part of the language itself), and not required for Turing-completeness.
Explanation/background
Ṅ×ịß
Ṅ Print {the left argument} and a newline; also resolves a parser ambiguity
ị {The left argument}th element of {the right argument}, wrapping on OoB
× Multiply {the left argument} by {the chosen element}
ß Recursive call; arguments: {the product} and {the same right argument}
I was reading through the answers to this entry and realised that iterated Collatz functions, which were used in quintopia's earlier answer, would be fairly short to represent in golfing languages in which list indexing wraps by default (i.e. the fifth element of [1,2,3]
is 2, because the list is being treated as [1,2,3,1,2,3,1,2,3,…]
). So it's easy to extract a particular Collatz operation from a list in very few characters. Can we implement the Collatz operation easily? Well, a Collatz operation is \$rx+s\$, which is a polynomial, and the "base conversion" builtin that many golfing languages have is actually a general-purpose polynomial evaluator in disguise. So all we have to do is index into a list of lists of digits, base-convert them, and we're done, right?
Unfortunately, it's not that simple. The first problem is that although Collatz functions can be defined entirely in terms of integers, that requires a divmod to extract the new value of \$x\$ (the definition where \$x\$ is the same value that's used to index into the list of Collatz operations requires rationals). Well, we just need a golfing language that supports rationals, right? M is a Jelly derivative that supports many types of arbitrary-precision arithmetic, and arithmetic on the rationals is part of its arsenal of mathematical operators.
Then we get to the second problem: M's base-conversion builtin ḅ
takes its arguments in the wrong order (it wants the list of digits to appear before the base). The problem with this is that M's default method of chaining together two binary operators given two arguments is \$x\oplus(x\otimes y)\$, and yet we'd want the Collatz operation (which can only fit the \$x\otimes y\$ part of this structure, as it's obtained by an index) to be on the left of the \${\oplus}\$. Sure, we could override the chaining behaviour to pretty much anything we want, but that would cost a whole byte, and the golfing language entries to this question are getting so short that a byte is a lot.
So I looked back and re-evaluated a bit. Are there any operations we could use instead of polynomial evaluation? Ideally, ones that are commutative, so we don't have to worry about argument order? Soon after that, I realised that Collatz functions are more complex than they need to be.
As a result, I created Tip, a simplification/tarpit-ification of iterated Collatz functions in which \$s\$ is always 0, meaning that instead of a polynomial evaluation, we can perform the various operations via a simple multiplication. The language is more complex to prove Turing-complete than Collatz functions are, but it still has enough power to implement any program; there's a proof on the Esolang page.
And of course, unlike base conversion (ḅ
), multiplication (×
) is commutative, and thus it doesn't matter what order the arguments are placed in. So all we need to write is ×ị
, and then place the program into an infinite recursion with ß
, and we have a Turing-complete language. Right?
Unfortunately, we run into a new problem. If a program starts with three binary operations, M engages in a special case that chains them as \$(x\odot y)\oplus(x\otimes y)\$ which is the worst possible structure for us, as it doesn't have the three nested function calls we'd need (index, multiply, and recursive call). So no matter what, we're going to need a fourth byte to disambiguate. ¹×ịß
(adding the identity function ¹
as a no-op so that the program doesn't start with three binary operators) does exactly what we'd need, causing them to nest inside each other in the way we want. We can use other operations in place of ¹
; Ṅ
is a good choice because it produces useful debug output.
Is three bytes possible? Unless I'm missing something, not with this specific choice of implementing and implemented language, but at this point it surely seems like it'd be possible somehow, as there are so many ways to do it in four and so many Turing-complete languages you could implement.
Good point I will do that and fix that other thing. Hope you will enter. – arodebaugh – 2017-02-25T22:04:50.790
3I would also recommend a rule that the implemented language must be different than the language that you use to implement it, to prevent trivial
eval
-like solutions. – ETHproductions – 2017-02-25T22:12:33.5301Actually, you might want to just ban
eval
commands/functions, as some languages have built-ins to evaluate code in another language. – ETHproductions – 2017-02-25T22:15:11.170@ETHproductions Agreed. My answer isn't very clever. – Okx – 2017-02-25T22:15:52.980
@ETHproductions That also makes sense... should have thought this over a little more. – arodebaugh – 2017-02-25T22:16:34.150
2
@arodebaugh For future challenges, you can post your idea in the sandbox where you can get feedback and iron out details like that before the challenges goes live and gets answered.
– Martin Ender – 2017-02-25T22:23:53.747@MartinEnder Yeah I literally saw that 5 minutes after I posted this. Oh well. – arodebaugh – 2017-02-25T22:25:30.527
1OK, you should probably be a little more specific and say something like "You may not simply execute code, via any method" to avoid other trivial answers like the Bash + perl one. – ETHproductions – 2017-02-25T23:06:17.487
@ETHproductions Gotcha – arodebaugh – 2017-02-25T23:16:10.067
Who will post MiniMAX in 8086 machine code?
– CalculatorFeline – 2017-02-27T03:57:47.687Related (not a dupe because of different scoring method). – DLosc – 2017-02-27T07:01:15.057
Related (closed StackOverflow question). – DLosc – 2017-02-27T07:02:41.027
1
Relevant video: On The Turing Completeness of PowerPoint (SIGBOVIK)
– sergiol – 2017-05-07T00:52:48.827Befunge/index.php interpreting BF, 5 bytes:
~:#X_
– Esolanging Fruit – 2017-05-07T19:47:39.223@Challenger5:
eval
-equivalents aren't allowed, even into a different language. – None – 2017-05-11T20:03:16.650@ais523 Which is why I posted it as a comment. – Esolanging Fruit – 2017-05-12T04:42:34.833
Identical but popcon: ULTIMATE CODEGOLF!!! (Codegolf a turing-complete system) [closed]
– user202729 – 2018-05-27T13:55:58.147I voted to reopen on the precedent of Does this code terminate?, which is a code golf to implement any code whose termination is an open mathematical problem. That is at least as broad as this and has been well-received.
– xnor – 2018-07-01T06:49:55.533