26

Summary Important differences between Association and CreateDataStructure["HashTable"] include: associations are immutable whereas hash tables are mutable associations are hash array mapped tries as opposed to simple hash tables Mutability As a rule, Wolfram Language's native data structures are immutable. Any attempt to change even just a part ...


18

The behavior of ValueQ has changed in version 12.2. In fact, you can provide a Method -> "Legacy" option to match the behavior the function had in Version 12.1 and earlier: The Details portion of the documentation for ValueQ now states that the default method in the 12.2 implementation (Automatic) effectively uses "OwnValuesPresent" ...


13

math/wolfram, MathKernel/WolframKernel are all the same: they are the Mathematica kernel. There is a difference between math and MathKernel on Windows in that the former is a console application (i.e. uses the standard terminal) while the latter is a GUI application, but otherwise they are the same thing. Mathematica/mathematica is the front end. ...


7

The issue is indeed that since both defaulter and Length are ascending operators, they are applied "bottom-up". That is, Length is applied to the lowest level prior to defaulter being applied to the middle level. We can defer the operation of Length so that it is processed after defaulter by means of a subquery: dta // Query[All, defaulter /* ...


7

Function does not do pattern matching. If you need pattern matching, you can do it manually: Function[x, Switch[x, a|b, 1, _, 0 (* this is the default choice for input that don't match preceding patterns *) ] ] Note that it is not possible to keep Function[...] unevaluated when there is no match.


6

The list of "keywords" in Wolfram Language can only really refer to the list of all of the defined symbols, which you can get by evaluating ?*. I think this is a somewhat narrow view of the implementation of programming languages. Not all languages have keywords in the sense that C-type languages do, and it's also important to define exactly what ...


6

Oh, I was also surprised by the differenxe, but I have an explanation for it: By using f[#]&, you explicitly say that the functions shall only use the first argument. Use ## otherwise. Apply[f[#] &, list] Apply[f[##] &, list] f["a"] f["a", "b"]


6

There are different usages of SetDelayed. Read SetDelayed documentation, Section Scope > Diffrent Kinds of Values for more information. This solution works on var := def (like your case) not var[] := def or other kinds. Code ClearAll[swapSetDelays]; SetAttributes[swapSetDelays, HoldAll]; swapSetDelays[a_, b_] := With[{temp = OwnValues[a]}, OwnValues[...


5

It sounds like you entered \.00, which matches the syntax for a character specified by hexadecimal character code. In this case, it's the null character (NUL; character code 0). From the documentation: ∖[Name] - a character with the specified full name ∖nnn - a character with octal code nnn ∖.nn - a character with hexadecimal code nn ∖:nnnn - a character ...


5

r[t_] = {3 Cos[t], 3 Sin[t], 0};(*Parametrized S*) F has three parameters so it should have three arguments. F[x_, y_, z_] = {2 y Cos[z], Exp[x] Sin[z], x Exp[y]}; Use Apply F @@ r[t] (* {6 Sin[t], 0, 3 E^(3 Sin[t]) Cos[t]} *)


5

HashTable seems a bit slower in creating, probably due to compiling, than Association: n = 10^6; ht["Insert", # -> 2 #] & /@ Range[n]; // Timing (*{1.5625, Null}*) as = Association[ Table[i -> 2 i, {i, n}] ]; // Timing (*{0.96875, Null}*) For retrieving there is no big difference, HashTable is slightly faster: n = 10^6; ht["Lookup&...


5

You are doing way! too much work in your code. The way it is set up, every time you evaluate f it reevaluates a and b which makes your code super slow. I suspect this is your issue, Mathematica will eventually produce the graph you desire - but it takes so long you say "it gives me no plot". I gave up on letting your code run after a minute or so. ...


4

So, one way we could approach this is by inspecting the evaluation stack: arg[a_] := a /; StackInhibit[Stack[] === {arg, RuleCondition}] StackInhibit just means we don't have to also worry about matching SameQ, so it's not totally necessary. This could also be subverted by appropriate StackBegins, but that could be viewed as either a bug or a feature: if we ...


4

In the rather unlikely case of you actually wanting to swap two definitions, e.g. D1 := RandomVariate[UniformDistribution[{-1, 0}]]; D2 := RandomVariate[UniformDistribution[{0, 1}]]; You can do so temporarily Module[{D1 = D2, D2 = D1}, Print[{D1, D2}]] {0.863742,-0.710931} If you've already used these definitions e.g. print := Print[{D1, D2}] print {-0....


3

Jose Martin-Garcia explains the Dataset Type System in this video: https://youtu.be/KQeDCEGRjKM?t=600


3

System` is a context, not a library. In other languages, this is called a namespace. Therefore, technically speaking, the fact that a symbol is part of the System` context does not mean that it is built-in. You can easily create symbols in the System` context. In practice, however, this is often a good-enough approximation to find built-in symbols. To ...


3

I don't think your table is necessarily incorrect, but I don't think it's the best way to think about it. In Mathematica, everything is an expression (see the linked tutorial for more details). Every1 expression is one of two things: Atomic: Things like numbers, symbols, etc. AtomQ[expr] returns True, and the head is not necessarily "part" of the ...


3

Can't you just define a single function? d[x_,y_]:=RandomVariate[UniformDistribution[{x, y}]]; Then call it as: D1 = d[-1,0] or D2 = d[0,1]


3

solution = {{p1 -> ConditionalExpression[2 r, r < 1], p2 -> ConditionalExpression[4 r, r < 1]}, {p1 -> ConditionalExpression[-2 r, r > 1], p2 -> ConditionalExpression[-4 r, r > 1]}}; {pw1, pw2} = # /. solution & /@ {p1, p2} /. ce : {__ConditionalExpression} :> Piecewise[List @@@ ce] Alternatively, Values @ ...


2

Clear["Global`*"] R = UnitConvert[Quantity[2.7828000000000004`*^7, "Meters"], "JupiterEquatorialRadius"]; i = 1.5135776449524154`;(*rad*) You are using Equal where you apparently mean to use Set M = Quantity[0.080, "JupiterMass"]/Sin[i]; If you want the result using "JupiterEquatorialRadius" use ρ = ...


2

I ran into this problem many years ago when I was learning Mathematica. I came up with this solution, which I've since learned has some drawbacks. However, for many uses, it's perfectly fine and convenient, and the drawbacks have no impact on performance. It takes advantage of polymorphism. ClearAll[F]; F[{x_, y_, z_}] := F[x, y, z]; (* define F for a ...


2

<<FormulaData` Needs@"GeneralUtilities`" GeneralUtilities`BlockProtected[{Tools`MathematicaFormulas`FormulaData`Private`MathematicaFormula}, Tools`MathematicaFormulas`FormulaData`Private`MathematicaFormula["MyFormula"] := QuantityVariable["a","ElectricPotential"] == QuantityVariable["b","...


2

e /. f -> Sin Cos[x] + Sin[x]


2

Clear["Global`*"] $Version (* "12.2.0 for Mac OS X x86 (64-bit) (December 12, 2020)" *) kglr's solution is fast. The performance differences are very dramatic for larger lists Manipulate[ SeedRandom[1234]; init = RandomInteger[10, n]; subs = RandomInteger[{11, 20}, n]; cond = Thread[init > 5]; t1 = RepeatedTiming[sol1 = (* Alan ...


2

In MMA arguments are evaluated before feeding them to a function. This means Intersection[pMenoDi25Anni, {pLavoroFullTime, pLavoroPartTime, pStudioEBasta}] is evaluated before feeding to Thread. Now, Intersection takes lists as arguments. This is fine for the first argument, but the second argument is a list of lists. Therefore, the intersection is empty....


1

As an educated guess, in the Stirling number example, the recurrence depending on $n-1$ is key. Mathematica expects that. What you are attempting depends on both $i-1$ and $i$. The documentation does not make this clear. However, it is still possible to use RecurrenceTable within its limitation. Using the usual recurrence technique is this code ClearAll[tt, ...


1

I do not know why RecurrenceTable does not work. But you can easily do it "by hand". For an example, I only calculate i,j up to 6: ClearAll[tt] tt[0, j_?NumericQ] = 0; tt[i_?NumericQ, 0] = 1; tt[i_?NumericQ, j_?NumericQ] = p*tt[i - 1, j] + (1 - p)*tt[i, j - 1]; Table[tt[i, j], {i, 0, 6}, {j, 0, 6}] // MatrixForm


1

The issue is not θ vs x. It's PolarPlot vs. Plot. They both have the HoldAll attribute. This is to prevent a value that the variable, either θ or x, might have outside the plot call from replacing the symbolic variable. While the plot functions both have the HoldAll attribute, they do different things with their arguments. This is undocumented, and one ...


1

Like this? g1[x_] = x*x + 1; g2[x_] = Log[x]; g3[x_] = 2 Cos[x]; funclist = "g" <> ToString[#] & /@ {1, 2, 3} // ToExpression; Plot[#[x] & /@ funclist, {x, -5, 5}] Better way: g[1][x_] = x*x + 1; g[2][x_] = Log[x]; Plot[g[#][x] & /@ {1, 2}, {x, -5, 5}] Actually, it's not recommended to do that in Python. eval is evil. You could ...


1

Clear["Global`*"] pltData = {{Sin[x], {0, 2 Pi}, {-1, 1}}, {y*Cos[y], {-2 Pi, 2 Pi}, {-6, 6}}, {{Sqrt[5^2 - x^2], -Sqrt[5^2 - x^2]}, {-5, 5}, {-5, 5}}, {{z^2 - z - 6}, {-3, 4}, Automatic}}; Column[Plot @@@ ({#[[1]], Insert[#[[2]], Variables[Level[#[[1]], {-1}]][[1]], 1], PlotRange -> #[[3]]} & /@ pltData)]


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