# Tag Info

49

I. General I will first try to briefly answer the questions, and then illustrate this with a small but practical application. 1.Speed of insertion / deletion Associations are based on so called Hash Array Mapped Trie persistent data structure. One can think of this as a nested hash table, but it is more than that, because it has the following properties: ...

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

30

Compose and Composition There is, but it is deprecated (in favor of Composition): Compose: MapThread[Compose, {{a, b, c}, {1, 2, 3}}] (* {a[1], b[2], c[3]} *) I still use Compose myself, but I would not take the responsibility to recommend this as a common practice. You can also use Composition[#1][#2] &, although this is hardly better than your ...

29

Between Versions 7 and 8 Hash now gives the hash of a raw sequence of characters when applied to Strings. In past versions the string characters (quotation marks) were included in the calculation of the hash. (Reference) Use "\"" <> string <> "\"" before hashing if you want output to match older versions. \[Dash], \[LongDash] and ...

27

First let me note that I didn't write PositionIndex, so I can't speak to its internals without doing a bit of digging (which at the moment I do not have time to do). I agree performance could be improved in the case where there are many collisions. Let's quantify how bad the situation is, especially since complexity was mentioned! We'll use the ...

20

I helped design Association, and I designed and implemented Dataset, so I wanted to comment on question 3: Dataset is designed explicitly for hierarchical data. It supports any 'shape' of data, inferring the shape when the Dataset is first created. It also tracks the shape of the data as transformations are applied to the dataset, using a type-inference ...

20

Updated Both Hold and Inactive block evaluation; the key difference is that Inactive is meant to be wrapped around heads rather than a whole expression. Inactivate does this. Inactivate[1 + 2 + 3 * 4 ^ 5 ] // FullForm Inactive[Plus][1, 2, Inactive[Times][3, Inactive[Power][4, 5]]] It is of course possible to use Inactive directly, and it will behave ...

19

The Wolfram Language is what we all know as Mathematica, but rebranded to help wider adoption to people, particularly for people who don't self-identify as "math" people. As a Mathematica programmer, emphasis on the "programmer", I see this as a good thing.

18

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

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[#]} ...

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

15

I'm guessing you're coming from a programming language where every expression must evaluate to a value, and if it didn't evaluate to something (like 5[Cos+Sin]), it's a syntax error. To me, Mathematica started to make a lot more sense, once I stopped thinking about functions and values, and started to think of every expression as evaluating to an "expression ...

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

14

Good News Everyone! Two-parameter syntax for Fold and FoldList has been (silently) implemented! Taliesin Beynon informs me that this was implemented in 2011, so check your older versions as well. Using version 10: Fold[f, a] FoldList[f, a] f[f[f[1, 2], 3], 4] {1, f[1, 2], f[f[1, 2], 3], f[f[f[1, 2], 3], 4]} And the held expression example: ...

13

Let's start by taking a look at the compiled form of one of our queries: DatasetCompileQuery[Query @ First @ spans] (* DatasetWithOverrides@*Checked[Slice[205 ;; 313], Identity] *) We can see that the operation is not implemented directly in terms of part. Indeed, there are three components: DatasetWithOverrides, GeneralUtilitiesChecked and ...

13

This is interesting: If you replace the symbol y with the string "y", Append works fine. Append[ds, <|"a" -> 5, "b" -> "y"|>] Also, if you start out with Symbols, then it works fine: ds = Dataset[{<|"a" -> 1, "b" -> x|>, <|"a" -> 2, "b" -> y|>, <| "a" -> 3, "b" -> z|>, <|"a" -> 4, "b" -> ...

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

12

One difference is that NDSolve directly supports Inactive. It can be used to specify operators such as divergence ($\nabla\cdot$) without automatically evaluating them to components. This is described here.

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

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

9

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]; ...

9

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

9

expr = Cos[3 x] + \[Pi]/cofe Exp[y^(c z)]; Cases[expr, _Symbol?(! NumericQ[#] &), Infinity] // Union (* {c, cofe, x, y, z} *) In this case the Union is not necessary; however, in general it is needed to eliminate duplicates.

9

You need to use InputForm to see the actual value of the numbers. x = -15*0.1 + 6*0.1; InputForm[x] Now when you wrote a[-15*0.1 + 6*0.1] = 5 Now 5 is actually stored in a[-0.8999999999999999] and not in a[-0.9], this is why a[-0.9] does not return the value 5 you expected. But when you wrote a[-0.8999999999999999] it did. Now, as to why ...

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

This is not an answer. It is just a very long comment. Both a simple manually operated drill press and a computer-controlled five-axis omni-mill can drill a hole through a piece of bar stock. And both will do the actual drilling in about the same amount of time. If one hole in one bar is all you want, then you will accomplish the job much faster with the ...

8

From the docs for Label Label must appear as an explicit element of a CompoundExpression object. So this works: p[1] = .9; i = 1; Label[begin]; i++; p[i] = p[i - 1] + 1; Print[i]; If[i < 5, Goto[begin], Goto[end]]; Label[end]; But this doesn't: p[1] = .9; i = 1; Label[begin]; i++; p[i] = p[i - 1] + 1; Print[i]; If[i < 5, Goto[begin], ...

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

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

We can use this function to see that the conversion is not made during parsing: parseString[s_String, prep : (True | False) : True] := FrontEndExecute[FrontEnd`UndocumentedTestFEParserPacket[s, prep]] parseString["x x"] {BoxData[RowBox[{"x", "x"}]], StandardForm} We can use this to see that the conversion does not take place while converting boxes ...

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