Tag Info

New answers tagged

4

If you have Version 10: rF = # /. Power[x_,y_]:>Inactive[Times]@@Table[x,{y}]&; (* or rF = # /. Power->(Inactive[Times]@@Table[#,{#2}]&)&; *) lst = {(a + b)^3, Ftp^2, Sin[th]^2}; rF@lst (* {(a+b)*(a+b)*(a+b),Ftp*Ftp,Sin[th]*Sin[th]} *) Or rF2 = Block[{Power=Inactive[Times]@@Table[#,{#2}]&},#]& rF2 @ lst (* ...


1

GetSubAndSuperscripts[expr_] := Cases[expr, Superscript[_, s__] | Subscript[_, s__] :> s, Infinity] Expr = (h*Superscript[u, g]*Superscript[Subscript[a, b, c], z])^Pi; GetSubAndSuperscripts[Expr] {g, b, c, z}


3

The solution depends on how you want a zero integer coefficient treated. list1 = {0 v, 3 a, 4 b, -2 c, 9 d}; Variables[list1] {a, b, c, d} list1 /. _Integer :> 1 {1, a, b, c, d} list1 /. x_Integer :> Unitize[x] {0, a, b, c, d}


4

You can use a pattern to just operate on the integers. For example, list1 /. _Integer -> 1 yields {a,b,c,d}. Not sure if it's as fast as you need it. Explanation: the underscore _ is an unnamed pattern and the attached Integer says that the pattern should only match things whose Head is Integer. You can use other heads after the _, of course, to ...


4

It looks like what you want is: list1 /. {_Integer -> 1}



Top 50 recent answers are included