Given a group and its finite presentation $G=\langle A\mid R\rangle$, I want the following algorithm:
Input: a finite set $W$ of words in $A\cup A^{-1}$ that generates a finitely presentable subgroup in $G$,
Output: a finite presentation of the subgroup generated by $W$.
I observed that the existence of such an algorithm solves the word problem in $G$, since one can input $W=\{w\}$, and by checking if the output is trivial or isomorphic to a non-trivial cyclic group, they know whether $w$ represents the identity element in $G$.
So if $G$ has solvable word problem, does such an algorithm exists? Specifically I'm working on $G$ being a Right-Angled Artin Group or a Mapping Class Group, so an answer for any of these two classes of groups will be helpful. Thanks!