# Tag Info

27

Clearly the @ notation is inspired by the usual mathematical notation for function composition. f@g[x] looks very similar to the mathematical notation $(f\circ g)(x)$. But it is important to understand that @ does not denote function composition. In mathematical notation $f\circ g$ is also a function. In Mathematica f@x is simply a different way to ...

20

Try this: Map[If[#==1,Unevaluated@Sequence[],#]&,{1,2,3}] Note the output. The 1 is gone. That's because Unevaluated@Sequence[] puts the empty sequence there, that is, "nothing". ##&[] is a shorthand that can be used in most places for same - ## is the sequence of arguments, & makes it a function to apply to something, [] is that something - ...

19

One way would be to redirect all messages issued by ToExpression to a string-stream. Here is an example of that approach, with minimal error-checking: Needs["Developer"] interpret[str_String] := Module[{s = StreamToString[], r, m} , Block[{$Messages = {s}}, r = ToExpression[str, InputForm, HoldComplete]] ; m = StringFromStream[s] ; Close[s] ; ... 19 I know this has been answered already on this site, but I cannot seem to find it. Map and Apply do subtly different things. For example, Map[f, {a,b,c}] (* {f[a], f[b], f[c]} *) If you have a list that is more deeply nested, without using the third argument which is for level specification, you get Map[f, {{a,b}, {c}}] (* {f[{a,b}], f[{c}]} *) or, if ... 14 So recently I've learned from John Fultz that RawBoxes are kind of verbatim indicator for MakeBoxes which is not well stressed out in documentation. This or I've missed the point but it doesn't matter, here we have handy way to do this: x = 5; ToExpression @ MakeBoxes[RawBoxes["x"] = 123]; x 123 13 As djp explains parentheses are unnecessary in the FullForm of an expression; it is logical for superfluous information to be removed. However if you want parentheses to persist you could use something like this:$PreRead = # /. RowBox[{"(", body___, ")"}] :> RowBox[{"paren", "[", body, "]"}] &; MakeBoxes[paren[body___], form_] := ...

11

You can have a single rule using Alternatives (|)... {a, b, c, d, e, f, g, h} /. x : (a | c | e | f) -> 12 Furthermore you can construct the rule on the fly... {a, b, c, d, e, f, g, h} /. x : Alternatives@@{a, c, e, f} -> 12 As noted by @Kuba below there is no requirement for the pattern to have a name (x) so... {a, b, c, d, e, f, g, h} /. (a | ...

11

We already have some answers explaining the issue. Let me give a solution to your problem. Let's say you have the code RegularExpression["((re)*)"] that you want to comment out. Since we have nested comments in Mathematica, just use a pair of (* to prevent your issue: Although I don't know the internal implementation of Mathematicas parser, the ...

11

A lot of functions in MMA have default values for Optional Arguments, for Example Flatten. It can take Flatten[expr] which means Flatten[expr, Infinity] Some functions don't have such option and you need to feed the Optional Arguments but you can go around by building your own function for your example, you can do this kind of trick like this: f[expr_, ...

10

This behaviour is very common, possibly near universal, in programming languages with matchfix comment syntax. The reason is that the contents of a comment sequence is presumed not to be code. Usually that presumption is correct, but not in this case. The general rule is You should be able to put anything inside a comment and the only special tokens ...

10

The behaviour we see is due to the precedence of &, which is much lower than the precedence of /@. As a consequence, the expression Line /@ (Print[#]; #) is bound tightly together by the high precedence /@ infix operator, yielding the single argument to the low precedence & postfix operator. This means that the second expression is interpreted as ...

10

... why introduce Composition as a new feature? Composition is used to create a new anonymous function that can be used in all the standard ways such as Map and Apply etc. To achieve the same thing without it one needs a Function. Much like operator forms the use of Composition allows one to eliminate extraneous Function constructs which can make code ...

9

The Notation package is not necessary to use an infix form of \[Star] as that is handled automatically. Also I recommend PadRight for constructing your expression (reference Generating a matrix using sublists A and B n times). SetAttributes[Star, HoldFirst] Star[a_List, n_Integer] := PadRight[a, n*Length@a, a] {1, 2}⋆5 (* ⋆ is \[Star] *) {1, 2, ...

9

Well, the following meets your formal requirements evenFunction[f_][args__] := f[Abs /@ Unevaluated[args]] evenFunction[even][a, b, c] even[Abs[a], Abs[b], Abs[c]] But is it really better than evenFunction[f_][args__] := f @@ Abs[{args}] I, myself, would choose the 2nd version over the 1st. Update It is not necessary to set the attribute ...

8

Also PlotRange[plot] PlotRange /. AbsoluteOptions[plot] Last @@ AbsoluteOptions[plot, PlotRange] PlotRange /. plot[[2]] all give (* {{0.,10.},{-0.999999,1.}} *) Note: Regarding usage of PlotRange as a function, it is undocumented, and the earliest reference I could find on this site is this answer dated Oct 11, 2012: The same range on each plot in a ...

8

You can make them an expression if you want. Let par[x.....] represent (x....). For example: (x+y)*z The FullForm would be: Times[par[Plus[x,y]], z] But in every such expression, the par[..] would only ever have on argument (in the example, Plus[x,y]). It would never modify the meaning of the argument. So in FullForm, there would be no point having ...

8

The documentation you linked to is more about how Infix is used to define output formats. You can find more information on how to use functions in infix form in the tutorials Special Ways to Input Expressions and Operator Input Forms. If you really want to use Partition in the infix form with an offset, you can use samplelist ~Partition~ Sequence[3, 2] ...

8

To summarize the comments into an answer: The second element is a list of lists because there may be several different tags sown. For example, Reap[Sow[1, x]; Sow[2, y]; result] (* {result, {{1}, {2}}} *) Another example by belisarius, Reap[Sow[1, {x, y}]; Sow[2, y]; Sow[3, x], _, tag] (* {3, {tag[x, {1, 3}], tag[y, {1, 2}]}} *) See also this ...

8

394 Unicode characters that are not valid Mathematica Symbols can be found from ss = Quiet@Table[{tem = "\\:" <> IntegerString[i, 16, 4], Symbol[tem]}, {i, 0, 16^4 - 1}]; notsym = Cases[ss, {z_, Symbol[__]} -> z] The list is largely but not entirely complete. To obtain the printable symbols for many of these unicodes, use ...

7

As already explained, this happens because MatrixForm act as a wrapper. The answer to the question about how this behavior is implemented and how can eventually be reproduced is contained in the Informmation of the system symbol $OutputForms. Indeed ??$OutputForms returns: $OutputForms is a list of the formatting functions that get stripped off ... 7 I believe it is important to get a fundamental understanding of what Pure Functions are that goes beyond the understanding using of a syntax. Hereafter an non-exhaustif summary of a few key understandings: 1) Pure Functions have they roots in Lambda calculus that forms the basis of functional programming paradigm implemented in Mathematica. 2) In ... 7 Unevaluated@Sequence[1, 2]~ConstantArray~10$\ \$ {1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2} Or using Notation << Notation Notation[ParsedBoxWrapper[ RowBox[{ RowBox[{"[", "const_", "]"}], "\[Star]", "reps_"}]] \[DoubleLongRightArrow] ParsedBoxWrapper[ RowBox[{ RowBox[{"Unevaluated", "@", RowBox[{"Sequence", "[", "const_", ...

7

Look at the Possible Issues section of the documentation for Sort: "Numeric expressions are sorted by structure as well as numerical value" list = {1/2 (1 + Sqrt[5]), 1, 1, 1/2 (1 - Sqrt[5]), 0}; The approach recommended there to Sort by numerical value only is sorted = Sort[list, Less] (* {(1/2)*(1 - Sqrt[5]), 0, 1, 1, (1/2)*(1 + Sqrt[5])} *) ...

6

Algohi's answer is the most appropriate if one of the function's arguments is primary and the others secondary. However, you can get closer to the syntax that you suggested in your question using {x^2 + 9 x + 5, 3} // Apply @ PolynomialMod which works in version 10 using the operator form of Apply. Or, to include earlier versions, you could define your ...

6

You should use Sequence PolynomialMod[x^2 + 9 x + 5, 3] PolynomialMod@Sequence[x^2 + 9 x + 5, 3] Sequence[x^2 + 9 x + 5, 3] // PolynomialMod 2 + x^2 all produce the same output. Works with any function Sequence[i, {i, 10}] // Table {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

6

If you cannot resolve the keyboard behavior try an alternate input form; I propose: EscdinttEsc To input: Then use Tab to move between the Placeholder fields.

6

Range[10] - Make a list of integers from 1 to 10. /. - Replace all occurrences of {x_ - anything, to which we will refer to as x /; - so long as the test PrimeQ[x] - for primality yields True -> - with x^2} - the square of itself.

6

Fixed code: r[t_] := Piecewise[{{{7 t, 0, 4 (1 + Cos[t])}, 0 <= t <= π}, {{5 Cos[t - 3 π/2] + 7*π, 3 Sin[t - 3 π/2] + 3, 0}, π < t <= 2 π}, {{7*π + 3*Cos[t - 3 π/2], 2*3 - 3 + 3*Sin[t - 3 π/2], 2/(3 π) (t - 2 π)^2}, 2 π < t <= 4 π}, {{7 π - 5 (t - 4 π), 6 + 4 ((t - 4 π)/π)^3, 2 - 1/π t^2 + 10 ...

6

Brief? How about this. Define: c = ConstantArray; Now you can get what you want using the infix notation: "a"~c~7 and 10~c~7 With lists {1, 2}~c~7 you'll need to Flatten.

6

This is pitched at the "how to understand" level, not the "how is it implemented" level. I've basically presented how I think of these things, without really caring about how Mathematica carries them out. The object h[2][x] is just another expression-with-head. The head is h[2], which just happens to have a more complicated form than is perhaps usual. In ...

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