I was messing around looking into the collatz conjecture in q/k4 and I realized that I could write the short cut collatz function without any conditionals as follows by taking advantage of the fact that you can use the result of x mod 2 to zero out some terms when x is even.<p>note: no operator precedence in q/k<p><pre><code> q)cc:{(x+(2*x*m)+m:x mod 2)div 2}
q)cc til 20
0 2 1 5 2 8 3 11 4 14 5 17 6 20 7 23 8 26 9 29
</code></pre>
After some algebra I arrived at<p><pre><code> cc:{(x*1+x)-(x div 2)*1+2*x}
</code></pre>
Figured I'd share what I found since I don't see this formula mentioned on <a href="https://en.wikipedia.org/wiki/Collatz_conjecture" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Collatz_conjecture</a> . Has anybody else encountered this formula?<p>I've linked a chart of the function with its definition in more familiar mathematical notation. It's extended onto the reals by utilizing the floor function.<p>PS: Notation is a tool of thought!