return null; String argStr = parts[1].substring(0, parts[1].length() - 1); if (!ParseUtils.checkBracketsConsistence(argStr)) return null;
public static Set<Integer> getAllIndices(ParseToken node) { Set<Integer> s = new HashSet<>(); getAllIndices1(node, s); return s; }
public static TIntSet getAllIndicesT(ParseToken node) { TIntSet set = new TIntHashSet(); getAllIndicesT1(node, set); return set; }
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); }
throw new IllegalArgumentException("Inconsistent indices."); Set<Integer> dummyIndices = ParseUtils.getAllIndices(node);
@Override public ParseToken transform(ParseToken node) { ensureMappedRulesInitialized(); int[] forbidden = ParseUtils.getAllIndicesT(node).toArray(); IndexGeneratorImpl generator = new IndexGeneratorImpl(forbidden); transformInsideFieldsAndScalarFunctions(node); ParseToken wrapped = new ParseToken(TokenType.Dummy, node); IITransformer transformer = createTransformer(wrapped); node = wrapped.content[0]; node.parent = null; if (transformer == null) return node; OuterIndices outerIndices = transformer.getOuterIndices(); int[][] upper = new int[TYPES_COUNT][], lower = new int[TYPES_COUNT][]; int j; for (byte i = 0; i < TYPES_COUNT; ++i) { upper[i] = new int[outerIndices.upper[i]]; for (j = 0; j < upper[i].length; ++j) upper[i][j] = 0x80000000 | generator.generate(i); lower[i] = new int[outerIndices.lower[i]]; for (j = 0; j < lower[i].length; ++j) lower[i][j] = generator.generate(i); } transformer.apply(generator, upper, lower); return node; }
substitutionToken = ParseUtils.tensor2AST(substitution); cachedLeviCivitaSelfContractions.put(numberOfIndices, substitutionToken);
private static void getAllIndices1(ParseToken node, Set<Integer> set) { if (node instanceof ParseTokenSimpleTensor) { Indices indices = node.getIndices(); for (int i = indices.size() - 1; i >= 0; --i) set.add(IndicesUtils.getNameWithType(indices.get(i))); } else for (ParseToken pn : node.content) if (!(pn instanceof ParseTokenScalarFunction)) getAllIndices1(pn, set); }
private static void getAllIndicesT1(ParseToken node, TIntSet set) { if (node instanceof ParseTokenSimpleTensor) { Indices indices = node.getIndices(); for (int i = indices.size() - 1; i >= 0; --i) set.add(IndicesUtils.getNameWithType(indices.get(i))); } else for (ParseToken pn : node.content) if (!(pn instanceof ParseTokenScalarFunction)) getAllIndicesT1(pn, set); } }