Question: is it possible to capture output of dismantle() (so I can convert it to string) ?

Is it possible to capture and convert the output of dismantle to one (long) string?

For example, if I do

r:=dismantle(x+sin(x));

SUM(5)
   NAME(4): x
   INTPOS(2): 1
   FUNCTION(3)
      NAME(4): sin #[protected, _syslib]
      EXPSEQ(2)
         NAME(4): x
   INTPOS(2): 1

I'd like to first capture the output in "r", which now it does not, it just goes to screen and "r" is left empty, and then convert the result to long string. (using convert()) So the result of the above will becomes

r:="SUM(5) NAME(4): x INTPOS(2): 1 FUNCTION(3) NAME(4): sin #[protected, _syslib]..."

The reason I need to capture the output, is so I can more easily look for some specific name/content inside the expression. which is now in a string, using string tools later on, which I think will be easier. For example, if I want to look for "sin" I can now search the above string and see if "sin" is there. Context is not important, just need to see if a name happens to be in the string.  The problem I do not know how to convert output of dismantle to string.

Maple 2016.2 on windows

 

Please Wait...