evaluation

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

applicative-order/call-by-value and normal-order/call-by-name differences

巧了我就是萌 提交于 2019-12-06 16:03:57
Background I am learning the sicp according to an online course and got confused by its lecture notes. In the lecture notes, the applicative order seems to equal cbv and normal order to cbn. Confusion But the wiki points out that, beside evaluation orders(left to right, right to left, or simultaneous), there is a difference between the applicative order and cbv: Unlike call-by-value, applicative order evaluation reduces terms within a function body as much as possible before the function is applied. I don't understand what does it mean by reduced. Aren't applicative order and cbv both going to

Disambiguation of expressions with neighboring operators of different associativity and same precedence

和自甴很熟 提交于 2019-12-06 11:54:31
Say I have an expression as follows (where ⨁ and ⨂ are binary operators which have the same precedence level but not the same associativity): x ⨁ y ⨂ z Would y belong to ⨁ or ⨂ , and based on what criteria? According to the Edsgar Dijkstra's Shunting-yard algorithm if neighboring two operators in an expressions have the same precedence level then the expression is disambiguated based on the associativity of the second operator. If the second operator is left associative then the operand belongs to the first operator. If the second operator is right associative then the operand belongs to the

Evaluation of multiples 'IN' Expressions in 'WHERE' clauses in mysql

有些话、适合烂在心里 提交于 2019-12-05 21:35:16
问题 Updating by @Cesar 's request. Hope I understood what you want, if not, please revert. Quassnoi. If I make an SQL query like this: SELECT * FROM TABLE_NAME WHERE b IN (2, 7) AND c IN (3, 9) , can I assume that MySQL will match only pairs from elements with same number in each list? That is, (2, 3) , (7, 9) , ...? For example, suppose we have a table like this: +----------+----------+----------+ | PK | b | c | +----------+----------+----------+ | 1 | 2 | 3 | +----------+----------+----------+

Mathematica — why does TreeForm[Unevaluated[4^5]] evaluate the 4^5?

独自空忆成欢 提交于 2019-12-05 03:49:44
If I give Mathematica the input TreeForm[Unevaluated[4^5]] I expect to see three boxes -- power, 4, and 5. Instead I see a single box with 1024. Can anyone explain? Compare TreeForm@Unevaluated[4^5] with TreeForm@Hold[4^5] From the help: Unevaluated[expr] represents the unevaluated form of expr when it appears as the argument to a function. and Hold[expr] maintains expr in an unevaluated form. so, as Unevaluated[4^5] gets to TreeForm ... it gets evaluated ... It works like this: f[x_+y_]:=x^y; f[3+4] (* -> f[7] *) f[Unevaluated[3+4]] (* ->81 *) A level of Unevaluated is stripped off with every

Forced strictness for lists in haskell

ぃ、小莉子 提交于 2019-12-05 00:54:19
I made really time consuming algorithm which produces a short string as the result. When I try to print it (via putStrLn) it appears on the screen character by character. I did understand why that happened, and I tried to force evaluation of the string before actual printing. myPrint !str = putStrLn str But this help very little. When I ran the program in debug I noticed that the !str forced evaluation only for the first character. Does anyone know why is that, and how to deal with this? (!) translates into seq , which evaluates strictly to Weak Head Normal Form -- that is, it only evaluates

Cluster quality measures

守給你的承諾、 提交于 2019-12-04 23:17:49
问题 Does Matlab provide any facility for evaluating clustering methods? (cluster compactness and cluster separation. ....) Or is there any toolbox for it? 回答1: Not in Matlab, but ELKI (Java) provides a dozen or so cluster quality measures for evaluation. 回答2: Matlab provides Silhouette index and there is a toolbox CVAP: Cluster Validity Analysis Platform for Matlab. Which includes following validity indexes: Davies-Bouldin Calinski-Harabasz Dunn index R-squared index Hubert-Levin (C-index)

Idris eager evaluation

瘦欲@ 提交于 2019-12-04 22:17:06
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 (spin 100000000) (void)) -- takes a moment In Idris , I might implement if like this: if' : Bool -> a -> a

Safely evaluating arithmetic expressions in R?

﹥>﹥吖頭↗ 提交于 2019-12-04 21:08:17
问题 Edit Ok, since there seems to be a lot of confusion, I'm going to simplify the question a little. You can try to answer the original question below, or you can tackle this version instead and ignore everything below the line. My goal is to take an arbitrary expression and evaluate it in an extremely restricted environment. This environment will contain only variables with the following types of values: Numeric vectors Pure functions that take one or more numeric vectors and return numeric

Create RMSLE metric in caret in r

拟墨画扇 提交于 2019-12-04 21:07:19
Could someone please help me with the following: I need to change my xgboost training model with caret package to an undefault metric RMSLE. By default caret and xgboost train and measure in RMSE. Here are the lines of code: create custom summary function in caret format custom_summary = function(data, lev = NULL, model = NULL){ out = rmsle(data[, "obs"], data[, "pred"]) names(out) = c("rmsle") out } create control object control = trainControl(method = "cv", number = 2, summaryFunction = custom_summary) create grid of tuning parameters grid = expand.grid(nrounds = 100, max_depth = 6, eta = 0