The problem, as usual, is precedence. You need to use parenthesis to group expressions. The code Scan[ (#^2 // Print) &, {1, 2, 3}] will now do what you want. Your reference to "mathematica pipe ...

The other answer by Andrew technically answers your question, but, maybe what you really wanted was Sum[If[b =!= 0, a[m], 0], {m, 1, 4}] which returns a + a + a + a The difference ...

One way to keep the order in l1 is this: l1 = {"qwe", "abc", "abb", "aba", "ddd"}; l2 = {"abc", "abd", "aba", "qwe&...

Similar to many other means, the geometric mean is homogenous. This means that GeometricMean[ c data ] == c GeometricMean[ data ] should be true for any number c. However, the problem is that $n$th ...

I think you have found one of the quirks of the convoluted Mathematica evaluation rules. I suggest you try instead the alternative code: D[f @@ {t. x, y, z}, x] /. {dd_[nn__][f][xx__] -> dd[nn][g][...

Something like this code should work: pExpand[x : (_Rational | _Integer), p_?PrimeQ, n_ /; Positive[n]] := Module[{q = p^n, num, den, v, e}, v = IntegerExponent[#, p] & /@ ({num, den} = #[x] ...

You may be able to use some code like this repl[prompt_: ""] := Module[{input}, Print[]; While[True, input = InputString[prompt]; If[input == "quit", Break[], Print[]; Print["Out[", ++$Line, "]... View answer 5 votes The following function seems to do what you want realToString[x_Real] := StringReplace[ToString[x,InputForm], StringExpression[a__~~"`"~~__~~"*^"~~b__]->a~~"*^"~~b];... View answer 5 votes The problem seems to be that the function f[n_, x_:(Sqrt-1)/2] := Product[ 1 / (1 - x^k/(1 - x^(2*k))), {k, 2, n}]; when called with f[n, x] returns -((-1 + x + x^2)*QPochhammer[-1, x, 1 + n]*... View answer 5 votes Define the function a[n_, k_] := SeriesCoefficient[ Sum[x^i, {i, 0, k}]^10, {x, 0, n}]; and you want a[3 k, k]. By the way, this is a$9$th degree polynomial function as given by ... View answer 5 votes A simple method uses a Rule[] to replace g'[t] with its value: ClearAll[x, g, dg]; dg[t_, 0] := g[t]; dg[t_, i_Integer /; i > 0] := D[dg[t, i - 1], t] /. g'[t] -> (t - x) g[t]; As a ... View answer Accepted answer 5 votes Try the code f[{a_, b_}] := {a^2, b^2}; f[c_Integer] := c^4; g[x: _Integer | {a_, b_}] := f@f@x; g /@ {2, {x, y}, 3.5} // InputForm which returns the result {65536, {x^4, y^4}, g[3.5]} which is ... View answer 5 votes The code \:22A0 will produce the Unicode character for BOX TIMES but the font used for output must support the Unicode character and not all of them do, otherwise an empty "Box" (or something similar) ... View answer 5 votes This is just a guess, but the problem seems to be that$\sqrt{x^2}\ne x$in general. The integral according to Mathematica had to choose a square root and it is wrong half of the time. More precisely, ... View answer 5 votes The simplest methods are usually the best. Try this code N[Cos[x] - Exp[-x 27/10] /. x -> 17*^-26, 15] // InputForm or a minor variation With[{x = 17*^-26}, N[Cos[x] - Exp[-x 27/10], 15]] // ... View answer Accepted answer 5 votes Thanks for asking! In version 9.0 only 16 solutions are returned and they are all valid. In version 10.2 there are 20 solutions, with the extra 4 all being invalid. Contragulations! I think you found ... View answer Accepted answer 5 votes Try the following code with an example: QP[a_, q_] := QPochhammer[a, q]; (* T[x, q] == Product[(1 - x q^k) (1 - q/x q^k), {k, 0, Infinity}] *) T[x_, q_] := QP[x, q] QP[q/x, q]; U[a_, x_, Q_] := With[{... View answer 4 votes You asked Any suggestions on an elegant, computational approach? It is not clear what you mean by that. Since this was a Putnam problem, the elegant approach would be to observe that$\,Q_n(x)=U_n(x/...

The FunctionPeriod function is fragile. For example, testing for four variants With[{f = Sin[a - x] Sin[x + a]}, FunctionPeriod[#, x] & /@ {f, f // Simplify, 2 f, 2 f // Simplify}] returns {2*Pi,...

The code binarytodecimal[b_String] := NumberForm[ToExpression["2^^"<>b], 20]; does what you want. For example binarytodecimal["0.0100101010101010101010"] evaluates to 0....

Usually the simplest methods tend to be the best. Try the code expr = ArcTan[x/y] - ArcTan[z/w]; StringReplace[ToString[expr, TeXForm], "\\tan ^{-1}" -> "\\arctan"] which returns \arctan\left(\...

(*" This code follows the Division Polynomial Wikipedia article "*) ClearAll[s, d, psi, phi, omega, P, x, y, X, Y, Z, A, B]; s = d = 0; d = d = 1; d = Y; d = Z; s[n_ /; n < 0] := -...

I suggest to modify your simple piece of code to make the output more informative. I define a function dim[] which is similar to the Dimensions[] function but is restricted to matrices and arrays. For ...

The following code: Simplify[expr, {f[a] > 0, f[b] > 0}] // InputForm returns (d*f[b])^(p1 - p2)*(f[a]*f[c])^(p1 + p2) which seems to be what you wanted. Assumptions in general are not ...

If I understand your question correctly, then the ** can be given a definition to do what you want. This code may work for you Unprotect[NonCommutativeMultiply]; ClearAll[NonCommutativeMultiply]; ...

dij[i_, j_] := If[i < j, 0, Mod[i - j, 2]] 4 i / If[j == 0, 2, 1]; d[n_] := Table[dij[i, j], {i, 0, n}, {j, 0, n}]; The function d[] returns a Mathematica matrix as a list of lists as you would ...

The following function returns a list of all the $n$th roots of unity in order. nth[n_] := Table[Exp[k 2 Pi I/n], {k, 0, n-1}]; You can do it with the more general code nth[n_] := Table[Root[#1^n - ...

Try the code poly = x^4 + a x^3 + b x^2 + a x + 1; soln = Solve[Discriminant[poly, x] == 0]; Print[soln // InputForm] Print[poly /. soln // Factor // InputForm] (* {{b -> -2 - 2*a}, {b -> -2 + 2*...