Tag Info

New answers tagged

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 Global`positionPayload ...


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] (* ...


1

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


4

Solution Suppose the list is list = Range[-3, 3] (* {-3, -2, -1, 0, 1, 2, -3} *) Then, the set of all subsets of, say, size 3 is sets = Subsets[list, {3}]; We define a list of signs that give all possible combinations of plusses and minuses to attach to each subset: signs = Tuples[{-1, 1}, 3] (* {{-1, -1, -1}, {-1, -1, 1}, {-1, 1, -1}, {-1, 1, 1} ...


-1

This should work: Replace[{484/45, -16 EulerGamma/3, -8 Log[2], PolyGamma[0, 1/Sqrt[2]], (48/5 + 2 I/5) Sqrt[2] Log[1 + Sqrt[2]]}, _?ExactNumberQ -> 1, 2] (* {1, EulerGamma, Log[2], PolyGamma[1, 1/Sqrt[2]], Sqrt[2] Log[1 + Sqrt[2]]}*)


3

To answer the question as asked, we modify the code as follows: replacementRule = Plus[ Dot[FRONT__, AA__, BACK__] , Dot[FRONT__, BB__, BACK__] ] :> Dot[FRONT, Plus[Dot[AA], Dot[BB]], BACK]}] w.a.b.r + w.c.d.r /. replacementRule First, we have changed -> (Rule) to :> (RuleDelayed) so that when the expression is re-written, it will write it ...


4

It can be done with w.a.b.r + w.c.d.r /. Dot[FRONT_, AA__, BACK_] + Dot[FRONT_, BB__, BACK_] :> Dot[FRONT, Dot[AA] + Dot[BB], BACK] w.(a.b + c.d).r However, I like function argument destructuring, so I would probably write f[Dot[w_, a__, r_] + Dot[w_, b__, r_]] := w.(Dot[a] + Dot[b]).r f[w.a.b.r + w.c.d.r] w.(a.b + c.d).r


0

I think the problem in your first line of code is that you're trying to set v to a structure which contains v, hence the recursion issue. Mathematica is indeed able to differentiate variables of the same letter and different subscripts. Note Subscript[v, x] == Subscript[v, y] evaluates False and Subscript[v, x] = 5; Subscript[v, y] = 4; Subscript[v, x] ...


7

You can generate the monomials by using CoefficientRules, like this In[55]:= monomialList[poly_, vars_] := Times @@ (vars^#) & /@ CoefficientRules[poly, vars][[All, 1]] monomialList[a x^2 + b x y + c y^2, {x, y}] Out[56]= {x^2, x y, y^2}


7

A pattern matching method: fn[x_, {var__}] := List @@ Pick[x, x, Alternatives[var]^_.] fn[a x^2 + b x y + c y^2, {x, y}] {x^2, x y, y^2} But a better approach I believe is (hopefully now corrected at last): fn2[x_, var_] := Collect[List @@ Expand @ x, var, 1 &] fn2[a x^2 + b x y + c y^2, {x, y}] {x^2, x y, y^2} fn2[x (x^2 + y^2), {x, y}] ...


4

This uses some undocumented functionality: poly = a x^2 + b x y + c y^2; vars = {x, y}; dl = GroebnerBasis`DistributedTermsList[poly, vars]; Inner[Power, vars, #, Times] & /@ dl[[1, All, 1]]


4

There's no single BoundedQ function that I know of, but there are several related functions: FunctionRange tries to compute the range of a function: range = FunctionRange[1/x, x, y] (* y < 0 || y > 0 *) It is clear that this is not bounded, but we can also try to get that result programmatically: BoundedRegionQ@ImplicitRegion[range, y] (* False *) ...


2

More ideas for you: in = {{1, 1}, {12, 1}, {7, 9}, {10, 14}}; Times @@ Inner[Plus, in, {a, b}, Beta] Times @@ (Beta[# + a, #2 + b] & @@@ in) Times @@ MapThread[Beta, in\[Transpose] + {a, b}]


2

Or this d = {{1, 1}, {12, 1}, {7, 9}, {10, 14}}; Times@@Beta @@@ (# + {a, b} & /@ d) Beta[1 + a, 1 + b] Beta[7 + a, 9 + b] Beta[10 + a, 14 + b] Beta[ 12 + a, 1 + b] Or if you want a,b,d and Beta all to be parameters to a function f: f[a_, b_, fn_, d_] := Times@@fn @@@ (# + {a, b} & /@ d) f[h, i, Beta, {{1, 7}, {2, 8}, {4, 5}}] ...


5

res = Rest@Select[Subsets@pol, PolynomialMod[#, factor] == 0 &] So, out of the 8192 (== 2^13) possible "sub-polys", only these ones are divisible by factor: Grid[Join[{{"pol == Non-factored", "Plus (factor by ...)"}}, {pol - # factor // Expand, #} & /@ (PolynomialQuotient[#, factor, z] & /@ res)], Frame -> All] ...


4

pol = x^2 y + x^4 z + x^3 y z + x^6 y z^2 + x y^2 z^2 + x^5 y^2 z^2 + x^5 z^3 + x^4 y z^3 + x^3 y^3 z^3 + x^2 y^4 z^3 + x^2 y^2 z^4 + x^4 y^5 z^4 + x^3 y^4 z^5; guess = (x^2 z^3 + y x^3 z^2 + x z); FullSimplify[pol/guess]*Simplify[guess] xz(1 + x^2*yz + xz^2)* (x^2*(x + y) + (x*y)/z + y^2*z + x*y^4*z^2 - (x^2*y*(xy + z))/ ...


5

f[a_, b_] := Fold[#1*Beta[#2[[1]] + a, #2[[2]] + b] &, 1, {{1, 1}, {12, 1}, {7, 9}, {10, 14}}] f[a, b] Beta[1 + a, 1 + b] Beta[7 + a, 9 + b] Beta[10 + a, 14 + b] Beta[12 + a, 1 + b]


7

You mean like this? Times @@ Map[ Beta[First[#] + a, Last[#] + b] &, {{1, 1}, {12, 1}, {7, 9}, {10, 14}}]



Top 50 recent answers are included