当前位置: 首页>>代码示例>>Python>>正文


Python Expression.has_form方法代码示例

本文整理汇总了Python中mathics.core.expression.Expression.has_form方法的典型用法代码示例。如果您正苦于以下问题:Python Expression.has_form方法的具体用法?Python Expression.has_form怎么用?Python Expression.has_form使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mathics.core.expression.Expression的用法示例。


在下文中一共展示了Expression.has_form方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_msg_list

# 需要导入模块: from mathics.core.expression import Expression [as 别名]
# 或者: from mathics.core.expression.Expression import has_form [as 别名]
 def get_msg_list(expr):
     if expr.has_form('MessageName', 2):
         expr = Expression('List', expr)
     if expr.get_name() == 'All':
         all = True
         messages = []
     elif expr.get_name() == 'None':
         all = False
         messages = []
     elif expr.has_form('List', None):
         all = False
         messages = []
         for item in expr.leaves:
             if item.has_form('MessageName', 2):
                 symbol = item.leaves[0].get_name()
                 tag = item.leaves[1].get_string_value()
                 if symbol and tag:
                     messages.append((symbol, tag))
                 else:
                     raise ValueError
             else:
                 raise ValueError
     else:
         raise ValueError
     return all, messages
开发者ID:KarlHeitmann,项目名称:Mathics,代码行数:27,代码来源:inout.py

示例2: apply

# 需要导入模块: from mathics.core.expression import Expression [as 别名]
# 或者: from mathics.core.expression.Expression import has_form [as 别名]
 def apply(self, f, x, xstart, xstop, y, ystart, ystop, evaluation, options):
     'DensityPlot[f_, {x_Symbol, xstart_, xstop_}, {y_Symbol, ystart_, ystop_}, OptionsPattern[DensityPlot]]'
     
     x = x.get_name()
     y = y.get_name()
     
     color_function = self.get_option(options, 'ColorFunction', evaluation, pop=True)
     color_function_scaling = self.get_option(options, 'ColorFunctionScaling', evaluation, pop=True)
     
     color_function_min = color_function_max = None
     if color_function.get_name() == 'Automatic':
         color_function = String('LakeColors')
     if color_function.get_string_value():
         func = Expression('ColorData', color_function.get_string_value()).evaluate(evaluation)
         if func.has_form('ColorDataFunction', 4):
             color_function_min = func.leaves[2].leaves[0].get_real_value()
             color_function_max = func.leaves[2].leaves[1].get_real_value()
             color_function = Expression('Function', Expression(func.leaves[3], Expression('Slot', 1)))
         else:
             evaluation.message('DensityPlot', 'color', func)
             return
     if color_function.has_form('ColorDataFunction', 4):
         color_function_min = color_function.leaves[2].leaves[0].get_real_value()
         color_function_max = color_function.leaves[2].leaves[1].get_real_value()
         
     color_function_scaling = color_function_scaling.is_true()
         
     try:
         xstart, xstop, ystart, ystop = [value.to_number(n_evaluation=evaluation) for value in
             (xstart, xstop, ystart, ystop)]
     except NumberError, exc:
         expr = Expression('DensityPlot', f, Expression('List', x, xstart, xstop),
             Expression('List', y, ystart, ystop), *options_to_rules(options))
         evaluation.message('DensityPlot', 'plln', exc.value, expr)
         return
开发者ID:cjiang,项目名称:Mathics,代码行数:37,代码来源:plot.py

示例3: post_parse

# 需要导入模块: from mathics.core.expression import Expression [as 别名]
# 或者: from mathics.core.expression.Expression import has_form [as 别名]
 def post_parse(self, expression):
     leaves = [leaf.post_parse() for leaf in expression.leaves]
     expression = Expression(expression.head.post_parse(), *leaves)
     if expression.has_form('Optional', 2) and expression.leaves[0].get_name():
         sub = expression.leaves[1]
         if sub.has_form(('Pattern', 'Optional'), 2):
             return Expression('Optional', Expression('Pattern', expression.leaves[0], sub.leaves[0]), sub.leaves[1])
         else:
             return Expression('Pattern', *[leaf.post_parse() for leaf in expression.leaves])
     else:
         return expression
开发者ID:cjiang,项目名称:Mathics,代码行数:13,代码来源:patterns.py

示例4: construct_graphics

# 需要导入模块: from mathics.core.expression import Expression [as 别名]
# 或者: from mathics.core.expression.Expression import has_form [as 别名]
    def construct_graphics(self, triangles, mesh_points, v_min, v_max,
                           options, evaluation):
        mesh_option = self.get_option(options, 'Mesh', evaluation)
        mesh = mesh_option.to_python()

        color_function = self.get_option(
            options, 'ColorFunction', evaluation, pop=True)
        color_function_scaling = self.get_option(
            options, 'ColorFunctionScaling', evaluation, pop=True)

        color_function_min = color_function_max = None
        if color_function.get_name() == 'Automatic':
            color_function = String('LakeColors')
        if color_function.get_string_value():
            func = Expression(
                'ColorData',
                color_function.get_string_value()).evaluate(evaluation)
            if func.has_form('ColorDataFunction', 4):
                color_function_min = func.leaves[2].leaves[0].get_real_value()
                color_function_max = func.leaves[2].leaves[1].get_real_value()
                color_function = Expression('Function', Expression(
                    func.leaves[3], Expression('Slot', 1)))
            else:
                evaluation.message('DensityPlot', 'color', func)
                return
        if color_function.has_form('ColorDataFunction', 4):
            color_function_min = \
                color_function.leaves[2].leaves[0].get_real_value()
            color_function_max = \
                color_function.leaves[2].leaves[1].get_real_value()

        color_function_scaling = color_function_scaling.is_true()
        v_range = v_max - v_min

        if v_range == 0:
            v_range = 1

        if color_function.has_form('ColorDataFunction', 4):
            color_func = color_function.leaves[3]
        else:
            color_func = color_function
        if (color_function_scaling and      # noqa
            color_function_min is not None and
            color_function_max is not None):
            color_function_range = color_function_max - color_function_min

        colors = {}

        def eval_color(x, y, v):
            v_scaled = (v - v_min) / v_range
            if (color_function_scaling and      # noqa
                color_function_min is not None and
                color_function_max is not None):
                v_color_scaled = color_function_min + \
                    v_scaled * color_function_range
            else:
                v_color_scaled = v

            # Calculate and store 100 different shades max.
            v_lookup = int(v_scaled * 100 + 0.5)

            value = colors.get(v_lookup)
            if value is None:
                value = Expression(color_func, Real(v_color_scaled))
                value = value.evaluate(evaluation)
                colors[v_lookup] = value
            return value

        points = []
        vertex_colors = []
        graphics = []
        for p in triangles:
            points.append(
                Expression('List', *(Expression('List', *x[:2]) for x in p)))
            vertex_colors.append(
                Expression('List', *(eval_color(*x) for x in p)))

        graphics.append(Expression(
            'Polygon', Expression('List', *points),
            Expression('Rule', Symbol('VertexColors'),
                       Expression('List', *vertex_colors))))

        if mesh == 'Full':
            for xi in range(len(mesh_points)):
                line = []
                for yi in range(len(mesh_points[xi])):
                    line.append(Expression('List', mesh_points[xi][yi][0],
                                mesh_points[xi][yi][1]))
                graphics.append(Expression('Line', Expression('List', *line)))
        elif mesh == 'All':
            for p in triangles:
                graphics.append(Expression(
                    'Line',
                    Expression('List', *(from_python(x[:2]) for x in p))))
        return graphics
开发者ID:jake100,项目名称:Mathics,代码行数:97,代码来源:plot.py

示例5: construct_graphics

# 需要导入模块: from mathics.core.expression import Expression [as 别名]
# 或者: from mathics.core.expression.Expression import has_form [as 别名]
    def construct_graphics(self, triangles, mesh_points, v_min, v_max, options, evaluation):
        mesh_option = self.get_option(options, "Mesh", evaluation)
        mesh = mesh_option.to_python()

        color_function = self.get_option(options, "ColorFunction", evaluation, pop=True)
        color_function_scaling = self.get_option(options, "ColorFunctionScaling", evaluation, pop=True)

        color_function_min = color_function_max = None
        if color_function.get_name() == "Automatic":
            color_function = String("LakeColors")
        if color_function.get_string_value():
            func = Expression("ColorData", color_function.get_string_value()).evaluate(evaluation)
            if func.has_form("ColorDataFunction", 4):
                color_function_min = func.leaves[2].leaves[0].get_real_value()
                color_function_max = func.leaves[2].leaves[1].get_real_value()
                color_function = Expression("Function", Expression(func.leaves[3], Expression("Slot", 1)))
            else:
                evaluation.message("DensityPlot", "color", func)
                return
        if color_function.has_form("ColorDataFunction", 4):
            color_function_min = color_function.leaves[2].leaves[0].get_real_value()
            color_function_max = color_function.leaves[2].leaves[1].get_real_value()

        color_function_scaling = color_function_scaling.is_true()
        v_range = v_max - v_min

        if v_range == 0:
            v_range = 1

        if color_function.has_form("ColorDataFunction", 4):
            color_func = color_function.leaves[3]
        else:
            color_func = color_function
        if color_function_scaling and color_function_min is not None and color_function_max is not None:
            color_function_range = color_function_max - color_function_min

        colors = {}

        def eval_color(x, y, v):
            v_scaled = (v - v_min) / v_range
            if color_function_scaling and color_function_min is not None and color_function_max is not None:
                v_color_scaled = color_function_min + v_scaled * color_function_range
            else:
                v_color_scaled = v
            v_lookup = int(v_scaled * 100 + 0.5)  # calculate and store 100 different shades max.
            value = colors.get(v_lookup)
            if value is None:
                value = Expression(color_func, Real(v_color_scaled))
                value = value.evaluate(evaluation)
                colors[v_lookup] = value
            return value

        points = []
        vertex_colors = []
        graphics = []
        for p1, p2, p3 in triangles:
            c1, c2, c3 = eval_color(*p1), eval_color(*p2), eval_color(*p3)
            points.append(
                Expression(
                    "List", Expression("List", *p1[:2]), Expression("List", *p2[:2]), Expression("List", *p3[:2])
                )
            )
            vertex_colors.append(Expression("List", c1, c2, c3))

        graphics.append(
            Expression(
                "Polygon",
                Expression("List", *points),
                Expression("Rule", Symbol("VertexColors"), Expression("List", *vertex_colors)),
            )
        )

        if mesh == "Full":
            for xi in range(len(mesh_points)):
                line = []
                for yi in range(len(mesh_points[xi])):
                    line.append(Expression("List", mesh_points[xi][yi][0], mesh_points[xi][yi][1]))
                graphics.append(Expression("Line", Expression("List", *line)))
        elif mesh == "All":
            for p1, p2, p3 in triangles:
                line = [from_python(p1[:2]), from_python(p2[:2]), from_python(p3[:2])]
                graphics.append(Expression("Line", Expression("List", *line)))
        return graphics
开发者ID:rnestler,项目名称:Mathics,代码行数:85,代码来源:plot.py


注:本文中的mathics.core.expression.Expression.has_form方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。