Repository: sympy/sympy
File: sympy/simplify/hyperexpand_doc.py (Python)

Code before:
        'exp': ':func:`~sympy.functions.elementary.exponential.exp`',
        'log': ':func:`~sympy.functions.elementary.exponential.log`',

        # miscellaneous
        'sqrt': ':func:`~sympy.functions.elementary.miscellaneous.sqrt`',
        'root': ':func:`~sympy.functions.elementary.miscellaneous.root`',

        # trignometric 
        'cos': ':func:`~sympy.functions.elementary.trigonometric.cos`',
        'sin': ':func:`~sympy.functions.elementary.trigonometric.sin`',

        # hyperbolic
        'cosh': ':func:`~sympy.functions.elementary.hyperbolic.cosh`',
        'sinh': ':func:`~sympy.functions.elementary.hyperbolic.sinh`',

        # Combinatorial functions
        'rf': ':func:`~sympy.functions.combinatorial.factorials.RisingFactorial`',
        'factorial': ':func:`~sympy.functions.combinatorial.factorials.factorial`',

        # Other special functions
        'lerchphi': ':func:`~sympy.functions.special.zeta_functions.lerchphi`',

    }

    def get_special_functions_used(expr):
        '''Extract special function names from an expression'''
        func_names = set()
        for atom in expr.atoms(Function):
            if not isinstance(atom, AppliedUndef):
                func_name = atom.func.__name__
                if func_name in FUNCTION_LINKS:
                    func_names.add(func_name)
        return sorted(func_names)

    c = FormulaCollection()

    doc = ""

    for f in c.formulae:
        obj = Eq(hyper(f.func.ap, f.func.bq, f.z),
                f.closed_form.rewrite('nonrepsmall'))
        doc += ".. math::\n  %s\n" % latex(obj)

        # Add links to special functions used
        special_funcs = get_special_functions_used(f.closed_form)
        if special_funcs:
            doc += "\n"
            if len(special_funcs) == 1:
                doc += "This formula uses %s.\n" % FUNCTION_LINKS[special_funcs[0]]
            else:
                func_links = ', '.join(FUNCTION_LINKS[fn] for fn in special_funcs[:-1])

Review comment (refactor):
The docstring uses three single quotes instead of three double quotes, which is inconsistent with Python's PEP 257 style guide that recommends using triple double-quotes for docstrings.
```suggestion
        """Extract special function names from an expression"""
```

Code after:
        # miscellaneous
        'sqrt': ':func:`~sympy.functions.elementary.miscellaneous.sqrt`',
        'root': ':func:`~sympy.functions.elementary.miscellaneous.root`',

        # trigonometric
        'cos': ':func:`~sympy.functions.elementary.trigonometric.cos`',
        'sin': ':func:`~sympy.functions.elementary.trigonometric.sin`',

        # hyperbolic
        'cosh': ':func:`~sympy.functions.elementary.hyperbolic.cosh`',
        'sinh': ':func:`~sympy.functions.elementary.hyperbolic.sinh`',

        # Combinatorial functions
        'RisingFactorial': ':func:`~sympy.functions.combinatorial.factorials.RisingFactorial`',
        'factorial': ':func:`~sympy.functions.combinatorial.factorials.factorial`',

        # Other special functions
        'lerchphi': ':func:`~sympy.functions.special.zeta_functions.lerchphi`',

    }

    def get_special_functions_used(expr):
        """Extract special function names from an expression."""
        func_names = set()
        for atom in expr.atoms(Function):
            if not isinstance(atom, AppliedUndef):
                func_name = atom.func.__name__
                if func_name in FUNCTION_LINKS:
                    func_names.add(func_name)
        return sorted(func_names)

    c = FormulaCollection()

    lines = []

    for f in c.formulae:
        obj = Eq(hyper(f.func.ap, f.func.bq, f.z),
                f.closed_form.rewrite('nonrepsmall'))
        lines.append(".. math::")
        lines.append("")
        lines.append("    %s" % latex(obj))
        lines.append("")
        # Add links to special functions used
        special_funcs = get_special_functions_used(f.closed_form)
        if special_funcs:
            lines.append("")
            n = len(special_funcs)
            if n == 1:
                lines.append("This formula involves %s." % FUNCTION_LINKS[special_funcs[0]])
            elif n == 2:
                lines.append("This formula involves %s and %s." % (