public override Operand Copy() { SymbolicScalarTerm clone = base.Copy() as SymbolicScalarTerm; clone.factorList = (from factor in factorList select factor.Copy()).ToList(); return(clone); }
public override Operand Inverse(Context context) { SymbolicScalarTerm term = this.Copy() as SymbolicScalarTerm; term.scalar = new Inverse(new List <Operand>() { term.scalar }); for (int i = 0; i < term.factorList.Count; i++) { term.factorList[i].exponent *= -1; } return(term); }
private Operand FactorBlade(string vectorName, Sum sum, Context context) { List <string> basisVectorList = context.ReturnBasisVectors(); basisVectorList = basisVectorList.Where(basisVectorName => !context.BilinearForm(vectorName, basisVectorName).IsAdditiveIdentity).ToList(); List <int> emptyBladeOffsetList = new List <int>(); foreach (List <int> bladeOffsetList in this.IteratePotentiallyFactorableBladesLists(emptyBladeOffsetList, sum, basisVectorList, vectorName)) { List <Operand> modifiedOperandList = new List <Operand>(); for (int i = 0; i < bladeOffsetList.Count; i++) { string basisVectorName = basisVectorList[i]; Blade blade = sum.operandList[bladeOffsetList[i]].Copy() as Blade; SymbolicScalarTerm term = blade.scalar as SymbolicScalarTerm; int j = blade.vectorList.IndexOf(basisVectorName); if (j % 2 == 1) { term.scalar = new GeometricProduct(new List <Operand>() { new NumericScalar(-1.0), term.scalar }); } blade.vectorList.Remove(basisVectorName); term.factorList = term.factorList.Where(factor => !(factor is SymbolicScalarTerm.SymbolicDot symbolicDot && symbolicDot.InvolvesVectors(vectorName, basisVectorName))).ToList(); modifiedOperandList.Add(ExhaustEvaluation(blade, context)); } bool canFactor = Enumerable.Range(0, modifiedOperandList.Count - 1).All(j => { Operand bladeA = modifiedOperandList[j]; Operand bladeB = modifiedOperandList[j + 1]; Operand difference = new Sum(new List <Operand>() { bladeA.Copy(), new GeometricProduct(new List <Operand>() { new NumericScalar(-1.0), bladeB.Copy() }) }); difference = ExhaustEvaluation(difference, context); return(difference.IsAdditiveIdentity); }); if (canFactor) { Sum remainderSum = new Sum(sum.operandList.Where(operand => !bladeOffsetList.Contains(sum.operandList.IndexOf(operand))).ToList()); Sum resultSum = new Sum(); resultSum.operandList.Add(new OuterProduct(new List <Operand>() { new Blade(vectorName), modifiedOperandList[0] })); resultSum.operandList.Add(new FactorDot(new List <Operand>() { remainderSum })); return(resultSum); } } return(null); }