# Tag Info

28

Operator Precedence Table Unless one wishes to write in FullForm a competent Mathematica user must be familiar with at least the majority of syntax precedence rules, which are described in the Operator Precedence table. Clarification: I do not mean that one must memorize (most of) this entire table be competent, but rather that one should know it well ...

19

Maybe I miss the point here, but FullForm[x ↗ y] gives UpperRightArrow[x,y]. This is described in the documentation to UpperRightArrow and since this symbol is not protected and has not built-in meaning, you can just define it the way you like: UpperRightArrow[x_, y_] := FooBar[x, y] and this instantly gives you Update: As answer to Jacobs ...

17

Actually, // is not a postfix operator, itself; it would be considered an infix operator, akin to + or -. It operates by turning x // f into f[x]. You can string several of them together, e.g. x // f // g which is equivalent to g[f[x]], and think of them as successive transformations. This can be very useful for crafting complex transformations, but it does ...

14

There is no need to play around with ReplaceAll, Rule, Block, Module or whatever using D, since you have an oparator Derivative really fulfilling your needs while you need not bother if the arguments were defined, so I recommend it to find symbolic derivatives of your function. Remember of shorthands f', f'' to represent first and second derivatives of ...

14

I can't answer how the association is made for the built-in operators, but I can show how to add your own. If your symbol is already an operator you can do this simply as halirutan showed. This question may be a duplicate of How can one define an infix operator with an arbitrary unicode character? but since it admits a simpler interpretation I shall not ...

13

A general idea as to how this can be done in a consistent way is explained in the help documents under NonCommutativeMultiply. The thing is that you want to use your operators in an algebraic notation, and that's what that page discusses. If, on the other hand, you're happy with a more formal Mathematica notation, then you would have the easier task of ...

13

It's not a bug if you consider this behavior as a logical continuation of the following permissible syntax: D[a + b x^3, x, x, x] (* ==> 6 b *) D[a + b x^3, x, x] (* ==> 6 b x *) D[a + b x^3, x] (* ==> 3 b x^2 *) D[a + b x^3] (* ==> a + b x^3 *) The point is that a Sequence of variables is allowed following the first argument of D. And ...

11

I propose using Interpolation. list = Prime~Array~3000; intf = Interpolation[ {list, Range@Length@list}\[Transpose], InterpolationOrder -> 0 ]; Then, for point x: x = 12225.4; Which[ x < First@list , {-\[Infinity], First@list}, x > Last@list , {Last@list, \[Infinity]}, True , list[[#-1 ;; #]]& @ intf @ ...

11

While the answer of Szabolcs is clearly the best alternative, if you have already assigned values to the variables and clearing them for some reason is no viable option, you can use Block[{s, L0, L1, a}, Hold@Evaluate@D[L[s, L0, L1, a], s]] Unlike Module, Block doesn't introduce new variable names but temporarily removes the values of those given. Hold ...

11

Here is the Mathematica proof. I'll leave out the prefactor $\hbar/i$ for simplicity. Also, in case this is a homework problem, I decided not to add too many comments to the code. Instead I'll let you figure it out. The basic idea is to do cross products and gradients in spherical coordinates. The calculation shown here actually gives you a way to calculate ...

10

Something like this f = D[#, x] + D[#, y] + z # & seems to work. Use as follows: f[x ψ[x, y, z]] to give $x \psi ^{(0,1,0)}(x,y,z)+x \psi ^{(1,0,0)}(x,y,z)+x z \psi (x,y,z)+\psi (x,y,z)$

10

If you need to work with a set of variables symbolically, but you also need to substitute in values for them occasionally, a good approach is to use a rule list: values = {a -> 0.04, L1 = 1, L0 -> 1} If the symbols have no values assigned, you can use them normally in symbolic calculations: L[s_, L0_, L1_, a_] := L1 + L0/(1 + s/a) D[L[s, L0, L1, ...

10

If you are looking for complete answer, take a look at Mr. Wizard's :) Also, see the comments of @JacobAkkerboom below, who proved I was too hasty. :) I was right that the function OP is asking about at the end is Precedence but I was wrong in my interpretation of what is happening. I will leave this for future visitors as it is not so obvious. Also, ...

10

The Notation package is the most convenient way to define new notation(s). <<Notation Define an infix notation. You can use the palette that the 'Notation package pops up to do this. InfixNotation[ParsedBoxWrapper["\[UpperRightArrow]"], FooBar] Check that the infix notation maps to the correct FullForm expression. x \[UpperRightArrow] y // ...

9

You can make use of BinCounts. I think this is a very simple to understand solution because BinCounts does almost exactly what you need already. f[x_, list_List] := Module[{bins}, bins = Join[{-Infinity}, Sort[list], {Infinity}]; First@Pick[Partition[bins, 2, 1], BinCounts[{x}, {bins}], 1] ] But it won't give you two intervals if the number is part ...

9

The problem is that the conversion happens at parsing stage, not evaluation. And after code has been parsed, the details of how function was invoked (prefix, normal way or postfix) are not stored any more, so by the time you evaluate the code, you have no way to tell whether you typed it as f@g@h, f[g[h]], or h // g // f. In the FrontEnd, you can do ...

7

FullForm prints the expression with no special syntax (e.g. Plus instead of +). FullForm[a*b] (* Times[a, b] *) So you change the expression's head. Table[fun @@ (a*b), {fun, {Plus, Subtract, Divide, Dot, Cross}}] (* {a + b, a - b, a/b, a.b, a\[Cross]b} *)

7

A brute force solution is to check all possible values of this function. num = {1/10, 1/2, 4/7, 3/5, 2/3}; pow = {0, 1, 2, 3, 4}; To obtain value for one combination use the Inner function Inner[Power, num, pow, Plus] (* => 2222701/992250 *) Then we apply function Inner[Power, num, #, Plus]& on all permutations prm = Permutations[pow]; val = ...

6

The solutions using Outer and Tuples will all blow up for large lists. The following is a compiled function that exploits the ordered nature of the lists and should be very fast and low on memory footprint even on very large lists. cf = With[{op = Plus}, Compile[{{list1, _Real, 1}, {list2, _Real, 1}, {n, _Integer}}, Module[{result = ...

6

In case you have any problems, I recommend using the Derivative operator instead of D, since the latter works on expressions, while the former one can work on pure functions. {Derivative[1, 0][f][x, y], Derivative[0, 1][f][x, y]} // TraditionalForm The subtlety here is that one cannot use it to find partial derivatives of f at {0,0}, e.g. ...

6

Preamble I can't resist to answer, although the answer won't be short :-). Below is an attempt to systematically capitalize on properties which weren't used (or at least used systematically) in other answers. I will use the same lists provided by the OP, for tests: l1 = {5.7832, 30.4713, 74.887, 139.04, 222.932, 326.563} l2 = {3.481, 9.2816, 15.7112, ...

5

My favorite: interval[x_,list_List]:=ReplaceList[Append[Prepend[Sort@list, -Infinity], Infinity], {___, a_, b_, ___} /; (a <= x <= b) :> {a, b}] EDIT: Much faster if we eliminate the condition checking as follows: interval2[x_, list_List] := ReplaceList[#, {___, a_, x, b_, ___} :> {a, b} ] &@ Join[{-Infinity}, ...

5

intervals[x_, list_List] := Cases[ Partition[Flatten[{-Infinity, Union[list], Infinity}], 2, 1] , {l_, u_} /; l <= x <= u ] Use cases: In[53]:= intervals[3, Range[10]] Out[53]= {{2,3},{3,4}} In[54]:= intervals[3, 2 * Range[10]] Out[54]= {{2,4}} intervals[-3, Range[10]] Out[55]= {{-∞,2}} In[56]:= intervals[999, Range[10]] Out[56]= ...

5

Assuming the list list is already ordered, the following should answer your question: f[x_,list_List]:= Module[{pos=Last@Ordering@Ordering[Append[list,x]]}, Which[pos==1,{-Infinity,First@list}, pos==Length[list]+1,{Last@list,Infinity}, True,list[[{pos-1,pos}]]]]

5

Lets start step by step. First let us see that your sum is transformed into an build in function Sum[i^a, {i, 1, r}] (* Out[36]= HarmonicNumber[r, -a] *) Now we can go two different ways: One way is to derivate this expression wrt r and keep the unknown a. Second is, we substitute a->2 and derive afterwards. If we replace a by the number 2 we get ...

5

A variation: mySet = {1/10, 1/2, 4/7, 3/5, 2/3}; perms = Permutations[mySet]; powersums = Total[Transpose @ perms^Range[0, 4]]; Extract[perms, Position[powersums, Max[powersums]]] {{1/10, 4/7, 2/3, 3/5, 1/2}} Another variation (beware: slower on large sets): Last @ Sort @ With[{perms = Permutations[{1/10, 1/2, 4/7, 3/5, 2/3}]}, ...

5

Here is a more generalized method for what you want to do: Let's define our momentum operator as you did above: P := -I * h * D[#, x]& Then we can define the nth power operator in a more general way as: T[n_] := Nest[P, #, n] & So for example the Kinetic energy operator (which is P^2 / (2 m)) will be: T[2] / (2 m) And we can use it on some ...

4

There is another way using RankedMin (we don't have to sort the whole list as we would do with Sort, SortBy) : RankedOrd[l1_, l2_, n_, f_] := With[{l = Flatten[Array[{f[l1[[#1]], l2[[#2]]], #1, #2} &, Length /@ {l1, l2}], 1]}, l[[#]] & /@ Table[Position[l, RankedMin[Transpose[l][[1]], i]][[1, 1]], {i, n}]] for the lists l1, l2 and ...

4

Something like : f[oper_, list1_, list2_, n_] := Sort[Flatten[ Outer[{oper[list1[[#1]], list2[[#2]]], #1, #2} &, Range[Length[list1]], Range[Length[list2]]], 1]][[1 ;; n]] f[Plus, l1, l2, 5] (* {{9.2642, 1, 1}, {15.0648, 1, 2}, {21.4944, 1, 3}, {33.6058, 1, 4}, {33.9523, 2, 1}} *) Also : f2[oper_, list1_, list2_, n_] := Sort[{oper[#[[1, 1]], ...

4

Here are several rules that can help to implement the Einstein convention: deltaSimplifyRules = { (a_ + b_)*x_ :> (a*x + b*x), KD[i_Symbol , j_]* x_ /; (MemberQ[Attributes[i], Temporary] && MemberQ[x, i, Infinity]) :> (x /. i :> j), KD[i_ , j_Symbol]* x_ /; (MemberQ[Attributes[j], Temporary] && ...

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