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' REDUCTION\n", 'utf-8')) 00037 00038 monomial_3x = Monomial(('+', 3, 1)) 00039 monomial_5x2 = Monomial(('+', 5, 2)) 00040 monomial_minus2x = Monomial(('-', 2, 1)) 00041 item_4 = Item(4) 00042 item_2 = Item(2) 00043 product_ab = Product([Item('-a'), Item('b')]) 00044 product_2ab = Product([Item(2), Item('a'), Item('b')]) 00045 product_minus7ab = Product([Item(-7), Item('a'), Item('b')]) 00046 #product_ab.set_compact_display(True) 00047 #product_2ab.set_compact_display(True) 00048 #product_minus7ab.set_compact_display(True) 00049 sum_testing = Sum([monomial_3x, monomial_5x2, product_minus7ab]) 00050 #sum_testing.set_exponent(2) 00051 sum_to_reduce = Sum([monomial_3x, 00052 item_4, 00053 sum_testing, 00054 product_ab, 00055 monomial_5x2, 00056 item_2, 00057 monomial_minus2x, 00058 product_2ab]) 00059 00060 polynomial_rubbish = Polynomial([Monomial(('+',1,2)), 00061 Monomial(('+',7,1)), 00062 Monomial(('-',10,2)), 00063 Monomial(('-',9,1)), 00064 Monomial(('+',9,2))]) 00065 00066 check(sum_to_reduce, 00067 ["3x+4+3x+5x^{2}-7ab-ab+5x^{2}+2-2x+2ab"]) 00068 00069 check(sum_to_reduce.intermediate_reduction_line(), 00070 ["(3+3-2)x+4+2+(5+5)x^{2}+(-7-1+2)ab"]) 00071 00072 check(sum_to_reduce.reduce_(), 00073 ["4x+6+10x^{2}-6ab"]) 00074 00075 check(polynomial_rubbish, 00076 ["x^{2}+7x-10x^{2}-9x+9x^{2}"]) 00077 00078 check(polynomial_rubbish.intermediate_reduction_line(), 00079 ["(1-10+9)x^{2}+(7-9)x"]) 00080 00081 check(polynomial_rubbish.reduce_(), 00082 ["-2x"]) 00083 00084 00085