What is an efficient way of multiplying massive polynomials in Java?

180 views Asked by At

I have a function that defines a very long polynomial useful in operations with matrices.

The formula multiplies binomials of the form (1+xi*yj) , where i and j are subscripted and correspond to the rows and columns of the matrix in question, respectively. The polynomial that results is the product of all binomials with every permutation of i and j.

For example, a 3 x 2 matrix will have the polynomial product be:

(1+x1*y1)(1+x1*y2)(1+x2*y1)(1+x2*y2)(1+x3*y1)(1+x3*y2)

For clarification, every number after the variable should be treated as a subscript.

Is it possible for java to compute something of this massive amount, or can the task be delegated to another mathematics engine?

If possible, how would one go about implementing this?

1

There are 1 answers

1
hpopiolkiewicz On BEST ANSWER

Maybe this idea will help you to solve your problem:

    int result = 1;
    int x = 2;
    int y = 3;

    Integer [][] polynomials = new Integer[x][y];
    polynomials[0][0] = 1;
    polynomials[0][1] = 2;
    polynomials[0][2] = 3;
    polynomials[1][0] = 4;
    polynomials[1][1] = 5;
    polynomials[1][2] = 6;

    for(int i = 0; i<x; i++) {
        for(int j = 0; j<y; j++) {
            result *= (1 + polynomials[i][j]);
        }
    }
    System.out.println(result);