Tag Info

Hot answers tagged

37

As an Eterprise CDF user, I can say I have really tried, and my current opinion is that creating a standalone GUI program with the Wolfram Language is not an easy/commercial/deliverable task at the moment. Here are my points: All the interface controls are very limited. You will have a lot of difficulty to do basic things like make Tab jump between fields, ...


17

Let's look at this with a simple example without considering complicated indexing and levels. Consider the list (the colours are merely for visual guidance): A = Array[Subscript[a, ##] &, {2, 3, 4}] Dimensions@A (* {2, 3, 4} *) This is a list containing 2 lists, each of which contains 3 sublists, which in turn contain 4 elements of the array. ...


16

Everything depends on what you try to do with this. First you could use Subsuperscript and get rid of one level which is introduced by your Power Subscript[e,3]^2//FullForm (* Power[Subscript[e,3],2] *) Subsuperscript[e,3,2]//FullForm (* Subsuperscript[e,3,2] *) Both forms look equally in the front-end, but now you can use TagSet to transform all e with ...


16

What the first part of the variable declaration does Manipulate initializes complexparts to {Re[#], Im[#]} & when it executes. (In general, a declaration of the form {{var, expr},...} in a Manipulate results in the local variable var being initialized to expr.) To use complexparts outside of the Manipulate, do this: complexparts = {Re[#], Im[#]} ...


14

# is a placeholder for an expression. If you want to define a function, $y(x)=x^2$, you just could do: f = #^2 & The & "pumps in" the expression into the # sign. That is important for pairing & and # when you have nested functions. f[2] (* 4 *) If you have a function operating on two variables, you could do: f = #1 + #2 & So ...


12

My experience is that while Mathematica does present some headaches with creating consistent layouts the limitations in creating a professional looking app are limited by your ability to do graphic design. For example most reading this could create a web page. But how many could create a cool looking web page? So there are two aspect: underlying code and ...


11

The problem is just name collisions, that isn't at all abstract and will happen in any programing language, so it would be odd to claim that it's impossible due to the way Mathematica works. The solution is simply to name your parameters when you write your functions so they don't collide, so you write for instance: RegionFunction -> Function[{a1, b1}, ...


11

I'm afraid my comment was too obscure to be noticed. Further, I disagree with one premise somewhere in the commentary, and I wish to make a fuller explanation to see if I understand correctly or incorrectly. Finally, I think the question is answered in the documentation on the Standard Evaluation Procedure: Evaluate the head of the expression. ...


10

You can use any built in operator modified with subscripts, superscripts, etc, and retain its precedence, for your own purposes. Perpaps fro your case a @@ with a number subscripted for the level of Apply seems appropriate MakeExpression[RowBox[{fun_, SubscriptBox["@@", i_], rhs_}], StandardForm] := MakeExpression[{fun, rhs, i}, StandardForm] /. ...


8

While the tutorial will undoubtedly explain better that I could the entire topic of pure functions, which is what Slot, or # has to do with, I'll answer the specific question at hand. The Slot is treated as the argument in an anonymous function. Specifically, the code #^2 & // FullForm Reveals that what is actually going on is ...


8

Here is another way: you can fool the depth-1 tag rule for UpValues with a few temporary symbols. Here is an example: ClearAll[e]; e /: Subscript[e, i_?IntegerQ] := e /: Subscript[e, i] = Module[{el}, el /: el^p_ := el /: el^p = Module[{elp}, elp /: NumericQ[elp] = True; Format[elp] := TraditionalForm[Subscript["e", i]^p]; ...


8

WordData can give you the IPA form of a word: Gather[ WordData[#, "PhoneticForm"] & /@ {"pray", "prey", "wade", "weighed"} ] (* {{"pr'ey", "pr'ey"}, {"w'eyd", "w'eyd"}} *) EDIT It seems WordData[word, "PhoneticForm"] no longer provides the proper IPA, however that data is still included in the paclet so we can make a new WordData property for that. ...


7

If I understand the question here are three ways to "nest" functions: f1 = Function[x, (# + x)/2 &]; f2 = With[{x = #}, (# + x)/2 &] &; f3 = # /. x_ :> ((# + x)/2 &) &; All work the same: #@7 & /@ {f1, f2, f3} {(#1 + 7)/2 &, (#1 + 7)/2 &, (#1 + 7)/2 &} Note that with the first form I used the Slot based ...


7

The original complete definition is cfRemainders[x_, iter_: Hold[$IterationLimit]] := NestWhileList[FractionalPart[1/#] &, FractionalPart[x], # != 0 &, 1, ReleaseHold[iter]] The iter_ : Hold[$IterationLimit] makes iter an Optional argument with the default value Hold[$IterationLimit] if the argument is omitted. Secondly, by using Hold, ...


6

You can use Notation package to treat anything like function and then set whatever attributes to this function: The only problem is that Notation don't support test patterns, so to make an expression numeric with only integer indexes:


6

I'm not surprised you're having trouble as {{complexparts, {Re[#], Im[#]} &}, None} is (to the best of my knowledge) a nonstandard "hack" and not part of the documented standard uses. I have used it myself but I still don't recommend it. Usually you can use the Initialization option instead. Evaluating {{complexparts, {Re[#], Im[#]} &}, None} by ...


6

With replaces occurrences of declared constants with their values, but it won't change the definition of force[] outside its scope. To do that you'd need to include the function definition like so :- With[{a = 1, b = 1}, force[x_] := a x - b x^3; force[1]] 0 Another option is to use Block, which does dynamic scoping Block[{a = 1, b = 1}, ...


5

I think that giving the language we use in Mathematica a name ("W", or whatever), and establishing it as separate from the Mathematica Interface is a step in the right direction. Mathematica is "Visual Wolfram" (arg) or something like that - an interactive interface for TWL. It has a REPL, renders graphics, formats tables, grids, etc.. That's not TWL - ...


5

The problem is that if you pass a symbol, it will be created already during the parsing stage, when you pass it, in the current context. Therefore I suggest to pass its string name instead. This function will do the job: ClearAll[f]; f[symbolName_String, value_, context_] := Block[{$ContextPath}, BeginPackage[context]; ToExpression[ ...


5

I'm not certain I understand your goals, though I too wish there were a cleaner way to do this. I presume that you are dissatisfied with the performance of this fairly direct solution: index[expr_] := {Extract[expr, #, HoldComplete], #} & /@ Position[expr, _] Your own method using both Position and Level is a clever way to vectorize this as it were. ...


5

I don't believe it is possible to implement your literal request. While you can make an UpSet definition for Head: Unprotect[Ket]; Head[Ket[_]] ^:= Bob Head[Ket[Subscript[x, B]]] ^:= BobKet Head[Ket[Subscript[x, A]]] ^:= AliceKet Head[Ket[Subscript[x, B]]] BobKet Since Head is not actually used by the pattern matcher this does not produce your ...


4

Actually this is more like a comment to Michael E.'s answer than an own answer, but it became too long for a comment. I think it is worth mentioning that $IterationLimit (and also $RecursionLimit and probably some others as well) is somewhat special and thus needs special treatment: For a "normal" variable it would be quite simple to achieve what Michael ...


4

What this does is set a default value for iter, meant for use if cfRemainders is called with only one argument. The default value for iter in this case is $IterationLimit, and the Hold[] enclosing it means cfRemainders will use $IterationLimit symbol for the new rule. If there was no enclosing Hold[], $IterationLimit would have been replaced with the Integer ...


4

This sort of programming is not my strength and I don't know Python. Reading the comments, perhaps this won't quite be perfect, but it might be good enough. It seems good enough for many purposes, at least in the way I interpret the question. It localizes all Symbols in the code that are in the "Global`" context and don't have Ownvalues or DownValues. If ...


4

Wolfram Language has not yet been released, so we can't say for sure. However it seems likely that the next release of Mathematica will include the new commands that you saw in Wolfram's demo. The alternative would be for Mathematica's language to diverge from the Wolfram Language, which seems like pointless complexity for Wolfram to manage, and such ...


3

Plot has Attributes HoldAll, so one possibility to get what you expect is to do just SetOptions[Plot, Evaluated -> True]; at the beginning. Another possibility (better documented) would be to use Evaluate inside Plot: Plot[Evaluate[...], {x, 0, 2}]


3

Solutions with Inner Here is the function I came up with ClearAll[toExprPosLists]; SetAttributes[toExprPosLists, HoldAllComplete] toExprPosLists[expr_] := Inner @@ Function[ Hold@ Evaluate[ List, Unevaluated @@ Level[Unevaluated@expr, {0, Infinity}, #, Heads -> True], Position[Unevaluated@expr, _], # ] ...


3

I believe this is what you want: f[symname_String, value_, context_] := (Begin[context]; With[{s = Symbol[symname]}, Set[s, value]]; End[]) Then use it like this: f["myvar", 4, "MyContext`"] Verify: ? MyContext`myvar Hope that helps


3

No, unfortunately you cannot create a new compound operator such as @@@@, as stated by Michael Pilat in response to my own question of similar nature: You can't do this with an operator syntax of your own invention (like @@&). Mathematica just doesn't have the capability to modify the language grammar at runtime like that. There are a variety of ...


3

How about something like: seqChopper[seq_Sequence, span_Span] := Sequence @@ ((List@seq)[[span]]) SetAttributes[seqChopper, SequenceHold] seqChopper[Sequence[1, 2, 3, 4, 5], 2 ;;] seqChopper[Sequence[1, 2, 3, 4, 5], 2 ;; -2] seqChopper[Sequence[1, 2, 3, 4, 5], -2 ;; 1 ;; -2] (* Sequence[2, 3, 4, 5] Sequence[2, 3, 4] Sequence[4, 2] *)



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