in reply to Obtaining terms in an expansion

I don't like how this question was asked, and seems I'm not the only one -- even after your reply to clarify, I still can't understand what you are after or why.

Are you multiplying polynomials? Taking the square root of a hamiltonian? Calculating the angular velocity of a catapulted gerbil? :)

Maybe it would help if you would link to an article describing the process you are trying to model in perl.

Replies are listed 'Best First'.
Re^2: Obtaining terms in an expansion
by randyk (Parson) on Jan 06, 2006 at 02:05 UTC

    I apologize if the motivation wasn't clear. At a mathematical level, it's a problem of multiplying N polynomials, each of which has two terms:

    For N=2: (a+b)*(c+d) = ac + ad + bc + bd For N=3: (a+b)*(c+d)*(e+f) = ace + acf + ade + adf + + bce + bcf + bde + bdf
    What I was after was an explicit expression for each of the 2**N terms on the right-hand-side of these equations.

    As for why one would want to do this beyond a homework question, this problem arises in theories of quantum computing, particularly in trying to write an arbitrary state in terms of what's called the computational basis for an N-qubit state.

      I believe that to solve this you would need to create two separate arrays; one to contain the variables on the left side of the equation and another to contain each of the terms on the right side of the equation.

      Since you know that you will have 2**N variables on the left side, you would want to create an array named, say, Variable{2**N-1) to contain the variables. Then you would create an array Terms[2**N-1] to contain the terms generated by multiplying the polynomials.

      I don't think one would need a two dimensional array. The first part of the program code could pop up a message box asking what N is, and then it would create the arrays as I described above. Then the code would step through array Variable[] multiplying the variables as appropriate and placing the resulting terms into array Terms[]. So the expansion is simply the sum of the elements of array Terms[2**N-1].

      I am new to Perl so I am still working on actual code to do what I've described. I think that this is an interesting problem.

      jdporter added code and p tags

      Completely irrelevant time waster:
      #!/your/perl/here use strict; use warnings; { # closure for sub terms my @term_list = ('A'..'Z', 'a'..'z'); sub terms { my $N = shift; my $last = 2*$N-1; my @pairs; my $index = 0; my $globber = ''; while ( $index < $last ) { $globber .= '{' . $term_list[$index++] . ',' . $term_list[$index++] . '}'; } my $terms = join ' + ', glob($globber); return $terms; } } # end closure for sub terms foreach my $n (1..5) { my $terms = terms($n); print "N=$n: <", $terms, ">\n"; } exit; __OUTPUT__ N=1: <A + B> N=2: <AC + AD + BC + BD> N=3: <ACE + ACF + ADE + ADF + BCE + BCF + BDE + BDF> N=4: <ACEG + ACEH + ACFG + ACFH + ADEG + ADEH + ADFG + ADFH + BCEG + B +CEH + BCFG + BCFH + BDEG + BDEH + BDFG + BDFH> N=5: <ACEGI + ACEGJ + ACEHI + ACEHJ + ACFGI + ACFGJ + ACFHI + ACFHJ + +ADEGI + ADEGJ + ADEHI + ADEHJ + ADFGI + ADFGJ + ADFHI + ADFHJ + BCEGI + + BCEGJ + BCEHI + BCEHJ + BCFGI + BCFGJ + BCFHI + BCFHJ + BDEGI + BD +EGJ + BDEHI + BDEHJ + BDFGI + BDFGJ + BDFHI + BDFHJ>

      -QM
      --
      Quantum Mechanics: The dreams stuff is made of

Re^2: Obtaining terms in an expansion
by ivancho (Hermit) on Jan 06, 2006 at 01:08 UTC
    hmm.. that seems pretty clear to me : here
    The problem arises in something we're looking at involving quantum ent +anglement - each of the a[i][0] + a[i][1] terms (i=0, 1, 2, ..., N-1) + represents a two-level quantum state. N such terms multiplied togeth +er thus represents a product state of N two-level states. We're then +seeing if a general state can be written in this form - if it cannot, + then the degree to which it can't is a measure of the degree of enta +nglement.