예제 #1
0
        private static BaseExpression?SmallestExponents(Number value)
        {
            var            bestLength = int.MaxValue;
            BaseExpression?best       = null;

            void Submit(BaseExpression exp)
            {
                if (exp.StaticEvaluate().Number != value)
                {
                    return;
                }

                var length = exp.ToString().Length;

                if (length < bestLength)
                {
                    bestLength = length;
                    best       = exp;
                }
            }

            for (var idx = 1; idx < 320; idx++)
            {
                var b = idx / 10m;
                try
                {
                    var log = Math.Log((double)value, (double)b);
                    if (double.IsNaN(log))
                    {
                        continue;
                    }

                    var exp = new Exponent(new ConstantNumber((Number)b), new ConstantNumber((Number)log));
                    Submit(exp);

                    var integral  = new Exponent(new ConstantNumber((Number)b), new ConstantNumber((Number)(int)Math.Round(log)));
                    var integralV = integral.StaticEvaluate().Number;
                    var integralE = value - integralV;
                    Submit(new Add(integral, new ConstantNumber(integralE)));
                }
                catch (OverflowException)
                {
                    // If the calculation overflows then don't submit this case
                }
            }

            return(best);
        }
예제 #2
0
        protected override BaseExpression Visit(ConstantNumber con)
        {
            if (con.Value.ToString().Length <= 3)
            {
                return(base.Visit(con));
            }

            var replacements = new[] {
                SmallestExponents(con.Value),
                BestFraction(con.Value),
            };

            var            shortestLength = int.MaxValue;
            BaseExpression?shortest       = null;

            foreach (var replacement in replacements)
            {
                if (replacement == null)
                {
                    continue;
                }

                var l = replacement.ToString().Length;
                if (l < shortestLength)
                {
                    shortestLength = l;
                    shortest       = replacement;
                }
            }

            if (shortest != null && shortestLength < con.ToString().Length)
            {
                return(base.Visit(shortest));
            }

            return(base.Visit(con));
        }
예제 #3
0
 public override bool Equals(BaseExpression?other)
 {
     return(other is LessThanEqualTo a &&
            a.Equals(this));
 }
예제 #4
0
 public override bool Equals(BaseExpression?other)
 {
     return(other is ConstantNumber num &&
            num.Equals(this));
 }
예제 #5
0
파일: Not.cs 프로젝트: martindevans/Yolol
 public override bool Equals(BaseExpression?other)
 {
     return(other is Not not &&
            not.Equals(this));
 }
예제 #6
0
 public override bool Equals(BaseExpression?other)
 {
     return(other is Factorial fac &&
            fac.Equals(this));
 }
예제 #7
0
 public override bool Equals(BaseExpression?other)
 {
     return(other is Variable var &&
            var.Equals(this));
 }
예제 #8
0
 public override bool Equals(BaseExpression?other)
 {
     return(other is Increment a &&
            a.Equals(this));
 }
예제 #9
0
 public override bool Equals(BaseExpression?other)
 {
     return(other is ConstantString str &&
            str.Equals(this));
 }
예제 #10
0
파일: Sqrt.cs 프로젝트: martindevans/Yolol
 public override bool Equals(BaseExpression?other)
 {
     return(other is Sqrt sqrt &&
            sqrt.Equals(this));
 }
예제 #11
0
 public override bool Equals(BaseExpression?other)
 {
     return(other is Cosine cos &&
            cos.Equals(this));
 }
예제 #12
0
 public override bool Equals(BaseExpression? other)
 {
     return other is ErrorExpression a
         && a.Equals(this);
 }
예제 #13
0
 public override bool Equals(BaseExpression?other)
 {
     return(other is Abs abs &&
            abs.Equals(this));
 }
예제 #14
0
 public override bool Equals(BaseExpression?other)
 {
     return(other is GreaterThan a &&
            a.Equals(this));
 }
예제 #15
0
 public override bool Equals(BaseExpression?other)
 {
     return(other is ArcSine asin &&
            asin.Equals(this));
 }
예제 #16
0
 public override bool Equals(BaseExpression?other)
 {
     return(other is ArcCos acos &&
            acos.Equals(this));
 }
예제 #17
0
 public override bool Equals(BaseExpression?other)
 {
     return(other is ArcTan atan &&
            atan.Equals(this));
 }
예제 #18
0
 public override bool Equals(BaseExpression?other)
 {
     return(other is Divide a &&
            a.Equals(this));
 }
예제 #19
0
 public override bool Equals(BaseExpression?other)
 {
     return(other is Negate neg &&
            neg.Equals(this));
 }
예제 #20
0
 public override bool Equals(BaseExpression?other)
 {
     return(other is Bracketed brk &&
            brk.Equals(this));
 }
예제 #21
0
 public override bool Equals(BaseExpression?other)
 {
     return(other is PostIncrement post &&
            post.Equals(this));
 }
예제 #22
0
 public abstract bool Equals(BaseExpression?other);
예제 #23
0
파일: Sine.cs 프로젝트: martindevans/Yolol
 public override bool Equals(BaseExpression?other)
 {
     return(other is Sine sine &&
            sine.Equals(this));
 }
예제 #24
0
 public override bool Equals(BaseExpression?other)
 {
     return(other is PreDecrement pre &&
            pre.Equals(this));
 }
예제 #25
0
 public override bool Equals(BaseExpression?other)
 {
     return(other is Tangent tan &&
            tan.Equals(this));
 }