Skip to main content
26 events
when toggle format what by license comment
Jun 16, 2020 at 9:23 history edited CommunityBot
Commonmark migration
Apr 13, 2017 at 12:55 history edited CommunityBot
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Sep 10, 2016 at 13:22 comment added luyuwuli @AlexeyPopkov I thought Villegas-Gayley technique for a while but still can't find the solution to the question. I've post a new question related to this. Wish you could help me.
Sep 10, 2016 at 13:21 history edited Alexey Popkov CC BY-SA 3.0
added 1326 characters in body
Sep 10, 2016 at 13:16 history edited Alexey Popkov CC BY-SA 3.0
added 1326 characters in body
Sep 10, 2016 at 12:45 comment added luyuwuli OK. Thanks for your explanation. I'll post a new question related to this:)
Sep 10, 2016 at 12:44 comment added Alexey Popkov @luyuwuli It is possible (in part) to achieve this using the Villegas-Gayley technique but in the case of Associations we probably have something deeply wired into the system. Actually Association originally didn't have the HoldAllComplete attribute at all, so strictly speaking the explanation provided in my answer may be only superficially correct. Unfortunately I can't provide better explanation, and I think that it is worth to ask specific question on this issue.
Sep 10, 2016 at 12:43 comment added luyuwuli @AlexeyPopkov Thanks for your links in the comment. Even though I've seen it long time ago, I'm still now struggling to understand the long post written by Leonid.
Sep 10, 2016 at 12:37 comment added luyuwuli @AlexeyPopkov Thanks for your reply. My confusion is, by internal definitions of Association, one can evaluate the "held part", however, compare x[1]=0; <|"x" -> x[1]|>(it returns <|"x" -> 0|>) with the example in your post (it only assign a name to it, and it returns <|"x" -> x[1]|>) How could be this possible? What prevents it from further evaluation (to <|"x" -> 0|>)?
Sep 10, 2016 at 12:35 comment added Alexey Popkov @luyuwuli You can ask a separate question on why it is implemented in this way (if there is no one already) but in a comment I can only say that the HoldAllComplete attribute prevents evaluation of arguments inside of the head which has this attribute and no more. For example: SetAttributes[f, HoldAllComplete]; f[arg_] := g[arg]; f[1 + 1] returns g[2] as expected. In the case of Association after evaluation you get entirely different object which isn't like HoldComplete[...].
Sep 10, 2016 at 11:35 comment added luyuwuli I'm confused about the HoldAllComplete attribute, if one evaluates x[1]=0; <|"x" -> x[1]|>, it will return <|"x" -> 0|>, however, as you've shown, assign a name (assoc) to Association and evaluate assoc again will somehow prevent it from further evaluation (to 0). Why would this happen? IMHO, the HoldAllComplete should even prevent <|"x"->1+1|> from being <|"x"->2|>.
Jun 29, 2016 at 22:48 vote accept masterxilo
Jun 29, 2016 at 22:42 history edited Alexey Popkov CC BY-SA 3.0
wrong reasonings are removed (see comments)
Jun 29, 2016 at 22:39 comment added Alexey Popkov The only thing that puzzles me is why Plot[g[<|"x" -> x|>], {x, 0, 1}] works with my definition for g. Even Plot[Evaluate@g[<|"x" -> x|>], {x, 0, 1}] works...
Jun 29, 2016 at 22:37 comment added Alexey Popkov @masterxilo It is indeed related to the HoldAllComplete attribute and works the same way if we use HoldComplete instead of Association. Try the definition h[HoldComplete[x_]] /; NumericQ[x] := x^2: evaluation of x =.; y = h[HoldComplete[x]]; x = 0; y returns h[HoldComplete[x]]. But if we replace HoldComplete with Hold, it returns 0. So I was wrong, I'll remove the corresponding part of my answer (but it will be kept in the edit history if one is interested).
Jun 29, 2016 at 22:26 comment added Alexey Popkov @masterxilo It seems I was wrong saying that g[a_Association] /; NumericQ[a["x"]] := a["x"]^2; should work. But the problem is subtle: once evaluated assoc = <|"x" -> x|> will never become <|"x" -> 0|> BUT assoc["x"] will return 0 if x = 0. With my definition I tried to use this feature. Now I see that if the RHS of the expression y = g[<|"x" -> x|>] is evaluated once to g[<|"x" -> x|>], then x = 0; y will return g[<|"x" -> x|>] with my definition.
Jun 29, 2016 at 22:10 comment added masterxilo I'm not sure whether your 'Further elaboration' really shows an additional problem. In line with what you said, Association has HoldAllComplete, so g[<|"x" -> x|>] will, after having been evaluated once, never evaluate to g[<|"x" -> 0|>], even when you assign 0 to x later on. I think the only real problem is in the inconsistency of Plot and NIntegrate et. al then?
Jun 29, 2016 at 10:29 history edited Alexey Popkov CC BY-SA 3.0
added 671 characters in body
Jun 29, 2016 at 9:59 comment added masterxilo Just curious: Can you maybe elaborate on what you can read from the error message other than that Experimental'NumericalFunction is involved, and that the expression is converted to it before stuff starts failing.
Jun 29, 2016 at 9:54 comment added masterxilo Oh, right, all of these functions localize variables effectively using Block, so in a sense they overwrite global variables during each evaluation and then reset them again.
Jun 29, 2016 at 9:38 history edited Alexey Popkov CC BY-SA 3.0
added 33 characters in body
Jun 29, 2016 at 8:27 history edited Alexey Popkov CC BY-SA 3.0
added 21 characters in body
Jun 29, 2016 at 8:02 history edited Alexey Popkov CC BY-SA 3.0
added 994 characters in body
Jun 29, 2016 at 7:44 history edited Alexey Popkov CC BY-SA 3.0
added 2 characters in body
Jun 29, 2016 at 7:28 history edited Alexey Popkov CC BY-SA 3.0
added 340 characters in body
Jun 29, 2016 at 7:19 history answered Alexey Popkov CC BY-SA 3.0