[Python] Algorithm for evaluating all compositions of three bivariate functions on subsets of...

Discussão em 'Python' iniciado por Stack, Janeiro 29, 2025.

  1. Stack

    Stack Membro Participativo

    I have three functions F(x,y), G(x,y), H(x,y) and five distinct data values a,b,c,d,e.

    I want to evaluate every possible composition of these functions in which distinct data values appear:

    G(d,b), ..., H(F(c,a),d), ..., H(e,H(G(b,c),a)), ..., G(F(F(H(a,b),c),d),e), ...


    How can I do that in Python?

    I'm hoping that some well-known algorithm (e.g., for nesting brackets) can be adapted for this, as I notice that each composition corresponds to a way of parenthesizing a subset of the data into nested pairs; i.e., the above examples correspond to

    (d,b), ..., ((c,a),d), ..., (e,((b,c),a)), ..., ((((a,b),c),d),e), ...


    (I think that for each n-point subset of the data, there are C_{n-1} * n! * 3^{n-1} different expressions, where the C_n are Catalan numbers; so the total number of compositions should be sum(n=2,3,4,5) binom(5,n) * C_{n-1} * n! * 3^{n-1}, which comes to exactly 1,050,000, which is doable for me.)

    Continue reading...

Compartilhe esta Página