/** * Returns string to directly paste into Java code. * * @return Java code for this permutation group */ public String toStringJava() { StringBuilder sb = new StringBuilder(); sb.append("PermutationGroup.createPermutationGroup( "); List<Permutation> gens = generators(); for (int i = 0; ; ++i) { String p = gens.get(i).toString().replace("[", "{").replace("]", "}").replace("+", "").replace("-", ""); if (gens.get(i).antisymmetry()) sb.append("Permutations.createPermutation(true, new int[][]").append(p).append(")"); else sb.append("Permutations.createPermutation(new int[][]").append(p).append(")"); if (i == gens.size() - 1) return sb.append(" )").toString(); sb.append(", "); } } }
synchronized private static Map<Permutation, Boolean> getEpsilonSymmetries(int indicesSize) { Map<Permutation, Boolean> symmetries = cachedLeviCivitaSymmetries.get(indicesSize); if (symmetries != null) return symmetries; symmetries = new HashMap<>(); PermutationGroup lc = PermutationGroup.antisymmetricGroup(indicesSize); for (Permutation symmetry : lc) symmetries.put(symmetry.toSymmetry(), symmetry.antisymmetry()); cachedLeviCivitaSymmetries.put(indicesSize, symmetries); return symmetries; }
static Permutation convertPermutation(Permutation permutation, int[] mapping, int newDimension) { return Permutations.createPermutation(permutation.antisymmetry(), convertPermutation(permutation.oneLine(), mapping, newDimension)); }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || !(o instanceof Permutation)) return false; Permutation that = (Permutation) o; if (antisymmetry != that.antisymmetry()) return false; if (internalDegree != that.degree()) return false; for (int i = 0; i < internalDegree; ++i) if (newIndexOf(i) != that.newIndexOf(i)) return false; return true; }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || !(o instanceof Permutation)) return false; Permutation that = (Permutation) o; if (antisymmetry != that.antisymmetry()) return false; if (internalDegree != that.degree()) return false; for (int i = 0; i < internalDegree; ++i) if (newIndexOf(i) != that.newIndexOf(i)) return false; return true; }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || !(o instanceof Permutation)) return false; Permutation that = (Permutation) o; if (antisymmetry != that.antisymmetry()) return false; if (internalDegree != that.degree()) return false; for (int i = 0; i < internalDegree; ++i) if (newIndexOf(i) != that.newIndexOf(i)) return false; return true; }
@Override public int compareTo(Permutation t) { final int max = Math.max(degree(), t.degree()); if (antisymmetry != t.antisymmetry()) return antisymmetry ? -1 : 1; for (int i = 0; i < max; ++i) if (newIndexOf(i) < t.newIndexOf(i)) return -1; else if (newIndexOf(i) > t.newIndexOf(i)) return 1; return 0; } }
@Override public int compareTo(Permutation t) { final int max = Math.max(degree(), t.degree()); if (antisymmetry != t.antisymmetry()) return antisymmetry ? -1 : 1; for (int i = 0; i < max; ++i) if (newIndexOf(i) < t.newIndexOf(i)) return -1; else if (newIndexOf(i) > t.newIndexOf(i)) return 1; return 0; } }
@Override public int compareTo(Permutation t) { final int max = Math.max(degree(), t.degree()); if (antisymmetry != t.antisymmetry()) return antisymmetry ? -1 : 1; for (int i = 0; i < max; ++i) if (newIndexOf(i) < t.newIndexOf(i)) return -1; else if (newIndexOf(i) > t.newIndexOf(i)) return 1; return 0; } }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || !(o instanceof Permutation)) return false; Permutation that = (Permutation) o; if (antisymmetry != that.antisymmetry()) return false; if (degree() != that.degree()) return false; for (int i = 0; i < degree(); ++i) if (newIndexOf(i) != that.newIndexOf(i)) return false; return true; }
@Override public int compareTo(Permutation t) { int c = Integer.compare(degree(), t.degree()); if (c != 0) return c; if (antisymmetry != t.antisymmetry()) return antisymmetry ? -1 : 1; for (int i = 0; i < degree(); ++i) if (newIndexOf(i) < t.newIndexOf(i)) return -1; else if (newIndexOf(i) > t.newIndexOf(i)) return 1; return 0; } }
@Override public Permutation composition(Permutation a, Permutation b, Permutation c) { if (this.isIdentity) return a.composition(b, c); if (a.isIdentity()) return composition(b, c); if (b.isIdentity()) return composition(a, c); if (c.isIdentity()) return composition(b, c); final int newLength = Math.max(c.degree(), Math.max( Math.max(degree(), a.degree()), b.degree())); final int[] result = new int[newLength]; int newInternalDegree = -1; boolean resultIsIdentity = true; for (int i = 0; i < newLength; ++i) { result[i] = c.newIndexOf(b.newIndexOf(a.newIndexOf(newIndexOf(i)))); resultIsIdentity &= result[i] == i; newInternalDegree = result[i] == i ? newInternalDegree : i; } try { return new PermutationOneLineInt(resultIsIdentity, antisymmetry ^ a.antisymmetry() ^ b.antisymmetry() ^ c.antisymmetry(), newInternalDegree + 1, result); } catch (InconsistentGeneratorsException ex) { throw new InconsistentGeneratorsException(this + " and " + a + " and " + b + " and " + c); } }
@Override public Permutation composition(Permutation a, Permutation b) { if (this.isIdentity) return a.composition(b); if (a.isIdentity()) return composition(b); if (b.isIdentity()) return composition(a); final int newLength = Math.max(Math.max(degree(), a.degree()), b.degree()); int newInternalDegree = -1; final int[] result = new int[newLength]; boolean resultIsIdentity = true; for (int i = 0; i < newLength; ++i) { result[i] = b.newIndexOf(a.newIndexOf(newIndexOf(i))); resultIsIdentity &= result[i] == i; newInternalDegree = result[i] == i ? newInternalDegree : i; } try { return new PermutationOneLineInt(resultIsIdentity, antisymmetry ^ a.antisymmetry() ^ b.antisymmetry(), newInternalDegree + 1, result); } catch (InconsistentGeneratorsException ex) { throw new InconsistentGeneratorsException(this + " and " + a + " and " + b); } }
@Override public Permutation composition(Permutation a, Permutation b, Permutation c) { if (this.isIdentity) return a.composition(b, c); if (a.isIdentity()) return composition(b, c); if (b.isIdentity()) return composition(a, c); if (c.isIdentity()) return composition(b, c); final int newLength = Math.max(c.degree(), Math.max( Math.max(degree(), a.degree()), b.degree())); if (newLength > Short.MAX_VALUE) return toIntRepresentation().composition(a, b, c); final short[] result = new short[newLength]; short newInternalDegree = -1; boolean resultIsIdentity = true; for (short i = 0; i < newLength; ++i) { result[i] = (short) c.newIndexOf(b.newIndexOf(a.newIndexOf(newIndexOf(i)))); resultIsIdentity &= result[i] == i; newInternalDegree = result[i] == i ? newInternalDegree : i; } try { return new PermutationOneLineShort(resultIsIdentity, antisymmetry ^ a.antisymmetry() ^ b.antisymmetry() ^ c.antisymmetry(), (short) (newInternalDegree + 1), result); } catch (InconsistentGeneratorsException ex) { throw new InconsistentGeneratorsException(this + " and " + a + " and " + b + " and " + c); } }
@Override public Permutation composition(final Permutation other) { if (this.isIdentity) return other; if (other.isIdentity()) return this; final int newLength = Math.max(degree(), other.degree()); int newInternalDegree = -1; final int[] result = new int[newLength]; boolean resultIsIdentity = true; for (int i = 0; i < newLength; ++i) { result[i] = other.newIndexOf(newIndexOf(i)); resultIsIdentity &= result[i] == i; newInternalDegree = result[i] == i ? newInternalDegree : i; } try { return new PermutationOneLineInt(resultIsIdentity, antisymmetry ^ other.antisymmetry(), newInternalDegree + 1, result); } catch (InconsistentGeneratorsException ex) { throw new InconsistentGeneratorsException(this + " and " + other); } }
@Override public Permutation composition(Permutation a, Permutation b, Permutation c) { if (this.isIdentity) return a.composition(b, c); if (a.isIdentity()) return composition(b, c); if (b.isIdentity()) return composition(a, c); if (c.isIdentity()) return composition(b, c); final int newLength = Math.max(c.degree(), Math.max( Math.max(degree(), a.degree()), b.degree())); if (newLength > Byte.MAX_VALUE) return toLargerRepresentation(newLength).composition(a, b, c); final byte[] result = new byte[newLength]; byte newInternalDegree = -1; boolean resultIsIdentity = true; for (byte i = 0; i < newLength; ++i) { result[i] = (byte) c.newIndexOf(b.newIndexOf(a.newIndexOf(newIndexOf(i)))); resultIsIdentity &= result[i] == i; newInternalDegree = result[i] == i ? newInternalDegree : i; } try { return new PermutationOneLineByte(resultIsIdentity, antisymmetry ^ a.antisymmetry() ^ b.antisymmetry() ^ c.antisymmetry(), (byte) (newInternalDegree + 1), result); } catch (InconsistentGeneratorsException ex) { throw new InconsistentGeneratorsException(this + " and " + a + " and " + b + " and " + c); } }
@Override public Permutation composition(Permutation a, Permutation b) { if (this.isIdentity) return a.composition(b); if (a.isIdentity()) return composition(b); if (b.isIdentity()) return composition(a); final int newLength = Math.max(Math.max(degree(), a.degree()), b.degree()); if (newLength > Short.MAX_VALUE) return toIntRepresentation().composition(a, b); short newInternalDegree = -1; final short[] result = new short[newLength]; boolean resultIsIdentity = true; for (short i = 0; i < newLength; ++i) { result[i] = (short) b.newIndexOf(a.newIndexOf(newIndexOf(i))); resultIsIdentity &= result[i] == i; newInternalDegree = result[i] == i ? newInternalDegree : i; } try { return new PermutationOneLineShort(resultIsIdentity, antisymmetry ^ a.antisymmetry() ^ b.antisymmetry(), (short) (newInternalDegree + 1), result); } catch (InconsistentGeneratorsException ex) { throw new InconsistentGeneratorsException(this + " and " + a + " and " + b); } }
@Override public Permutation composition(Permutation a, Permutation b) { if (this.isIdentity) return a.composition(b); if (a.isIdentity()) return composition(b); if (b.isIdentity()) return composition(a); final int newLength = Math.max(Math.max(degree(), a.degree()), b.degree()); if (newLength > Byte.MAX_VALUE) return toLargerRepresentation(newLength).composition(a, b); byte newInternalDegree = -1; final byte[] result = new byte[newLength]; boolean resultIsIdentity = true; for (byte i = 0; i < newLength; ++i) { result[i] = (byte) b.newIndexOf(a.newIndexOf(newIndexOf(i))); resultIsIdentity &= result[i] == i; newInternalDegree = result[i] == i ? newInternalDegree : i; } try { return new PermutationOneLineByte(resultIsIdentity, antisymmetry ^ a.antisymmetry() ^ b.antisymmetry(), (byte) (newInternalDegree + 1), result); } catch (InconsistentGeneratorsException ex) { throw new InconsistentGeneratorsException(this + " and " + a + " and " + b); } }
@Override public Permutation composition(final Permutation other) { if (this.isIdentity) return other; if (other.isIdentity()) return this; final int newLength = Math.max(degree(), other.degree()); if (newLength > Short.MAX_VALUE) return toIntRepresentation().composition(other); short newInternalDegree = -1; final short[] result = new short[newLength]; boolean resultIsIdentity = true; for (short i = 0; i < newLength; ++i) { result[i] = (short) other.newIndexOf(newIndexOf(i)); resultIsIdentity &= result[i] == i; newInternalDegree = result[i] == i ? newInternalDegree : i; } try { return new PermutationOneLineShort(resultIsIdentity, antisymmetry ^ other.antisymmetry(), (short) (newInternalDegree + 1), result); } catch (InconsistentGeneratorsException ex) { throw new InconsistentGeneratorsException(this + " and " + other); } }
@Override public Permutation composition(final Permutation other) { if (this.isIdentity) return other; if (other.isIdentity()) return this; final int newLength = Math.max(degree(), other.degree()); if (newLength > Byte.MAX_VALUE) return toLargerRepresentation(newLength).composition(other); byte newInternalDegree = -1; final byte[] result = new byte[newLength]; boolean resultIsIdentity = true; for (byte i = 0; i < newLength; ++i) { result[i] = (byte) other.newIndexOf(newIndexOf(i)); resultIsIdentity &= result[i] == i; newInternalDegree = result[i] == i ? newInternalDegree : i; } try { return new PermutationOneLineByte(resultIsIdentity, antisymmetry ^ other.antisymmetry(), (byte) (newInternalDegree + 1), result); } catch (InconsistentGeneratorsException ex) { throw new InconsistentGeneratorsException(this + " and " + other); } }