Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • $\begingroup$ Just want to note, that if you remove OneIdentity attribute, then you will get quite different results. I think here is key of the problem. $\endgroup$ Commented Nov 7, 2014 at 10:06
  • $\begingroup$ @user18792 No, as explained in the document of Flat: "when functions that are Flat are used in pattern matching, they often also require the attribute OneIdentity", so removing OneIdentity will make the function ill defined. Even if OneIdentity is removed, the slowdown of f@@A is still there. My question is about the slowdown due to the Flat attribution. I don't think OneIdentity plays any role in this phenomenon. $\endgroup$ Commented Nov 7, 2014 at 10:17
  • $\begingroup$ Just an observation that you may or may not be aware of is that the order of the definition of the downvalues of f is important and it may be what causes the more/less efficient evaluation of f for different ordered arguments. For instance, if you exchange the first two definitions, f@@B is -2 whereas f@@A still 0. $\endgroup$ Commented Nov 7, 2014 at 12:12
  • $\begingroup$ @gpap Thanks for your comment. The ordering of downvalue definitions indeed matters. Also f@@B evaluates to -2 is a bug. I do not expect the result to change. I found one has to enforce the condition i != j in the definition of f[i_, j_] in order to get the right result. But usually having defined f[i_, i_], f[i_, j_] is assumed to take different i and j. But I don't understand why it does not behave as expected here. $\endgroup$ Commented Nov 7, 2014 at 19:03