Tag Info

Hot answers tagged

8

It is sometimes beneficial to first work with functions (in mathematical sense) as symbols and apply to them some pointwise operations. Then, just at the end, convert resulting expression to pure function (in Mathematica sense) and pass some arguments. This can be automated using something like this: ClearAll[purify] Options[purify] = {"FunctionPattern" ...


7

I have used a method similar to your "dirty code" myself and I don't see an apparent alternative as Pattern requires a true Symbol for its first parameter. I will note that your Unique Symbols should be made Temporary, or you can generate them with Module to add this attribute automatically. And since you are trying things for fun you could use Map in ...


6

To get the polynomial, the easiest way is res = M /. Rationalize@Solve[a == 0, M]; poly = res[[1, 1]][M] 900 + 14400 M^5 + M^4 (50400 - 8944 z) - 1909 z + M^3 (65700 - 27760 z - 14612 z^2) + M (9900 - 13690 z + 98 z^2) + M^2 (38700 - 30597 z - 14514 z^2 + 147 z^3) Now I don't know what Solve does, but I did the following. Take the numerator ...


6

You can achieve this defining an UpValue for g: g/:Power[g,2]:=g[#]^2& Or more generally: g/:Power[g,n_Integer]:=g[#]^n& Using Through now works as wanted: Through[(f + g^2)[x]] (*Out=f[x]+g[x]^2*)


6

The first thing I came up with was: Permutations[l] The second thing I came up with was an inductive answer: perms[l_] := Flatten[With[{p = perms[Rest@l]}, Function[{n}, Insert[#, First[l], n] & /@ p] /@ Range[Length[l]]], 1] perms[{a_}] := {{a}} I can't think of a pattern-based one at the moment, but I'm sure there's a clever one.


4

I'm probably missing an important point, but what is wrong with (f[#] + g[#]^2)&[x] f[x]+g[x]^2


2

The original version works just fine: Through[(f + Composition[Power[#,2]&, g])[x]] or, for MMA ver. 10 and above, Through[(f + (Power[#,2]&) @* g)[x]] result in (* f[x] + g[x]^2 *) Alternatively, you could do, from the beginning, Through[(f + (g[#]^2 &))[x]] which is perhaps a little easier to parse since it doesn't use Composition. ...



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