public static bool CollectSummands(ISignalSet signals)
        {
            bool changed = false;
            for(int i = 0; i < signals.Count; i++)
            {
                Signal s = signals[i];
                if(!s.BehavesAsBeingDriven(false))
                    continue;

                Port p = s.DrivenByPort;
                if(p.Entity.EntityId.Equals(AdditionArchitectures.EntityIdentifier))
                {
                    signals.RemoveAt(i);
                    ISignalSet inputs = p.InputSignals;
                    for(int j = 0; j < inputs.Count; j++)
                        signals.Insert(i + j, inputs[j]);
                    i--;
                    changed = true;
                    continue;
                }

                if(p.Entity.EntityId.Equals(SubtractionArchitectures.EntityIdentifier))
                {
                    ISignalSet inputs = p.InputSignals;
                    signals[i] = inputs[0];
                    i--;
                    for(int j = 1; j < inputs.Count; j++)
                        signals.Insert(i + j, Std.Negate(inputs[j]));
                    changed = true;
                    continue;
                }
            }
            return changed;
        }
        public static bool SimplifySummands(ISignalSet signals)
        {
            bool changed = CollectSummands(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 (acc == null)
                    {
                        acc = Accumulator <IntegerValue, RationalValue> .Create(IntegerValue.AdditiveIdentity);
                    }
                    signals.RemoveAt(i);
                    changed = true;
                    acc     = acc.Add(s.Value);
                }
            }
            if (acc != null && !acc.Value.Equals(IntegerValue.AdditiveIdentity))
            {
                signals.Insert(0, Std.DefineConstant(acc.Value));
            }
            return(changed);
        }
Esempio n. 3
0
        public static bool CollectFactors(ISignalSet signals)
        {
            bool changed = false;

            for (int i = 0; i < signals.Count; i++)
            {
                Signal s = signals[i];
                if (!s.BehavesAsBeingDriven(false))
                {
                    continue;
                }

                Port p = s.DrivenByPort;
                if (p.Entity.EntityId.Equals(MultiplicationArchitectures.EntityIdentifier))
                {
                    signals.RemoveAt(i);
                    ISignalSet inputs = p.InputSignals;
                    for (int j = 0; j < inputs.Count; j++)
                    {
                        signals.Insert(i + j, inputs[j]);
                    }
                    i--;
                    changed = true;
                    continue;
                }

                if (p.Entity.EntityId.Equals(DivisionArchitectures.EntityIdentifier))
                {
                    ISignalSet inputs = p.InputSignals;
                    signals[i] = inputs[0];
                    i--;
                    for (int j = 1; j < inputs.Count; j++)
                    {
                        signals.Insert(i + j, Std.Invert(inputs[j]));
                    }
                    changed = true;
                    continue;
                }
            }
            return(changed);
        }
Esempio n. 4
0
        public static bool CollectSummands(ISignalSet signals)
        {
            bool changed = false;

            for (int i = 0; i < signals.Count; i++)
            {
                Signal s = signals[i];
                if (!s.BehavesAsBeingDriven(false))
                {
                    continue;
                }

                Port p = s.DrivenByPort;
                if (p.Entity.EntityId.Equals(AdditionArchitectures.EntityIdentifier))
                {
                    signals.RemoveAt(i);
                    ISignalSet inputs = p.InputSignals;
                    for (int j = 0; j < inputs.Count; j++)
                    {
                        signals.Insert(i + j, (i == 0 && j != 0) ? Std.Negate(inputs[j]) : inputs[j]);
                    }
                    i--;
                    changed = true;
                    continue;
                }

                if (p.Entity.EntityId.Equals(SubtractionArchitectures.EntityIdentifier))
                {
                    ISignalSet inputs = p.InputSignals;
                    signals[i] = inputs[0];
                    i--;
                    for (int j = 1; j < inputs.Count; j++)
                    {
                        signals.Insert(i + j, (i == 0) ? inputs[j] : Std.Negate(inputs[j]));
                    }
                    changed = true;
                    continue;
                }
            }
            return(changed);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        public static bool SimplifySummands(ISignalSet signals)
        {
            bool changed = CollectSummands(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.AdditiveIdentity);
                    }
                    signals.RemoveAt(i);
                    changed = true;
                    acc     = acc.Add(s.Value);
                }
            }
            if (acc != null && !acc.Value.Equals(IntegerValue.AdditiveIdentity))
            {
                Signal first = signals[0];
                if (Std.IsConstantComplex(first))
                {
                    acc        = acc.Subtract(first.Value).Negate();
                    signals[0] = Std.DefineConstant(acc.Value);
                    changed    = true;
                }
                else
                {
                    signals.Insert(1, Std.DefineConstant(acc.Value));
                }
            }
            return(changed);
        }
 public static bool SimplifySummands(ISignalSet signals)
 {
     bool changed = CollectSummands(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(acc == null)
                 acc = Accumulator<IntegerValue, RationalValue>.Create(IntegerValue.AdditiveIdentity);
             signals.RemoveAt(i);
             changed = true;
             acc = acc.Add(s.Value);
         }
     }
     if(acc != null && !acc.Value.Equals(IntegerValue.AdditiveIdentity))
     {
         signals.Insert(0, Std.DefineConstant(acc.Value));
     }
     return changed;
 }
        public static bool CollectFactors(ISignalSet signals)
        {
            bool changed = false;
            for(int i = 0; i < signals.Count; i++)
            {
                Signal s = signals[i];
                if(!s.BehavesAsBeingDriven(false))
                    continue;

                Port p = s.DrivenByPort;
                if(p.Entity.EntityId.Equals(MultiplicationArchitectures.EntityIdentifier))
                {
                    signals.RemoveAt(i);
                    ISignalSet inputs = p.InputSignals;
                    for(int j = 0; j < inputs.Count; j++)
                        signals.Insert(i + j, (i == 0 && j != 0) ? Std.Invert(inputs[j]) : inputs[j]);
                    i--;
                    changed = true;
                    continue;
                }

                if(p.Entity.EntityId.Equals(DivisionArchitectures.EntityIdentifier))
                {
                    ISignalSet inputs = p.InputSignals;
                    signals[i] = inputs[0];
                    i--;
                    for(int j = 1; j < inputs.Count; j++)
                        signals.Insert(i + j, (i == 0) ? inputs[j] : Std.Invert(inputs[j]));
                    changed = true;
                    continue;
                }
            }
            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--)  //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 SimplifySummands(ISignalSet signals)
 {
     bool changed = CollectSummands(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.AdditiveIdentity);
             signals.RemoveAt(i);
             changed = true;
             acc = acc.Add(s.Value);
         }
     }
     if(acc != null && !acc.Value.Equals(IntegerValue.AdditiveIdentity))
     {
         Signal first = signals[0];
         if(Std.IsConstantComplex(first))
         {
             acc = acc.Subtract(first.Value).Negate();
             signals[0] = Std.DefineConstant(acc.Value);
             changed = true;
         }
         else
         {
             signals.Insert(1, Std.DefineConstant(acc.Value));
         }
     }
     return changed;
 }