Tag Info

29

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 ...

19

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 ...

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 ...

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 ...

12

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 ...

12

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 ...

8

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 ...

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 ...

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

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

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

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

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 ...

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 ...

3

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 ...

2

With the suggested edits from Rojo in the comments above, the following is what answers my question: plus[args__] := Row[Riffle[{args}, " + "]] Then, Block[{Plus = plus}, x + 1 + i + 4 + z] // TraditionalForm returns:

2

Maybe it helps. It's another ways to copy and change internal functions attributes using Function. Here we create a function myEqual just as Equal but listable, so we don't have to use Block: {A, B} = Developer`ToPackedArray /@ {A, B}; myEqual=Function[Null,Equal[#1,#2],Listable]; A ~myEqual~ B ...

2

One solution might be ... Method 1. Define some variables: x = Table[Unique[], {5}]; Form the inner product and differentiate: D[Inner[Times, x, Range@Length@x], x[[2]]] 2 Or if you prefer it in a functional form: sum[n_] := Inner[Times, x[[1 ;; n]], Range@n] /; ( Length@x >= n) D[sum[4], x[[3]]] 3 Method 2. You could take a ...

2

I don't understand why OneIdentity doesn't work for you but this trick appears to work: SetAttributes[M, Flat]; rule = M[x : Repeated[_F1, {1}]] | M[x : Repeated[_F2, {1}]] :> x; Replace[M[F1[a]], rule] Replace[M[F2[a]], rule] Replace[M[F3[a]], rule] F1[a] F2[a] M[F3[a]] Please make sure to use RuleDelayed (:>) as I did above when working ...

1

EDIT My original answer posted below was a naive misunderstanding. However, For what its worth (apologies again for previous misconception): SetAttributes[Equal, Listable] Pick[#, Release@(Hold[DivisorSigma[1, #] == 2 #])] &@Range[8] works... OLD Pick[#, DivisorSigma[1, #] == 2 #] &@Range[8] your test applies to elements whereas you expect ...

1

For a starter, I would use a function angleExpand like this: SetAttributes[AngleBracket, Orderless]; ruAB = { AngleBracket[a_ (k_?NumericQ), b_] :> k AngleBracket[a, b], AngleBracket[(k_?NumericQ) a_, b_] :> k AngleBracket[a, b], AngleBracket[a_, (k_?NumericQ) b_] :> k AngleBracket[a, b], AngleBracket[a_, b_ (k_?NumericQ)] :> k ...

1

I like image_doctor's solution better, but how about using Array and looking for the position using that index each time? Like this: xx = Array[x, 10, 1]; sum[n_] := Times[List @@ xx , Range[10]] sum[n] (* {x[1], 2 x[2], 3 x[3], 4 x[4], 5 x[5], 6 x[6], 7 x[7], 8 x[8], 9 x[9], 10 x[10]} *) Now sum[n_] := Times[List @@ xx^4, Range[10]] D[sum[n], ...

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