mathmaker
0.6(alpha)
|
00001 # -*- coding: utf-8 -*- 00002 00003 # Mathmaker creates automatically maths exercises sheets 00004 # with their answers 00005 # Copyright 2006-2014 Nicolas Hainaux <nico_h@users.sourceforge.net> 00006 00007 # This file is part of Mathmaker. 00008 00009 # Mathmaker is free software; you can redistribute it and/or modify 00010 # it under the terms of the GNU General Public License as published by 00011 # the Free Software Foundation; either version 3 of the License, or 00012 # any later version. 00013 00014 # Mathmaker is distributed in the hope that it will be useful, 00015 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 # GNU General Public License for more details. 00018 00019 # You should have received a copy of the GNU General Public License 00020 # along with Mathmaker; if not, write to the Free Software 00021 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00022 00023 import os 00024 import sys 00025 00026 from core import * 00027 from core.base_calculus import * 00028 00029 from maintenance.autotest import common 00030 00031 check = common.check 00032 00033 00034 def action(): 00035 if common.verbose: 00036 os.write(common.output, bytes("--- SUMS\n", 'utf-8')) 00037 00038 00039 # -------------------------------------------------------------------------- 00040 00041 sum_a_plus_b_plus_sum_a_plus_b = Sum([Sum(['a', 'b']), 00042 Sum(['a', 'b'])]) 00043 00044 sum_minus_one_plus_x = Sum([Monomial(('-', 1, 0)), 00045 Monomial(('+', 1, 1))]) 00046 00047 sum_minus_one_plus_x_bis = Sum([Product(Item(-1)), Item('x')]) 00048 00049 sum_one_plus_x = Sum([Product(Item(1)), Item('x')]) 00050 00051 temp_product = Product([Item(3)]) 00052 temp_product.set_exponent(2) 00053 sum_1 = Sum([temp_product, 00054 Item(5) 00055 ]) 00056 00057 sum_2_product_polynomial_minus10x2_9 = \ 00058 Sum([Item(2), 00059 Product([ 00060 Polynomial([Monomial(('-', 10, 2)), 00061 Monomial(('+', 9, 0))]) 00062 ]) 00063 00064 ]) 00065 00066 sum_binomial_followed_by_positive_simple_expd = \ 00067 Sum([BinomialIdentity((Monomial(('+', 6, 0)), 00068 Monomial(('+', 1, 1)))), 00069 Expandable((Monomial(('+', 12, 0)), 00070 Sum([ 00071 Polynomial([Monomial(('+', 2, 0)), 00072 Monomial(('+', 11, 1))]) 00073 ]) 00074 )) 00075 ]) 00076 00077 sum_binomial_followed_by_positive_item = \ 00078 Sum([BinomialIdentity((Monomial(('+', 6, 0)), 00079 Monomial(('+', 1, 1)))), 00080 Item(1) 00081 ]) 00082 00083 sum_sum_and_positive_item = \ 00084 Sum([Sum([Item(5), 00085 Item(7) 00086 ]), 00087 Item(1) 00088 ]) 00089 00090 check(sum_a_plus_b_plus_sum_a_plus_b, 00091 ["a+b+a+b"]) 00092 00093 check(sum_minus_one_plus_x, 00094 ["-1+x"]) 00095 00096 check(sum_minus_one_plus_x_bis, 00097 ["-1+x"]) 00098 00099 check(sum_one_plus_x, 00100 ["1+x"]) 00101 00102 check(sum_1, 00103 ["3^{2}+5"]) 00104 00105 check(sum_2_product_polynomial_minus10x2_9, 00106 ["2-10x^{2}+9"]) 00107 00108 check(sum_binomial_followed_by_positive_simple_expd, 00109 ["(6+x)^{2}+12(2+11x)"]) 00110 00111 check(sum_binomial_followed_by_positive_item, 00112 ["(6+x)^{2}+1"]) 00113 00114 check(sum_sum_and_positive_item, 00115 ["5+7+1"]) 00116 00117 00118 # -------------------------------------------------------------------------- 00119 00120 sum_of_squared_numbers = Sum([Item(('+', 4, 2)), 00121 Item(('+', 5, 2))]) 00122 00123 check(sum_of_squared_numbers, 00124 ["4^{2}+5^{2}"]) 00125 00126 check(sum_of_squared_numbers.calculate_next_step(), 00127 ["16+25"]) 00128 00129 00130