New answers tagged

2

The problem can be reduced (I think) to the problem of defining a phase function $\arg(f(x))$ that is continuous on the interval $x \in [0, 1]$. This is tricky, because the path $f(x)$ may "wind" around the origin, leading to different values of the "continuous argument" for the same value of the "conventional argument". A ...


0

Here's a variation of bbgodfrey's answer that doesn't require quieting: g[a_,b_]:=Activate @ Block[{NIntegrate=Inactive[NIntegrate]},Derivative[1,0][f][a,b]] Check: g[1, 1] 1.80525 The trick is that Mathematica knows how to take derivatives of inactive integrals, so temporarily inactivating NIntegrate avoids having NIntegrate trying to integrate a ...


6

One can use Composition (which should be the true meaning of the product of operators) with (pure) Function: ClearAll[op, ff] ff[j_] := f \[Function] D[f, x] - j f op[n_] := Composition @@ Table[ff[j], {j, n}] op[2][f[x]] // Simplify 2 f[x] - 3 f'[x] + f''[x] Update The version without Apply (@@) (actually Composition can be also replaced by ...


7

Clear["Global`*"] Defining the operator recursively, dOp[func_, x_Symbol, 1] := dOp[func, x, 1] = D[func, x] - func; dOp[func_, x_Symbol, n_Integer?Positive] := dOp[func, x, n] = D[dOp[func, x, n - 1], x] - n*dOp[func, x, n - 1]; For example, dOp[f[x], x, 2] // Expand (* 2 f[x] - 3 f'[x] + f''[x] *) Looking at the first several, Table[{n, ...


3

op[f_, x_, n_] := Block[{d}, Total[MapIndexed[#1*If[#2[[1]] == 1, 1, D[f[x], {x, #2[[1]] - 1}]] &, CoefficientList[Product[d - j, {j, 1, n}], d]]]] op[g, y, 2] gives 2 - 3 g'[y] + g''[y] Update based on your comment: op[f_, x_, n_] := Block[{d}, Total[MapIndexed[#1*D[f[x], {x, #2[[1]] - 1}] &, CoefficientList[Product[d - j, {j, 1, ...


5

A couple of ways: f[x__] /; ! OrderedQ[{x}] := f @@ Sort[{x}] call : f[x__] := Block[{f}, Sort[call] /; ! OrderedQ[call]] The first way seems better, or at least faster.


3

Here a solution which will adjust the behaviour of a set of rules which contains "duplicate" rules: adjust[strategy_, rules_] := Hold@@@GatherBy[rules, First] // Map[With[{vs = #[[All, 2]]}, strategy[RuleDelayed@@{#[[1, 1]], Unevaluated@vs}]]&] cycle[k_ :> vs_] := Module[{i = 0}, k :> vs[[1+Mod[i++, Length@vs]]]] oneshot[k_ :> vs_]...


3

This uses FirstPosition and ReplacePart. It works on the OP's example, not sure how extensible it is. replaceOnceOnly[expr_, rules_] := Module[{val = expr, part}, Function[ If[Not[MissingQ[part = FirstPosition[val, #]]], val = ReplacePart[val, part -> #2] ] ]@@@rules; val ]; In[14]:= replaceOnceOnly[{a, b, a}, {a -&...


5

One way is to use the following: GeneralUtilities`ListIterator GeneralUtilities`IteratorExhausted Then it can be done with Replace or ReplaceAll: Needs@"GeneralUtilities`" Module[{hold}, SetAttributes[hold, HoldAll]; oneTimeRules[rules_] := Normal@Merge[rules, ListIterator] /. Rule -> RuleDelayed /. i_GeneralUtilities`...


2

I think this does the trick. It's a bit ugly and procedural though: useRulesOnce[item_, rules_] := Module[{result, citem = item, rrules}, rrules = Reap[Do[ With[{repl = (citem /. r)}, If[repl =!= citem, citem = repl; (* Print["replacing using " <> ToString[r]] *), Sow[r]]]; , {r, rules}]] /. Null -> Nothing;...


1

As m is just an integer multiple of n+1, you can do this with Mod: f[x_, n_] := Piecewise[{{1, Mod[x, n+1] == 0}}, n^3 *x^2] f[4, 3] (* returns 1 *) f[5, 3] (* returns 675 == 3^3 * 5^2 *) table = Table[f[x, n], {x, 1, 5}, {n, 0, 5}] (* returns: {{1, 1, 8, 27, 64, 125}, {1, 1, 32, 108, 256, 500}, {1, 9, 1, 243, 576, 1125}, {1, 1, 128, 1, 1024, 2000}, {1, ...


Top 50 recent answers are included