# Tag Info

33

For this purpose, I wrote a small Symbol Information Palette. This palette let's you quickly look up usages, options and attributes of symbols and was tested on Mac OSX and Linux. Installation The source code is hosted on my GitHub site but to preview or install the palette you only have to evaluate this: Get["http://goo.gl/QPywk"] The link is just ...

24

Your question really is about how to make attributes of f affect also the evaluation of other groups of elements, like y and z in f[x___][y___][z___]. To my knowledge, you can not do it other than using tricks like returning a pure function and the like. This is because, the only tool you have to intercept the stages of evaluation sequence when y and z are ...

15

The best option then is to bestow the attribute NHold on the head f. In[2]:= SetAttributes[f, NHoldAll] In[3]:= 2 + f[Sqrt[2] + 1] // N Out[3]= 2. + f[1 + Sqrt[2]]

14

Here is the simplest answer: sum[n_] := Sum[i x[i], {i, 1, n}] x /: D[x[i_], x[j_], NonConstants -> {x}] := KroneckerDelta[i, j] D[sum[n], x[2], NonConstants -> x] $\begin{cases} 2 & n>1 \\ 1-n & \text{True} \end{cases}$ The trick here is the use of the NonConstants option of the derivative operator. This then has to be ...

14

Generally, a good advice would be to set attributes before giving definitions to the function. The difference in your case is caused by the effect that I call evaluation during assignments. There was a question devoted to it in the past, where I contributed an answer with a detailed analysis of the problem. I also mentioned this problem in my recent ...

14

Ok, I'm going to try to explain my best conjuecture as to how this happens, and don't even try to answer why. There are three reasons for this behaviour: SetDelayed left hand side evaluation As others have mentioned, even though SetDelayed has attributes that indicate it holds the lhs, it does evaluate the head and the arguments of it, just not the ...

13

Yes, this form exists, and was first shown to me by Leonid. It is: Function[Null, (* body with ## *), (* attributes *)] As always the Null may be implicit, so in your application: Function[, Length[Unevaluated@#1]{##2}, HoldFirst][1+2,2+3,3+1] {10, 8}

12

It is because, in version 9, the implementation of Plot is loaded from a dump file on its first usage, rather than loading when the kernel starts. One can see this by clearing the ReadProtected attribute: ClearAttributes[Plot, ReadProtected] Information[Plot] (* -> Plot := SystemDumpAutoLoad[ Hold[Plot], Hold[syms], VisualizationProto ...

9

Here's an example that should help: In[1]:= makeFoo[] := foo @@ RandomInteger[10, 3] foo[first_, _, _]["First"] := first foo[_, second_, _]["Second"] := second foo[_, _, third_]["Third"] := third foo[a_, b_, c_][x_] := a x^2 + b x + c In[6]:= f = makeFoo[] Out[6]= foo[4, 2, 9] In[7]:= f["Second"] Out[7]= 2 In[8]:= f[x] Out[8]= 9 + 2 x + 4 x^2 For the ...

9

No, I do not believe it is. As the documentation for your error message says: The attributes available in each version of Mathematica are fixed and cannot be changed. The system attributes are low level properties that fundamentally change the evaluation of symbols. I think it makes sense that these are not mixed with high-level user constructs, even ...

9

My guess would be this: ToExpression[ Names["pack`*"], InputForm, Function[sym,SetAttributes[sym, {ReadProtected(*,Locked*)}],HoldFirst] ] The problem is that functions defined with # - & notation do not hold their arguments.

9

You could also use Distribute: Integrate[integrand, mp] // Distribute $m^2 \text{mp}+\frac{\text{mp}^3}{3}+\int \text{mp} f[\text{mp}] \, d\text{mp}$

9

Save defaults before any changes attrLog = Log // Attributes; ClearAttributes[Log, Listable] Log // Attributes {NumericFunction, Protected} Restore defaults Attributes[Log] = attrLog {Listable, NumericFunction, Protected}

8

When you don't restart the Kernel (by using Quit[] or restarting Mathmeatica) then you will always get this behaviour because (1) you have protected the functions yourself and (2) you try to redefine them by reloading the package. It is like evaluating the following twice: f[x_]:=x^2; Protect[f] During evaluation of SetDelayed::write: Tag f in f[x_] ...

8

If you have not saved the attributes before changing them, and also can't quit the Kernel, then you could launch a Subkernel and get the original attributes that way: ClearAttributes[Log, Listable] Attributes[Log] {NumericFunction, Protected} First@ParallelEvaluate[Attributes[Log]] {Listable,NumericFunction,Protected}

7

I did some computation of formal derivatives a while back which might be of interest in this context (though keep in mind that this is anything but bullet proof! it does work for the cases I bothered to check though). Clear[a]; Format[a[k_]] = Subscript[a, k] Let us say we have an objective function which is formally a function of the vector a[i] Q ...

7

This is the expected behaviour of Unevaluated, but is not fully covered in the documentation. Unevaluated is a special head that changes the attributes temporarily so that the function f holds its argument. It is supposed to work as if you had given it one of the HoldFirst/HoldAll, etc. attribute, but only for that evaluation. The key point though, is that ...

7

For your specific problem, the following piece of code will work In[1]:= myFunc[data_] := Module[{result}, result["property"] = "123abc"; result[v_] := data + v*3; Return[result]; ]; In[2]:= a=myFunc[10]; a["property"] a[x] Out[2]= 123abc 10 + 3x

7

It is not very common, but sometimes, $Failed is used as a head, like f[x___]:=$Failed[x] This makes it possible to have "return code" returned, rather than just a fact of failure. Basically, when this is used, it is usually in the error-reporting fall-back rule. In some cases, one may want to not evaluate the arguments x (e.g. if f is Hold*). I don't ...

6

You have to think about, what happens when you evaluate the line l1={a,b,c}. At this point, all your variables on the right side are evaluated and l1 contains only the data. The solution is simple: use Hold instead of List a = 1; b = 2; c = 3; l1 = Hold[a, b, c]; ReleaseHold[{printName /@ l1}]

5

You can use Map because it works with expressions of Head other than List, too: integrand = m^2 + mp^2 + mp f[mp]; Map[Integrate[#, mp] &, integrand] $\int \text{mp} f(\text{mp}) \, d\text{mp}+m^2 \text{mp}+\frac{\text{mp}^3}{3}$ Or the definitie integral: Map[Integrate[#, {mp, -1, 1}] &, integrand] \$\int_{-1}^1 \text{mp} ...

5

You're right, applying FullDefinition I see that DiracDelta lacks the NumericFunction attribute. And indeed, NumericQ[DiracComb[1]] yields True whereas NumericQ[DiracDelta[0]] doesn't. Although I'm not sure why that difference exists, you may perhaps be able to get the desired result (you didn't say what your bug was) by setting SetAttributes[DiracDelta, ...

5

This is what I have so far. It's far from complete, but still a good start I think. listableQ[s_Symbol] /; MemberQ[Attributes @ s, Listable] := True listableQ[s_Symbol] := MatchQ[DownValues[s], {__?test2}] listableQ[Verbatim[Function][_, _, attr_]] /; ! FreeQ[{attr}, Listable] := True listableQ[Verbatim[Function][vars_, body_, ___]] := test1[vars, body] ...

5

This is only a hack, but maybe it just gives you short way out of this. Lately, we had a similar discussion in chat about NValues where the problem was related. It this cases Rojo wanted to use NValues to prevent some of the arguments to stay untouched by N. There too, the problem was when N was called from very outside and dived into the subexpressions ...

5

This is obviously an annoying problem - you can't easily keep the flexibility to reload the package with Get during the development and at the same time keep certain functions Protected / Locked. Just Protected by itself can be dealt with, as explained by halirutan in his answer, but if you add Locked, you are out of luck. Perhaps, the easiest way out is to ...

4

I researched Flat a little bit about a year ago when I wrote this answer. It isn't as clear as can be. It needs updating, and perhaps I'll do that soon. In any case, taking the relevant paragraph: When the pattern matcher finds itself comparing arguments of an expression whose head (let's call it head) has attribute Flat, it behaves differently: patterns of ...

4

From your question it can be deduced that you're interested only in the Euclidean scalar product for real vector spaces, so I'll make that assumption. In version 9, I think the cleanest way to do the symbolic manipulations you're after is to use the new capabilities of TensorReduce. The special case of a null vector does require care because the product of ...

4

Using << (or Get) always attempts to evaluate the package. As you have protected your definitions you get the error messages unless you start a new Mathematica kernel. Better is to use Needs to load your packages (when you are not actively developing the package in question). This checks to see if the package context is already known and only ...

3

Using the built-in functions mentioned in @Oska's comment: ws = RandomGraph[WattsStrogatzGraphDistribution[6, 0.1, 2]]; centralities = {LocalClusteringCoefficient, EccentricityCentrality, VertexDegree, ClosenessCentrality, BetweennessCentrality}; Through[centralities[ws]] // Style[TableForm[Round[#, .001], TableHeadings -> {centralities, ...

3

Fundamental problem Pardon me if I miss some points of your question as I didn't attempt to understand what your code is intended to do, because I think I understand what the problem is from the title alone. Please consider: SetAttributes[f, {HoldFirst, Listable}]; f[x_] := foo[x] f[{1, 2, 3}] {foo[1], foo[2], foo[3]} bar = {1, 2, 3}; f[bar] ...

Only top voted, non community-wiki answers of a minimum length are eligible