Example #1
0
		internal static Component ToComponent(Evaluatable thing)
		{
			if (thing is Expression)
			{
				return ToComponent((Expression)thing);
			}

			if (thing is Component)
			{
				return ToComponent((Component)thing);
			}

			if (thing is Factor)
			{
				return ToComponent((Factor)thing);
			}

			if (thing is ComponentListFactor)
			{
				var clf = (ComponentListFactor)thing;
				if (clf.IsInNumerator)
				{
					return ToComponent(clf.Factor);
				}

				return new SingleFactorComponent(new ExpressionFactor(new SingleComponentExpression(new ComponentList(new List<ComponentListFactor> { clf }))));
			}

			throw new UnexpectedTypeException(thing.GetType());
		}
		public override bool Equals(Evaluatable other)
		{
			var clf = other as ComponentListFactor;
			if (clf != null)
			{
				return IsInNumerator == clf.IsInNumerator && Factor.Equals(clf.Factor);
			}

			return false;
		}
Example #3
0
		public QueryBrowser(IHandlerRegistry handlerRegistry, Evaluatable evaluatable)
		{
			InitializeComponent();

			_handlerRegistry = handlerRegistry;
			_evaluatable = evaluatable;
			evaluatableBrowser.Evaluatable = evaluatable;
			evaluatableBrowser.SelectedItemChanged += evaluatableBrowser_SelectedItemChanged;
			Application.Idle += Application_OnIdle;
		}
Example #4
0
		public override bool Equals(Evaluatable other)
		{
			var componentList = other as ComponentList;
			if (componentList != null)
			{
				if (Factors.Count < componentList.Factors.Count || Factors.Count > componentList.Factors.Count) return false;
				return !Factors.Where((t, i) => !t.Equals(componentList.Factors[i])).Any();
			}

			return false;
		}
		public override bool Equals(Evaluatable other)
		{
			var fc = other as FunctionComponent;
			if (fc != null)
			{
				return Function.Name == fc.Function.Name &&
					   !fc.Operands.Where((t, i) => !t.Equals(fc.Operands[i])).Any();
			}

			return false;
		}
		public override bool Equals(Evaluatable other)
		{
			var dfc = other as DualFactorComponent;
			if (dfc != null)
			{
				return LeftFactor.Equals(dfc.LeftFactor) &&
				       RightFactor.Equals(dfc.RightFactor) &&
				       IsMultiply == dfc.IsMultiply;
			}

			return false;
		}
Example #7
0
		internal static bool IsFunction(Evaluatable evaluatable, out FunctionComponent function)
		{
			var component = Componentizer.ToComponent(evaluatable);
			if (component is FunctionComponent)
			{
				function = (FunctionComponent)component;
				return true;
			}

			function = null;
			return false;
		}
Example #8
0
		internal static bool IsList(Evaluatable input, out ExpressionList output)
		{
			var factor = Factorizer.ToFactor(input);
			if (factor is ExpressionList)
			{
				output = (ExpressionList)factor;
				return true;
			}

			output = null;
			return false;
		}
Example #9
0
		internal static bool IsConstant(Evaluatable expression, out Number value)
		{
			var factor = Factorizer.ToFactor(expression);
			if (factor is AlphabeticFactor)
			{
				var name = ((AlphabeticFactor)factor).Value;

				if (Constants.IsNamedConstant(name))
				{
					value = new Float(Constants.Get(name));
					return true;
				}
			}

			value = Integer.Zero;
			return false;
		}
Example #10
0
		internal static bool IsIntegerFraction(Evaluatable evaluatable, out IntegerFraction fraction)
		{
			var component = Componentizer.ToComponent(evaluatable);
			if (component is IntegerFraction)
			{
				fraction = (IntegerFraction)component;
				return true;
			}

			var factor = Factorizer.ToFactor(evaluatable);
			if (factor is NumericFactor)
			{
				var number = ((NumericFactor)factor).Number;
				if (number is Integer)
				{
					fraction = new IntegerFraction((Integer)number);
					return true;
				}
			}

			fraction = null;
			return false;
		}
Example #11
0
		public override bool Equals(Evaluatable other)
		{
			var frac = other as IntegerFraction;
			if (frac != null)
			{

			}

			return false;
		}
Example #12
0
		private Expression EvaluateExponent(Evaluatable left, Evaluatable right)
		{
			// ln(a ^ b) = b * ln(a)
			return new DualFactorComponent(
				Factorizer.ToFactor(right.Evaluate()),
				Factorizer.ToFactor(new FunctionComponent(Name, new List<Expression> { left.Evaluate() })),
				true).Evaluate();
		}
Example #13
0
		private Expression EvaluateDivision(Evaluatable left, Evaluatable right)
		{
			// ln(a / b) = ln(a) - ln(b)
			return new DualComponentExpression(
				Componentizer.ToComponent(new FunctionComponent(Name, new List<Expression> { left.Evaluate() }).Evaluate()),
				Componentizer.ToComponent(new FunctionComponent(Name, new List<Expression> { right.Evaluate() }).Evaluate()),
				false).Evaluate();
		}
Example #14
0
		private Expression EvaluateMultiplication(Evaluatable left, Evaluatable right)
		{
			// ln(a * b) = ln(a) + ln(b)
			return new DualComponentExpression(
				Componentizer.ToComponent(new FunctionComponent(Name, new List<Expression> { left.Evaluate() }).Evaluate()),
				Componentizer.ToComponent(new FunctionComponent(Name, new List<Expression> { right.Evaluate() }).Evaluate()),
				true).Evaluate();
		}
		public override bool Equals(Evaluatable other)
		{
			var sfc = other as SingleFactorComponent;
			return sfc != null && Factor.Equals(sfc.Factor);
		}
Example #16
0
		internal static bool IsFloat(Evaluatable evaluatable, out Number number)
		{
			return IsNumber(evaluatable, out number) && number is Float;
		}
		public override bool Equals(Evaluatable other)
		{
			var sce = other as SingleComponentExpression;
			return sce != null && Component.Equals(sce.Component);
		}
Example #18
0
		private static Expression Evaluate(ExpressionList leftNumber, Evaluatable right)
		{
			return Expressionizer.ToExpression(new ExpressionList(leftNumber.Expressions.Select(e => new Exponent().Evaluate(e, Expressionizer.ToExpression(right)).Evaluate()).ToList()));
		}
Example #19
0
		internal static bool IsNumber(Evaluatable evaluatable, out Number number)
		{
			return IsNumber(Componentizer.ToComponent(evaluatable), out number);
		}
Example #20
0
		public override bool Equals(Evaluatable other)
		{
			var sf = other as StringFactor;
			return sf != null && _value == sf._value;
		}
		public override bool Equals(Evaluatable other)
		{
			var af = other as AlphabeticFactor;
			return af != null && Value == af.Value;
		}
Example #22
0
		private static Expression Evaluate(ExpressionList leftNumber, Evaluatable right, bool isMultiply)
		{
			return Expressionizer.ToExpression(new ExpressionList(leftNumber.Expressions.Select(e => new DualFactorComponent(Factorizer.ToFactor(e), Factorizer.ToFactor(right), isMultiply).Evaluate()).ToList()));
		}
Example #23
0
		private static string ToString(Evaluatable expression, bool isBase)
		{
			var asFactor = Factorizer.ToFactor(expression);
			if (expression is DualComponentExpression ||
				 (isBase && (asFactor as NumericFactor)?.Number is Float))
			{
				return string.Format("({0})", expression);
			}

			var component = Componentizer.ToComponent(expression);
			if (component is DualFactorComponent || component is ComponentList)
			{
				var output = expression.ToString();
				if (output.Contains("("))
				{
					return string.Format("({0})", expression);
				}
			}

			return expression.ToString();
		}
Example #24
0
		public override bool Equals(Evaluatable other)
		{
			throw new System.NotImplementedException();
		}
		public override bool Equals(Evaluatable other)
		{
			var ef = other as ExpressionFactor;
			return ef != null && Expression.Equals(ef.Expression);
		}
Example #26
0
		public override bool Equals(Evaluatable other)
		{
			var nf = other as NumericFactor;
			return nf != null && Number.Equals(nf.Number);
		}
		public override bool Equals(Evaluatable other)
		{
			return other is UndefinedExpression;
		}
		public override bool Equals(Evaluatable other)
		{
			var dce = other as DualComponentExpression;
			if (dce != null)
			{
				return _leftComponent.Equals(dce._leftComponent) &&
				       _rightComponent.Equals(dce._rightComponent) &&
				       _isAdd == dce._isAdd;
			}

			return false;
		}