# Tag Info

2

Here's how I handle roots of integer power: myroot[x_, n_, k_] := Root[#^n - x &, k] allroots[multivalexpr_] := FixedPoint[ Function[{expr}, Flatten[MapAt[ Function[{ex}, Replace[ex, myroot[sym_, i_] :> (myroot[sym, i, #] & /@ Range[i])]], expr, FirstPosition[expr, myroot[_, _], {0}]]]], multivalexpr] Then ...

2

To fix this problem on Mma 10.1 on OS X 10.10.4 I took off one of the blanks on term, i.e. ReplaceAll[a.b.c.d + a.ss.e.g.r + Transpose[a.b.c.d], {Plus[front___, term__, middle___, Transpose[term__], end___] :> Plus[front, middle, end, 2*term]}] a.b.c.d + a.ss.e.g.r + Transpose[a.b.c.d] ReplaceAll[a.b.c.d + a.ss.e.g.r + Transpose[a.b.c.d], ...

8

I think you've found a bug in pattern matcher. This problem can be reduced to matching sequence of length one with named BlankSequence patterns in Orderless functions, it stopped working in v10.1. In previous versions your replacement rule works (as noted by belisarius). Minimal example of this behavior is: ClearAll[f, a] SetAttributes[f, {Orderless}] ...

9

f[m_] = 1/(2*E^((-m + Log[5])^2/8)*Sqrt[2*Pi]); Integrate[f[m], {m, -Infinity, Infinity}] 1 dist = ProbabilityDistribution[f[m], {m, -Infinity, Infinity}]; Since the integral of f[m] is unity, f[m] does not have to be scaled to be a distribution. A candidate distribution will probably have two parameters and must be defined on the interval ...

12

UPDATE: quite interesting parallel discussion and solutions (see Emerson Willard answer) can be found HERE. Maybe this is not exactly what you are looking for, but at least this gives you a very close guess and it is easy to figure out the rest. dis = ProbabilityDistribution[ 1/(2*E^((-m + Log[5])^2/8)*Sqrt[2*Pi]), {m, -Infinity, Infinity}]; PDF[dis, ...

3

I'm certain that this will not be the solution to whatever real problem there is behind your question, but incidentally, you could use this function from a former answer fultzTokenize[t_String] := Cases[MathLinkCallFrontEnd[ FrontEndUndocumentedTestFEParserPacket[t, False]], _String, Infinity] fultzTokenize["a+b+c-c"] it gives you but be ...

1

I think I'll go with this one. {a, b, c} = With[{r = Minimize[{x - y, -3 x^2 + 2 x y - y^2 >= -1}, {x, y}]}, Extract[r, Position[r, _?NumericQ]]]

1

I think that the following three methods are clear and sufficiently verbose (and work in all MMa versions at least starting from version 5): res = Minimize[{x - y, -3 x^2 + 2 x y - y^2 >= -1}, {x, y}]; Clear[a, b, c] {a, {b, c}} = res /. Rule[_, v_] :> v {-1, {0, 1}} Clear[a, b, c] {a, {b, c}} = res /. r_Rule :> Last[r] {-1, {0, 1}} ...

2

In V10, here are a few ways to use Values: {a = #, {b, c} = Values[#2]} & @@ Minimize[{x - y, -3 x^2 + 2 x y - y^2 >= -1}, {x, y}] (* {-1, {0, 1}} *) {a, {b, c}} = Minimize[{x - y, -3 x^2 + 2 x y - y^2 >= -1}, {x, y}] /. sol : {__Rule} :> Values[sol] (* {-1, {0, 1}} *) With[{minsol = Minimize[{x - y, -3 x^2 + 2 x y - y^2 >= -1}, ...

1

I believe the most clear way is something like {a, {b, c}} = {#[[1]], {x, y} /. #[[2]]} &@ Minimize[{x - y, -3 x^2 + 2 x y - y^2 >= -1}, {x, y}]

3

If I understand you correctly: {a, b, c} = Extract[{{1}, {2, 1, 2}, {2, 2, 2}}]@ {-1, {x -> 0, y -> 1}} After this, a == -1 && b == 0 && c == 1.

6

Update In the interest of simplifying the code somewhat, I've modified one of the replacements. For instance, we can do expr2 = Thread[expr1, Plus] /. Plus -> Times or epxr2 = expr1 /. expT[Plus[a__]] :> Times @@ expT /@ a rather than expr2 = expr1 //. {expT[a_ + b_] :> expT[a] expT[b]} So: f[expr_] := Thread[expr /. Power[E, a_] :> ...

18

One way would be to redirect all messages issued by ToExpression to a string-stream. Here is an example of that approach, with minimal error-checking: Needs["Developer"] interpret[str_String] := Module[{s = StreamToString[], r, m} , Block[{\$Messages = {s}}, r = ToExpression[str, InputForm, HoldComplete]] ; m = StringFromStream[s] ; Close[s] ; ...

6

The following appears to be what you want. repl[expr_, max_] := With[{largest = Max[Cases[expr, C[n_] :> n, Infinity]]}, If[largest <= max, expr /. (R[C[largest], anything__] :> R[C[largest], anything].(II + R[C[largest + 1], C[largest]])) // repl, expr] ] repl[myExpr, 7] Alternative formulation if recursion doesn't float ...

2

My one shot at answering this question: Attributes[convert] = {HoldFirst}; convert[def_Symbol?ValueQ] := With[{old = def, pats = Quiet[Sequence @@ Cases[Variables @ def, s_Symbol :> s_]]}, ClearAll[def]; def[pats] := old; ] Test: positionPayload = 2. x + 3. t^2; convert[positionPayload] ?? positionPayload GlobalpositionPayload ...

3

You might try something like this, which makes pure functions, which means the variables used int the expression to converted only have to be clear at time expToF is called. expToF[exp_, vars : {_Symbol ..}] := With[{body = exp /. Thread[Rule[vars, Slot /@ Range @ Length[vars]]]}, Function[body]] Clear[x,t] f = expToF[2. x + 3. t^2, {x, t}]; f[x,t] ...

4

Not that I would recommend this, but anyway: positionPayload = 2. x + 3. t^2; variableList = Variables[positionPayload]; positionPayload = Function[Evaluate@variableList, Evaluate@positionPayload]; positionPayload[q, r] (* 3. q^2 + 2. r *) Edit positionPayload = 2. x[1] + 3. t[3]^2; variableList = Variables[positionPayload]; ul = ...

2

positionPayload = 2. x + 3. t^2 (* 3. t^2 + 2. x *) variableList = DeleteDuplicates[Variables[positionPayload]] (* {t, x} *) temp = positionPayload; positionPayload =. Evaluate[positionPayload @@ (Pattern[#, Blank[]] & /@ variableList)] := Evaluate@temp Definition@positionPayload (* positionPayload[t_, x_] := 3. t^2 + 2. x *) positionPayload[q, r] (* ...

3

This expression, designated exp for convenience, can be simplified substantially as follows. num = Map[FullSimplify[#] &, Numerator[exp]]; Map[FullSimplify[#, θ[_] ∈ Reals && ϕ[_] ∈ Reals] &, Denominator[exp] /. Abs[z_]^2 :> FullSimplify[Abs[z]^2, θ[_] ∈ Reals && ϕ[_] ∈ Reals]; /. Abs[z_]^2 :> z^2] den = ...

4

This is indeed somewhat confusing when you are new to Mathematica. In Mathematica, == stands for mathematical equality. Thus a == 0 does not evaluate to either True or to False until a is replaced by a numerical value. a is considered to be a variable that may or may not be zero. A pattern like x_ /; condition will only match if condition is explicitly ...

4

I'm not thrilled with the question since it provided no example, but there was a serious response and also a request to see an ILP approach. Here is one such. Start by creating an example. SeedRandom[1111]; n = 10; m = 4; intset = RandomInteger[100, n] (* Out[335]= {9, 78, 23, 59, 95, 51, 24, 29, 99, 68} *) Now we set up the ILP. We have our n -1/0/1 ...

Top 50 recent answers are included