Tag Info

New answers tagged

6

The Notation package is built for this. Needs["Notation`"]; Notation[ParsedBoxWrapper[RowBox[{"\[LeftAngleBracket]", "x___", "\[RightAngleBracket]"}]] \[DoubleLongLeftRightArrow] ParsedBoxWrapper[RowBox[{"{", "x___", "}"}]]] (It looks better when input via the Notation palette. Don't be frightened by the box manipulation - I used the palette to construct ...


2

Edit As it was correctly noted the Notation package is not necessary here and the key point is recursive definition which builds the desired ordering: LeftArrow[x_,y_,z__] := LeftArrow[LeftArrow[x,y],z] ; Notice that the z__ argument is followed by a double underscore, which allows the pattern to match an arbitrary number of arguments. Original answer ...


5

Here is a palette that does the slashing when you select a character and press the button: CreatePalette[{Button["Slash it!", NotebookWrite[InputNotebook[], Replace[FromCharacterCode[ Join[ToCharacterCode[ ToString[NotebookRead[InputNotebook[]]]], {824}]], FromCharacterCode[{8706, 824}] :> ...


1

I did not attempt to implement everything you show but only what is needed for the two final examples. I initially seemed to have a problem with precedence but now it is working? I am not certain of what change made the difference, if any, but I'll post what I have now in case it is special in some way. I added these lines at the top of ...


11

I don't like the idea of redefining Or (||). Rather, I would suggest defining a function with the name DoubleVerticalBar. There is a special double vertical bar character which will be interpreted as the infix operator for DoubleVerticalBar and can be input with Esc+Space+|+|+Esc. SetAttributes[ DoubleVerticalBar, {NumericFunction, Orderless, Flat, ...


11

Use upvalues. You don't want || to change its behavior except when it's operating on impedances. So, use a wrapper (z[ ], say) around the quantities that represent impedances, and associate upvalues with the wrapper. This lets you redefine how standard operators work on the wrapped values: z[a_] || z[b_] ^= z[1/(1/a + 1/b)]; z[a_] + z[b_] ^= z[a + b]; a_ ...


7

(I would love to hear from someone more knowledgeable about how to improve this answer.) It is possible to redefine the || operator if you're willing to redefine the built-in Or, but I would certainly not recommend that because Or is a very common function upon which Mathematica probably relies internally all over the place. Possibly more robust but still ...


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


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.


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



Top 50 recent answers are included