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

Code before:
        'fresnels': ':func:`~sympy.functions.special.error_functions.fresnels`',
        'fresnelc': ':func:`~sympy.functions.special.error_functions.fresnelc`',

        # Elliptic integrals
        'elliptic_k': ':func:`~sympy.functions.special.elliptic_integrals.elliptic_k`',
        'elliptic_e': ':func:`~sympy.functions.special.elliptic_integrals.elliptic_e`',

        # Elementary functions 
        # exponential
        '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)

Review comment (refactor):
The key 'rf' in FUNCTION_LINKS should be 'RisingFactorial' instead. When extracting function names using atom.func.__name__ on line 68, the name returned will be 'RisingFactorial' (the actual class name), not 'rf' (which is just an alias). This means formulas using rf will not have their function links added correctly.
```suggestion
        'RisingFactorial': ':func:`~sympy.functions.combinatorial.factorials.RisingFactorial`',
```

Code after:

        # Elliptic integrals
        'elliptic_k': ':func:`~sympy.functions.special.elliptic_integrals.elliptic_k`',
        'elliptic_e': ':func:`~sympy.functions.special.elliptic_integrals.elliptic_e`',

        # Elementary functions - exponential
        '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`',

        # 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("")