# Tag Info

12

Extract all Greek letters from the documentation and make replacement rules: nb = Get @ FileNameJoin[{$InstallationDirectory, "Documentation", "English", "System", "Tutorials", "LettersAndLetterLikeForms.nb"}]; letters = Cases[nb, StyleBox[s_String, "TR"] :> s, {-2}]; letters = DeleteCases[letters, "π" | "∈"]; (* reserved Symbols *) names = ... 7 In the first case, the type of the dataset was deduced via type deduction mechanism applied at Dataset construction. In the second case, it was inferred using a set of type inference rules. The fact that this happens even with inert replacement does not matter: as long as ReplaceAll is used, type of the resulting Dataset is inferred rather than deduced. ... 6 i = 0; number = 11113132434242342342342342535646657758768872132131111119; sumrule = value_ :> (i++; Total[IntegerDigits[value]]); number //. sumrule i This is a quick and dirty way to do this. 6 Unevaluated[Limit[(c^(1 - g) - 1)/(1 - g), g -> d]] /. d -> 1 Hold[Limit[(c^(1 - g) - 1)/(1 - g), g -> d]] /. d -> 1 // ReleaseHold With[{d = 1}, Limit[(c^(1 - g) - 1)/(1 - g), g -> d]] Limit[(c^(1 - g) - 1)/(1 - g), g -> #] &@1 Block[{Limit}, SetAttributes[Limit, HoldAll]; Limit[(c^(1 - g) - 1)/(1 - g), g -> d] /. d -> 1] ... 6 Here is something which works: Normal@Series[f[x], {x, x0, 4}] /. (x - x0) -> h The reason your attempt doesn't work can be determined by examining the FullForm: FullForm@Series[f[x], {x, x0, 4}] (*SeriesData[x, x0, List[f[x0], Derivative[1][f][x0], Times[Rational[1, 2], Derivative[2][f][x0]], Times[Rational[1, 6], Derivative[3][f][x0]], ... 5 You could define it with Array[Subscript[a, Min[##], Max[##]] &, {4, 4}] 4 If we wish to handle an arbitrary list of rules in the second parameter of ReplaceRepeated we can by using a single wrapping rule with a counter and handing off the actual processing to ReplaceAll. This avoids the memory overhead of keeping all intermediate results for FixedPointList. countReplace[expr_, rules_] := Module[{i = -1}, {expr //. all_ ... 4 Here is another solution, that works with a list of rules and with held expressions cRepRep2[expr_, snd_] := {Last@#, Length@# - 2} &@ FixedPointList[# /. snd &, expr] Here is a similar solution, that saves on memory by using FixedPoint rather than FixedPointList. It also works with held expressions cRepRep3[expr_, snd_] := Module[ {c = -1, ... 4 There is nothing special about ToString. In this kind of replacement you need to use RuleDelayed, :>. Subscript[A, 1] /. Subscript[A, x_] :> ToString[x] Try applying Trace to both forms of the expression and compare the order things are evaluated. 4 As I said in the comment, it's not the replace that's the problem, it's that you create an invalid expression as a result. Here's one way to do this kind of thing, many others... eq = a + b^c - 2 d/e; vars ={a,b,c,d,e}; alist = {1, 2, 3}; blist = {2, 4, 6}; clist = {3, 5, 7}; dlist = {1, 2}; elist = {-1, -2, 2}; eq /. Map[Rule @@@ Transpose[{vars, #}] ... 4 You can do: Times @@@ Tuples[{{1, 2, 3}, {10, 100}}] or Times @@@ Tuples@({a, b} /. {a -> {1, 2, 3}, b -> {10, 100}}) The issue is multiplication not replacement. For the more general case: f @@@ Tuples[lst] e.g. 4 You can apply a rule using Condition: mat2 /. Subscript[a, i_, j_] :> Subscript[a, j, i] /; j > i giving$$\left( \begin{array}{cccc} a_{1,1} & a_{2,1} & a_{3,1} & a_{4,1} \\ a_{2,1} & a_{2,2} & a_{3,2} & a_{4,2} \\ a_{3,1} & a_{3,2} & a_{3,3} & a_{4,3} \\ a_{4,1} & a_{4,2} & a_{4,3} & a_{4,4} \\ ... 4 Using the built-in matrix manipulation commmands mat = Array[Subscript[a, ##] &, {4, 4}]; LowerTriangularize[mat] + Transpose[LowerTriangularize[mat]] - DiagonalMatrix[Diagonal[mat]] gives the same answer. This takes the lower triangular part and adds it to the transpose of itself, giving a symmetric matrix in which the diagonal entries have been ... 3 rules = {runBool -> True, linearBool -> True, ab -> 3, linx -> 10}; FilterRules[rules, _?(StringMatchQ[ToString[#], "lin*"] &)] (*{linearBool -> True, linx -> 10}*) 3 rules = {runBool -> True, linearBool -> True, ab -> 3, linx -> 10}; FilterRules[rules, x_ /; With[{z = ToString@x}, StringLength@z >= 3 && StringTake[z, 3] == "lin"]] (* {linearBool -> True, linx -> 10} *) But something like Pick[rules, StringMatchQ[ToString /@ rules[[All, 1]], "lin*"]] is cleaner, IMO, and allows ... 3 If you aim to exclude the derivative, try this: 1/2 k q[t]^2 + Derivative[1][q][t] (m Derivative[1][q][t] + y q[t]) - 1/2 m Derivative[1][q][t]^2 - y q[t] Derivative[1][q][t] /. q'[t] -> p/m - y/m*q[t] // Simplify (* (p^2 - 2 p y q[t] + (k m + y^2) q[t]^2)/(2 m) *) If, on the other hand, you aim to exclude the q[t], try this: 1/2 k ... 3 I have a list of replacement rules, ex. list = {"name1"->1, "name2"->2, "name3"->3}. I am hoping to change values of these rules without having to know the orders of the list. Why not use Association? myRules = <|"name1" -> 1, "name2" -> 2|>; list = {"name1", "name2", "name3"}; list /. myRules Now you can change a rule without ... 3 Try also this: list = {"name1" -> 1, "name2" -> 2, "name3" -> 3}; list /. ("name1" -> x_) -> ("name1" -> a) (* {"name1" -> a, "name2" -> 2, "name3" -> 3} *) Another way would be to use associations as it has been already mentioned by Nasser above. The Associations have a very simple way to change a value for a given key: ... 2 This embarrassingly simple approach also works. list = {"name1" -> 1, "name2" -> 2, "name3" -> 3}; list /. Rule["name2", 2] -> Rule["name2", 4] which produces {"name1" -> 1, "name2" -> 4, "name3" -> 3} 2 ReplaceAll follows The Standard Evaluation Procedure. Some function have Attributes that make them follow a Non-Standard Evaluation procedure. 2 list = {"name1" -> 1, "name2" -> 2, "name3" -> 3}; rrF1 = # /. HoldPattern[#2 -> _] :> (#2 -> #3) &; rrF1[list, "name2", 4] (* {"name1" -> 1, "name2" -> 4, "name3" -> 3} *) Or rrF2 = ReplacePart[#, {1, -1} Position[#, #2][[1]] -> #3] &; rrF2[list, "name1", 5] (* {"name1" -> 5, "name2" -> 2, "name3" -> 3} *) ... 2 Not the safest way: s = Series[f[x], {x, x0, 4}]; s[[2]] = x - h; s // Normal$\frac{1}{24} h^4 f^{(4)}(\text{x0})+\frac{1}{6} h^3 f^{(3)}(\text{x0})+\frac{1}{2} h^2 f''(\text{x0})+h f'(\text{x0})+f(\text{x0})\$

2

in = {{a > b && b < c && c < 1}, {a < b && b < c && d < c && d < 1}}; in /. And -> (Sequence @@ GatherBy[{##}, FreeQ[c | d]] &) {{{a > b}, {b < c, c < 1}}, {{a < b}, {b < c, d < c, d < 1}}} The code above uses the v10 operator form for FreeQ; if you are using an ...

2

What you have laid out is inefficient in a number of ways. But, I will tackle your question, as is, first, then I will lay out how I would approach it. Since your bottleneck is Table[{j dx, k dy, p[j, k] /. sol}, {j, 1, m}, {k, 1, m}] you need to use a more efficient layout for your replacement rules: Dispatch. Replace sol = Solve[eqns, vars][[1]]; ...

1

Someone else posted a working answer yesterday, which is gone today; maybe it was deleted by the author for some reason. The solution was to define a function arg[num_] := ArcTan[ComplexExpand[Im[num]]/ComplexExpand[Re[num]]]

1

It seems that a direct replacement (using ReplaceAll and RuleDelayed) may be adequate: Arg[1 + I a] /. Arg[1 + I*x_] :> ArcTan[x] ArcTan[a]

1

Based on your update I think this is the simplest way to achieve what I believe you want: express = 1; tSet = Range[1, 5]; Table[express, {t, tSet}] {1, 1, 1, 1, 1} express = t^2; Table[express, {t, tSet}] {1, 4, 9, 16, 25} You lose the direct vector evaluation of Listable functions but this is both more general and a solution to your specific ...

1

For example, here is a way to do what you want with one single function. In the following example, instead of Null, the "forbiden" value is 1, and someactionis computing Mod[x, 2] function (which gives the remainder on division of x by 2). Let's define someaction, Mathematica allows to do this : someaction[x_List] := someaction /@ DeleteCases[x, 1]; ...

1

LayeredGraphPlot[set, EdgeRenderingFunction -> ({If[MemberQ[set /. Rule -> List, Reverse@#2] && ! SameQ @@ #2, Black, Blue], Arrow[#1, 0.1]} &)] Remove the SameQ check if you want self-loops to be considered a hit. If you expect lager graphs, probably wise to pre-compute some stuff... Per OP comment, ...

1

Tsys0 = 1/2 Subscript[m, 3] Derivative[1][x][ t]^2 + (IG1 (Derivative[1][x][t]/ r - ((-l^2 + r^2 + x[t]^2) Derivative[1][x][ t])/(2 r x[t]^2))^2)/(2 (1 - (-l^2 + r^2 + x[t]^2)^2/(4 r^2 x[t]^2))); Subscript[T, sysmod] = Tsys0 /. {D[x[t], t] -> xd, x[t] -> x}

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