expression-evaluation

Matlab - Evaluate Function from String [duplicate]

房东的猫 提交于 2019-12-12 04:44:09
问题 This question already has an answer here : How can I create function pointers from a string input in MATLAB? (1 answer) Closed 2 years ago . Some Matlab functions handle string functions representation as f='a^x^b+sin(c*x)+d' --i.e. Curve Fitting, Optimization, etc.-- Suppose the variables a , b , c , d and x are given. Is there any function for evaluating f from its string representation? 回答1: You can do eval(f) , but using eval is really discouraged https://uk.mathworks.com/help/matlab

Left to right expression evaluation

女生的网名这么多〃 提交于 2019-12-10 14:28:48
问题 In C# is it guaranteed that expressions are evaluated left to right? For example: myClass = GetClass(); if (myClass == null || myClass.Property > 0) continue; Are there any languages that do not comply? 回答1: You actually refer to a language feature called "short-circuiting logical expressions": What this means is this: When the outcome of a logical expression cannot change anymore, e.g. when it is clear that the expression will evaluate to "true" or "false" no matter what, remaining parts of

Macro which prints an expression and evaluates it (with __STRING)

隐身守侯 提交于 2019-12-10 14:17:18
问题 For learning and demonstrating, I need a macro which prints its parameter and evaluates it. I suspect it is a very common case, may be even a FAQ but I cannot find actual references. My current code is: #define PRINT(expr) (fprintf(stdout, "%s -> %d\n", __STRING(expr), (expr))) and then: PRINT(x & 0x01); It works fine but I am not sure of the legal status of the __STRING macro, specially since it is in the private __ namespace. So, my questions: Is there a better way to write this macro? Is _

Building and evaluating expressions using Delphi RTTI

断了今生、忘了曾经 提交于 2019-12-10 12:18:58
问题 I am faced with a task of allowing the user to define the expressions using the compiled classes with RTTI enabled. Let me put it in a simple way. TAnimal = class(TPersistent) private fWeight : Double; fHeight : Double; fName : string; published property Weight : Double read fWeight write fWeight; property Height : Double read fHeight write fHeight; property Name : string read fName write fName; end; And i have a routine which will evaluate the animal with the supplied expression function

Double assignment of the same variable in one expression in C++11

∥☆過路亽.° 提交于 2019-12-09 09:03:41
问题 The C++11 standard (5.17, expr.ass) states that In all cases, the assignment is sequenced after the value computation of the right and left operands, and before the value computation of the assignment expression. With respect to an indeterminately-sequenced function call, the operation of a compound assignment is a single evaluation As I understand it, all expressions which are a part of the given assignment will be evaluated before the assignment itself. This rule should work even if I

Idris eager evaluation

假装没事ソ 提交于 2019-12-06 16:36:31
问题 In Haskell , I might implement if like this: if' True x y = x if' False x y = y spin 0 = () spin n = spin (n - 1) This behaves how I expect : haskell> if' True (spin 1000000) () -- takes a moment haskell> if' False (spin 1000000) () -- immediate In Racket , I could implement a flawed if like this: (define (if2 cond x y) (if cond x y)) (define (spin n) (if (= n 0) (void) (spin (- n 1)))) This behaves how I expect : racket> (if2 #t (spin 100000000) (void)) -- takes a moment racket> (if2 #f

Arithmetic Expression Evaluation using Reverse Polish Notation (RPN)

风格不统一 提交于 2019-12-05 17:30:28
A mathematical expression is usually expressed in infix notation. For evaluation purposes, we can change it to postfix (reverse polish) notation (using algorithms like Shunting-Yard ) and then evaluate the postfix notation using stack. I found out that calculators use this technique, but do today's modern compilers use this for arithmetic expression evaluation? Is it efficient enough or other techniques (or algorithms) are being used? To answer this question let's focus on the concepts you mention, infix notation , Shunting-Yard and evaluation and then relate them to compiling. To start with

How to add a new function to Ncalc

戏子无情 提交于 2019-12-05 04:21:21
问题 I'm using Ncalc in my new project and it already has almost everything I need . I said almost everything, because now I need to expand some functions and also add new ones such as : nth root,random, etc Do you know if anyone has already implemented those functions? Or could you give me any tips or guides to extend the function list of Ncalc??? Thanks in advance. 回答1: If I understand correctly: As much as I was using it is by creating a static function private static void

updating references in an expression with a nested assignment

為{幸葍}努か 提交于 2019-12-05 04:03:45
Looking at this example code similar to this question : public class A { public static void main(String args[]){ A a = new A(); System.out.println(a.equals((a = null))); } } This prints false. Why doesn't it fail with a NullPointerException? The assignment has to get processed before the equals method can run, but somehow that doesn't affect the reference that equals is called on until after the whole line is evaluated? I didn't see where in the Java language spec it describes this, did I miss it somewhere? ζ-- From JLS : At run time, method invocation requires five steps. First, a target

What is the most efficient way to recalculate attributes of a Boost Spirit parse with a different symbol table?

孤人 提交于 2019-12-05 02:56:25
问题 I'm using Boost Spirit to implement functionality in some software that allows the user to enter a mathematical equation that will be repeatedly applied to an input stream. Input stream values are represented as symbols using boost::spirit::qi::symbols which the user can reference in their equation. (e.g. out1 = 3 * in1 + in2 ) Parsing and compiling the user's equation is not performance sensitive but calculating its output value is as it forms part of a time-critical pipeline. The standard