@Test public void testPow() { for (int i = -5; i <= 5; i++) { try { assertTrue("simple_pow error: wrong_result: " + i + " : " + Arrays.deepToString(simple_pow_results.get(i)) + " vs " + simple.power(state, Rational.valueOf(i)), deepEqualsCorrected(simple_pow_results.get(i), getBase((SetlMatrix) simple.power(state, Rational.valueOf(i))).getArray())); } catch (SetlException ex) { System.err.println(ex.getMessage()); fail("simple_pow error: exception"); } } try { sns.power(state, sdi.get(0)); fail("pow missing_error"); } catch (IncompatibleTypeException ex) { assertTrue("pow wrong_error: " + ex.getMessage(), ex.getMessage().equals("Power is only defined on square matrices.")); } catch (SetlException ex) { System.err.println(ex.getMessage()); fail("pow wrong_error: exception"); } }
@Override public Value power(final State state, final Value exponent) throws SetlException { if(!this.isSquare()) { throw new IncompatibleTypeException("Power is only defined on square matrices."); } if(exponent.jIntConvertible()) { int ex = exponent.toJIntValue(state); if(ex == 0) { Jama.Matrix base = new Jama.Matrix(this.matrix.getRowDimension(), this.matrix.getRowDimension()); for(int i = 0; i < this.matrix.getRowDimension(); i++) { base.set(i, i, 1); } return new SetlMatrix(base); } Jama.Matrix base; if (ex < 0) { base = this.inverse().matrix; ex = -ex; } else { base = this.matrix; } Jama.Matrix result = base; for (int i = 1; i < ex; i++) { result = result.times(base); } return new SetlMatrix(result); } else { throw new IncompatibleTypeException("Power on matrices is only defined for integer exponents."); } }
SetlMatrix extends IndexedCollectionValue { @Override public Value power(final State state, final Value exponent) throws SetlException { if(!this.isSquare()) { throw new IncompatibleTypeException("Power is only defined on square matrices."); } if(exponent.jIntConvertible()) { int ex = exponent.toJIntValue(state); if(ex == 0) { Jama.Matrix base = new Jama.Matrix(this.matrix.getRowDimension(), this.matrix.getRowDimension()); for(int i = 0; i < this.matrix.getRowDimension(); i++) { base.set(i, i, 1); } return new SetlMatrix(base); } Jama.Matrix base; if (ex < 0) { base = this.inverse().matrix; ex = -ex; } else { base = this.matrix; } Jama.Matrix result = base; for (int i = 1; i < ex; i++) { result = result.times(base); } return new SetlMatrix(result); } else { throw new IncompatibleTypeException("Power on matrices is only defined for integer exponents."); } } }
SetlMatrix extends IndexedCollectionValue { @Override public Value power(final State state, final Value exponent) throws SetlException { if(!this.isSquare()) { throw new IncompatibleTypeException("Power is only defined on square matrices."); } if(exponent.jIntConvertible()) { int ex = exponent.toJIntValue(state); if(ex == 0) { Jama.Matrix base = new Jama.Matrix(this.matrix.getRowDimension(), this.matrix.getRowDimension()); for(int i = 0; i < this.matrix.getRowDimension(); i++) { base.set(i, i, 1); } return new SetlMatrix(base); } Jama.Matrix base; if (ex < 0) { base = this.inverse().matrix; ex = -ex; } else { base = this.matrix; } Jama.Matrix result = base; for (int i = 1; i < ex; i++) { result = result.times(base); } return new SetlMatrix(result); } else { throw new IncompatibleTypeException("Power on matrices is only defined for integer exponents."); } } SetlMatrix(Jama.Matrix v);  SetlMatrix(final State state, final List<SetlVector> vectors);  SetlMatrix(final State state, final CollectionValue init);  SetlMatrix(final State state, final SetlVector vector); }
SetlMatrix extends IndexedCollectionValue { @Override public Value power(final State state, final Value exponent) throws SetlException { if(!this.isSquare()) { throw new IncompatibleTypeException("Power is only defined on square matrices."); } if(exponent.jIntConvertible()) { int ex = exponent.toJIntValue(state); if(ex == 0) { Jama.Matrix base = new Jama.Matrix(this.matrix.getRowDimension(), this.matrix.getRowDimension()); for(int i = 0; i < this.matrix.getRowDimension(); i++) { base.set(i, i, 1); } return new SetlMatrix(base); } Jama.Matrix base; if (ex < 0) { base = this.inverse().matrix; ex = -ex; } else { base = this.matrix; } Jama.Matrix result = base; for (int i = 1; i < ex; i++) { result = result.times(base); } return new SetlMatrix(result); } else { throw new IncompatibleTypeException("Power on matrices is only defined for integer exponents."); } } SetlMatrix(Jama.Matrix v);  SetlMatrix(final State state, final List<SetlVector> vectors);  SetlMatrix(final State state, final CollectionValue init);  SetlMatrix(final State state, final SetlVector vector); @Override Value clone(); @Override Iterator<Value> iterator(); @Override Iterator<Value> descendingIterator(); @Override SetlBoolean isMatrix(); SetlVector toVector(); @Override Value difference(final State state, final Value subtrahend); @Override Value differenceAssign(final State state, final Value subtrahend); @Override Value factorial(final State state); @Override Value power(final State state, final Value exponent); @Override Value product(final State state, final Value multiplier); @Override Value productAssign(final State state, final Value multiplier); @Override Value sum(final State state, final Value summand); @Override Value sumAssign(final State state, final Value summand); @Override void addMember(State state, Value element); @Override SetlBoolean containsMember(State state, Value element); @Override Value firstMember(); @Override Value getMember(int index); @Override Value getMember(State state, Value index); @Override Value getMembers(final State state, final int expectedNumberOfMembers, final int lowFromStart, final int highFromStart); @Override Value lastMember(); @Override Value maximumMember(State state); @Override Value minimumMember(State state); @Override Value removeFirstMember(); @Override Value removeLastMember(); @Override void removeMember(State state, Value element); @Override void setMember(final State state, final Value index, final Value value); @Override void setMember(final State state, int index, final Value value); @Override int size(); SetlDouble condition(); SetlDouble determinant(); SetlList eigenVectors(State state); SetlMatrix hadamardProduct(State state, Value other); SetlList eigenValues(State state); SetlMatrix pseudoInverse(); SetlList singularValueDecomposition(State state); Value solve(SetlMatrix other); @Override void appendString(final State state, final StringBuilder sb, final int tabs); @Override void canonical(final State state, final StringBuilder sb); @Override MatchResult matchesTerm(State state, Value other); @Override int compareTo(CodeFragment other); @Override long compareToOrdering(); @Override boolean equalTo(Object other); @Override int hashCode(); }
SetlMatrix extends IndexedCollectionValue { @Override public Value power(final State state, final Value exponent) throws SetlException { if(!this.isSquare()) { throw new IncompatibleTypeException("Power is only defined on square matrices."); } if(exponent.jIntConvertible()) { int ex = exponent.toJIntValue(state); if(ex == 0) { Jama.Matrix base = new Jama.Matrix(this.matrix.getRowDimension(), this.matrix.getRowDimension()); for(int i = 0; i < this.matrix.getRowDimension(); i++) { base.set(i, i, 1); } return new SetlMatrix(base); } Jama.Matrix base; if (ex < 0) { base = this.inverse().matrix; ex = -ex; } else { base = this.matrix; } Jama.Matrix result = base; for (int i = 1; i < ex; i++) { result = result.times(base); } return new SetlMatrix(result); } else { throw new IncompatibleTypeException("Power on matrices is only defined for integer exponents."); } } SetlMatrix(Jama.Matrix v);  SetlMatrix(final State state, final List<SetlVector> vectors);  SetlMatrix(final State state, final CollectionValue init);  SetlMatrix(final State state, final SetlVector vector); @Override Value clone(); @Override Iterator<Value> iterator(); @Override Iterator<Value> descendingIterator(); @Override SetlBoolean isMatrix(); SetlVector toVector(); @Override Value difference(final State state, final Value subtrahend); @Override Value differenceAssign(final State state, final Value subtrahend); @Override Value factorial(final State state); @Override Value power(final State state, final Value exponent); @Override Value product(final State state, final Value multiplier); @Override Value productAssign(final State state, final Value multiplier); @Override Value sum(final State state, final Value summand); @Override Value sumAssign(final State state, final Value summand); @Override void addMember(State state, Value element); @Override SetlBoolean containsMember(State state, Value element); @Override Value firstMember(); @Override Value getMember(int index); @Override Value getMember(State state, Value index); @Override Value getMembers(final State state, final int expectedNumberOfMembers, final int lowFromStart, final int highFromStart); @Override Value lastMember(); @Override Value maximumMember(State state); @Override Value minimumMember(State state); @Override Value removeFirstMember(); @Override Value removeLastMember(); @Override void removeMember(State state, Value element); @Override void setMember(final State state, final Value index, final Value value); @Override void setMember(final State state, int index, final Value value); @Override int size(); SetlDouble condition(); SetlDouble determinant(); SetlList eigenVectors(State state); SetlMatrix hadamardProduct(State state, Value other); SetlList eigenValues(State state); SetlMatrix pseudoInverse(); SetlList singularValueDecomposition(State state); Value solve(SetlMatrix other); @Override void appendString(final State state, final StringBuilder sb, final int tabs); @Override void canonical(final State state, final StringBuilder sb); @Override MatchResult matchesTerm(State state, Value other); @Override int compareTo(CodeFragment other); @Override long compareToOrdering(); @Override boolean equalTo(Object other); @Override int hashCode();  }