Пример #1
0
        /// <summary>
        /// Checks whether a signal is a single variable monomial, e.g. '2*x^3'
        /// </summary>
        /// <remarks><see cref="signal"/> is assumed to be automatic simplified</remarks>
        public static bool IsMonomial(Signal signal, Signal variable)
        {
            if (signal == null)
            {
                throw new ArgumentNullException("signal");
            }

            if (Std.IsAlwaysRational(signal))
            {
                return(true);
            }
            if (signal.IsDrivenByPortEntity("Multiply", "Std") && signal.DrivenByPort.InputSignalCount == 2 && Std.IsAlwaysRational(signal.DrivenByPort.InputSignals[0]))
            {
                signal = signal.DrivenByPort.InputSignals[1];
            }
            if (signal.Equals(variable))
            {
                return(true);
            }
            if (signal.IsDrivenByPortEntity("Power", "Std"))
            {
                Signal b = signal.DrivenByPort.InputSignals[0];
                Signal e = signal.DrivenByPort.InputSignals[1];
                if (b.Equals(variable) && Std.IsAlwaysPositiveInteger(e))
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #2
0
        /// <summary>
        /// Evaluates the degree of the single-variable monomial <see cref="signal"/>.
        /// </summary>
        /// <returns>
        /// <see cref="UndefinedSymbol"/> if <see cref="signal"/> is not a single-variable monomial.
        /// <see cref="NegativeInfinitySymbol"/> if <see cref="signal"/> is zero.
        /// Otherwise an <see cref="IntegerValue"/> representing the asked degree.
        /// </returns>
        /// <remarks><see cref="signal"/> is assumed to be automatic simplified.</remarks>
        public static IValueStructure MonomialDegree(Signal signal, Signal variable)
        {
            if (signal == null)
            {
                throw new ArgumentNullException("signal");
            }

            if (Std.IsConstantAdditiveIdentity(signal))
            {
                return(NegativeInfinitySymbol.Instance);
            }
            if (Std.IsAlwaysRational(signal))
            {
                return(IntegerValue.Zero);
            }
            if (signal.IsDrivenByPortEntity("Multiply", "Std") && signal.DrivenByPort.InputSignalCount == 2 && Std.IsAlwaysRational(signal.DrivenByPort.InputSignals[0]))
            {
                signal = signal.DrivenByPort.InputSignals[1];
            }
            if (signal.Equals(variable))
            {
                return(IntegerValue.One);
            }
            if (signal.IsDrivenByPortEntity("Power", "Std"))
            {
                Signal b = signal.DrivenByPort.InputSignals[0];
                Signal e = signal.DrivenByPort.InputSignals[1];
                if (b.Equals(variable) && Std.IsAlwaysPositiveInteger(e))
                {
                    return(e.Value);
                }
            }
            return(UndefinedSymbol.Instance);
        }
Пример #3
0
        public static Signal[] PolynomialVariables(Signal signal)
        {
            List <Signal> variables = new List <Signal>();
            ISignalSet    monomials;

            if (signal.IsDrivenByPortEntity("Add", "Std"))
            {
                monomials = signal.DrivenByPort.InputSignals;
            }
            else
            {
                monomials = new SignalSet(signal);
            }
            for (int i = 0; i < monomials.Count; i++)
            {
                ISignalSet factors;
                if (monomials[i].IsDrivenByPortEntity("Multiply", "Std"))
                {
                    factors = monomials[i].DrivenByPort.InputSignals;
                }
                else
                {
                    factors = new SignalSet(monomials[i]);
                }
                for (int j = 0; j < factors.Count; j++)
                {
                    if (Std.IsAlwaysRational(factors[j]))
                    {
                        continue;
                    }
                    if (factors[j].IsDrivenByPortEntity("Power", "Std"))
                    {
                        Signal b = factors[j].DrivenByPort.InputSignals[0];
                        if (Std.IsAlwaysPositiveInteger(factors[j].DrivenByPort.InputSignals[1]))
                        {
                            if (!variables.Contains(b))
                            {
                                variables.Add(b);
                            }
                        }
                        else
                        {
                            if (!variables.Contains(signal))
                            {
                                variables.Add(signal);
                            }
                        }
                    }
                    else
                    if (!variables.Contains(factors[j]))
                    {
                        variables.Add(factors[j]);
                    }
                }
            }
            return(variables.ToArray());
        }
Пример #4
0
        /// <summary>
        /// Returns the coefficient factor in the monomial <see cref="signal"/>
        /// </summary>
        /// <returns>
        /// Constant UndefinedSymbol if <see cref="signal"/> is not a single-variable monomial.
        /// Otherwise the coefficient factor of the term.
        /// </returns>
        /// </returns>
        /// <remarks><see cref="signal"/> is assumed to be automatic simplified.</remarks>
        public static Signal MonomialCoefficient(Signal signal, Signal variable, out IValueStructure degree)
        {
            if (signal == null)
            {
                throw new ArgumentNullException("signal");
            }

            if (Std.IsConstantAdditiveIdentity(signal))
            {
                degree = NegativeInfinitySymbol.Instance;
                return(signal);
            }
            if (Std.IsAlwaysRational(signal))
            {
                degree = IntegerValue.Zero;
                return(signal);
            }
            Signal coeff = IntegerValue.ConstantOne;

            if (signal.IsDrivenByPortEntity("Multiply", "Std") && signal.DrivenByPort.InputSignalCount == 2 && Std.IsAlwaysRational(signal.DrivenByPort.InputSignals[0]))
            {
                coeff  = signal.DrivenByPort.InputSignals[0];
                signal = signal.DrivenByPort.InputSignals[1];
            }
            if (signal.Equals(variable))
            {
                degree = IntegerValue.One;
                return(coeff);
            }
            if (signal.IsDrivenByPortEntity("Power", "Std"))
            {
                Signal b = signal.DrivenByPort.InputSignals[0];
                Signal e = signal.DrivenByPort.InputSignals[1];
                if (b.Equals(variable) && Std.IsAlwaysPositiveInteger(e))
                {
                    degree = e.Value;
                    return(coeff);
                }
            }
            degree = UndefinedSymbol.Instance;
            return(UndefinedSymbol.Constant);
        }