@Override public boolean equals(Object obj) { if (obj == null) return false; if (getClass() != obj.getClass()) return false; final StructureOfIndices other = (StructureOfIndices) obj; if (size != other.size()) return false; if (size == 0) return true; return Arrays.equals(this.typesCounts, other.typesCounts) && Arrays.deepEquals(this.states, other.states); }
/** * Doing nothing */ @Override public void setSymmetries(IndicesSymmetries symmetries) { if (symmetries.getStructureOfIndices().size() != 0) throw new IllegalArgumentException("Symmetries dimensions are not equal to indices size."); }
/** * Returns positions of indices in the array of orbits of underlying permutation group. Specifically, this method * returns {@link cc.redberry.core.groups.permutations.PermutationGroup#getPositionsInOrbits()} converted to * {@code short[]}. This method returns same reference each time; so, if one will use the returned array, do not * forget to clone it, The invocation of this method makes this instance unmodifiable, i.e. invocation of method * {@code add(...)} after invocation of this method will cause exception. * * @return positions of indices in the array of orbits of underlying permutation group * @see cc.redberry.core.groups.permutations.PermutationGroup#getPositionsInOrbits() */ public short[] getPositionsInOrbits() { if (positionsInOrbits == null) { final int[] positionsInOrbitsInt = getPermutationGroup().getPositionsInOrbits(); positionsInOrbits = new short[structureOfIndices.size()]; int i = 0; for (; i < positionsInOrbitsInt.length; ++i) { assert positionsInOrbitsInt[i] < Short.MAX_VALUE; positionsInOrbits[i] = (short) positionsInOrbitsInt[i]; } for (; i < structureOfIndices.size(); ++i) positionsInOrbits[i] = (short) i; } return positionsInOrbits; }
@Override public IndicesSymmetries clone() { if (structureOfIndices.size() == 0) return getEmpty(); return new IndicesSymmetries(structureOfIndices, new ArrayList<>(generators), permutationGroup); }
/** * Creates symmetries of indices with specified structure and with specified generating set. * * @param structureOfIndices structure of indices for which this symmetries can be assigned * @param generators generating set * @return symmetries with specified generating set for indices with specified structure * @throws java.lang.IllegalArgumentException if some generator in {@code generators} have degree different from * size of {@code structureOfIndices} */ public static IndicesSymmetries create(StructureOfIndices structureOfIndices, List<Permutation> generators) { for (Permutation p : generators) if (p.degree() > structureOfIndices.size()) throw new IllegalArgumentException("Permutation degree not equal to indices size."); if (structureOfIndices.size() == 0) return getEmpty(); return new IndicesSymmetries(structureOfIndices, new ArrayList<>(generators), null); }
/** * Creates symmetries with empty generating set. * * @param structureOfIndices structure of indices for which this symmetries can be assigned * @return symmetries with empty generating set for indices with specified structure */ public static IndicesSymmetries create(StructureOfIndices structureOfIndices) { if (structureOfIndices.size() == 0) return getEmpty(); return new IndicesSymmetries(structureOfIndices); }
/** * Creates symmetries of indices with specified structure and with specified permutation group. * * @param structureOfIndices structure of indices for which this symmetries can be assigned * @param group permutation group * @return symmetries with specified permutation group for indices with specified structure * @throws java.lang.IllegalArgumentException if {@code group.degree() != structureOfIndices.size()} */ public static IndicesSymmetries create(StructureOfIndices structureOfIndices, PermutationGroup group) { if (group.degree() != structureOfIndices.size()) throw new IllegalArgumentException("Degree of permutation group not equal to indices size."); if (structureOfIndices.size() == 0) return getEmpty(); return new IndicesSymmetries(structureOfIndices, group.generators(), group); }
/** * Adds specified symmetry to symmetries of indices of specified type. * * @param type type of indices * @param symmetry symmetry * @throws java.lang.IllegalStateException if this instance of symmetries is already in use (permutation group * calculated) * @throws java.lang.IllegalArgumentException if this structure of indices is inconsistent with specified * permutation (permutation mixes indices of different types) */ public void addSymmetry(byte type, Permutation symmetry) { if (symmetry.isIdentity()) return; if (permutationGroup != null) throw new IllegalStateException("Permutation group is already in use."); StructureOfIndices.TypeData data = structureOfIndices.getTypeData(type); if (data == null) throw new IllegalArgumentException("No such type: " + IndexType.getType(type)); if (data.length < symmetry.degree()) throw new IllegalArgumentException("Wrong symmetry length."); int[] s = new int[structureOfIndices.size()]; int i = 0; for (; i < data.from; ++i) s[i] = i; for (int j = 0; j < data.length; ++j, ++i) s[i] = symmetry.newIndexOf(j) + data.from; for (; i < structureOfIndices.size(); ++i) s[i] = i; generators.add(Permutations.createPermutation(symmetry.antisymmetry(), s)); }
private void checkConsistency() { int i; for (i = 0; i < actualInput; ++i) { if (!(inputValues[i].get(0) instanceof SimpleTensor)) throw new IllegalArgumentException(); SimpleTensor st = (SimpleTensor) inputValues[i].get(0); NameDescriptor nd = CC.getNameDescriptor(st.getName()); if (!nd.getName(null).equals(getStringInputName(i))) throw new IllegalArgumentException(); } for (; i < INPUT_VALUES_GENERAL_COUNT; ++i) if (inputValues[i] != null) throw new IllegalArgumentException(); SimpleIndices indices = (SimpleIndices) inputValues[1].get(0).getIndices(); StructureOfIndices structureOfIndices = indices.getStructureOfIndices(); if (structureOfIndices.getTypeData(IndexType.LatinLower.getType()).length != structureOfIndices.size()) throw new IllegalArgumentException("Only Latin lower indices are legal."); int matrixIndicesCount = indices.size() - operatorOrder; if (matrixIndicesCount % 2 != 0) throw new IllegalArgumentException(); if (inputValues[0].get(0).getIndices().size() != matrixIndicesCount) throw new IllegalArgumentException(); for (i = 1; i < actualInput; ++i) { structureOfIndices = ((SimpleIndices) inputValues[i].get(0).getIndices()).getStructureOfIndices(); if (structureOfIndices.getTypeData(IndexType.LatinLower.getType()).length != structureOfIndices.size()) throw new IllegalArgumentException("Only Latin lower indices are legal."); if (structureOfIndices.size() + i - 1 != operatorOrder + matrixIndicesCount) throw new IllegalArgumentException(); } }
symmetries.addSymmetry(convertPermutation(p, mapping[0], baseStructure.size())); int cycle[]; for (i = 0; i < orders.length; ++i) { if (structuresOfIndices[i + 1].size() != 0 && orders[i] >= 2) { cycle = Permutations.createBlockCycle(structuresOfIndices[i + 1].size(), 2); aggregator.addAll(mapping[j]); aggregator.addAll(mapping[j + 1]); symmetries.addSymmetry( Permutations.createPermutation(convertPermutation(cycle, aggregator.toArray(), baseStructure.size()))); aggregator.addAll(mapping[j + k]); cycle = Permutations.createBlockCycle(structuresOfIndices[i + 1].size(), orders[i]); symmetries.addSymmetry( Permutations.createPermutation(convertPermutation(cycle, aggregator.toArray(), baseStructure.size())));
private void ensurePartitionInitialized() { if (indicesPartitionMapping != null) return; if (!isDerivative()) { int[][] ret = new int[structuresOfIndices.length][]; Arrays.fill(ret, 1, ret.length, new int[0]); ret[0] = ArraysUtils.getSeriesFrom0(structuresOfIndices[0].size()); indicesPartitionMapping = ret; } NameDescriptorForTensorField parent = getParent(); StructureOfIndices[] partition = new StructureOfIndices[ArraysUtils.sum(orders) + 1]; partition[0] = parent.getStructureOfIndices(); int i, j; int totalOrder = 1; for (i = 0; i < structuresOfIndices.length - 1; ++i) { for (j = orders[i] - 1; j >= 0; --j) partition[totalOrder++] = parent.getArgStructureOfIndices(i); } indicesPartitionMapping = structuresOfIndices[0].getPartitionMappings(partition); }
private NameDescriptor createDescriptor(final String sname, final StructureOfIndices[] structuresOfIndices, int id) { if (structuresOfIndices.length != 1) return new NameDescriptorForTensorFieldImpl(sname, structuresOfIndices, id, sname.equals(diracDeltaName) && structuresOfIndices.length == 3); final StructureOfIndices its = structuresOfIndices[0]; if (its.size() != 2) return new NameDescriptorForSimpleTensor(sname, structuresOfIndices, id); for (byte b = 0; b < IndexType.TYPES_COUNT; ++b) if (its.typeCount(b) == 2) { if (CC.isMetric(b)) { if (sname.equals(kroneckerAndMetricNames[0]) || sname.equals(kroneckerAndMetricNames[1])) { NameDescriptor descriptor = new NameDescriptorForMetricAndKronecker(kroneckerAndMetricNames, b, id); descriptor.getSymmetries().add(b, false, 1, 0); return descriptor; } } else { if (sname.equals(kroneckerAndMetricNames[1])) throw new ParserException("Metric is not specified for non metric index type."); if (sname.equals(kroneckerAndMetricNames[0])) { if (its.getTypeData(b).states.get(0) != true || its.getTypeData(b).states.get(1) != false) throw new ParserException("Illegal Kroneckers indices states."); NameDescriptor descriptor = new NameDescriptorForMetricAndKronecker(kroneckerAndMetricNames, b, id); return descriptor; } } } return new NameDescriptorForSimpleTensor(sname, structuresOfIndices, id); }
public int[] nextIndices(StructureOfIndices structureOfIndices) { int[] indices = new int[structureOfIndices.size()]; int[] typeInd; int p = 0; for (byte b : TYPES) { StructureOfIndices.TypeData typeData = structureOfIndices.getTypeData(b); if (typeData == null || typeData.length == 0) continue; typeInd = new int[typeData.length]; if (typeData.states != null) { //in the case of matrix indices int[] names = nextPermutation(typeInd.length); for (int i = 0; i < typeInd.length; ++i) typeInd[i] = IndicesUtils.createIndex(names[i], b, typeData.states.get(i)); } else { int i; int contracted = (contracted = nextInt(indices.length / 2)) == 0 ? 1 : contracted; for (i = 0; i < typeInd.length / contracted; ++i) typeInd[i] = IndicesUtils.setType(b, i); if (i - contracted < 0) contracted = i; for (; i < typeInd.length; ++i) typeInd[i] = IndicesUtils.createIndex(i - contracted, b, true); shuffle(typeInd); } System.arraycopy(typeInd, 0, indices, p, typeInd.length); p += typeInd.length; } return indices; }
Indices free = descriptor.getIndices().getFree(); StructureOfIndices its = IndicesFactory.createSimple(null, free).getStructureOfIndices(); int[] factorIndices = new int[its.size()]; int position = 0; for (byte b : TYPES) {