# Tag Info

26

Assuming you don't have any built-in symbols in that list, you could simply do: DeleteDuplicates@Cases[Leff, _Symbol, Infinity] (* {da, ma, dm, mc, La, h, R} *) If you do have symbols from built-in contexts or packages, you can simply pick out only those that are in the Global context with: With[{globalQ = Context@# === "Global" &}, ...

15

Using an undocumented function: ReduceFreeVariables[(mc dm^2 + mc/12*(h^2 + 3 R^2) + ma da^2 + ma/12 La^2)/ (mc dm + ma da)] {da, dm, h, La, ma, mc, R}

13

A few examples fun[x_] := x^2 sphere = Graphics3D[{Sphere[{0, 0, 0}, 0.01]}, Boxed -> False, ImageSize -> 30]; str = {"1", "Pi", "{f}", "f", "f[x]", "f+f", "Inactivate[f+f,Plus]", "Hold[1+2+3]", "{1,{2,{3}}}", "fun", "fun[x]", "Cos[Exp[x]]", "Red", "sphere", "DateObject[{2014,10}]"}; table = With[{exp = ToExpression /@ str}, ...

13

Look at the system context to see what the convention is. I can find 257 built-in symbols in 11.3, symbols = Names["System$*"]; Length @ symbols (* 257 *) In the system context there seems to be two main uses of the$ naming convention. It is used for static symbols without value, that can indicate e.g. evaluation status, like $Aborted,$Failed, $Canceled,... 13 Well, the easy way is to evaluate it for [x,y]. f[x_, y_] = Sqrt[-1 + Tanh[#1 - #2]^2] &[x, y]; If you'd rather do it with a replacement, you should understand the FullForm because that's what replacement works on. Sqrt[-1 + Tanh[#1 - #2]^2] & // FullForm (* Function[Sqrt[Plus[-1,Power[Tanh[Plus[Slot,Times[-1,Slot]]],2]]]] *) So, you want ... 13 I think the easiest way would be to define(name) the pure function f f = Sqrt[-1 + Tanh[#1 - #2]^2] & and use it accordingly f[x,y] (*Sqrt[-1 + Tanh[x - y]^2]*) 11 Use MapThread MapThread[Set, {ls, v}] 11 Using an undocumented function: ReduceFreeVariables[u] === Sort[vas] 11 There are couple of problems with your code. It is an image, it would be way nicer not to have to rewrite it. Plotting Series If you go to ref / Series / Application you will see that Normal is used to plot a Series as otherwise O[x]^n will make Plot confused. Function definition Functions are defined more or less like that f[x_]:=... but if x is an ... 10 This works, though it'd be nicer to have a built-in way to do it: SetAttributes[fullyQualifiedName, {HoldAll, Listable}]; fullyQualifiedName[a_] := Context[a] <> SymbolName[Unevaluated@a] Some demonstrations: In:= fullyQualifiedName[a] Out= "Globala" In:= foo = 3 Out= 3 In:= fullyQualifiedName[foo] Out= "Globalfoo" In:= ... 10 The below code for getAllVariables was lifted without attribution from some StackOverflow post. headlist = {Or, And, Equal, Unequal, Less, LessEqual, Greater, GreaterEqual, Inequality}; getAllVariables[f_?NumericQ] := Sequence[] getAllVariables[{}] := Sequence[] getAllVariables[t_] /; MemberQ[headlist, t] := Sequence[] getAllVariables[ll_List] := ... 10 I suspect it's an internal decision by WRI to allow as variables only expressions of the form A[0, 1, 2], that is, a symbol with integer arguments. You could try reporting your desired functionality to WRI; maybe they will extend what expressions are allowed. Instead of being localized in the usual way, the expressions are remapped to Unique[] symbols. For ... 10 Update Following your updated question I recommend filtering Level output with Variables as I proposed here. Then Sort vas and check for equivalence. Sort[vas] === Variables @ Level[u, {-1}] Original proposals The first idea that came to mind: Level[u, {-1}] ⋂ vas === Sort[vas] Equivalently: Complement[vas, Level[u, {-1}]] === {} A method using ... 9 Here's a way: var1 = 10; var2 = 11; var3 = 17; var4 = 5; compvar := {var1, var2, var3, var4} compvar; (*all variables assigned*) ClearAll[f]; SetAttributes[f, {HoldAll}]; f[x_, y__] := Flatten@{f[x], f[y]} f[x_] := SymbolName@Unevaluated@x OwnValues[compvar] /. {HoldPattern[y_] :> {x__}} :> f[x] (* {"var1", "var2", "var3", "var4"} *) 9 This is a variation of Leonid's answer that avoids the dependence on a context like "Test" that must be empty: SetAttributes[fq, {Listable, HoldAll}]; fq[sym_] := Block[{Internal$ContextMarks = True},ToString[Unevaluated[sym]]] fq[{fq, Print, Developer$MaxMachineInteger}] (* {"Globalfq", "SystemPrint", "Developer$MaxMachineInteger"} *)

9

Here is an alternative: ClearAll[f]; SetAttributes[f, HoldAll]; f[a_Symbol] := Block[{$ContextPath = {"Test"},$Context = "Test"}, ToString[Unevaluated@a] ]; It is based on the way Mathematica treats short and long names depending on the current settings of $Context and$ContextPath. The context "Test" must not exist for it to be fully ...

9

As stated in the comments, a is evaluated before being fed into Remove. We can prevent this by using Unevaluated: a = 1; b = 2; c = 3; Remove /@ Unevaluated[{a, b, c}]; a a One can also use Apply instead of Map to effectively achieve Remove[a, b, c]: a = 1; b = 2; c = 3; Remove @@ Unevaluated[{a, b, c}]; a a

9

You attempt to solve the ODE at the time of definition of lsolve. At this point, q does not depend on x. You really want to use SetDelayed here: lsolve[r_, q_, a_, eta_] := y[x] /. First@DSolve[{y'[x] == r - q*y[x], y[a] == eta}, y[x], x]; nwe = lsolve[x, 2*x, 0, 0] // Simplify 1/2 - E^-x^2/2

8

In addition to Mr.Wizard's answer here is a collection of other possibilities: data1 = {1, 1}; data2 = {2, 2}; datalist := {data1, data2}; ToString /@ Map[HoldForm, OwnValues[datalist], {3}][[1, 2]] ToString /@ Map[Unevaluated, OwnValues[datalist], {3}][[1, 2]] ToString /@ Thread[HoldForm[datalist] /. OwnValues[datalist]] ToString /@ Thread[Extract[...

8

Begin["mycontext"] affects the parser, not the evaluator. These are separate expressions: Begin["mycontext"]; myvar = 7; Print[Context[]]; Print[Context[myvar]]; End[]; They get parsed and evaluated one by one. Once Begin["mycontext"]; is evaluated, the new context applies to all subsequent lines. This is a single expression: Do[ Begin["...

7

If you have even more complicated expressions, you might want to use Heads -> True. expr = {f, Subscript[g, i], h[i[j[a, b]]], s'[t] == u[t] + v[t]}; Union @ Cases[expr, Except[__Symbol?(Context @ # === "System" &), _Symbol], {1, ∞}, Heads -> True] {a, b, f, g, h, i, j, s, t, u, v} Without checking heads: Union @ Cases[expr, ...

7

You must introduce some form of holding in you definition of compvar as otherwise, assuming it is defined after var1, var2, etc., there is no information to retrieve: var1 = 10; var2 = 11; var3 = 17; var4 = 5; compvar = {var1, var2, var3, var4}; Definition[compvar] compvar = {10, 11, 17, 5} You could use Hold but then you would need to ReleaseHold (or ...

7

Remember that = is really Set, and Set is a pretty ordinary function. Also, RandomInteger can make a list all by itself, so you don't need Table. Edit 11/15: Jerry Guern pointed out the need to be careful with quoting to have it work repeatedly. Here, I use Unevaluated to quote each variable: r = Unevaluated /@ {a, b, c, d, e, f, g, h, i}; Now, you may ...

7

I think there must be a better way to accomplish the OP's ultimate goal than the general approach outlined above. But be that as it may, the following culls all the Set[] commands from the last input line (so it has a little broader scope than what was asked for). lastInputSets[] := Block[{Set}, Grid@Cases[Hold[In[#]] &[\$Line - 1] /. DownValues[In], ...

7

YES. Use Script Numbers like ScriptThree \[ScriptThree]=4

6

This is an example of unintended behavior in Mathematica that the developers are aware of. There are a number of workarounds. The simplest is to wrap a function around the appropriate bounds; instead of Manipulate[m, {n, {10}}, {m, n - 1, 2 n, 1}] which illustrates the problem, try Manipulate[Floor@m, {n, {10}}, {m, n - 1, 2 n, 1}] A solution can also ...

6

This is really easy if you understand the internal form of {a,b,c,d}. Let's look at it: p={a,b,c,d}; FullForm[p] (* List[a,b,c,d] *) as you see what you want is not really far away because basically, you only need to replace List with f. This is exactly what Apply (or as operator @@) does: f @@ p (* f[a, b, c, d] *)

6

You're going to first need to hold {data1,data2} unevaluated in some way; either define it first, use SetDelayed (short form :=), or use Hold. I choose :=. data1 = {1, 1}; data2 = {2, 2}; datalist := {data1, data2}; Cases[OwnValues[datalist], x_ :> ToString@Unevaluated@x, {3}] // Rest {"data1", "data2"} Or using my step function: Cases[step[datalist]...

6

Beside using Block as ciao suggests in his comment to the question, you can also play with the attribute Protected. Thus, Attributes[Pi] {Constant, Protected, ReadProtected} Unprotect[Pi]; Pi = 42; Protect[Pi]; Area[Disk[]] Tan[Pi/4] 42 Tan[21/2] To restore Pi to its special symbolic status, you should execute Unprotect[Pi]; Pi =. Protect[Pi/4]; ...

6

f[g[x,t],t] /. g[___]->g (* f[g, t] *)

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