+2  A: 

Using Sympy, a python symbolic maths package.

You will need to read the documentation if you want to expand on what I have written. Your question is difficult to understand, so this is the best I can do.

import sympy

a, b, c, d, f = sympy.symbols('abcdf')
g = sympy.Symbol('g')
m, n, o, p, q = sympy.symbols('mnopq')

eq1 = a**g**n + b**g**o + c**g**p + d**g**q

def s1(k, eqn):
    """This is a helper function to simplify 's'."""
    var1, exp1 = eqn.args
    var2, exp2 = exp1.args
    if var2 == g:
        return var1**var2**(exp2 + k)
    return eqn

def s(k, eqn):
    return sum(s1(k, part) for part in eqn.args)

print eq1 + a**g**f
print s(m, eq1) + a**g**f
PreludeAndFugue
A: 

Simplifying assumptions: All variables are a single lower-case letter. All operators are binary and are represented by a single non-letter. There are no constants.

  1. Parse the expression into a tree.

  2. Walk over the tree (depth first). Ignore any g at the "top level" ("in parentheses" requirement needs clarification). For each 'g' that's the left operand of '^', insert nodes to change g ^ right_operand to g ^ (right_operand + m). For each other g, replace it by nodes equivalent to g ^ m.

  3. Decompile the tree to a string.

John Machin