Ejemplo n.º 1
0
    def analyze(self, expr):
        name = "f"

        self.analyzer = Analyzer(expr)
        self.function_view.set_from_expression(expr, name=name + "(x)")
        self.function_view.set_font_size(40)

        box = ListBox("Dominio")
        self.box.pack_start(box, False, False, 0)

        domain_block = EqualBlock(TextBlock("D(f)"), TextBlock(interval_to_string(self.analyzer.domain)))
        box.make_row_with_child(domain_block)

        box = ListBox("Raíces")
        self.box.pack_start(box, False, False, 0)

        roots_block = TextBlock(set_to_string(self.analyzer.roots.keys()))
        box.make_row_with_child(roots_block)

        box = ListBox("Signo")
        self.box.pack_start(box, False, False, 0)

        if self.analyzer.positive.__class__ != sympy.EmptySet:
            positive_block = TextBlock("+  " + interval_to_string(self.analyzer.positive))
            box.make_row_with_child(positive_block)

        if self.analyzer.negative.__class__ != sympy.EmptySet:
            negative_block = TextBlock("-  " + interval_to_string(self.analyzer.negative))
            box.make_row_with_child(negative_block)

        box = ListBox("Continuidad")
        self.box.pack_start(box, False, False, 0)

        if self.analyzer.continuity == self.analyzer.domain:
            block = TextBlock("f es continua en todo su dominio.")

        else:
            block = TextBlock("f es continua para los x %s %s\n" % (Chars.BELONGS, interval_to_string(self.analyzer.continuity)))

        box.make_row_with_child(block)

        box = ListBox("Ramas")
        self.box.pack_start(box, False, False, 0)

        if self.analyzer.branches[sympy.oo] is not None:
            block = TextBlock("f posee %s cuando" % Branch.get_name(*self.analyzer.branches[sympy.oo]))
            row = box.make_row_with_child(block)
            trend_block = TrendBlock(TextBlock("x"), TextBlock("+" + Chars.INFINITY))
            trend_block.set_margin_left(10)
            row.add_child(trend_block)

        if self.analyzer.branches[-sympy.oo] is not None:
            block = TextBlock("f posee %s cuando" % Branch.get_name(*self.analyzer.branches[-sympy.oo]))
            row = box.make_row_with_child(block)
            trend_block = TrendBlock(TextBlock("x"), TextBlock("-" + Chars.INFINITY))
            trend_block.set_margin_left(10)
            row.add_child(trend_block)

        box = ListBox("Crecimiento")
        self.box.pack_start(box, False, False, 0)

        block = MathView.new_from_expression(self.analyzer.derived, name + "'(x)")
        box.make_row_with_child(block)

        if self.analyzer.derived_things.negative.__class__ != sympy.EmptySet:
            block = TextBlock(name + " decrece en ")
            row = box.make_row_with_child(block)
            row.add_child(make_interval_points(self.analyzer.derived_things.negative))

        if self.analyzer.derived_things.positive.__class__ != sympy.EmptySet:
            block = TextBlock(name + " crece en ")
            row = box.make_row_with_child(block)
            row.add_child(make_interval_points(self.analyzer.derived_things.positive))

        mins, maxs = self.analyzer.get_minimums_and_maximums()

        if mins:
            block = TextBlock("Mínimos: ")
            row = box.make_row_with_child(block)

            for point in mins:
                _x = MathView.new_from_expression(point[0])
                _y = MathView.new_from_expression(point[1])
                block = PointBlock(_x, _y)
                row.add_child(block)

        if maxs:
            block = TextBlock("Máximos: ")
            row = box.make_row_with_child(block)

            for point in maxs:
                _x = MathView.new_from_expression(point[0])
                _y = MathView.new_from_expression(point[1])
                block = PointBlock(_x, _y)
                row.add_child(block)

        box = ListBox("Concavidad")
        self.box.pack_start(box, False, False, 0)

        block = MathView.new_from_expression(self.analyzer.derived2, name + "''(x)")
        box.make_row_with_child(block)

        if self.analyzer.derived2_things.positive.__class__ != sympy.EmptySet:
            block = TextBlock("f tiene concavidad positiva en: ")
            row = box.make_row_with_child(block)
            row.add_child(make_interval_points(self.analyzer.derived2_things.positive))

        if self.analyzer.derived2_things.negative.__class__ != sympy.EmptySet:
            block = TextBlock("f tiene concavidad negativa en: ")
            row = box.make_row_with_child(block)
            row.add_child(make_interval_points(self.analyzer.derived2_things.negative))

        _analyzer = Analyzer(self.analyzer.derived)
        mins, maxs = _analyzer.get_minimums_and_maximums()
        inflection_points = mins + maxs

        if inflection_points:
            block = TextBlock("Puntos de inflexión: ")
            row = box.make_row_with_child(block)

            for point in inflection_points:
                _x = MathView.new_from_expression(point[0])
                _y = MathView.new_from_expression(point[1])
                block = PointBlock(_x, _y)
                block.set_margin_right(10)
                row.add_child(block)

        self.show_all()