Example #1
0
def test_f6_simplification_line():
    """Is this Fraction's simplification line correct?"""
    assert Fraction(('+',
                     Product([Item(10), Item(5)]),
                     Product([Item(5), Item(9)])))\
        .simplification_line().printed == \
        wrap_nb('\\frac{10\\times \\bcancel{5}}{\\bcancel{5}\\times 9}')
Example #2
0
def test_product_sum_2_3x_times_sum_minus4_6x_is_not_reducible():
    """Is this Product not reducible?"""
    p = Product([
        Sum([Item(2), Monomial(('+', 3, 1))]),
        Sum([Item(-4), Monomial(('+', 6, 1))])
    ])
    assert not p.is_reducible()
Example #3
0
def test_eq15_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Item(1), Item(2)), number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[1=2\]'
                                           'This equation has no solution.'
                                           '\\newline ')
Example #4
0
def test_product_9_times_minus2_times_7ab_printed():
    """Is this Product correctly printed?"""
    assert Product([Item(9),
                    Product([Item(-2),
                             Item(7),
                             Item('a'),
                             Item('b')])])\
        .printed == wrap_nb('9\\times (-2)\\times 7ab')
def fig0b():
    fig0b = InterceptTheoremConfiguration(sketch=False,
                                          rotate_around_isobarycenter=40)
    fig0b.set_lengths([6, 12, 9], Fraction((Item(4), Item(3))))
    fig0b.setup_labels(['?', True, False, True, True, True, False, False],
                       segments_list=[fig0b.u, fig0b.side[1], fig0b.v] +
                       fig0b.small + fig0b.chunk)
    return fig0b
Example #6
0
def test_f5_simplification_line():
    """Is this Fraction's simplification line correct?"""
    assert Fraction(('+',
                     Product([Item(8), Item(3)]),
                     Product([Item(5), Item(6)])))\
        .simplification_line().printed == \
        wrap_nb('\\frac{\\bcancel{2}\\times 4\\times \\bcancel{3}}{5\\times'
                ' \\bcancel{2}\\times \\bcancel{3}}')
Example #7
0
def test_f3_simplification_line():
    """Is this Fraction's simplification line correct?"""
    assert Fraction(('+',
                     Product([Item(7), Item(6)]),
                     Product([Item(3), Item(3)])))\
        .simplification_line().printed == \
        wrap_nb('\\frac{7\\times \\bcancel{3}\\times 2}'
                '{\\bcancel{3}\\times 3}')
def test_cpeq1_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = CrossProductEquation((Item(6), Item(1.4), Item(1.5), Item("AB")))
    assert eq.auto_resolution(dont_display_equations_name=True,
                              skip_fraction_simplification=True,
                              decimal_result=2) == \
        wrap_nb('\[\\frac{6}{1.5}=\\frac{1.4}{\\text{AB}}\]'
                '\[\\text{AB}=\\frac{1.4\\times 1.5}{6}\]'
                '\[\\text{AB}=0.35\]')
Example #9
0
def test_eq25_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Item(
        ('+', 5, 2)), Sum([Item(
            ('+', 4, 2)), Monomial(('+', 1, 1))])),
                  number=1)
    assert eq.auto_resolution(dont_display_equations_name=True) == \
        wrap_nb('\[5^{2}=4^{2}+x\]'
                '\[25=16+x\]'
                '\[x=25-16\]'
                '\[x=9\]')
Example #10
0
def test_eq37_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Monomial((Fraction(
        (Item(2), Item(3))), 1)), Fraction((Item(4), Item(5)))))
    assert eq.auto_resolution(dont_display_equations_name=True) == \
        wrap_nb('\[\\frac{2}{3}x=\\frac{4}{5}\]'
                '\[x=\\frac{4}{5}\div \\frac{2}{3}\]'
                '\[x=\\frac{4}{5}\\times \\frac{3}{2}\]'
                '\[x=\\frac{4\\times 3}{5\\times 2}\]'
                '\[x=\\frac{\\bcancel{2}\\times 2\\times 3}'
                '{5\\times \\bcancel{2}}\]'
                '\[x=\\frac{6}{5}\]')
Example #11
0
def big_product():
    s = Sum(['x', 3])
    s.set_exponent(3)
    p = Product(Monomial((1, 2)))
    p.set_exponent(3)
    p1 = Product([2, 3])
    p1.set_exponent(3)
    return Product([
        Monomial((2, 1)),
        Monomial((-4, 2)), s,
        Item(5), p,
        Item(('+', -1, 2)), p1
    ])
Example #12
0
def complicated_sum_to_reduce():
    return Sum([
        Monomial(('+', 3, 1)),
        Item(4),
        Sum([
            Monomial(('+', 3, 1)),
            Monomial(('+', 5, 2)),
            Product([Item(-7), Item('a'), Item('b')])
        ]),
        Product([Item('-a'), Item('b')]),
        Monomial(('+', 5, 2)),
        Item(2),
        Monomial(('-', 2, 1)),
        Product([Item(2), Item('a'), Item('b')])
    ])
Example #13
0
def test_eq32_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Monomial(('+', 1, 1)), SquareRoot(Item(16))))
    assert eq.auto_resolution(dont_display_equations_name=True,
                              decimal_result=2) == \
        wrap_nb('\[x=\\sqrt{\mathstrut 16}\]'
                '\[x=4\]')
Example #14
0
def test_eq29_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation(
        (Monomial(('+', 1, 1)),
         Sum([Fraction((Item(1), Item(4))),
              Fraction((Item(1), Item(8)))])),
        number=1)
    assert eq.auto_resolution(decimal_result=2) == \
        wrap_nb('$(\\text{E}_{1}): $'
                '\[x=\\frac{1}{4}+\\frac{1}{8}\]'
                '\[x=\\frac{1\\times 2}{4\\times 2}'
                '+\\frac{1}{8}\]'
                '\[x=\\frac{2}{8}+\\frac{1}{8}\]'
                '\[x=\\frac{2+1}{8}\]'
                '\[x=\\frac{3}{8}\]'
                '\[x\\simeq0.38\]')
Example #15
0
def test_eq28_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Monomial(('+', 8, 1)), Item(6)), number=1)
    assert eq.auto_resolution(decimal_result=2) == \
        wrap_nb('$(\\text{E}_{1}): $'
                '\[8x=6\]'
                '\[x=\\frac{6}{8}\]'
                '\[x=0.75\]')
Example #16
0
def test_eq23_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation(
        (Item(5),
         Sum([
             Expandable(
                 (Item(1), Sum([Monomial(('+', 1, 1)),
                                Monomial(('-', 2, 0))]))),
             Item(7)
         ])),
        number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[5=(x-2)+7\]'
                                           '\[5=x-2+7\]'
                                           '\[5=x+5\]'
                                           '\[x=5-5\]'
                                           '\[x=0\]')
Example #17
0
def test_eq27_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Monomial(('+', 3, 1)), Item(1)), number=1)
    assert eq.auto_resolution(decimal_result=2) == \
        wrap_nb('$(\\text{E}_{1}): $'
                '\[3x=1\]'
                '\[x=\\frac{1}{3}\]'
                '\[x\\simeq0.33\]')
Example #18
0
def test_eq5_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Monomial(('+', 12, 1)), Item(8)), number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[12x=8\]'
                                           '\[x=\\frac{8}{12}\]'
                                           '\[x=\\frac{\\bcancel{4}\\times 2}'
                                           '{\\bcancel{4}\\times 3}\]'
                                           '\[x=\\frac{2}{3}\]')
Example #19
0
def test_eq0_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Polynomial([Monomial(
        ('+', 1, 1)), Monomial(('+', 7, 0))]), Item(3)),
                  number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[x+7=3\]'
                                           '\[x=3-7\]'
                                           '\[x=-4\]')
Example #20
0
def test_eq1_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Polynomial([Monomial(
        ('-', 8, 0)), Monomial(('+', 1, 1))]), Item(-2)),
                  number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[-8+x=-2\]'
                                           '\[x=-2+8\]'
                                           '\[x=6\]')
Example #21
0
def test_eq36_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Item(
        ('+', "EF", 2)), Sum([Item(
            ('+', 60, 2)), Item(('+', 91, 2))])),
                  number=1,
                  variable_letter_name="AB")
    assert eq.auto_resolution(dont_display_equations_name=True,
                              pythagorean_mode=True,
                              unit='cm') == \
        wrap_nb('\[\\text{EF}^{2}=60^{2}+91^{2}\]'
                '\[\\text{EF}^{2}=3600+8281\]'
                '\[\\text{EF}^{2}=11881\]'
                '\[\\text{EF}='
                '\\sqrt{\mathstrut 11881}'
                '\\text{ because \\text{EF} '
                'is positive.}\]'
                '\[\\text{EF}=109\\text{ cm}\]')
Example #22
0
def test_fractions_by_items_01_next_step():
    """Is this Product's calculation's next step correct?"""
    p = Product([
        Fraction((Item(3), Item(5))),
        Item(8),
        Fraction((Item(7), Item(11))),
        Item(4),
        Fraction((Item(13), Item(17)))
    ])
    assert p.calculate_next_step().printed == \
        wrap_nb('\\frac{3\\times 8\\times 7\\times 4\\times 13}{5\\times 11'
                '\\times 17}')
Example #23
0
def test_eq12_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Polynomial([Monomial(
        ('+', 2, 1)), Monomial(('+', 1, 0))]), Item(1)),
                  number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[2x+1=1\]'
                                           '\[2x=1-1\]'
                                           '\[2x=0\]'
                                           '\[x=0\]')
Example #24
0
def test_eq35_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Item(
        ('+', 73, 2)), Sum([Item(
            ('+', 48, 2)), Item(('+', "AB", 2))])),
                  number=1,
                  variable_letter_name="AB")
    assert eq.auto_resolution(dont_display_equations_name=True,
                              decimal_result=2,
                              pythagorean_mode=True) == \
        wrap_nb('\[73^{2}=48^{2}+\\text{AB}^{2}\]'
                '\[5329=2304+\\text{AB}^{2}\]'
                '\[\\text{AB}^{2}=5329-2304\]'
                '\[\\text{AB}^{2}=3025\]'
                '\[\\text{AB}='
                '\\sqrt{\mathstrut 3025}'
                '\\text{ because \\text{AB} '
                'is positive.}\]'
                '\[\\text{AB}=55\]')
Example #25
0
def test_eq6_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Polynomial([Monomial(
        ('+', 2, 1)), Monomial(('+', 3, 0))]), Item(8)),
                  number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[2x+3=8\]'
                                           '\[2x=8-3\]'
                                           '\[2x=5\]'
                                           '\[x=\\frac{5}{2}\]')
Example #26
0
def test_eq2_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation(
        (Item(-5), Polynomial([Monomial(
            ('+', 1, 1)), Monomial(('+', 3, 0))])),
        number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[-5=x+3\]'
                                           '\[x=-5-3\]'
                                           '\[x=-8\]')
Example #27
0
def test_eq17_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation(
        (Expandable((Item(-1), Sum([Monomial(
            (-11, 1)), Item(-10)]))),
         Sum([
             Expandable((Item(1), Sum([Item(-15), Monomial((12, 1))]))),
             Item(-1)
         ])),
        number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[-(-11x-10)=(-15+12x)-1\]'
                                           '\[11x+10=-15+12x-1\]'
                                           '\[11x+10=-15-1+12x\]'
                                           '\[11x+10=-16+12x\]'
                                           '\[11x-12x=-16-10\]'
                                           '\[(11-12)x=-26\]'
                                           '\[-x=-26\]'
                                           '\[x=26\]')
Example #28
0
def test_eq18_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Sum([
        Monomial(('-', 8, 0)),
        Monomial(('+', 9, 0)),
        Monomial(('-', 1, 0))
    ]), Expandable((Item(10), Sum([Item(-2), Monomial((-12, 1))])))),
                  number=1)
    assert eq.auto_resolution() == \
        wrap_nb('$(\\text{E}_{1}): $'
                '\[-8+9-1=10(-2-12x)\]'
                '\[0=10\\times (-2)+10\\times (-12x)\]'
                '\[0=-20-120x\]'
                '\[120x=-20\]'
                '\[x=-\\frac{20}{120}\]'
                '\[x=-\\frac{\\bcancel{10}\\times'
                ' 2}{\\bcancel{10}\\times 12}\]'
                '\[x=-\\frac{\\bcancel{2}}'
                '{\\bcancel{2}\\times 6}\]'
                '\[x=-\\frac{1}{6}\]')
Example #29
0
    def __init__(self, numbers_to_use, **options):
        nb_list = list(numbers_to_use)
        hole = Item(Value('...'))
        self.hidden_one = None
        visible_one = None
        self.product = Item(Product([nb_list[0], nb_list[1]]).evaluate())

        if isinstance(nb_list[1], Fraction):
            self.hidden_one = nb_list[1]
            visible_one = nb_list[0]
        else:
            nb1 = randomly.pop(nb_list)
            nb2 = randomly.pop(nb_list)
            nb_list = [nb1, nb2]
            self.hidden_one = Item(randomly.pop(nb_list))
            visible_one = randomly.pop(nb_list)

        factors = [visible_one, hole]
        self.holed_product = Product([randomly.pop(factors),
                                      randomly.pop(factors)])
        self.holed_product.set_compact_display(False)
Example #30
0
def test_eq22_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Sum([
        Expandable(
            (Item(3), Sum([Monomial(
                ('-', 9, 0)), Monomial(('+', 6, 1))]))),
        Item(-8)
    ]), Sum([Item(9)])),
                  number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[3(-9+6x)-8=9\]'
                                           '\[3\\times (-9)+3\\times 6x-8=9\]'
                                           '\[-27+18x-8=9\]'
                                           '\[-27-8+18x=9\]'
                                           '\[-35+18x=9\]'
                                           '\[18x=9+35\]'
                                           '\[18x=44\]'
                                           '\[x=\\frac{44}{18}\]'
                                           '\[x=\\frac{\\bcancel{2}\\times 22}'
                                           '{\\bcancel{2}\\times 9}\]'
                                           '\[x=\\frac{22}{9}\]')