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(); }
@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); }
Tensor[] indexlessFrom = from.getIndexless(), indexlessTo = to.getIndexless();
Tensor[] indexless = product.getIndexless(), newIndexless = null; Tensor[] data = product.data, newData = null;
Tensor[] indexless = product.getIndexless(), newIndexless = null; Tensor[] data = product.data, newData = null;