Extending Compose block

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:

integrated lift definition

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.

The iteration library pipe operator is also quite useful for these sort :slight_smile: of operations

Thanks @cymplecy,

Looks amazing. I will study pipe a bit to understand it. :grinning:

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)

built-in lift

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:

euclidean distance using pipe

and use lift:

euclidean distance using lift

I like both solutions. What about you guys?

Can be done without custom sum reporter
untitled script pic (36)

(just drop #1 onto the + operator)

Clever, thanks @cymplecy. :+1:

Hi @bh and @cymplecy,

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?):
lift implemented with pipe euclidean distance example

Of course, we can accept varadic input slots:

lift implemented with pipe euclidean distance example varidic input

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.

flexible lift final version - ex1

flexible lift final version - ex2

Finally, euclidean distance of two points:

euclidean distance using flexible lift

euclidean distance using flexible lift - example

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! :~)