/** * Creates with generator with specified engaged data. * * @param indices forbidden indices */ public IndexGeneratorImpl(Indices indices) { this(indices.getAllIndices().copy()); }
/** * Appends specified {@code Indices}. * * @param indices indices to be appended * @return a reference to this object */ public IndicesBuilder append(Indices indices) { return append(indices.getAllIndices()); }
private Mapper(Indices fromSubIndices, Indices toSubIndices) { from = fromSubIndices.getAllIndices().copy(); to = toSubIndices.getAllIndices().copy(); ArraysUtils.quickSort(from, to); }
private static void checkConsistent(Tensor tensor, final int[] from) { int[] freeIndices = tensor.getIndices().getFree().getAllIndices().copy(); Arrays.sort(freeIndices); if (!Arrays.equals(freeIndices, from)) throw new IllegalArgumentException("From indices are not equal to free indices of tensor."); }
private static Tensor setIndices(Tensor t, Indices from, Indices to) { return ApplyIndexMapping.applyIndexMapping(t, new Mapping(from.getAllIndices().copy(), to.getAllIndices().copy()), new int[0]); }
public static int hashWithIndices(final Tensor tensor, final Indices indices) { return hashWithIndices(tensor, indices.getAllIndices().copy()); }
/** * This method returns array of integers representing set of indices names * present in the {@link Indices} object. * * @param indices object to process * @return see description */ public static int[] getSortedDistinctIndicesNames(Indices indices) { int[] indsArray = indices.getAllIndices().copy(); for (int i = 0; i < indsArray.length; ++i) indsArray[i] = IndicesUtils.getNameWithType(indsArray[i]); return MathUtils.getSortedDistinct(indsArray); }
/** * Creates unordered indices from specified {@code Indices} object. The resulting indices * will contain exactly the same indices as specified {@code Indices} object, by may have different * terms of ordering, in case when the specified indices are {@link SimpleIndices}. * * @param indices {@code Indices} object * @return unordered indices created from specified {@code Indices} object */ public static Indices create(Indices indices) { if (indices.size() == 0) return EMPTY_INDICES; if (indices instanceof SortedIndices) return indices; return new SortedIndices(indices.getAllIndices().copy()); }
/** * Creates simple indices from specified {@link Indices} object and with specified symmetries. * * @param symmetries symmetries of indices * @param indices {@link Indices} object * @return simple indices */ public static SimpleIndices createSimple(IndicesSymmetries symmetries, Indices indices) { if (indices.size() == 0) return EmptySimpleIndices.EMPTY_SIMPLE_INDICES_INSTANCE; if (indices instanceof AbstractSimpleIndices) return new SimpleIndicesIsolated(((AbstractSimpleIndices) indices).data, symmetries); return new SimpleIndicesIsolated(indices.getAllIndices().copy(), symmetries); }
private Tensor __newTo(DFromTo fromTo, TensorField currentField, Tensor currentNode, SubstitutionIterator iterator) { TensorField from = fromTo.from; Mapping mapping = IndexMappings.simpleTensorsPort(from, currentField).take(); if (mapping == null) return currentNode; Indices[] fromIndices = from.getArgIndices(), currentIndices = currentField.getArgIndices(); List<Tensor> argFrom = new ArrayList<>(), argTo = new ArrayList<>(); Tensor fArg; int[] cIndices, fIndices; int i; for (i = from.size() - 1; i >= 0; --i) { if (IndexMappings.positiveMappingExists(currentNode.get(i), from.get(i))) continue; fIndices = fromIndices[i].getAllIndices().copy(); cIndices = currentIndices[i].getAllIndices().copy(); assert cIndices.length == fIndices.length; fArg = ApplyIndexMapping.applyIndexMapping(from.get(i), new Mapping(fIndices, cIndices), new int[0]); argFrom.add(fArg); argTo.add(currentNode.get(i)); } Tensor newTo = fromTo.to; newTo = new SubstitutionTransformation( argFrom.toArray(new Tensor[argFrom.size()]), argTo.toArray(new Tensor[argTo.size()]), false).transform(newTo); return applyIndexMappingToTo(currentNode, newTo, mapping, iterator); }
@Override public ParseToken transform(ParseToken node) { final int[] freeIndices = node.getIndices().getFree().getAllIndices().copy(); int i; for (i = 0; i < freeIndices.length; ++i)
public static Tensor[] allStatesCombinations(Tensor st) { int[] indicesArray = indices.getAllIndices().copy();
/** * Returns {@code true} if tensor u mathematically (not programming) equals to tensor v, * {@code false} if they they differ only in the sign and {@code null} otherwise. * * @param u tensor * @param v tensor * @return {@code true} {@code false} if tensor u mathematically (not programming) equals to tensor v, * {@code true} if they they differ only in the sign and {@code null} otherwise */ public static Boolean compare1(Tensor u, Tensor v) { Indices freeIndices = u.getIndices().getFree(); if (!freeIndices.equalsRegardlessOrder(v.getIndices().getFree())) return null; int[] free = freeIndices.getAllIndices().copy(); IndexMappingBuffer tester = new IndexMappingBufferTester(free, false); IndexMappingBuffer buffer = IndexMappings.createPortOfBuffers(tester, u, v).take(); if (buffer == null) return null; return buffer.getSign(); }
/** * Returns {@code true} if tensor u mathematically (not programming) equals to tensor v. * * @param u tensor * @param v tensor * @return {@code true} if specified tensors are mathematically (not programming) equal */ public static boolean equals(Tensor u, Tensor v) { if (u == v) return true; Indices freeIndices = u.getIndices().getFree(); if (!freeIndices.equalsRegardlessOrder(v.getIndices().getFree())) return false; int[] free = freeIndices.getAllIndices().copy(); IndexMappingBuffer tester = new IndexMappingBufferTester(free, false); OutputPort<IndexMappingBuffer> mp = IndexMappings.createPortOfBuffers(tester, u, v); IndexMappingBuffer buffer; while ((buffer = mp.take()) != null) if (!buffer.getSign()) return true; return false; }
Tensor result = average(ib.getIndices().getAllIndices().copy()); long factor = ArithmeticUtils.pow((long) 2, count) * ArithmeticUtils.factorial(count + 1);//may be BigInteger? Complex number = new Complex((long) factor).reciprocal();
private void transformInsideFieldsAndScalarFunctions(ParseToken pn) { if (pn.tokenType == TokenType.TensorField) { ParseTokenTensorField pntf = (ParseTokenTensorField) pn; for (int i = 0; i < pn.content.length; ++i) { ParseToken newArgNode = transform(pntf.content[i]); pntf.content[i] = newArgNode; newArgNode.parent = pntf; SimpleIndices oldArgIndices = pntf.argumentsIndices[i]; if (oldArgIndices != null) { IntArrayList newArgIndices = new IntArrayList(oldArgIndices.getAllIndices().copy()); Indices newIndices = newArgNode.getIndices(); for (byte j = 0; j < TYPES_COUNT; ++j) { if (oldArgIndices.size(IndexType.getType(j)) < newIndices.size(IndexType.getType(j))) { if (oldArgIndices.size(IndexType.getType(j)) != 0) throw new IllegalArgumentException("Error in field arg indices."); newArgIndices.addAll(newIndices.getOfType(IndexType.getType(j)).getAllIndices()); } } pntf.argumentsIndices[i] = IndicesFactory.createSimple(null, newArgIndices.toArray()); } } } if (pn.tokenType == TokenType.Power || pn.tokenType == TokenType.ScalarFunction) { for (int i = 0; i < pn.content.length; ++i) pn.content[i] = transform(pn.content[i]); } for (int i = 0; i < pn.content.length; ++i) transformInsideFieldsAndScalarFunctions(pn.content[i]); }
sortedFreeIndices = indices.getAllIndices().copy(); Arrays.sort(sortedFreeIndices); } else if (!indices.equalsRegardlessOrder(tensor.getIndices().getFree()))
public static Tensor symmetrizeUpperLowerIndices(Tensor tensor, boolean multiplyOnSymmetryFactor) { Indices indices = IndicesFactory.create(tensor.getIndices().getFree()); int[] indicesArray = indices.getAllIndices().copy(); List<Permutation> symmetries = TensorUtils.getIndicesSymmetriesForIndicesWithSameStates(indicesArray, tensor); int lowerCount = indices.getLower().size(), upperCount = indices.getUpper().size();
private static Tensor differentiate(Tensor tensor, Transformation[] expandAndContract, SimpleTensor var, boolean useDeltaFunction) { if (var.getIndices().size() != 0) { TIntHashSet allTensorIndices = TensorUtils.getAllIndicesNamesT(tensor); TIntHashSet dummyTensorIndices = new TIntHashSet(allTensorIndices); dummyTensorIndices.removeAll(tensor.getIndices().getFree().getAllIndices().copy()); if (containsIndicesNames(allTensorIndices, var.getIndices().getNamesOfDummies()) || containsIndicesNames(dummyTensorIndices, var.getIndices())) { allTensorIndices.addAll(IndicesUtils.getIndicesNames(var.getIndices())); var = (SimpleTensor) renameDummy(var, TensorUtils.getAllIndicesNamesT(tensor).toArray()); tensor = renameDummy(tensor, TensorUtils.getAllIndicesNamesT(var).toArray(), allTensorIndices); } else allTensorIndices.addAll(IndicesUtils.getIndicesNames(var.getIndices())); tensor = renameIndicesOfFieldsArguments(tensor, allTensorIndices); } return differentiate1(tensor, createRule(var, useDeltaFunction), expandAndContract); }
TIntHashSet allTensorIndices = TensorUtils.getAllIndicesNamesT(tensor); TIntHashSet dummyTensorIndices = new TIntHashSet(allTensorIndices); dummyTensorIndices.removeAll(tensor.getIndices().getFree().getAllIndices().copy());