public static bool SimplifyFactors(ISignalSet signals) { bool changed = CollectFactors(signals); if (signals.Count < 2) { return(changed); } IAccumulator acc = null; for (int i = signals.Count - 1; i > 0; i--) //don't touch first item! { Signal s = signals[i]; if (Std.IsConstantComplex(s)) { if (acc == null) { acc = Accumulator <IntegerValue, RationalValue> .Create(IntegerValue.MultiplicativeIdentity); } signals.RemoveAt(i); changed = true; if (Std.IsConstantAdditiveIdentity(s)) { signals.Clear(); signals.Add(UndefinedSymbol.Constant); return(true); } acc = acc.Multiply(s.Value); } } if (acc != null && !acc.Value.Equals(IntegerValue.MultiplicativeIdentity)) { Signal first = signals[0]; if (Std.IsConstantComplex(first)) { acc = acc.Divide(first.Value).Invert(); signals[0] = Std.DefineConstant(acc.Value); changed = true; } else { signals.Insert(1, Std.DefineConstant(acc.Value)); } } return(changed); }
public IAccumulator Divide(IValueStructure operand) { object other; if (ValueConverter <T> .TryConvertLosslessFrom(operand, out other)) { TDivision res = _value.Divide((T)other); if (_value is IAlgebraicDivisionExtension <T, T> ) { _value = (T)(object)res; return(this); } return(Escalate <TDivision, TDivision>(res)); } else { IAccumulator acc = Escalate(operand.TypeId, _value, true); return(acc.Divide(operand)); } }