Product pfrom = (Product) from, pto = (Product) to; if (pfrom.sizeWithoutFactor() != pto.sizeWithoutFactor()) return IndexMappingProvider.Util.EMPTY_PROVIDER; Boolean booluon = compareFactors(pfrom.getFactor(), pto.getFactor()); if (booluon == null) return IndexMappingProvider.Util.EMPTY_PROVIDER; if (pfrom.getFactor().equals(pto.getFactor())) for (int i = 0; i < pfrom.sizeWithoutFactor(); ++i) if (pfrom.getWithoutFactor(i).hashCode() != pto.getWithoutFactor(i).hashCode()) return IndexMappingProvider.Util.EMPTY_PROVIDER; ProductContent fromContent = pfrom.getContent(), toContent = pto.getContent(); if (!fromContent.getStructureOfContractionsHashed().equals(toContent.getStructureOfContractionsHashed())) return IndexMappingProvider.Util.EMPTY_PROVIDER; Tensor[] fromScalars = pfrom.getAllScalarsWithoutFactor(), toScalars = pto.getAllScalarsWithoutFactor(); if (fromScalars.length != toScalars.length) return IndexMappingProvider.Util.EMPTY_PROVIDER;
@Override public Tensor transform(Tensor t) { if (!(t instanceof Product)) return t; Product p = (Product) t; if (p.indexlessLength() == 0) return t; Tensor indexless = p.getIndexlessSubProduct(); return Tensors.multiply(ExpandTransformation.expand(indexless), p.getDataSubProduct()); // boolean needExpandSums = false, needExpandPowers = false; // if (indexless instanceof Product) // for (Tensor i : indexless) { // if (i instanceof Sum) // needExpandSums = true; // if (isExpandablePower(i)) // needExpandPowers = true; // } // if (needExpandSums) // return Tensors.multiply(expandProductOfSums1(indexless, new Transformation[0], false), p.getDataSubProduct()); // return t; } };
public PrimitiveProductSubstitution(Tensor from, Tensor to) { super(from, to); Product product = (Product) from; this.fromFactor = product.getFactor(); this.fromIndexless = product.getIndexless(); this.fromContent = product.getContent(); this.fromData = fromContent.getDataCopy(); }
Product(Indices indices, Complex factor, Tensor[] indexless, Tensor[] data) { super(indices); this.factor = getDefaultReference(factor); this.indexlessData = indexless; this.data = data; Arrays.sort(data); Arrays.sort(indexless); this.contentReference = new SoftReferenceWrapper<>(); calculateContent(); this.hash = calculateHash(); }
int sizeOfIndexless = product.sizeOfIndexlessPart(); ProductContent productContent = product.getContent(); PrimitiveSubgraph[] subgraphs = PrimitiveSubgraphPartition.calculatePartition(productContent, matrixType); partition[i] = sizeOfIndexless + partition[i]; if (!isUnitaryMatrixOrOne(product.get(partition[i]), unitaryMatrix)) continue out; calculatedTraces.put(traceOfProduct(product.select(partition))); positionsOfMatrices.addAll(partition); c = product.remove(positionsOfMatrices.toArray()); c = multiply(c, calculatedTraces.build()); iterator.set(simplifications.transform(c));
@Override public Tensor set(int i, Tensor tensor) { if (i >= size() || i < 0) throw new IndexOutOfBoundsException(); Tensor old = get(i); if (old == tensor) return this; return this; if (tensor instanceof Complex) return setComplex(i, (Complex) tensor); int size = size(), j; if (TensorUtils.passOutDummies(tensor)) { TIntHashSet forbidden = new TIntHashSet(); for (j = 0; j < size; ++j) if (j != i) TensorUtils.appendAllIndicesNamesT(get(j), forbidden); tensor = ApplyIndexMapping.renameDummy(tensor, forbidden.toArray()); tensor = Tensors.negate(tensor); newFactor = factor.negate(); newFactor = getDefaultReference(newFactor); Tensor[] newIndexless = indexlessData.clone(); newIndexless[i] = tensor; return new Product(indices, newFactor, newIndexless, data, contentReference); } else { Tensor[] newData = data.clone(); newData[i - indexlessData.length] = tensor;
private Tensor expandDiracStructures(final Tensor t) { FromChildToParentIterator iterator = new FromChildToParentIterator(t); Tensor current; while ((current = iterator.next()) != null) { if (!(current instanceof Product)) continue; //early termination if (!containsGammaOr5Matrices(current)) continue; Product product = (Product) current; //positions of matrices PrimitiveSubgraph[] partition = PrimitiveSubgraphPartition.calculatePartition(product.getContent(), matrixType); //traces (expand brackets) boolean containsTraces = false; traces: for (PrimitiveSubgraph subgraph : partition) { if (subgraph.getGraphType() != GraphType.Cycle) continue traces; //expand each cycle containsTraces = true; } if (containsTraces) iterator.set(multiply(product.getIndexlessSubProduct(), expandAndEliminate.transform(product.getDataSubProduct()))); } return iterator.result(); }
final int differentIndicesCount = (getIndices().size() + freeIndices.size()) / 2; final short[] stretchIndices = calculateStretchIndices(); //for performance index = tInds.get(i); state = IndicesUtils.getStateInt(index); info[state][pointer[state]] = packToLong(tensorIndex, stretchIndices[tensorIndex], diffIds[i]); indices[state][pointer[state]++] = IndicesUtils.getNameWithType(index); infoToTensorIndices(upperInfo), infoToTensorIndices(lowerInfo), data.length + 1); nonScalar = data[0]; else nonScalar = new Product(this.indices, Complex.ONE, new Tensor[0], data, this.contentReference, 0); ((Product) nonScalar).hash = ((Product) nonScalar).calculateHash(); //TODO !!!discuss with Dima!!!
@Override Tensor newTo_(Tensor currentNode, SubstitutionIterator iterator) { Product product = (Product) currentNode; Complex factor = product.getFactor(); PContent content = new PContent(product.getIndexless(), product.getDataSubProduct()); //TODO getForbidden only if necessary!!!!!!!!!!!!!!!!! ForbiddenContainer forbidden = new ForbiddenContainer(); SubsResult subsResult = atomicSubstitute(content, forbidden, iterator); if (subsResult == null) return currentNode; List<Tensor> newTos = new ArrayList<>(); while (true) { if (subsResult == null) break; factor = factor.divide(fromFactor); newTos.add(subsResult.newTo); content = subsResult.remainder; subsResult = atomicSubstitute(content, forbidden, iterator); } Tensor[] result = new Tensor[newTos.size() + content.indexless.length + 2]; System.arraycopy(newTos.toArray(new Tensor[newTos.size()]), 0, result, 0, newTos.size()); System.arraycopy(content.indexless, 0, result, newTos.size(), content.indexless.length); result[result.length - 2] = content.data; result[result.length - 1] = factor; return Tensors.multiply(result); }
private static Mapping0 buildMapping(Tensor eps, Tensor part) { if (!(part instanceof Product)) return null; Product p = (Product) part; Complex factor = p.getFactor(); Mapping mapping = IndexMappings.getFirst(eps, p.getDataSubProduct()); if (mapping == null) return null; return new Mapping0(factor, mapping); }
private static Tensor inverseOrderInProduct(Product product, IndexType type) { ProductContent pc = product.getContent(); PrimitiveSubgraph[] subgraphs = PrimitiveSubgraphPartition.calculatePartition(pc, type); Tensor[] data = pc.getDataCopy(); return Tensors.multiply(product.getIndexlessSubProduct(), Tensors.multiply(data));
ProductContent content = product.getContent(); ns = new ArrayList<>(content.size()); ns.add(product.getIndexlessSubProduct()); sums = new ArrayList<>(content.size()); for (Tensor t : content) else ns.add(t); } else { ns = new ArrayList<>(product.size()); sums = new ArrayList<>(product.size()); for (Tensor t : product) if (ExpandUtils.sumContainsIndexed(t)) sums.add((Sum) t);
public It(int gamma, int gamma5, Product product, IndexType matrixType, Indicator<GraphType> filter) { this.gamma = gamma; this.gamma5 = gamma5; this.product = product; this.content = product.getContent(); this.matrixType = matrixType; this.partition = PrimitiveSubgraphPartition.calculatePartition(this.content, matrixType); this.filter = filter; }
assert t instanceof Product; if (t instanceof Product) { Tensor[] sc = ((Product) t).getAllScalarsWithoutFactor(); if (sc.length == 0) continue; rebuild.put(Tensors.multiply(((Product) t).getFactor(), newCoefficient, ((Product) t).getDataSubProduct()));
if (complex == Complex.ONE)//case a*b factor = tensor; else if (product.size() == 2)//case 2*a factor = product.get(1); else//case 2*a*b => factor = a*b factor = new Product(Complex.ONE, product.indexlessData, product.data, product.contentReference.getReferent(), product.indices); } else { complex = Complex.ONE; summand = new Sum(s.indices, sumData, s.hashCode()); } else summand = new Product(product.factor, product.indexlessData, new Tensor[0], ProductContent.EMPTY_INSTANCE, IndicesFactory.EMPTY_INDICES); factor = new Product(Complex.ONE, new Tensor[0], product.data, product.contentReference.getReferent(), product.indices); } else { summand = Complex.ONE;
void printData() { ArrayList<SubgraphContainer> subgraphs = new ArrayList<>(); for (IndexType type : matrixTypes) { PrimitiveSubgraph[] sgs = PrimitiveSubgraphPartition.calculatePartition(getContent(), type); out0: for (PrimitiveSubgraph sg : sgs) { newSg = false; matched.add(i); } else if (includes(partition, container.partition) && sg.getGraphType() == container.graphType) { else subgraphs.remove(i); } else if (intersects(points, container.points)) {
public static Tensor expandProductOfSums(Product product, Transformation[] transformations) { Tensor indexless = product.getIndexlessSubProduct(), data = product.getDataSubProduct(); boolean expandIndexless = false, expandData = false, containsIndexlessSumNeededExpand = false; if (indexless instanceof Sum && sumContainsIndexed(indexless)) {
if (tensor instanceof Product) { Product product = (Product) tensor; ProductContent pc = product.getContent(); if (pc.size() == 1) { int dataHash = _hashWithIndices(pc.get(0), indices); return product.getFactor().isOneOrMinusOne() ? dataHash : dataHash * product.getFactor().hashCode();
private static Monomial getFromProduct(Tensor t, SimpleTensor[] coefficients) { if (!(t instanceof Product)) return null; for (int j = 0; j < t.size(); j++) { if (!(t.get(j) instanceof SimpleTensor)) continue; for (int i = 0; i < coefficients.length; i++) if (t.get(j).equals(coefficients[i])) return new Monomial(((Product) t).remove(j), i); } return null; }