How this calculation works
Fold generators of a free-group subgroup into a based inverse automaton, decide membership and extract a free basis.
A reduced word w belongs to H exactly when it labels a closed based path in the folded core graph of H; rank(H)=E−V+1.A worked example
For H generated by ab and a in the free group on a,b, folding exposes a single based vertex with loops a and b. The subgroup is the whole rank2 free group, so query b belongs to H.
Good to know
Free rank1–4, at most12 subgroup generators and total reduced length at most300, query length at most300. Build bouquet loops, fold same-label outgoing edges, retain based core, then read query loops and a spanning-tree free basis. Exact word operations, finite graph cap. No relations in an ambient quotient group or arbitrary word-problem solver.
Subgroups of a free group are concrete
A free group has generators and their formal inverses, with cancellation of adjacent inverse pairs as its only defining relation. A finitely generated subgroup is specified by a finite list of words in those letters. The membership question asks whether a supplied word can be expressed using the subgroup generators and their inverses, not whether its letters happen to occur somewhere in the input.
Stallings folding turns that subgroup into a finite labeled graph whose based loops recognize exactly its reduced words. This is different from Fox differentiation, which produces group-ring derivatives, and from coset enumeration in a quotient given by additional relators. No extra ambient-group relations are introduced here. A word equal to identity is precisely one that freely reduces to the empty word.
Compare this with the Fox derivative calculator for free group words and presentation Jacobians. Construct a folded inverse automaton for a finitely generated subgroup of a free group, decide membership of supplied words, and extract a free subgroup basis. Fox differentiation computes group-ring derivatives; finite presented-group coset enumeration may not terminate and answers a different quotient-group problem.
Use a clear signed-letter convention
The input convention uses signed one-based integers for generators:1 means a,−1 means its inverse,2 means b, and so on. Word order is significant. Adjacent letters x and−x cancel, but letters cannot be commuted past each other. Generator words and the membership query are reduced before their graph interpretation is used.
Supply the ambient rank explicitly so a letter outside the allowed alphabet can be rejected. The total input length and folded-graph size are bounded. An empty word is legitimate and represents identity, which belongs to every subgroup. Empty or redundant subgroup generator words do not create independent generators, so their number alone does not determine subgroup rank.
Construct and fold the bouquet
Begin with one loop path for each subgroup generator, sharing a common base vertex. For every directed edge carrying a letter, include its reverse carrying the inverse letter. Whenever a vertex has two outgoing edges with the same label, identify their endpoints and merge those edges. Repeat until each label has at most one outgoing edge from each vertex.
These identifications are the folding operations. They preserve the subgroup recognized by closed based paths while removing nondeterministic duplication in the graph. The based core retains the part relevant to subgroup loops; it must preserve the distinguished basepoint correctly, including any based stem. Treating the graph as an unbased collection of cycles would lose the conjugation information carried by the chosen base.
Read membership as a path
Start at the base vertex and follow the reduced query one letter at a time. If a required labeled edge is missing, the query is not in the subgroup. If the entire word is readable, membership requires the path to return to the base vertex. Ending at some other vertex is not enough, even if the final vertex lies on a cycle.
This gives a finite certificate for either outcome. A positive query has a closed path spelling the word. A negative query has either a first missing transition or a final vertex different from the base. These checks use the fully folded graph, not an arbitrary finite prefix of an infinite search through products of subgroup generators.
Extract a free basis from a tree
Choose a spanning tree in the connected folded graph. For every non-tree edge, take the word along the tree from the base to the edge’s origin, then the edge label, then the inverse tree path from its endpoint back to the base. Freely reduce those words. One orientation of each inverse edge pair gives the corresponding basis generator.
The resulting words form a free basis for the represented subgroup. Count each inverse pair as one unoriented edge when applying rank E−V+1; otherwise the formula would double-count edges and overstate rank. Different spanning trees can yield different free bases with the same rank. The calculator returns a construction, not a unique canonical list of subgroup words.
Work through H generated by ab and a
The word ab initially gives a two-edge loop from the base, while a gives a one-edge loop. Folding the two outgoing a edges identifies the intermediate vertex with the base. The remaining b edge also becomes a loop. The folded graph therefore has one vertex and two independent labeled loops, one for a and one for b.
Its rank is2−1+1=2. Both ambient generators can be read as closed based paths, so this subgroup is the whole free group on a,b. In particular, the default query b is accepted. Algebraically, b=a⁻¹(ab), which is a short independent membership witness. The example shows why two original words can encode a simpler basis than their initial bouquet suggests.
Know what the finite graph proves
Every supplied subgroup generator should read as a based loop in the final graph. Extracted basis words must do the same, and independent folding or membership software can cross-check their generated subgroup. Inverse queries must agree on membership. For a finite-index subgroup, a complete covering has every generator label available at every vertex, providing an additional structural check.
The finite folded core is not the full infinite Cayley graph, nor does it solve word problems after arbitrary quotient relations are imposed. Resource limits bound input and graph construction; hitting one gives an unresolved result. Within the completed free-group construction, however, membership is exact and does not rely on sampling product words to a guessed maximum length.
A few questions, answered
Can a and b commute in the input?
No. The ambient group is free; only adjacent inverse-letter cancellation is permitted.
Does a readable word automatically belong?
Only if its path returns to the distinguished base vertex; readability ending elsewhere is insufficient.
Why can two runs return different bases?
Different spanning trees can produce different free bases of the same subgroup and rank.
Does this handle extra group relations?
No. Adding relators creates a quotient-group problem outside the stated Stallings free-group model.