private static Dictionary <BaseSi, int> Expan(Variable v) { var expanInBaseSi = new Dictionary <BaseSi, int>(); if (!v.IsComplexDimension) { return(expanInBaseSi = v.Dimension.ExpansionInBaseSi); } else { return(expanInBaseSi = DimensionConvertor.Expan(v.ComplexDimension)); } }
private static Variable ReturnVariable(Variable v1, Variable v2) { var newV1 = toSiConvertor.Convert(v1); var newV2 = toSiConvertor.Convert(v2); var siDimensionV1 = Expan(newV1); var siDimensionV2 = Expan(newV2); var newValue = newV1.Value + newV2.Value; if (DimensionComparator.IsEquals(siDimensionV1, siDimensionV2)) { if (newV1.IsComplexDimension) { return(new Variable(newValue, DimensionConvertor.Narrow(siDimensionV1))); } return(new Variable(newValue, newV1.Dimension)); } return(null); }
public static Variable Multiplication(Variable v1, Variable v2) { var newV1 = toSiConvertor.Convert(v1); var newV2 = toSiConvertor.Convert(v2); var siDimensionV1 = Expan(newV1); var siDimensionV2 = Expan(newV2); var compositeDimension = CloneDimension.Clone(siDimensionV1); foreach (var item in siDimensionV2) { if (compositeDimension.ContainsKey(item.Key)) { if (compositeDimension[item.Key] + item.Value != 0) { compositeDimension[item.Key] += item.Value; } else { compositeDimension.Remove(item.Key); } } else { compositeDimension.Add(item.Key, item.Value); } } double newValue = newV1.Value * newV2.Value; if (compositeDimension.Count != 0) { return(new Variable(newValue, DimensionConvertor.Narrow(compositeDimension))); } else { return(new Variable(newValue, Si.ND)); } }