3
$\begingroup$

I have the following expression containing functions eg. Log, PolyLog etc,

expr=(4 (12 (-1 + x^2) + \[Pi]^2 (1 + x^2)))/(3 (1 + x)) -
     ( 4 (1 + x^2) Log[x]^2)/(1 + x) + Log[x] (-8 (1 + x) +
     (16 (1 + x^2) Log[1 + x])/(1 + x)) + (16 (1 + x^2) PolyLog[2, -x])/(1 + x) +
     x Log[x] PolyLog[2, -x]^2;

I want to list all these functions (Log, PolyLog) in this expression. But I similarly want them as they appear (say a basis constructed out of these functions and their powers). In this example, the expected list will look as follows,

{Log[x]^2,Log[x],Log[1 + x]*Log[x],PolyLog[2, -x],Log[x] PolyLog[2, -x]^2}

With Cases I get only the distinct functions ( and their Powers ) but not multiplication,

Join[Cases[expr, _Log^_., -1], Cases[expr, _PolyLog^_., -1]] // Flatten // Union

{Log[x], Log[x]^2, Log[1 + x], PolyLog[2, -x], PolyLog[2, -x]^2}

Any suggestions? (I believe it could be done with Cases or SequenceCases but eg. Cases[expr, _Log^_.*_PolyLog^_., -1] does not work)

$\endgroup$

1 Answer 1

4
$\begingroup$

You can use the power of *Coefficient* functions in Mathematica, but you have to temporarily convert all your functions into "pure" symbols so that they are recognized as variables.

basisFunctions[expr_, funs_] := Module[{fs, map},
  fs = DeleteDuplicates@Cases[expr, Alternatives @@ (Blank /@ funs), All];
  map = (# -> Unique[f]) & /@ fs;
  MonomialList @ 
   FromCoefficientRules[
    CoefficientRules[expr /. map, 
      fs /. map] /. ((r_ -> _) :> (r -> 1)), fs]
  ]

basisFunctions[expr, {Log, PolyLog}]
(* {Log[x]^2, Log[x] Log[1 + x], Log[x] PolyLog[2, -x]^2, Log[x], PolyLog[2, -x], 1} *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.