/* R. J. Cano, Jun 9 2014 */

A080575byRows(m,seq=1)={
  my(n=0,l0:list,l1:list,l2:list,l3:list);
  l0=List();
  listput(l0,[1,vector(1)]);
  l3=List();
  while(n++<=m,
    l1=List();
    l2=List();
    for(k=1,#l0,listput(l1,[1,vector(n)]);listput(l2,[1,vector(n)]);l1[k][1]=l0[k][1];l2[k][1]=l0[k][1];for(j=1,n-1,l1[k][2][j+1]=l0[k][2][j];l2[k][2][j+1]=l0[k][2][j]));
    l0=List();
    for(k=1,#l1,forstep(j=#l1[k][2],1,-1,if(l1[k][2][j],listput(l0,l1[k]);l0[#l0][1]*=l0[#l0][2][j];l0[#l0][2][j]--;if(j>1,l0[#l0][2][(j-1)]++)));l2[k][2][n]++;listput(l0,l2[k]));
    for(u=1,#l0-1,forstep(w=#l0,u+1,-1,if(l0[u][2]==l0[w][2],l0[u][1]+=l0[w][1];l0[w]*=0)));
    l1=l0;
    l0=List();
    for(k=1,#l1,if(l1[k][1],listput(l0,l1[k])));
    if(seq,for(k=1,#l0,listput(l3,l0[k][1])));
  );
  if(seq,l3,l0);
}

/* Notes:
 * 
 * a) If seq then #A080575byRows() will be: sum(k=1,m,numbpart(k)); Else it will be simply: numbpart(m);
 * 
 * b) Here is not considered rigorously the validity of assuming that the mixed partial derivatives are
 *    permutable among them (Neither by the Schwartz theorem nor another similar result). So this point
 *    is left as a pending matter of care for the reader/user according on the functions or expressions
 *    which he/she aims to deal with.
 *
 * c) (When seq is 0) The associated place (reversed: (m-j+1) instead of simply j) inside the vector for each
 *    stored value gives the inner derivative that must be taken and the stored value in such place is the degree
 *    for the corresponding power to its factor (the number of consecutive times that the same operator must be applied).
 * 
 *    For example:
 * 
 *    After loaded this script in GP, the following call:
  
      ? A080575yRows(2,0)
      
 *    Replies:
 
      List([[1, [1, 0]], [1, [0, 2]]])
      
 *    "The second inner derivative once plus the first inner derivative consecutively applied twice"
 *    (the sum of the described applications).
 *    
 *    By using TeX/LaTeX notation the previous one would be an informal description for something similar to:
 *
 
   \frac{d^{2}}{d\lambda^{2}}F\left(\lambda\right)
   = \left(\left(\sum_{u=1}^{s}\frac{d^{2}Q_{u}}{d\lambda^{2}}\frac{\partial}{\partial Q_{u}}\right)
   +\left(\sum_{w=1}^{s}\frac{dQ_{w}}{d\lambda}\frac{\partial}{\partial Q_{w}}\right)^{2}\right)
   F\left(Q_{1}\left(\lambda\right),Q_{2}\left(\lambda\right),\cdots,Q_{s}\left(\lambda\right)\right)
   
 *    Where lambda is the unique parameter. This is also similar to what you get by calling texsourcegen(2);
 *
 *   For example, with the call texsourcegen(6,1) the resulting eleven terms would fill an A4 sized page.
 *
 */

/* 
 * Tex/LaTeX source generator for an operator series of which its coefficients are the rows in A080575.
 * 
 * Usage: olbt means "one line by term" and str contains a command for a line break (inside a math environment).
 * 
 * (By default the line break command assumed here is the double backslash).
 * 
 */

texsourcegen(m,olbt=1,str="\\\\",envtype=1,pageHeight=14)={my(data=A080575byRows(m,0),i,q=0,u);if(olbt,equationenv(envtype,1));for(k=1,#data,if(k!=1,if(olbt,print1(str));print1("+"));if(data[k][1]!=1,print1(data[k][1]));i=0;for(j=1,m,u=m;for(l=1,m,if(!data[k][2][l],u--));if(data[k][2][j],print1("\\left(\\sum_{ \\left(k_{"k","1+u-(i++)"}\\right)=1}^{s}\\frac{d^{");if(m-j+1!=1,print1(m-j+1));print1("}Q_{\\left(k_{"k","1+u-i"}\\right)}}{d\\lambda^{");if(m-j+1!=1,print1(m-j+1));print1("}}\\frac{\\partial}{\\partial Q_{\\left(k_{"k","1+u-i"}\\right)}}\\right)^{");if(data[k][2][j]!=1,print1(data[k][2][j]));print1("}")));if(((k!=#data)&&olbt)&&(!((q++)%pageHeight)),q*=0;equationenv(envtype,3)));if(olbt,equationenv(envtype,2))}

/* Aid routine for texsourcegen().
 * 
 * This is processed only if olbt is 1, else all what you get is simply a long line with all the terms.
 * 
 * By specifying olbt as 1, it is assumed that one of the two supported environments (see below) is requested.
 * 
 * Usage: (envtype)  1= pair of "$"; 2= "equation*"
 *        (whichOne) 1= Begins the environment, 2= Ends the environment, 3= Splits the environment;
 * 
 */
equationenv(envtype,whichOne)=if (enabled,print1([["$","$","$\\\\$"],["\\begin{equation*}\\begin{aligned}","\\end{aligned}\\end{equation*}","\\end{aligned}\\end{equation*}\\begin{equation*}\\begin{aligned}"]][envtype][whichOne]));

/*
 * Note 1: At its current state, these routines generate TeX/LaTeX code that might require some packages like amsmath and amssymb.
 *
 * Note 2: Formerly this code used listcreate() instead of List(); It was reviewed and updated/fixed
 *            on Aug 29 2014 due listcreate() is considered obsolete and will be no longer available for
 *            future versions of PARI-GP.
 *	
 *	       (See: http://pari.math.u-bordeaux.fr/dochtml/html.stable/Vectors,_matrices,_linear_algebra_and_sets.html).	
*/