
cc.redberry.transformation.Transformations Maven / Gradle / Ivy
/*
* Redberry: symbolic tensor computations.
*
* Copyright (c) 2010-2012:
* Stanislav Poslavsky
* Bolotin Dmitriy
*
* This file is part of Redberry.
*
* Redberry is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Redberry is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Redberry. If not, see .
*/
package cc.redberry.transformation;
import cc.redberry.core.tensor.Derivative;
import cc.redberry.core.tensor.Tensor;
import cc.redberry.core.tensor.TensorNumber;
import cc.redberry.core.transformations.RenameConflictingIndices;
import cc.redberry.transformation.collect.CollectPowers;
import cc.redberry.transformation.concurrent.EACScalars;
import cc.redberry.transformation.contractions.IndicesContractionsTransformation;
import cc.redberry.transformation.fraction.*;
import cc.redberry.transformation.numbers.*;
import cc.redberry.transformation.substitutions.n.Substitutions;
/**
*
* @author Dmitry Bolotin
* @author Stanislav Poslavsky
*/
public class Transformations {
private Transformations() {
}
public static Tensor transform(Tensor tensor, Transformation... transformations) {
return new Transformer(transformations).transform(tensor);
}
public static Tensor transform(Tensor tensor, boolean tensorFirst, Transformation... transformations) {
return new Transformer(transformations).transform(tensor, tensorFirst);
}
public static Tensor toMinusRepresentation(Tensor tensor) {
return transform(tensor, MinusRepresentationTo.INSTANCE, RemoveOneFromProduct.INSTANCE);
}
public static Tensor fromMinusRepresentation(Tensor tensor) {
return transform(tensor, MinusRepresentationFrom.INSTANCE);
}
public static Tensor expandBrackets(Tensor tensor) {
return transform(tensor, ExpandBrackets.EXPAND_ALL);
}
public static Tensor expandBracketsExceptSymbols(Tensor tensor) {
return transform(tensor, ExpandBrackets.EXPAND_EXCEPT_SYMBOLS);
}
public static Tensor multiplyNumbers(Tensor tensor) {
return transform(tensor, false,
MultiplyNumbers.INSTANCE,
RemoveOneFromProduct.INSTANCE,
FractionToNumber.INSTANCE);
}
public static Tensor sumNumbers(Tensor tensor) {
return transform(tensor, false,
SumNumbers.INSTANCE,
RemoveZeroFromSum.INSTANCE,
FractionToNumber.INSTANCE);
}
public static Tensor calculateNumbers(Tensor tensor) {
return transform(tensor, false,
MultiplyNumbers.INSTANCE,
RemoveOneFromProduct.INSTANCE,
SumNumbers.INSTANCE,
RemoveZeroFromSum.INSTANCE,
FractionToNumber.INSTANCE);
}
public static Tensor collectPowers(Tensor t) {
return transform(t, CollectPowers.INSTANCE);
}
public static Tensor renameConflictingIndices(Tensor tensor) {
return transform(tensor, false, RenameConflictingIndices.INSTANCE);
}
public static Tensor substitute(Tensor target, String substitution) {
return Substitutions.createSubstitution(substitution).transform(target);
}
public static Tensor contractMetrics(Tensor tensor) {
return IndicesContractionsTransformation.CONTRACTIONS_WITH_METRIC.transform(tensor);
}
public static Tensor contractKroneckers(Tensor tensor) {
return IndicesContractionsTransformation.CONTRACTIONS_WITH_KRONECKER.transform(tensor);
}
public static Tensor getDerivative(Derivative derivative) {
return GetDerivative1.INSTANCE.transform(derivative);
}
public static Tensor getFullDerivative(Derivative derivative) {
return transform(derivative, false, new GetFullDerivative());
}
public static Tensor expandNumeratorSum(Tensor tensor) {
return transform(tensor, new ExpandNumeratorSum());
}
public static Tensor reduceFraction(Tensor tensor) {
return transform(tensor, false, new ReduceFraction());
}
public static Tensor multiplyFractions(Tensor tensor) {
return transform(tensor, false, new MultiplyFractions());
}
// public static Tensor collectScalars(Tensor tensor) {
// return transform(tensor, false, CollectScalars.INSTANCE);
// }
public static Tensor toCommonDenominator(Tensor tensor) {
return transform(tensor, false, new ToCommonDenominator());
}
@Deprecated
public static Tensor toCommonDenominatorOld(Tensor tensor) {
return transform(tensor, false, new ToCommonDenominatorOld());
}
//public static Tensor applyIndexMapping(Tensor tensor, IndexMappingBuffer indexMapping) {
// return transform(tensor, new ApplyIndexMappingTransformation(indexMapping, new IndexGenerator(tensor.getIndices())));
//}
public static Tensor expandAndCollectAllScalars(Tensor t) {
//FIXME temporary variant fur fisiks
t = calculateNumbers(t);
if (t instanceof TensorNumber)
return t;
return transform(t, false,
MultiplyNumbers.INSTANCE,
EACScalars.INSTANCE,
RemoveOneFromProduct.INSTANCE,
SumNumbers.INSTANCE,
RemoveZeroFromSum.INSTANCE,
FractionToNumber.INSTANCE);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy