@Override public void apply(IndexMapper indexMapper, IGWrapper generator, int[] upper, int[] lower) { SimpleIndices oldIndices = node.indices; int[] _newIndices = new int[oldIndices.size() + 2 * upper.length]; int i; for (i = 0; i < oldIndices.size(); ++i) _newIndices[i] = indexMapper.map(oldIndices.get(i)); System.arraycopy(upper, 0, _newIndices, oldIndices.size(), upper.length); System.arraycopy(lower, 0, _newIndices, oldIndices.size() + upper.length, lower.length); for (i = 0; i < upper.length; ++i) _newIndices[i + oldIndices.size()] |= 0x80000000; node.indices = IndicesFactory.createSimple(null, _newIndices); } }
/** * Creates simple indices of simple tensor. * * @param symmetries symmetries * @param indices indices * @return simple indices of simple tensor */ public static SimpleIndices createOfTensor(IndicesSymmetries symmetries, SimpleIndices indices) { if (indices.size() == 0) return IndicesFactory.EMPTY_SIMPLE_INDICES; return new SimpleIndicesOfTensor(true, ((AbstractIndices) indices).data, symmetries); }
protected static void checkNotation(SimpleTensor gammaMatrix) { final IndexType[] types = TraceUtils.extractTypesFromMatrix(gammaMatrix); IndexType metricType = types[0]; IndexType matrixType = types[1]; if (gammaMatrix.getIndices().size() != 3 || gammaMatrix.getIndices().size(metricType) != 1 || gammaMatrix.getIndices().size(matrixType) != 2) throw new IllegalArgumentException("Not a gamma: " + gammaMatrix); }
public SqrSubs(SimpleTensor st) { if (st.getIndices().size() != 1) throw new IllegalArgumentException(); name = st.getName(); }
/** * Appends specified simple indices to this taking into account symmetries of passing indices. * * @param indices simple indices * @return this */ public SimpleIndicesBuilder append(SimpleIndices indices) { if (indices.size() == 0) return this; data.addAll(((AbstractSimpleIndices) indices).data); symmetries.add(new SymmetriesHolder(indices.size(), indices.getSymmetries().getGenerators())); return this; }
/** * Gives the multiple derivative of specified order of specified tensor with respect to specified simple tensor. * * @param tensor tensor to be differentiated * @param var simple tensor * @param order order of derivative * @param useDeltaFunction use Dirac deltas * @return derivative * @throws IllegalArgumentException if both order is not one and var is not scalar. */ public static Tensor differentiate(Tensor tensor, SimpleTensor var, int order, boolean useDeltaFunction) { if (var.getIndices().size() != 0 && order > 1) throw new IllegalArgumentException(); for (; order > 0; --order) tensor = differentiate(tensor, new Transformation[0], var, useDeltaFunction); return tensor; }
/** * Returns {@code true} if this is structure of specified indices. * * @param indices indices * @return {@code true} if this is structure of specified indices */ public boolean isStructureOf(SimpleIndices indices) { if (size != indices.size()) return false; return equals(indices.getStructureOfIndices()); }
private static void checkLeviCivita(SimpleTensor LeviCivita) { SimpleIndices indices = LeviCivita.getIndices(); if (indices.size() <= 1) throw new IllegalArgumentException("Levi-Civita cannot be a scalar."); byte type = getType(indices.get(0)); for (int i = 1; i < indices.size(); ++i) if (type != getType(indices.get(i))) throw new IllegalArgumentException("Levi-Civita have indices with different types."); } }
/** * Returns the structure of specified simple indices. * * @param indices simple indices */ public static StructureOfIndices create(SimpleIndices indices) { if (indices.size() == 0) return getEmpty(); return new StructureOfIndices(indices); }
String toString0(OutputFormat mode) { //Initializing StringBuilder StringBuilder sb = new StringBuilder(); sb.append(CC.getNameDescriptor(name).getName(indices, mode)); //If there are no indices return builder content if (indices.size() == 0) return sb.toString(); //Writing indices boolean external = mode.is(OutputFormat.WolframMathematica) || mode.is(OutputFormat.Maple); if (external) sb.append("["); sb.append(indices.toString(mode)); if (external) sb.append("]"); return sb.toString(); }
public IndicesInsertion(SimpleIndices upper, SimpleIndices lower, Indicator<ParseTokenSimpleTensor> indicator) { checkIndices(upper, lower); int[] upperArray = new int[upper.size()]; for (int i = upper.size() - 1; i >= 0; --i) upperArray[i] = IndicesUtils.getNameWithType(upper.get(i)); this.upper = upperArray; this.lower = lower.getAllIndices().copy(); this.indicator = indicator; }
private static void check(IndexType type, SimpleTensor momentum) { if (momentum.getIndices().size() != 1) throw new IllegalArgumentException("Not a momentum: " + momentum); if (type != null && type != getTypeEnum(momentum.getIndices().get(0))) throw new IllegalArgumentException("Not a momentum: " + momentum + " wrong index type"); }
private void checkSpinorNotation(SimpleTensor spinor, boolean bar) { if (spinor == null) return; SimpleIndices m = spinor.getIndices().getOfType(matrixType); if (m.size() != 1 || bar == getState(m.get(0))) throw new IllegalArgumentException("Illegal notation for spinor " + spinor); }
private static SimpleTensorDifferentiationRule createRule(SimpleTensor var, boolean useDeltaFunction) { if (var.getIndices().size() == 0) return new SymbolicDifferentiationRule(var, useDeltaFunction); return new SymmetricDifferentiationRule(var, useDeltaFunction); }
private static void checkIndices(SimpleIndices upper, SimpleIndices lower) { if (upper.size() != lower.size()) throw new IllegalArgumentException("Upper indices size not equal to lower indices size."); int size = upper.size(); for (int i = 0; i < size; ++i) { if (!IndicesUtils.getState(upper.get(i)) || IndicesUtils.getState(lower.get(i))) throw new IllegalArgumentException(); if (IndicesUtils.getType(upper.get(i)) != IndicesUtils.getType(lower.get(i))) throw new IllegalArgumentException(); if (i != 0) if (IndicesUtils.getType(upper.get(i - 1)) != IndicesUtils.getType(upper.get(i))) throw new IllegalArgumentException("Many types."); } }
private SimpleIndices transformIndices(SimpleIndices old, NameAndStructureOfIndices oldDescriptor) { int[] newIndices = new int[old.size()]; for (int i = old.size() - 1; i >= 0; --i) { newIndices[i] = IndicesUtils.setType(transformer.newType(IndicesUtils.getTypeEnum(old.get(i)), oldDescriptor), old.get(i)); newIndices[i] = transformer.newIndex(newIndices[i], oldDescriptor); } return IndicesFactory.createSimple(null, newIndices); } }
private SimpleTensor setMatrixIndices0(SimpleTensor tensor, int... indices) { int[] newIndices = new int[tensor.getIndices().size()]; int j = 0; for (int i = 0; i < tensor.getIndices().size(); ++i) if (getType(tensor.getIndices().get(i)) == matrixType.getType()) newIndices[i] = indices[j++]; else newIndices[i] = tensor.getIndices().get(i); return setIndices(tensor, createSimple(null, newIndices)); }
/** * Makes simple tensor symmetric with respect to indices of specified type. * * @param tensor simple tensor * @param type type of indices * @throws java.lang.IllegalStateException if this tensor is already in use (it's permutation group calculated) */ public static void setSymmetric(SimpleTensor tensor, IndexType type) { int dimension = tensor.getIndices().size(type); tensor.getIndices().getSymmetries().addSymmetry(type, Permutations.createCycle(dimension)); tensor.getIndices().getSymmetries().addSymmetry(type, Permutations.createTransposition(dimension)); }
/** * Makes simple tensor antisymmetric with respect to indices of specified type. * * @param tensor simple tensor * @param type type of indices * @throws java.lang.IllegalStateException if this tensor is already in use (it's permutation group calculated) */ public static void setAntiSymmetric(SimpleTensor tensor, IndexType type) { int dimension = tensor.getIndices().size(type); addSymmetry(tensor, type, true, Permutations.createTransposition(dimension)); if (dimension > 2) tensor.getIndices().getSymmetries().addSymmetry(type.getType(), Permutations.createPermutation(dimension % 2 == 0 ? true : false, Permutations.createCycle(dimension))); }
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); }