Example #1
0
 public override bool Inequality(QsValue value)
 {
     return(this.Value != ((QsBoolean)value).Value);
 }
Example #2
0
 public override void SetIndexedItem(QsParameter[] indices, QsValue value)
 {
     throw new NotImplementedException();
 }
Example #3
0
        public override QsValue ColonOperator(QsValue value)
        {
            int p = (int)((QsScalar)value).NumericalQuantity.Value;

            return(ValueToQsValue(ThisFlow[p].Value));
        }
Example #4
0
 public override bool LessThan(QsValue value)
 {
     throw new NotImplementedException();
 }
Example #5
0
 public override bool Inequality(QsValue value)
 {
     throw new NotImplementedException();
 }
Example #6
0
 public override QsValue DivideOperation(QsValue value)
 {
     return(ContentValue.DivideOperation(value));
 }
Example #7
0
 public override QsValue SubtractOperation(QsValue value)
 {
     throw new NotImplementedException();
 }
Example #8
0
 public override bool LessThanOrEqual(QsValue value)
 {
     return(ContentValue.LessThanOrEqual(value));
 }
Example #9
0
 public override bool GreaterThanOrEqual(QsValue value)
 {
     return(ContentValue.GreaterThanOrEqual(value));
 }
Example #10
0
        /// <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();
        }
Example #11
0
 public override QsValue ModuloOperation(QsValue value)
 {
     return(ContentValue.ModuloOperation(value));
 }
Example #12
0
 public override QsValue SubtractOperation(QsValue value)
 {
     return(new QsBoolean {
         Value = this.Value | !((QsBoolean)value).Value
     });
 }
Example #13
0
 public override QsValue AddOperation(QsValue value)
 {
     return(new QsBoolean {
         Value = this.Value | ((QsBoolean)value).Value
     });
 }
Example #14
0
 public override QsValue LeftShiftOperation(QsValue times)
 {
     throw new NotImplementedException();
 }
Example #15
0
 public override QsValue SubtractOperation(QsValue value)
 {
     return(ContentValue.SubtractOperation(value));
 }
Example #16
0
 public override bool Inequality(QsValue value)
 {
     return(ContentValue.Inequality(value));
 }
Example #17
0
 public override QsValue MultiplyOperation(QsValue value)
 {
     return(ContentValue.MultiplyOperation(value));
 }
Example #18
0
 public override QsValue DotProductOperation(QsValue value)
 {
     return(ContentValue.DotProductOperation(value));
 }
Example #19
0
 public override QsValue PowerOperation(QsValue value)
 {
     return(ContentValue.PowerOperation(value));
 }
Example #20
0
 public override QsValue CrossProductOperation(QsValue value)
 {
     return(ContentValue.CrossProductOperation(value));
 }
Example #21
0
 public override QsValue ModuloOperation(QsValue value)
 {
     throw new NotImplementedException();
 }
Example #22
0
 public override QsValue TensorProductOperation(QsValue value)
 {
     return(ContentValue.TensorProductOperation(value));
 }
Example #23
0
 public override bool GreaterThanOrEqual(QsValue value)
 {
     throw new NotImplementedException();
 }
Example #24
0
 public override QsValue LeftShiftOperation(QsValue times)
 {
     return(ContentValue.LeftShiftOperation(times));
 }
Example #25
0
 public override QsValue TensorProductOperation(QsValue value)
 {
     throw new NotImplementedException();
 }
Example #26
0
 public override void SetIndexedItem(QsParameter[] indices, QsValue value)
 {
     ContentValue.SetIndexedItem(indices, value);
 }
Example #27
0
        /// <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));
        }
Example #28
0
 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();
            }
        }
Example #30
0
 public override QsValue MultiplyOperation(QsValue value)
 {
     return(new QsBoolean {
         Value = this.Value & ((QsBoolean)value).Value
     });
 }