コード例 #1
0
    public static Constant Create(Fraction value)
    {
        var val = value.Reduce();

        if (val.den == 1)
        {
            return(ConstantWhole.Create(val.num));
        }
        return(new ConstantFraction(val));
    }
コード例 #2
0
 protected TermConstant(BigInteger val) : this(ConstantWhole.Create(val))
 {
 }
コード例 #3
0
        public static TermsBase Create(IEnumerable <TermBase> terms)
        {
            if (terms == null)
            {
                throw new ArgumentNullException(nameof(terms));
            }
            var(constants, ones, variables, ts) = terms.OfType <TermConstant, TermOne, TermVariables, Term>();
            var constant = TermConstant.Create(constants.Aggregate((Constant) new ConstantZero(), (c1, c2) => c1 + c2.Coeff) + ConstantWhole.Create(ones.Count()));
            var variable = variables.Select(t => (c: (Constant) new ConstantOne(), v: t.Variables)).Concat(ts.Select(t => (c: t.Coeff, v: t.Var))).ToLookup(t => t.v, t => t.c).Select(SumGroup);
            var lookup   = variable.Concat(new[] { constant });

            if (lookup.Count() == 1)
            {
                return(TermsSingle.Create(lookup.First()));
            }
            if (lookup.Count() < 1)
            {
                return(new TermsZero());
            }
            return(new Terms(lookup));
        }