Tag Info

Hot answers tagged

18

You can get the syntax highlighting that you desire by modifying your UnicodeCharacters.tr file (path given by System`Dump`unicodeCharactersTR), though I don't know how advisable this practice is. For example, adding: 0x20B0 \[PennyOp] ($penny$) Infix 155 None 5 5 I can use EscpennyEsc to enter: I am not aware of ...


14

Currying I don't know if it is possible to make all functions work in the Currying form (h[x1][x2][..]) but it is at least possible to extend Hold behavior to all arguments which natively that pattern will not have. I will copy my favorite method which I learned from this post by Grisha Kirilin: SetAttributes[f, HoldAllComplete] f[a_, b_, c_] := Hold[a, ...


9

Instead of using the Notation package, you can achieve the translation by doing the following: MakeExpression[RowBox[{x_, "⟗", y_}], StandardForm] := MakeExpression[ RowBox[{"FlatJoin", "[", x, ",", y, "]"}], StandardForm ] This takes care of the input translation. Now it's possible to enter expressions like 1 ⟗ (3 + 4 ⟗ 2) and have ...


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


8

The possibility to insert operators and functions as you know them from mathematics is not possible for all things. Usually, you find the special input possibilities on the reference page of the function in the Details section. See for instance the documentation of Integrate. For Binomial there seems to be no such 2d input, because as you already found out, ...


8

What I usually suggest for such cases is to use custom environments, inside which you can change the rules of the game. Here is a lexical one for your case: ClearAll[withNCTimes]; SetAttributes[withNCTimes, HoldAll]; withNCTimes[code_] := Unevaluated[code] /. Times -> NonCommutativeMultiply so that withNCTimes[a*b*c] (* a**b**c *) and here is ...


8

You cannot simply type Symbolize[...] which you should probably know from an error message you should be getting. For example what you have in your question gives: Symbolize[Subscript[q, 1],Subscript[q, 2]] To see why you get this message you can use show expression to see what is being pasted via the palette: From this we can see that Symbolize ...


8

Unlike arrays in many other languages, in many cases Mathematica allows you to deal with lists of data without the need for indexes at all. Lists can be of variable depth and lengths if you need them to be. cities = {"NewYork","LosAngeles","Chicago"}; costs = {{1,2}, {3,4},{5,6}}; Transpose[{cities, costs}] This gives you a list of cities and associated ...


7

That's how I finally defined haskell operators: rapply[x_] := x rapply[x_, y__] := x[rapply[y]] InfixNotation[ParsedBoxWrapper["|"], rapply] lapply[x_] := x lapply[x__, y_] := lapply[x][y] InfixNotation[ParsedBoxWrapper["\[SmallCircle]"], lapply] InfixNotation[ParsedBoxWrapper["\[CenterDot]"], Composition] Now $\circ$, $\dot{}{}$ and | act exactly like ...


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_", ...


6

What you are really looking for is InputAutoReplacements. If I understand your question correctly you are looking for a simple/quick way to input mildly complex strings of characters. In your example you want to find an easy way to input $\beta$. But there is no point in creating another symbol beta, since the 2 symbols are meant to always be "equivalent" ...


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.


5

One of the problems of the Notation` package is that it is rather heavy and opaque, while what it actually does is rather simple. I suggest a very light-weight substitute for your case: Clear[MakeExpression,makeExpression]; MakeExpression[expr_,form_]:= With[{result=makeExpression[expr,form]}, result /; Head[result]===HoldComplete ]; ...


5

You appear to be looking for the functionality of $PreRead: $PreRead = # /. "beta" -> "\[Beta]" &;


4

I won't say anything about the performance, since I think there are not enough information what exactly your data is. Furthermore, I won't say anything about the Notation Package because I don't think it's necessary. Could I somehow give the dataframe a custom head of DataFrame, preferably without breaking anything? Yes, I think that's and easy and ...


4

I would not think that either of the methods you mentioned is good enough. Notation` package is more or less limited to the FrontEnd (although one can come up with some hacks to make it work also in packages), while overloading Set is generally a bad idea. Having in mind your particular application, something like this may work: ClearAll[makePoint]; ...


4

It doesn't recurse because you are using a definition of Notation (from the Notation` package) that is restricted to parsing: This means that you will have to explicitly ShiftReturn for the notation to take effect. Notice the following: You can achieve what you want using straightforward definitions instead: Clear@WW WW[a__, Verbatim[Alternatives][b_, ...


4

Without giving this much thought you might proceed as follows: naturalQ = IntegerQ[#] && Positive[#] &; You can then define: fn[n_?naturalQ] := 2*n; fn /@ {-1, 0, 1} {fn[-1], fn[0], 2} For the second problem you might make use of SubValues syntax: SetAttributes[nFun, HoldAll] nFun[p_, body_][arg_?naturalQ] := With[{p = arg}, body] ...


4

Using \((a + b ) \^ c \) where \^ is short form for SuperscriptBox within \( ...\), gives SuperscriptBox[RowBox[{"(", RowBox[{"a", "+", "b"}], ")"}], "c"] as pointed out by @jkuczm, you can then solve by using RowBox. So I tried to do for the cases it didn't work and for others, like $(\frac{a}{b})^c$ I played a bit with the pattern matching in ...


3

There are many ways of solving this problem, including redoing everything from the start, but let's begin with your last line by defining ans = S[%] // Simplify. Define a rule for collecting together terms with the same index. collect = Plus[u___, a1_. state[spin1_, index_], v___, a2_. state[spin2_, index_], w___] :> Plus[u, state[a1 spin1 + a2 ...


3

If your custom notation is identical to that of Power, I would do it the lazy way: MakeBoxes[ myPower[base_, exp_], form_ ] := TagBox[ MakeBoxes[ base^exp, form], myPower] ; myPower @@@ {{x, y}, {x + y, z}, {x y, z}, {myPower[x, y], z}, {f[x, y], z}} { xy, (x+y)z, (x y)z, (xy)z, f[x, y]z } % // InputForm {myPower[x, y], myPower[x + y, z], ...


3

but it is not working The above does not describe the problem you are having. When you say not working, you need to explain how it is not working, and what you tried. I just downloaded it and I see no problem. Using V10.01, on windows. Downloaded it from http://library.wolfram.com/infocenter/MathSource/577/ Here are some examples ...


3

"these will end up being more trouble than they are worth." - to my mind, this is a very accurate assessment of the situation. As far as syntax is concerned, you will face multiple obstacles, starting from package and front-end parser differences you outlined (which makes the use of e.g. Notation package in packages quite non-trivial if not problematic), ...


2

I would strongly recommend that you not follow this approach. It is not a good idea to modify built-ins, especially something as fundamental as Times as this could lead to unintended consequences elsewhere. Instead, I would suggest that you utilize one of the many infix operators without any pre-defined meaning. That said, you could do something like: ...


2

The Notation function is part of the Notation package. You need to load the package first, then you can use the Notation palette to simply paste the Notation template and fill the placeholders. If you cannot use the notation palette,for ex. because you are using a code editor like in WB, then you use the notation template with option Action -> ...


2

Method #1 If you define each Subscript using TagSet(1)(2) the value will be associated with the Symbol, e.g. k: k /: Subscript[k, 1] = "val1"; k /: Subscript[k, 2] = "val2"; k /: Subscript[k, 3] = "val3"; You could then use definitions such as: kval[] := UpValues[k][[All, 2]] ksym[] := HoldForm @@@ UpValues[k][[All, 1]] These will always be up to ...


2

As a workaround you can wrap base of MyPower with additional RowBox: Notation[ ParsedBoxWrapper[SuperscriptBox[RowBox[{"A_", ""}],"B_"]] \[DoubleLongLeftArrow] ParsedBoxWrapper[RowBox[{"MyPower", "[", "A_", ",", "B_", "]"}]] ] It works with Plus, Times, nested MyPower and custom functions: MyPower[x, y] MyPower[x + y, z] MyPower[x y, z] ...


2

First of all, I don't see any need for the Notation package here. So I'll just omit that. Also, you need to replace -> by :> in the definition for c, otherwise a may be polluted by a global value. The rest can be done as follows: (*Creates a subscripted integer*) fock[n_Integer, m_] := Subscript[n, m] (*Creates a series of 0's indexed from 1 to nm*) ...


1

This seems to work Format[△[θ_], TraditionalForm] := HoldForm[△ θ]


1

Perhaps MatLink is an alternative solution. http://matlink.org/



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