public SqrSubs(SimpleTensor st) { if (st.getIndices().size() != 1) throw new IllegalArgumentException(); name = st.getName(); }
@Override public String newName(String oldName, NameAndStructureOfIndices old) { switch (oldName) { case unitaryMatrixName: return unitaryMatrix.getStringName(); case structureConstantName: return structureConstant.getStringName(); case symmetricConstantName: return symmetricConstant.getStringName(); case dimensionName: if (!(dimension instanceof Complex)) return dimension.toString(OutputFormat.Redberry); default: return oldName; } } });
@Override public NameDescriptorForTensorField getNameDescriptor() { return (NameDescriptorForTensorField) super.getNameDescriptor(); }
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); }
private Var(SimpleTensor simpleTensor) { this.simpleTensor = simpleTensor; this.name = simpleTensor.getName(); }
public static ParseToken tensor2AST(Tensor tensor) { if (tensor instanceof TensorField) { TensorField tf = (TensorField) tensor; ParseToken[] content = new ParseToken[tf.size()]; int i = 0; for (Tensor t : tf) content[i++] = tensor2AST(t); return new ParseTokenTensorField(tf.getIndices(), tf.getStringName(), content, tf.getArgIndices()); } if (tensor instanceof SimpleTensor) { SimpleTensor st = (SimpleTensor) tensor; return new ParseTokenSimpleTensor(st.getIndices(), st.getStringName()); } if (tensor instanceof Complex) return new ParseTokenNumber((Complex) tensor); if (tensor instanceof Expression) return new ParseTokenExpression(false, tensor2AST(tensor.get(0)), tensor2AST(tensor.get(1))); ParseToken[] content = new ParseToken[tensor.size()]; int i = 0; for (Tensor t : tensor) content[i++] = tensor2AST(t); if (tensor instanceof ScalarFunction) return new ParseTokenScalarFunction(tensor.getClass().getSimpleName(), content); return new ParseToken(TokenType.valueOf(tensor.getClass().getSimpleName()), content); }
/** * Returns an instance of specified simple tensor with specified indices * * @param tensor simple tensor * @param indices indices * @return instance of specified simple tensor with specified indices */ public static SimpleTensor setIndices(SimpleTensor tensor, SimpleIndices indices) { if (tensor.getIndices() == indices) return tensor; NameDescriptor descriptor = tensor.getNameDescriptor(); if (!descriptor.getStructureOfIndices().isStructureOf(indices)) throw new IllegalArgumentException(String.format("Illegal structure of indices (tensor = %s, indices = %s).", tensor, indices)); if (indices.size() == 0) return tensor; if (descriptor.isField()) return new TensorField(tensor.name, UnsafeIndicesFactory.createOfTensor(descriptor.getSymmetries(), indices), ((TensorField) tensor).args, ((TensorField) tensor).argIndices); else return new SimpleTensor(tensor.name, UnsafeIndicesFactory.createOfTensor(descriptor.getSymmetries(), indices)); }
@Override public String toString(OutputFormat mode) { return toString(mode, null); }
@Override public String toString0(OutputFormat mode) { //TODO add argIndices toString(REDBERRY) StringBuilder sb = new StringBuilder(); sb.append(super.toString0(mode)); if (mode.is(OutputFormat.Maple)) sb.append('('); else sb.append('['); for (Tensor t : args) { sb.append(t.toString(mode)); sb.append(','); } sb.deleteCharAt(sb.length() - 1); if (mode.is(OutputFormat.Maple)) sb.append(')'); else sb.append(']'); return sb.toString(); }
/** * Returns new simple tensor with specified int name (see {@link cc.redberry.core.context.NameManager} * for details) and indices. * * @param name int name of the tensor * @param indices indices * @return new instance of {@link SimpleTensor} object */ public static SimpleTensor simpleTensor(int name, SimpleIndices indices) { NameDescriptor descriptor = CC.getNameDescriptor(name); if (descriptor == null) throw new IllegalArgumentException("This name is not registered in the system."); if (!descriptor.getStructureOfIndices().isStructureOf(indices)) throw new IllegalArgumentException("Specified indices ( " + indices + " )are not indices of specified tensor ( " + descriptor + " )."); if (indices.size() == 0) { assert indices == IndicesFactory.EMPTY_SIMPLE_INDICES; NameDescriptorForSimpleTensor nst = (NameDescriptorForSimpleTensor) descriptor; if (nst.getCachedSymbol() == null) { SimpleTensor st; nst.setCachedInstance(st = new SimpleTensor(descriptor.getId(), indices)); return st; } else return nst.getCachedSymbol(); } return new SimpleTensor(name, UnsafeIndicesFactory.createOfTensor(descriptor.getSymmetries(), indices)); }
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"); }
public SchoutenIdentities4(SimpleTensor leviCivita) { this.leviCivita = leviCivita; ChangeIndicesTypesAndTensorNames tokenTransformer = new ChangeIndicesTypesAndTensorNames(TypesAndNamesTransformer.Utils.and( TypesAndNamesTransformer.Utils.changeName(new String[]{"e"}, new String[]{leviCivita.getStringName()}), TypesAndNamesTransformer.Utils.changeType(IndexType.LatinLower, IndicesUtils.getTypeEnum(leviCivita.getIndices().get(0))))); this.schouten1 = new Tensor[schoutenCombinations1.length]; for (int i = 0; i < schouten1.length; i++) schouten1[i] = tokenTransformer.transform(CC.current().getParseManager().getParser().parse(schoutenCombinations1[i])).toTensor(); this.schouten2 = new Tensor[schoutenCombinations2.length]; for (int i = 0; i < schouten2.length; i++) schouten2[i] = tokenTransformer.transform(CC.current().getParseManager().getParser().parse(schoutenCombinations2[i])).toTensor(); this.schouten3 = new Tensor[schoutenCombinations3.length]; for (int i = 0; i < schouten3.length; i++) schouten3[i] = tokenTransformer.transform(CC.current().getParseManager().getParser().parse(schoutenCombinations3[i])).toTensor(); allSchouten = new Tensor[][]{schouten1, schouten2, schouten3}; }
@Override public String toString(OutputFormat f) { StringBuilder sb = new StringBuilder().append("Differentiate["); for (int i = 0; ; ++i) { sb.append(vars[i].toString(f)); if (i == vars.length) return sb.append("]").toString(); } }
&& !CC.isMetric(IndicesUtils.getType(indices.get(0)))) { String str = clazz == Sum.class ? "1" : ""; return indices.getFree().size() == 0 ? toString0(mode.printMatrixIndices()) : str; EnumSet<IndexType> matrixTypes = IndicesUtils.nonMetricTypes(indices); if (matrixTypes.isEmpty()) return toString0(mode); sb.append("Tr[").append(toString0(mode)); if (traces.size() != matrixTypes.size()) { sb.append(", "); return sb.toString(); } else return toString0(mode); } else return toString0(mode); return toString0(mode);
/** * Returns new simple tensor with specified string name and indices. * * @param name string name of the tensor * @param indices indices * @return new instance of {@link SimpleTensor} object */ public static SimpleTensor simpleTensor(String name, SimpleIndices indices) { NameDescriptor descriptor = CC.getNameManager().mapNameDescriptor(name, indices.getStructureOfIndices()); if (indices.size() == 0) { assert indices == IndicesFactory.EMPTY_SIMPLE_INDICES; NameDescriptorForSimpleTensor nst = (NameDescriptorForSimpleTensor) descriptor; if (nst.getCachedSymbol() == null) { SimpleTensor st; nst.setCachedInstance(st = new SimpleTensor(descriptor.getId(), indices)); return st; } else return nst.getCachedSymbol(); } return new SimpleTensor(descriptor.getId(), UnsafeIndicesFactory.createOfTensor(descriptor.getSymmetries(), indices)); }
/** * Returns {@code true} if specified tensor is a metric tensor * * @param t tensor * @return {@code true} if specified tensor is a metric tensor */ public boolean isMetric(SimpleTensor t) { return nameManager.isKroneckerOrMetric(t.getName()) && IndicesUtils.haveEqualStates(t.getIndices().get(0), t.getIndices().get(1)); }
protected static void checkNotation(SimpleTensor gammaMatrix, SimpleTensor gamma5Matrix, SimpleTensor leviCivita) { 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); if (gamma5Matrix != null && (gamma5Matrix.getIndices().size() != 2 || gamma5Matrix.getIndices().size(matrixType) != 2)) throw new IllegalArgumentException("Not a gamma5: " + gamma5Matrix); if (leviCivita != null && (leviCivita.getIndices().size() != 4 || leviCivita.getIndices().size(metricType) != 4)) throw new IllegalArgumentException("Not a Levi-Civita: " + leviCivita); }
private static boolean isLeviCivita(Tensor tensor, int leviCivitaName) { return tensor instanceof SimpleTensor && ((SimpleTensor) tensor).getName() == leviCivitaName; }
@Override public String newName(String oldName, NameAndStructureOfIndices old) { switch (oldName) { case unitaryMatrixName: return unitaryMatrix.getStringName(); case structureConstantName: return structureConstant.getStringName(); case symmetricConstantName: return symmetricConstant.getStringName(); case dimensionName: if (!(dimension instanceof Complex)) return dimension.toString(OutputFormat.Redberry); default: return oldName; } } });