Umm okay let me let this soak in a while...
No problem.
I have now combined the lift n f gs block with the unarify block ( args... ) together to form a generic lift block:
To my pleasant surprise, this newly created function is compatible with the builtin sort function, take a look:
and also compatible with my merge sort block:
(Notice I switched ordering in the second invocation, sort the list of lists according the length in descending order)
Now lift has some general applications. I will now find some interesting applications, other than my original sort problem.
Thanks @cymplecy,
Looks amazing. I will study pipe a bit to understand it.
In your example, is there any reason you used extra step? I did the following:
Or simply (without using pipe at all):
However, pipe is powerful in applying a chain of unary functions to a single input, it's basically a generalized compose function, but in reverse order.
(x) (g1, g2, ..., gn) = gn(... g2(g1(x))
However, the power of your example (@cymplecy) lies in this: (which to be honest, I did not realize until I read your post)
Which is a lift in itself, especially for 2-ary (binary), 3-ary functions, however, for a general n-ary function, the lift function may still be useful.
I am so happy to see this example. thanks a bunch, @cymplecy.
One example, I search on the internet for examples of n-ary functions. The most obvious question is to find the Euclidean distance between any two points in n-dimensional space, which could translate to find the distance between any point to the center, because one can easily using the minus block to get the directional vector of the two points. One can use (thanks to @cymplecy) pipe:
and use lift:
I like both solutions. What about you guys?
Can be done without custom sum reporter
(just drop #1 onto the + operator)
I finally made an implementation using pipe, and it's very clean, this implementation is not possible without either of your ideas:
The following is the euclidean distance to the center (or the norm?, is it the proper name?):
Of course, we can accept varadic input slots:
I am pretty happy with this new implementation.
Update:
only notice the difference between this version and the original version is that the input for f, f is supposed to be n-arity function, while this last implementation is assuming it's one input (just like pipe) but with all the (variadic) inputs combined to become a list. This is useful sometimes, after careful consideration on various usage, I decide to make a flexible lift which would accept f in both situations, this flexibility will make our usage much easier.
Now two examples, one assumes f with 1-input, the second assume f has 3-inputs.
Finally, euclidean distance of two points:
It would not have occurred to me to use PIPE with only one function input. :~)
This is a nice piece of work. All your examples from the algebra of functions reminds me that in some course long ago I learned about functions of the form $$f^{-1} \circ g \circ f$$ which are applicable to things like solving Rubik's cube. What is the name for those functions, and in what context did I learn about them?
Hi @bh ,
You are really amazing in remembering the connection between
and Rubik's cube. It's a permutation group where each element of the group is a permutation. Each move of a Rubik's cube is a permutation.
You remembered too! :~)