/** Simple constructor. * @param n number of steps of the multistep method * (excluding the one being computed) */ private AdamsNordsieckTransformer(final int n) { final int rows = n - 1; // compute exact coefficients FieldMatrix<BigFraction> bigP = buildP(rows); FieldDecompositionSolver<BigFraction> pSolver = new FieldLUDecomposition<BigFraction>(bigP).getSolver(); BigFraction[] u = new BigFraction[rows]; Arrays.fill(u, BigFraction.ONE); BigFraction[] bigC1 = pSolver.solve(new ArrayFieldVector<BigFraction>(u, false)).toArray(); // update coefficients are computed by combining transform from // Nordsieck to multistep, then shifting rows to represent step advance // then applying inverse transform BigFraction[][] shiftedP = bigP.getData(); for (int i = shiftedP.length - 1; i > 0; --i) { // shift rows shiftedP[i] = shiftedP[i - 1]; } shiftedP[0] = new BigFraction[rows]; Arrays.fill(shiftedP[0], BigFraction.ZERO); FieldMatrix<BigFraction> bigMSupdate = pSolver.solve(new Array2DRowFieldMatrix<BigFraction>(shiftedP, false)); // convert coefficients to double update = MatrixUtils.bigFractionMatrixToRealMatrix(bigMSupdate); c1 = new double[rows]; for (int i = 0; i < rows; ++i) { c1[i] = bigC1[i].doubleValue(); } }
/** Simple constructor. * @param field field to which the time and state vector elements belong * @param n number of steps of the multistep method * (excluding the one being computed) */ private AdamsNordsieckFieldTransformer(final Field<T> field, final int n) { this.field = field; final int rows = n - 1; // compute coefficients FieldMatrix<T> bigP = buildP(rows); FieldDecompositionSolver<T> pSolver = new FieldLUDecomposition<T>(bigP).getSolver(); T[] u = MathArrays.buildArray(field, rows); Arrays.fill(u, field.getOne()); c1 = pSolver.solve(new ArrayFieldVector<T>(u, false)).toArray(); // update coefficients are computed by combining transform from // Nordsieck to multistep, then shifting rows to represent step advance // then applying inverse transform T[][] shiftedP = bigP.getData(); for (int i = shiftedP.length - 1; i > 0; --i) { // shift rows shiftedP[i] = shiftedP[i - 1]; } shiftedP[0] = MathArrays.buildArray(field, rows); Arrays.fill(shiftedP[0], field.getZero()); update = new Array2DRowFieldMatrix<T>(pSolver.solve(new Array2DRowFieldMatrix<T>(shiftedP, false)).getData()); }
/** Simple constructor. * @param nSteps number of steps of the multistep method * (excluding the one being computed) */ private AdamsNordsieckTransformer(final int nSteps) { // compute exact coefficients FieldMatrix<BigFraction> bigP = buildP(nSteps); FieldDecompositionSolver<BigFraction> pSolver = new FieldLUDecomposition<BigFraction>(bigP).getSolver(); BigFraction[] u = new BigFraction[nSteps]; Arrays.fill(u, BigFraction.ONE); BigFraction[] bigC1 = pSolver .solve(new ArrayFieldVector<BigFraction>(u, false)).toArray(); // update coefficients are computed by combining transform from // Nordsieck to multistep, then shifting rows to represent step advance // then applying inverse transform BigFraction[][] shiftedP = bigP.getData(); for (int i = shiftedP.length - 1; i > 0; --i) { // shift rows shiftedP[i] = shiftedP[i - 1]; } shiftedP[0] = new BigFraction[nSteps]; Arrays.fill(shiftedP[0], BigFraction.ZERO); FieldMatrix<BigFraction> bigMSupdate = pSolver.solve(new Array2DRowFieldMatrix<BigFraction>(shiftedP, false)); // convert coefficients to double update = MatrixUtils.bigFractionMatrixToRealMatrix(bigMSupdate); c1 = new double[nSteps]; for (int i = 0; i < nSteps; ++i) { c1[i] = bigC1[i].doubleValue(); } }
private FieldVector<Complex> get_start_state(final String qubits) { FieldVector<Complex> state = new ArrayFieldVector<Complex>(ComplexField.getInstance(), (int) Math.pow(2, qubits.length())); state.setEntry(Integer.parseInt(qubits, 2), new Complex(1)); return state; }
/** * Convert JAS <code>RingElem</code> to commons-math * <code>FieldElement</code>. * @param <C> ring element type * @param v JAS vector of ring elements * @return commons-math vector of CMFieldElementr objects */ public static <C extends RingElem<C>> FieldVector<CMFieldElement<C>> toCMFieldElementVector(GenVector<C> v) { if (v == null) { return null; } return new ArrayFieldVector<CMFieldElement<C>>(CMFieldElementUtil.<C> toCMFieldElement(v.val)); }