public override bool Inequality(QsValue value) { return(this.Value != ((QsBoolean)value).Value); }
public override void SetIndexedItem(QsParameter[] indices, QsValue value) { throw new NotImplementedException(); }
public override QsValue ColonOperator(QsValue value) { int p = (int)((QsScalar)value).NumericalQuantity.Value; return(ValueToQsValue(ThisFlow[p].Value)); }
public override bool LessThan(QsValue value) { throw new NotImplementedException(); }
public override bool Inequality(QsValue value) { throw new NotImplementedException(); }
public override QsValue DivideOperation(QsValue value) { return(ContentValue.DivideOperation(value)); }
public override QsValue SubtractOperation(QsValue value) { throw new NotImplementedException(); }
public override bool LessThanOrEqual(QsValue value) { return(ContentValue.LessThanOrEqual(value)); }
public override bool GreaterThanOrEqual(QsValue value) { return(ContentValue.GreaterThanOrEqual(value)); }
/// <summary> /// /// </summary> /// <param name="value"></param> /// <returns></returns> public override QsValue MultiplyOperation(QsValue value) { var sc = value as QsScalar; if (!Object.ReferenceEquals(sc, null)) { if (sc.ScalarType == ScalarTypes.FunctionQuantity) { if (!Object.ReferenceEquals(sc.FunctionQuantity, null)) { var f = (QsFunction)sc.FunctionQuantity.Value; foreach (var op in operations) { switch (op.Operation) { case Operator.Differentiate: f = (QsFunction)f.DifferentiateOperation(op.value); break; default: throw new NotImplementedException(); } } return(f.ToQuantity().ToScalar()); } } else if (sc.ScalarType == ScalarTypes.SymbolicQuantity) { var f = sc.SymbolicQuantity.Value; foreach (var op in operations) { switch (op.Operation) { case Operator.Differentiate: { var dsv = ((QsScalar)op.value).SymbolicQuantity.Value; int times = (int)dsv.SymbolPower; while (times > 0) { f = f.Differentiate(dsv.Symbol); times--; } } break; default: throw new NotImplementedException(); } } return(f.ToQuantity().ToScalar()); } else { //throw new QsException("Can't multiply current operation for this scalar " + sc.ScalarType.ToString()); return(QsScalar.Zero); } } throw new NotImplementedException(); }
public override QsValue ModuloOperation(QsValue value) { return(ContentValue.ModuloOperation(value)); }
public override QsValue SubtractOperation(QsValue value) { return(new QsBoolean { Value = this.Value | !((QsBoolean)value).Value }); }
public override QsValue AddOperation(QsValue value) { return(new QsBoolean { Value = this.Value | ((QsBoolean)value).Value }); }
public override QsValue LeftShiftOperation(QsValue times) { throw new NotImplementedException(); }
public override QsValue SubtractOperation(QsValue value) { return(ContentValue.SubtractOperation(value)); }
public override bool Inequality(QsValue value) { return(ContentValue.Inequality(value)); }
public override QsValue MultiplyOperation(QsValue value) { return(ContentValue.MultiplyOperation(value)); }
public override QsValue DotProductOperation(QsValue value) { return(ContentValue.DotProductOperation(value)); }
public override QsValue PowerOperation(QsValue value) { return(ContentValue.PowerOperation(value)); }
public override QsValue CrossProductOperation(QsValue value) { return(ContentValue.CrossProductOperation(value)); }
public override QsValue ModuloOperation(QsValue value) { throw new NotImplementedException(); }
public override QsValue TensorProductOperation(QsValue value) { return(ContentValue.TensorProductOperation(value)); }
public override bool GreaterThanOrEqual(QsValue value) { throw new NotImplementedException(); }
public override QsValue LeftShiftOperation(QsValue times) { return(ContentValue.LeftShiftOperation(times)); }
public override QsValue TensorProductOperation(QsValue value) { throw new NotImplementedException(); }
public override void SetIndexedItem(QsParameter[] indices, QsValue value) { ContentValue.SetIndexedItem(indices, value); }
/// <summary> /// ! Operator /// </summary> /// <param name="key"></param> /// <returns></returns> public override QsValue ExclamationOperator(QsValue value) { string vt = ((QsText)value).Text; return(ValueToQsValue(ThisFlow[vt].Value)); }
public override QsValue AddOperation(QsValue value) { return(ContentValue.AddOperation(value)); }
/// <summary> /// Take the value and operation in text and return the current function operationed by value. /// </summary> /// <param name="value"></param> /// <param name="operation"></param> /// <returns></returns> private QsFunction FOperation(QsValue value, string operation) { if (value is QsFunction) { QsFunction fn2 = (QsFunction)value; string fParameters = RemoveRedundantParameters(this.ParametersNames.Union(fn2.ParametersNames).ToArray()); string thisFunctionBody = this.FunctionBody; foreach (string p in this.ParametersNames) { thisFunctionBody = thisFunctionBody.Replace(p, "$" + p); } string targetFunctionBody = fn2.FunctionBody; foreach (string p in fn2.ParametersNames) { targetFunctionBody = targetFunctionBody.Replace(p, "$" + p); } // form the expressions that will be parsed. string fpt = "(" + thisFunctionBody + ")" + operation + "(" + targetFunctionBody + ")"; fpt = fpt.Replace("!", "__FAC__"); // replacing the ! sign with __FAC__ to include the '!' sign into the calculations {because '!' is operator in parsing so it doesn't enter the algebraic calculations} //evaulate fpt try { QsScalar sc = (QsScalar)QsEvaluator.CurrentEvaluator.SilentEvaluate(fpt); string FuncBody = sc.SymbolicQuantity.Value.ToString().Replace("__FAC__", "!"); string WholeFunction = "_(" + fParameters + ") = " + FuncBody; return(QsFunction.ParseFunction(QsEvaluator.CurrentEvaluator, WholeFunction)); } catch (QsIncompleteExpression) { // something happened make the operation in old fashion string WholeFunction; Token FunctionToken = JoinFunctionsArrayTokensWithOperation(operation, out WholeFunction, this, fn2); return(QsFunction.ParseFunction(QsEvaluator.CurrentEvaluator, WholeFunction, FunctionToken)); } } else if (value is QsScalar) { QsScalar svl = (QsScalar)value; var fname = "_"; var fbody = this.FunctionBody; if (svl.ScalarType == ScalarTypes.SymbolicQuantity) { fbody = "(" + fbody + ")" + operation + "(" + svl.SymbolicQuantity.Value.ToString() + ")"; } else if (svl.ScalarType == ScalarTypes.NumericalQuantity) { fbody = "(" + fbody + ")" + operation + svl.NumericalQuantity.Value.ToString(); } else if (svl.ScalarType == ScalarTypes.RationalNumberQuantity) { fbody = "(" + fbody + ")" + operation + svl.RationalQuantity.Value.Value.ToString(); } else if (svl.ScalarType == ScalarTypes.FunctionQuantity) { fbody = "(" + fbody + ")" + operation + "(" + svl.FunctionQuantity.Value.FunctionBody + ")"; } else { throw new QsException("Operation '" + operation + "' for the target scalar type (" + svl.ScalarType + ") is not supported"); } QsScalar fb = SymbolicVariable.Parse(fbody).ToQuantity().ToScalar(); string FuncBody = string.Empty; if (fb.ScalarType == ScalarTypes.SymbolicQuantity) { FuncBody = fb.SymbolicQuantity.Value.ToString().Replace("__FAC__", "!"); } else { FuncBody = fb.ToExpressionParsableString(); } string[] functionParametersArray = this.ParametersNames; // this is the available parameters for the original function. if (svl.ScalarType == ScalarTypes.SymbolicQuantity) { List <string> newParametersList = new List <string>(functionParametersArray); newParametersList.AddRange(svl.SymbolicQuantity.Value.InvolvedSymbols); functionParametersArray = newParametersList.ToArray(); } if (svl.ScalarType == ScalarTypes.FunctionQuantity) { List <string> newParametersList = new List <string>(functionParametersArray); newParametersList.AddRange(svl.FunctionQuantity.Value.ParametersNames); functionParametersArray = newParametersList.ToArray(); } var f = fname + "(" + RemoveRedundantParameters(functionParametersArray) + ") = " + FuncBody; return(QsFunction.ParseFunction(QsEvaluator.CurrentEvaluator, f)); } else { throw new NotImplementedException(); } }
public override QsValue MultiplyOperation(QsValue value) { return(new QsBoolean { Value = this.Value & ((QsBoolean)value).Value }); }