printer_mathml.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:bce 作者: bce-toolkit 项目源码 文件源码
def _print_Function(self, e):
        """Print a Function object.

        :param e: The expression.
        :rtype : bce.dom.mathml.all.Base
        :return: The printed MathML object.
        """

        assert isinstance(e, _sympy.Function)

        #  Check the function.
        fn_object = _mexp_function.find_sympy_function(e.func.__name__)
        if fn_object is None:
            raise RuntimeError("Unsupported function: \"%s\"." % e.func.__name__)
        if fn_object.get_argument_count() != len(e.args):
            raise RuntimeError("Argument count mismatch.")

        #  Build the node.
        node = _mathml.RowComponent()
        node.append_object(_mathml.TextComponent(fn_object.get_function_name()))
        node.append_object(_mathml.OperatorComponent(_mathml.OPERATOR_LEFT_PARENTHESIS))
        for arg_id in range(0, len(e.args)):
            arg_value = e.args[arg_id]
            node.append_object(self.doprint(arg_value))
            if arg_id + 1 != len(e.args):
                node.append_object(_mathml.OperatorComponent(_mathml.OPERATOR_SEPARATOR))
        node.append_object(_mathml.OperatorComponent(_mathml.OPERATOR_RIGHT_PARENTHESIS))

        return node
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号