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

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