/** * Subtracts {@code b} from {@code a} * * @param a tensor * @param b tensor * @return {@code a} - {@code b} * @throws TensorException if tensors have different free indices */ public static Tensor subtract(Tensor a, Tensor b) { return sum(a, negate(b)); }
private static Tensor renameDummyWithSign(Tensor tensor, int[] forbidden, boolean sign) { Tensor result = renameDummy(tensor, forbidden); return sign ? Tensors.negate(result) : result; }
Tensor toTensor() { BigInteger exponent = this.exponent; if (minExponent != null && minExponent.value != null) { exponent = exponent.subtract(minExponent.value); if (diffSigns && minExponent.value.testBit(0)) return Tensors.negate(Tensors.pow(tensor, new Complex(exponent))); } return Tensors.pow(tensor, new Complex(exponent)); }
private Tensor simplifyProduct(List<Tensor> gammas) { int upper = gammas.get(0).getIndices().getUpper().get(matrixType, 0), lower = gammas.get(gammas.size() - 1).getIndices().getLower().get(matrixType, 0); int initialSize = gammas.size(); boolean sign = false; int dummy = -1; for (int i = gammas.size() - 1; i >= 0; --i) { if (isGamma5(gammas.get(i))) { sign ^= (gammas.size() - i) % 2 == 0; dummy = del(gammas, i); } } if ((initialSize - gammas.size()) % 2 == 1) { //adding last gamma if (gammas.isEmpty()) gammas.add(simpleTensor(gamma5Name, createSimple(null, upper, lower))); else { Tensor t = gammas.get(gammas.size() - 1); gammas.set(gammas.size() - 1, setLowerMatrixIndex((SimpleTensor) t, dummy)); gammas.add(simpleTensor(gamma5Name, createSimple(null, raise(dummy), t.getIndices().getLower().get(matrixType, 0)))); } } Tensor r = multiply(gammas); if (sign) r = negate(r); return r; } }
Tensor applyIndexMappingToTo(Tensor oldFrom, Tensor to, Mapping mapping, SubstitutionIterator iterator) { if (toIsSymbolic) return mapping.getSign() ? Tensors.negate(to) : to; if (possiblyAddsDummies) return ApplyIndexMapping.applyIndexMapping(to, mapping, iterator.getForbidden()); return ApplyIndexMapping.applyIndexMappingAndRenameAllDummies(to, mapping, TensorUtils.getAllDummyIndicesT(oldFrom).toArray()); }
private static Tensor det1(Tensor[][] matrix) { if (matrix.length == 1) return matrix[0][0]; SumBuilder sum = new SumBuilder(); Tensor temp; for (int i = 0; i < matrix.length; ++i) { temp = multiplyAndRenameConflictingDummies(matrix[0][i], det(deleteFromMatrix(matrix, 0, i))); if (i % 2 == 1) temp = negate(temp); sum.put(temp); } return sum.build(); }
/** * Gives inverse matrix. * * @param matrix matrix * @return inverse matrix */ public static Tensor[][] inverse(Tensor[][] matrix) { checkMatrix(matrix); if (matrix.length == 1) return new Tensor[][]{{reciprocal(matrix[0][0])}}; Tensor det = det(matrix); int length = matrix.length; Tensor[][] inverse = new Tensor[length][length]; for (int i = 0; i < length; ++i) { for (int j = 0; j < length; ++j) { inverse[j][i] = divideAndRenameConflictingDummies(det(deleteFromMatrix(matrix, i, j)), det); if ((i + j) % 2 != 0) inverse[j][i] = negate(inverse[j][i]); } } return inverse; }
/** * Applies specified mapping of indices to tensor preventing some dummy index to be equal to one of the specified * <i>forbidden</i> indices. * * @param tensor tensor * @param mapping mapping of indices * @param forbidden forbidden indices * @return tensor with renamed indices */ public static Tensor applyIndexMapping(Tensor tensor, Mapping mapping, int[] forbidden) { if (mapping.isEmpty()) { if (tensor.getIndices().getFree().size() != 0) throw new IllegalArgumentException("From length does not match free indices size."); return renameDummyWithSign(tensor, forbidden, mapping.getSign()); } int[] freeIndicesNames = IndicesUtils.getIndicesNames(tensor.getIndices().getFree()); Arrays.sort(freeIndicesNames); if (!mapping.getFromNames().equalsToArray(freeIndicesNames)) { String fromIndices; try { fromIndices = IndicesUtils.toString(mapping.getFromNames().copy()); } catch (Exception e) { fromIndices = "error"; } throw new IllegalArgumentException("From indices names (" + fromIndices + ") does not match free indices names of tensor (" + IndicesUtils.toString(freeIndicesNames) + ")."); } Tensor result = _applyIndexMapping(tensor, mapping, forbidden); return mapping.getSign() ? Tensors.negate(result) : result; }
public static Expression[] setMandelstam(Tensor[][] momentums, Tensor s, Tensor t, Tensor u) { checkMandelstamInput(momentums, 4); if (s.getIndices().getFree().size() != 0 || t.getIndices().getFree().size() != 0 || u.getIndices().getFree().size() != 0) throw new IllegalArgumentException("Mandelstam variables should be scalar."); Expression[] result = new Expression[10]; int i; // (k1,k1) = m1^2, (k2,k2) = m2^2, (k3,k3) = m3^2, (k4,k4) = m4^2 for (i = 0; i < 4; ++i) result[i] = expression(square(momentums[i][0]), pow(momentums[i][1], 2)); //2(k1, k2) = s - k1^2 - k2^2 //2(k3, k4) = s - k3^2 - k4^2 result[i++] = expression(multiply(Complex.TWO, contract(momentums[0][0], momentums[1][0])), sum(s, negate(sum(pow(momentums[0][1], 2), pow(momentums[1][1], 2))))); result[i++] = expression(multiply(Complex.TWO, contract(momentums[2][0], momentums[3][0])), sum(s, negate(sum(pow(momentums[2][1], 2), pow(momentums[3][1], 2))))); //-2(k1, k3) = t - k1^2 - k3^2 //-2(k2, k4) = t - k2^2 - k4^2 result[i++] = expression(multiply(Complex.MINUS_TWO, contract(momentums[0][0], momentums[2][0])), sum(t, negate(sum(pow(momentums[0][1], 2), pow(momentums[2][1], 2))))); result[i++] = expression(multiply(Complex.MINUS_TWO, contract(momentums[1][0], momentums[3][0])), sum(t, negate(sum(pow(momentums[1][1], 2), pow(momentums[3][1], 2))))); //-2(k1, k4) = u - k1^2 - k4^2 //-2(k2, k3) = u - k2^2 - k3^2 result[i++] = expression(multiply(Complex.MINUS_TWO, contract(momentums[0][0], momentums[3][0])), sum(u, negate(sum(pow(momentums[0][1], 2), pow(momentums[3][1], 2))))); result[i++] = expression(multiply(Complex.MINUS_TWO, contract(momentums[1][0], momentums[2][0])), sum(u, negate(sum(pow(momentums[1][1], 2), pow(momentums[2][1], 2))))); return result; }
match = IndexMappings.getFirst(transformed[0], oldCoefficient); if (match != null) { newCoefficient = match.getSign() ? Tensors.negate(transformed[1]) : transformed[1]; break;
public static Tensor applyIndexMappingAndRenameAllDummies(Tensor tensor, Mapping mapping, int[] allowedDummies) { if (TensorUtils.isZero(tensor)) return tensor; int[] freeIndicesNames = IndicesUtils.getIndicesNames(tensor.getIndices().getFree()); Arrays.sort(freeIndicesNames); if (!mapping.getFromNames().equalsToArray(freeIndicesNames)) throw new IllegalArgumentException("From indices names does not match free indices names of tensor. Tensor: " + tensor + " mapping: " + mapping); final int[] dummies = TensorUtils.getAllDummyIndicesT(tensor).toArray(); int[] from = new int[mapping.size() + dummies.length]; int[] to = new int[mapping.size() + dummies.length]; ArraysUtils.arraycopy(mapping.getFromNames(), 0, from, 0, mapping.size()); ArraysUtils.arraycopy(mapping.getToData(), 0, to, 0, mapping.size()); System.arraycopy(dummies, 0, from, mapping.size(), dummies.length); IndexGeneratorFromData generator = new IndexGeneratorFromData(allowedDummies); for (int i = mapping.size() + dummies.length - 1, mappingSize = mapping.size(); i >= mappingSize; --i) to[i] = generator.generate(IndicesUtils.getType(from[i])); ArraysUtils.quickSort(from, to); tensor = applyIndexMapping(tensor, new IndexMapper(from, to)); if (mapping.getSign()) tensor = Tensors.negate(tensor); return tensor; }
private Expression createBarSubs(SimpleTensor spinor, boolean negate) { if (spinor == null) return null; int dummy = spinor.getIndices().get(matrixType, 0), free = dummy + 1; SimpleTensor gamma = simpleTensor(gammaName, createSimple(null, setState(true, dummy), free, setType(metricType, 0))); SimpleTensor mom = setIndices(momentum, createSimple(null, setState(true, setType(metricType, 0)))); SimpleTensor rhs = setMatrixIndices0(spinor, free); return expression(multiply(spinor, gamma, mom), negate ? negate(multiply(mass, rhs)) : multiply(mass, rhs)); }
private Expression createSubs(SimpleTensor spinor, boolean negate) { if (spinor == null) return null; int dummy = setState(false, spinor.getIndices().get(matrixType, 0)), free = setState(true, dummy + 1); SimpleTensor gamma = simpleTensor(gammaName, createSimple(null, free, dummy, setType(metricType, 0))); SimpleTensor mom = setIndices(momentum, createSimple(null, setState(true, setType(metricType, 0)))); SimpleTensor rhs = setMatrixIndices0(spinor, free); return expression(multiply(spinor, gamma, mom), negate ? negate(multiply(mass, rhs)) : multiply(mass, rhs)); }
tensor = Tensors.negate(tensor); newFactor = factor.negate(); newFactor = getDefaultReference(newFactor);
private Tensor traceOfArray(Tensor[] data) { //calculates trace using recursive algorithm if (data.length == 1) return Complex.ZERO; if (data.length == 2) return multiply(traceOfOne.get(1), createMetricOrKronecker(data[0].getIndices().get(metricType, 0), data[1].getIndices().get(metricType, 0))); if (data.length % 2 != 0) return Complex.ZERO; SumBuilder sb = new SumBuilder(); Tensor temp; for (int i = 0; i < data.length - 1; ++i) { temp = multiply(Complex.TWO, createMetricOrKronecker(data[i].getIndices().get(metricType, 0), data[i + 1].getIndices().get(metricType, 0)), traceOfArray(subArray(data, i, i + 1))); if (i % 2 != 0) temp = negate(temp); sb.put(temp); swap(data, i, i + 1); } return multiply(Complex.ONE_HALF, sb.build()); }
substitution = expression(substitution.get(0), negate(substitution.get(1))); return substitution;
t = tensor.get(i); if (denominatorIndicator.is(t)) { exponent = Tensors.negate(t.get(1)); denominators.put(Tensors.pow(t.get(0), exponent)); if (temp instanceof Product)