public void addInsertionRule(NameDescriptor nd, IndexType omittedIndexType) { NameAndStructureOfIndices originalStructureAndName = NameDescriptor.extractKey(nd); StructureOfIndices structure = nd.getStructureOfIndices(); if (structure.getTypeData(omittedIndexType.getType()).length == 0) throw new IllegalArgumentException("No indices of specified type in tensor."); if (CC.isMetric(omittedIndexType.getType())) { int omittedIndicesCount = structure.getTypeData(omittedIndexType.getType()).length; if ((omittedIndicesCount % 2) == 1) throw new IllegalArgumentException("The number of omitted indices for metric types should be even."); omittedIndicesCount /= 2; BitArray omittedIndices = structure.getTypeData(omittedIndexType.getType()).states; for (int i = 0, size = omittedIndices.size(); i < size; ++i) { if (i < omittedIndicesCount && !omittedIndices.get(i)) throw new IllegalArgumentException("Inconsistent states signature for metric type."); if (i >= omittedIndicesCount && omittedIndices.get(i)) throw new IllegalArgumentException("Inconsistent states signature for metric type."); } } mappedRules = null; InsertionRule rule = initialRules.get(originalStructureAndName); if (rule == null) initialRules.put(originalStructureAndName, rule = new InsertionRule(originalStructureAndName)); rule.indicesAllowedToOmit.add(omittedIndexType); }