public IAccumulator Multiply(IValueStructure operand) { object other; if (ValueConverter <T> .TryConvertLosslessFrom(operand, out other)) { _value = _value.Multiply((T)other); return(this); } else { IAccumulator acc = Escalate(operand.TypeId, _value, false); return(acc.Multiply(operand)); } }
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 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--) { Signal s = signals[i]; if (Std.IsConstantComplex(s)) { if (Std.IsAdditiveIdentity(s)) { signals.Clear(); signals.Add(s); return(true); } if (acc == null) { acc = Accumulator <IntegerValue, RationalValue> .Create(IntegerValue.MultiplicativeIdentity); } signals.RemoveAt(i); changed = true; acc = acc.Multiply(s.Value); } } if (acc != null && !acc.Value.Equals(IntegerValue.MultiplicativeIdentity)) { signals.Insert(0, Std.DefineConstant(acc.Value)); } return(changed); }