neuper@37906: (* tests for rationals neuper@37906: Stefan Karnel neuper@37906: 2002 neuper@37906: use"../kbtest/rational.sml"; neuper@37906: use"kbtest/rational.sml"; neuper@37906: use"rational.sml"; neuper@37906: *) neuper@37906: neuper@37906: (*--------------------------------15.10.02--- neuper@37906: (* tests*) neuper@37906: print("\n\n********************* tests *************************\n\n"); neuper@37906: print("\n\n***** divide tests *****\n"); neuper@37906: val mv_pquot1 = (#1(mv_division([(1,[1,1,1]),(1,[1,1,0]),(1,[1,0,1]),(1,[0,0,0])],[(1,[1,1,0]),(1,[0,0,0])],LEX_))); neuper@37906: (* result: [(1,[0,0,1]),(1,[0,0,0])] *) neuper@38031: if mv_pquot1=[(1,[0,0,1]),(1,[0,0,0])] then () else error ("Test failed"); neuper@37906: neuper@37906: val mv_prest1 = (#2(mv_division([(1,[1,1,1]),(1,[1,1,0]),(1,[1,0,1]),(1,[0,0,0])],[(1,[1,1,0]),(1,[0,0,0])],LEX_))); neuper@37906: (* result: [(1,[1,0,1]),(~1,[0,0,1])] *) neuper@38031: if mv_prest1=[(1,[1,0,1]),(~1,[0,0,1])] then () else error ("Test failed"); neuper@37906: neuper@37906: val mv_pquot2 = (#1(mv_division([(4,[2]),(8,[1]),(16,[0])],[(1,[1]),(1,[0])],LEX_))); neuper@37906: (* result: [(4,[1]),(4,[0])] *) neuper@38031: if mv_pquot2=[(4,[1]),(4,[0])] then () else error ("Test failed"); neuper@37906: neuper@37906: val mv_prest2 = (#2(mv_division([(4,[2]),(8,[1]),(16,[0])],[(1,[1]),(1,[0])],LEX_))); neuper@37906: (* result: [(12,[0]] *) neuper@38031: if mv_prest2=[(12,[0])] then () else error ("Test failed"); neuper@37906: neuper@37906: val mv_pquot3 = (#1(mv_division([(4,[2]),(~4,[0])],[(2,[1]),(2,[0])],LEX_))); neuper@37906: (* [(2,[1]),(~2,[0])] *) neuper@38031: if mv_pquot3=[(2,[1]),(~2,[0])] then () else error ("Test failed"); neuper@37906: neuper@37906: val mv_prest3 = (#2(mv_division([(1,[2]),(~1,[0])],[(2,[1]),(2,[0])],LEX_))); neuper@37906: (* [(1,[2]),(~1,[0])] *) neuper@38031: if mv_prest3=[(1,[2]),(~1,[0])] then () else error ("Test failed"); neuper@37906: neuper@37906: val mv_pquot4 = (#1(mv_division([(3,[1,1,1]),(4,[1,0,1]),(3,[0,0,1])],[(2,[1,0,0]),(4,[0,0,1])],LEX_))); neuper@37906: (* [(1,[0,1,1])] *) neuper@38031: if mv_pquot4=[(1,[0,1,1])] then () else error ("Test failed"); neuper@37906: neuper@37906: val mv_prest4 = (#2(mv_division([(3,[1,1,1]),(4,[1,0,1]),(3,[0,0,1])],[(2,[1,0,0]),(4,[0,0,1])],GGO_))); neuper@37906: (* [(1,[1,1,1]),(~4,[0,1,2]),(4,[1,0,1]),(3,[0,0,1])] *) neuper@38031: if mv_prest4 =[(1,[1,1,1]),(~4,[0,1,2]),(4,[1,0,1]),(3,[0,0,1])] then () else error ("Test failed"); neuper@37906: neuper@37906: val mv_pquot5 = (#1(mv_division([(3,[1,1,1]),(4,[1,0,1]),(3,[0,0,1]),(6,[2,1,3]),(4,[0,4,1]),(1,[2,2,1])],[(1,[0,0,1])],LEX_))); neuper@37906: (* [(1,[2,2,0]),(6,[2,1,2]),(3,[1,1,0]),(4,[1,0,0]),(4,[0,4,0]),(3,[0,0,0])]*) neuper@38031: if mv_pquot5=[(1,[2,2,0]),(6,[2,1,2]),(3,[1,1,0]),(4,[1,0,0]),(4,[0,4,0]),(3,[0,0,0])] then () else error ("Test failed"); neuper@37906: neuper@37906: val mv_prest5 = (#2(mv_division([(3,[1,1,1]),(4,[1,0,1]),(3,[0,0,1]),(6,[2,1,3]),(4,[0,4,1]),(1,[2,2,1])],[(1,[0,0,1])],LEX_))); neuper@37906: (* [] *) neuper@38031: if mv_prest5=[] then () else error ("Test failed"); neuper@37906: neuper@37906: (* (x^2 + 2(a+1)x + (a^2+2a+1)) / (x+a+1) = x+a+1 *) neuper@37906: val mv_pquot6 = (#1(mv_division([(1,[2,0,0]),(2,[1,1,0]),(2,[1,0,0]),(1,[0,2,0]),(2,[0,1,0]),(1,[0,0,0])],[(1,[1,0,0]),(1,[0,1,0]),(1,[0,0,0])],LEX_))); neuper@38031: if mv_pquot6=[(1,[1,0,0]),(1,[0,1,0]),(1,[0,0,0])] then () else error ("Test failed"); neuper@37906: neuper@37906: val mv_prest6 = (#2(mv_division([(1,[2,0,0]),(2,[1,1,0]),(2,[1,0,0]),(1,[0,2,0]),(2,[0,1,0]),(1,[0,0,0])],[(1,[1,0,0]),(1,[0,1,0]),(1,[0,0,0])],LEX_))); neuper@38031: if mv_prest6=[] then () else error ("Test failed"); neuper@37906: neuper@37906: (* Exception tests *) neuper@37906: (* mv_division ([(1,[0,0,0])],[(0,[1,2,3])],LEX_); *) neuper@37906: neuper@37906: print("\n\n***** MV_CONTENT-TESTS *****\n"); neuper@37906: val mv_cont1=mv_content([(1,[2,1]),(1,[2,0]),(1,[1,1]),(1,[1,0]),(1,[0,1]),(1,[0,0])]); neuper@37906: (* [(1,[0,1]),(1,[0,0])] *) neuper@38031: if mv_cont1=[(1,[0,1]),(1,[0,0])] then () else error ("Test failed"); neuper@37906: neuper@37906: val mv_pp1=mv_pp([(1,[1,1]),(1,[1,0]),(1,[0,1]),(1,[0,0])]); neuper@37906: (*[(1,[1,0]),(1,[0,0])]*) neuper@38031: if mv_pp1=[(1,[1,0]),(1,[0,0])] then () else error ("Test failed"); neuper@37906: neuper@37906: val mv_cont2=mv_content([(2,[1]),(4,[0])]); neuper@37906: (* [(2,[0])] *) neuper@38031: if mv_cont2=[(2,[0])] then () else error ("Test failed"); neuper@37906: neuper@37906: val mv_pp2=mv_pp([(2,[1]),(4,[0])]); neuper@37906: (* [(1,[1]),(2,[0])] *) neuper@38031: if mv_pp2=[(1,[1]),(2,[0])] then () else error ("Test failed"); neuper@37906: neuper@37906: val mv_cont3=mv_content[(8,[2,1,1]),(12,[1,0,2]),(10,[2,2,0]),(16,[1,1,1])]; neuper@37906: (* [(2,[0,0,0])] *) neuper@38031: if mv_cont3=[(2,[0,0,0])] then () else error ("Test failed"); neuper@37906: neuper@37906: val mv_pp3=mv_pp[(8,[2,1,1]),(12,[1,0,2]),(10,[2,2,0]),(16,[1,1,1])]; neuper@37906: (* [(5,[2,2,0]),(4,[2,1,1]),(8,[1,1,1]),(6,[1,0,2])] *) neuper@38031: if mv_pp3=[(5,[2,2,0]),(4,[2,1,1]),(8,[1,1,1]),(6,[1,0,2])] then () else error ("Test failed"); neuper@37906: neuper@37906: val mv_cont4=mv_content[(2,[2,1,0]),(3,[1,0,1]),(2,[1,1,0]),(3,[0,0,1])]; neuper@37906: (* [(1,[0,0,0])] *) neuper@38031: if mv_cont4=[(1,[0,0,0])] then () else error ("Test failed"); neuper@37906: neuper@37906: val mv_pp4=mv_pp [(2,[2,1,0]),(3,[1,0,1]),(2,[1,1,0]),(3,[0,0,1])]; neuper@37906: (* [(2,[2,1,0]),(2,[1,1,0]),(3,[1,0,1]),(3,[0,0,1])] *) neuper@38031: if mv_pp4=[(2,[2,1,0]),(2,[1,1,0]),(3,[1,0,1]),(3,[0,0,1])] then () else error ("Test failed"); neuper@37906: neuper@37906: val con1=mv_content([(9,[2,0]),(15,[1,1]),(12,[1,0]),(6,[0,2]),(12,[0,1])]); neuper@37906: (* [(3,[0,0])] *) neuper@38031: if con1=[(3,[0,0])] then () else error ("Test failed"); neuper@37906: neuper@37906: val pp1=mv_pp([(9,[2,0]),(15,[1,1]),(12,[1,0]),(6,[0,2]),(12,[0,1])]); neuper@37906: (* [(3,[2,0]),(5,[1,1]),(4,[1,0]),(2,[0,2]),(4,[0,1])] *) neuper@38031: if pp1=[(3,[2,0]),(5,[1,1]),(4,[1,0]),(2,[0,2]),(4,[0,1])] then () else error ("Test failed"); neuper@37906: neuper@37906: val con2=mv_content([(1,[2,0]),(1,[1,1]),(1,[1,0]),(1,[0,2]),(1,[0,1])]); neuper@37906: (* [(1,[0,0])] *) neuper@38031: if con2=[(1,[0,0])] then () else error ("Test failed"); neuper@37906: neuper@37906: val pp2 =mv_pp([(1,[2,0]),(1,[1,1]),(1,[1,0]),(1,[0,2]),(1,[0,1])]); neuper@37906: (* [(1,[2,0]),(1,[1,1]),(1,[1,0]),(1,[0,2]),(1,[0,1])] *) neuper@38031: if pp2=[(1,[2,0]),(1,[1,1]),(1,[1,0]),(1,[0,2]),(1,[0,1])] then () else error ("Test failed"); neuper@37906: neuper@37906: val cont1 = mv_content [(1,[2,1,0]),(2,[2,1,0])]; neuper@37906: (* [(3,[0,1,0])] *) neuper@38031: if cont1=[(3,[0,1,0])] then () else error ("Test failed"); neuper@37906: neuper@37906: val pp1 = mv_pp [(1,[2,1,0]),(2,[2,1,0])]; neuper@37906: (* [(1,[2,0,0])] *) neuper@38031: if pp1=[(1,[2,0,0])] then () else error ("Test failed"); neuper@37906: neuper@37906: val cont2 = mv_content [(4,[1,2,0]),(2,[2,1,0])]; neuper@37906: (* [(2,[0,1,0])] *) neuper@38031: if cont2=[(2,[0,1,0])] then () else error ("Test failed"); neuper@37906: neuper@37906: val pp2 = mv_pp [(4,[1,2,0]),(2,[2,1,0])]; neuper@37906: (* [(1,[2,0,0]),(2,[1,1,0])] *) neuper@38031: if pp2=[(1,[2,0,0]),(2,[1,1,0])] then () else error ("Test failed"); neuper@37906: neuper@37906: print("\n\n\n\n********************************************************\n\n"); neuper@37906: val cont3=mv_content [(65,[3,2,2]),(52,[3,2,1]),(26,[3,1,2]),(~95,[2,2,3]),(~76,[2,2,2]),(35,[2,2,1]),(28,[2,2,0]),(~38,[2,1,3]),(14,[2,1,1])]; neuper@38031: (*if cont3=[(1,[0,1,0])] then () else error ("Test failed"); *) neuper@37906: val pp3=mv_pp [(65,[3,2,2]),(52,[3,2,1]),(26,[3,1,2]),(~95,[2,2,3]),(~76,[2,2,2]),(35,[2,2,1]),(28,[2,2,0]),(~38,[2,1,3]),(14,[2,1,1])]; neuper@37906: neuper@37906: neuper@37906: print("\n\n***** gcd-tests *****\n"); neuper@37906: val ggt1 = gcd_poly [(4,[2,2]),(8,[1,1]),(4,[0,0])] [(2,[1,1]),(2,[0,0])]; neuper@37906: (* [(2,[1,1]),(2,[0,0])] *) neuper@38031: if ggt1=[(2,[1,1]),(2,[0,0])] then () else error ("Test failed"); neuper@37906: neuper@37906: val ggt2 = gcd_poly [(8,[2,1,1]),(12,[1,0,2]),(10,[2,2,0]),(15,[1,1,1])] [(2,[2,1,0]),(3,[1,0,1]),(2,[1,1,0]),(3,[0,0,1])]; neuper@37906: (* [(2,[1,1,0]),(3,[0,0,1])] *) neuper@38031: if ggt2=[(2,[1,1,0]),(3,[0,0,1])] then () else error ("Test failed"); neuper@37906: neuper@37906: val ggt3 = gcd_poly [(1,[2,0,0]),(~2,[1,0,1]),(1,[0,0,2])] [(1,[1,0,0]),(~1,[0,0,1])]; neuper@37906: (* [(1,[1,0,0]),(~1,[0,0,1])] *) neuper@38031: if ggt3=[(1,[1,0,0]),(~1,[0,0,1])] then () else error ("Test failed"); neuper@37906: neuper@37906: val ggt4 = gcd_poly [(1,[2,1,0]),(2,[2,1,0])] [(5,[1,0,0])]; neuper@37906: (* [(1,[1,0,0])] *) neuper@38031: if ggt4=[(1,[1,0,0])] then () else error ("Test failed"); neuper@37906: neuper@37906: val ggt5 = gcd_poly [(4,[2,0,0]),(~8,[1,0,1]),(4,[0,0,2])] [(1,[2,0,0]),(~1,[0,0,2])]; neuper@37906: (* [(1,[1,0,0]),(~1,[0,0,1])] *) neuper@38031: if ggt5=[(1,[1,0,0]),(~1,[0,0,1])] then () else error ("Test failed"); neuper@37906: neuper@37906: val ggt6 = gcd_poly [(10,[2,1,1]),(14,[1,1,0]),(3,[1,0,1]),(20,[1,2,1])] [(5,[1,1,1]),(7,[2,1,1])]; neuper@37906: (* [(1,[0,0,0])] *) neuper@38031: if ggt6=[(1,[1,0,0])] then () else error ("Test failed"); neuper@37906: neuper@37906: val ggt7 = gcd_poly [(~169,[4,3,3]),(273,[4,2,2]),(247,[3,3,4]),(~91,[3,3,2]),(78,[3,3,1]),(~399,[3,2,3]),(147,[3,2,1]),(~114,[2,3,2]),(42,[2,3,0])] [(65,[3,2,2]),(52,[3,2,1]),(26,[3,1,2]),(~95,[2,2,3]),(~76,[2,2,2]),(35,[2,2,1]),(28,[2,2,0]),(~38,[2,1,3]),(14,[2,1,1])]; neuper@37906: (* [(13,[3,1,1]),(~19,[2,1,2]),(7,[2,1,0])] *) neuper@38031: if ggt7=[(13,[3,1,1]),(~19,[2,1,2]),(7,[2,1,0])] then () else error ("Test failed"); neuper@37906: neuper@37906: print("\n\n***** kgv-tests *****\n"); neuper@37906: val kgv1=lcm_poly [(10,[])] [(15,[])]; neuper@37906: (* [(30,[])] *) neuper@38031: if kgv1=[(30,[])] then () else error ("Test failed"); neuper@37906: neuper@37906: val kgv2=lcm_poly [(1,[2,0,0]),(~2,[1,0,1]),(1,[0,0,2])] [(1,[1,0,0]),(~1,[0,0,1])]; neuper@37906: (* [(1,[2,0,0]),(~2,[1,0,1]),(1,[0,0,2])] *) neuper@38031: if kgv2=[(1,[2,0,0]),(~2,[1,0,1]),(1,[0,0,2])] then () else error ("Test failed"); neuper@37906: neuper@37906: val kgv3=lcm_poly [(4,[2,0,0]),(~8,[1,0,1]),(4,[0,0,2])] [(1,[2,0,0]),(~1,[0,0,2])]; neuper@37906: (* [(4,[3,0,0]),(~4,[2,0,1]),(~4,[1,0,2]),(4,[0,0,3])] *) neuper@38031: if kgv3=[(4,[3,0,0]),(~4,[2,0,1]),(~4,[1,0,2]),(4,[0,0,3])] then () else error ("Test failed"); neuper@37906: neuper@37906: (* neuper@37906: print("***** TERM2POLY-TESTS *****\n"); neuper@37906: val t0 = (term_of o the o (parse thy)) "3 * 4"; neuper@37906: val t1 = (term_of o the o (parse thy)) "27"; neuper@37906: val t11= (term_of o the o (parse thy)) "27 * c"; neuper@37906: val t2 = (term_of o the o (parse thy)) "b"; neuper@37906: val t23= (term_of o the o (parse thy)) "c^^^7"; neuper@37906: val t24= (term_of o the o (parse thy)) "5 * c^^^7"; neuper@37906: val t26= (term_of o the o (parse thy)) "a * b"; neuper@37906: val t3 = (term_of o the o (parse thy)) "2 + a"; neuper@37906: val t4 = (term_of o the o (parse thy)) "b + a"; neuper@37906: val t5 = (term_of o the o (parse thy)) "2 + a^^^3";*) neuper@37906: val t6 = (term_of o the o (parse thy)) "5*a^^^2*b^^^3*c+4*a^^^4*b+2*a*c"; neuper@37906: val t7 = (term_of o the o (parse thy)) "a-b"; neuper@37906: (* neuper@37906: (the o term2poly) t0; neuper@37906: (the o term2poly) t1; neuper@37906: (the o term2poly) t11; neuper@37906: (the o term2poly) t2; neuper@37906: (the o term2poly) t23; neuper@37906: (the o term2poly) t24; neuper@37906: (the o term2poly) t26; neuper@37906: (the o term2poly) t3; neuper@37906: (the o term2poly) t4; neuper@37906: (the o term2poly) t5; neuper@37906: (the o term2poly) t6; neuper@37906: (the o term2poly) t7;*) neuper@37906: neuper@37906: neuper@37906: print("\n\n***** STEP_CANCEL_TESTS: *****\n"); neuper@37906: (* neuper@37906: val term2 = (term_of o the o (parse thy)) " (9 * a^^^2 * b) /// (6 * a * c)"; neuper@37906: val div2 = step_cancel term2; neuper@37906: atomt div2; neuper@37906: *) neuper@37906: neuper@37906: val term1 = (term_of o the o (parse thy)) "(10 * a^^^2 * b * c + 14 * a * b + 3 * a * c + 20 * a * b^^^2 * c) /// a"; neuper@37906: val div1 = step_cancel term1; neuper@38031: (*if div1 = (term_of o the o (parse thy)) "((10 * a * b * c + 14 * b + 3 * c + 20 * b^^^2 * c) * a) /// (1 * a)" then () else raise error ("Test failed");*) neuper@37906: neuper@37906: val term2 = (term_of o the o (parse thy)) "(10 * a^^^2 * b * c + 14 * a * b + 3 * a * c + 20 * a * b^^^2 * c) /// (5 * a * b * c + 7 * a^^^2 * b * c) "; neuper@37906: val div2 = step_cancel term2; neuper@38031: (*if div2 = ([(10,[1,1,1]),(20,[0,2,1]),(14,[0,1,0]),(3,[0,0,1])],[(1,[1,0,0])],[(7,[1,1,1]),(5,[0,1,1])]) then () else raise error ("Test failed");*) neuper@37906: neuper@37906: neuper@37906: val term3 = (term_of o the o (parse thy)) "(10 * a^^^2 * b * c) /// (1 * x * y * z) "; neuper@37906: val div3 = step_cancel term3; neuper@37906: neuper@37906: neuper@37906: neuper@37906: (*val mul1=(term_of o the o (parse thy)) "(5*a*b*c+4*a*b+2*a*c)"; neuper@37906: val mul2=(the (term2poly((term_of o the o (parse thy)) "13*a^^^2*b*c+7*a*b-19*a*b*c^^^2"))); neuper@37906: val mul3=(the (term2poly((term_of o the o (parse thy)) "6*a*b^^^2-13*a^^^2*b^^^2*c^^^2+21*a^^^2*b*c"))); neuper@37906: val t1=mv_mul(mul1,mul2,LEX_); neuper@37906: val t2=mv_mul(mul3,mul2,LEX_); neuper@37906: val div3=step_cancel t1 t2; neuper@38031: if div3=([(5,[0,1,1]),(4,[0,1,0]),(2,[0,0,1])],[(13,[3,1,1]),(~19,[2,1,2]),(7,[2,1,0])],[(~13,[1,2,2]),(21,[1,1,1]),(6,[0,2,0])]) then () else error ("Test failed");*) neuper@37906: neuper@37906: print("\n\n***** all tests successfull ;-) ******\n\n"); neuper@37906: neuper@37906: neuper@37906: neuper@37906: val thy = Rational.thy; neuper@37906: val rls = Prls {func=cancel}; neuper@37906: val t = (term_of o the o (parse thy)) neuper@37906: "(1 + 1 * a ^^^ 1)///(-2 + 2 * a ^^^ 2)"; neuper@37906: val (t,asm) = the (rewrite_set_ thy eval_rls false rls t); neuper@37906: neuper@37906: neuper@37991: val thy' = "Rational"; neuper@37906: val rls' = "cancel"; neuper@37906: val t' = "(1 + 1 * a ^^^ 1)///(-2 + 2 * a ^^^ 2)"; neuper@37906: val (t',asm') = the (rewrite_set thy' "eval_rls" false rls' t'); neuper@37906: (*if t' = "1 /// (-2 + 2 * a)" then () neuper@38031: else error "tests/rationals.sml(1): new behaviour";*) neuper@37906: neuper@37906: neuper@37991: val thy' = "Rational"; neuper@37906: val rls' = "cancel"; neuper@37906: val t' = "(10 * a^^^2 * b * c + 14 * a * b + 3 * a * c + 20 * a * b^^^2 * c) /// (5 * a * b * c + 7 * a^^^2 * b * c) "; neuper@37906: val (t',asm') = the (rewrite_set thy' "eval_rls" false rls' t'); neuper@37906: neuper@37991: val thy' = "Rational"; neuper@37906: val rls' = "cancel"; neuper@37906: val t' = "(a^^^2 * b + 2 * a * b + b ) /// ( a^^^2 - 1 )"; neuper@37906: val (t',asm') = the (rewrite_set thy' "eval_rls" false rls' t'); neuper@37906: neuper@37906: (* neuper@37906: val term2 = (term_of o the o (parse thy)) "(a^^^2 * b + 2 * a * b + b ) /// ( a^^^2 - 1 )"; neuper@37906: val div2 = direct_cancel term2; neuper@37906: val t = (term_of o the o (parse thy)) "(1 + 1 * a ^^^ 1)///(-2 + 2 * a ^^^ 2) = 0";*) neuper@37906: neuper@37906: neuper@37906: neuper@37906: (*WN folgendes aus examples he"uberkopiert ...*) neuper@37906: neuper@37906: (* examples from: neuper@37906: Mathematik 1 neuper@37906: Schalk neuper@37906: Reniets Verlag *) neuper@37906: neuper@37991: val thy' = "Rational"; neuper@37906: val rls' = "cancel"; neuper@37906: val mp = "make_polynomial"; neuper@37906: neuper@37906: (* page 63 *) neuper@37906: neuper@37906: print("\n\nexample 186:\n"); neuper@37906: print("a)\n"); neuper@37906: val e186a'="(14 * x * y) / ( x * y )"; neuper@37906: val e186a = the (rewrite_set thy' "rational_erls" false rls' e186a'); neuper@37906: print("b)\n"); neuper@37906: val e186b'="(60 * a * b) / ( 15 * a * b )"; neuper@37906: val e186b = the (rewrite_set thy' "rational_erls" false rls' e186b'); neuper@37906: print("c)\n"); neuper@37906: val e186c'="(144 * a^^^2 * b * c) / (12 * a * b * c )"; neuper@37906: val e186c = (the (rewrite_set thy' "rational_erls" false rls' e186c')) neuper@37906: handle e => print_exn e; neuper@37906: val t = (term_of o the o (parse thy)) e186c'; neuper@37906: atomt t; neuper@37906: neuper@37906: print("\n\nexample 187:\n"); neuper@37906: print("a)\n"); neuper@37906: val e187a'="(12 * x * y) / (8 * y^^^2 )"; neuper@37906: val e187a = the (rewrite_set thy' "rational_erls" false rls' e187a'); neuper@37906: print("b)\n"); neuper@37906: val e187b'="(8 * x^^^2 * y * z ) / (18 * x * y^^^2 * z )"; neuper@37906: val e187b = the (rewrite_set thy' "rational_erls" false rls' e187b'); neuper@37906: print("c)\n"); neuper@37906: val e187c'="(9 * x^^^5 * y^^^2 * z^^^4) / (15 * x^^^6 * y^^^3 * z )"; neuper@37906: val e187c = the (rewrite_set thy' "rational_erls" false rls' e187c'); neuper@37906: neuper@37906: print("\n\nexample 188:\n"); neuper@37906: print("a)\n"); neuper@37906: val e188a'="(8 * x + -8) / (9 * x + -9 )"; neuper@37906: val e188a = the (rewrite_set thy' "rational_erls" false rls' e188a'); neuper@37926: val SOME (t,_) = rewrite_set thy' "rational_erls" false mp "(8*((-1) + x))/(9*((-1) + x))"; neuper@37906: if t="((-8) + 8 * x) / ((-9) + 9 * x)"then() neuper@38031: else error "rationals.sml: e188a new behaviour"; neuper@37906: print("b)\n"); neuper@37906: val e188b'="(5 * x + -15) / (6 * x + -18 )"; neuper@37906: val e188b = the (rewrite_set thy' "rational_erls" false rls' e188b'); neuper@37906: print("c)\n"); neuper@37906: val e188c'="( a + -1 * b ) / ( b + -1 * a )"; neuper@37906: val e188c = the (rewrite_set thy' "rational_erls" false rls' e188c'); neuper@37926: val SOME (t,_) = rewrite_set thy' "rational_erls" false mp "((-1)*(b + (-1) * a))/(1*(b + (-1) * a))"; neuper@37906: if t="(a + -1 * b) / (b + -1 * a)"then() neuper@38031: else error "rationals.sml: e188c new behaviour"; neuper@37906: neuper@37906: print("\n\nexample 190:\n"); neuper@37906: print("c)\n"); neuper@37906: val e190c'="( 27 * a^^^3 + 9 * a^^^2 + 3 * a + 1 ) / ( 27 * a^^^3 + 18 * a^^^2 + 3 * a )"; neuper@37906: val e190c = the (rewrite_set thy' "rational_erls" false rls' e190c'); neuper@37926: val SOME (t,_) = rewrite_set thy' "rational_erls" false mp "((1 + 9 * a ^^^ 2)*(1 + 3 * a))/((3 * a + 9 * a ^^^ 2)*(1 + 3 * a))"; neuper@37906: if t="(1 + (3 * a + (27 * a ^^^ 3 + 9 * a ^^^ 2))) /\n(3 * a + (18 * a ^^^ 2 + 27 * a ^^^ 3))"then() neuper@37906: (*TERMORDER ~~~~~~~ ~~~~~~~*) neuper@38031: else error "rationals.sml: e190c new behaviour"; neuper@37906: neuper@37906: print("\n\nexample 191:\n"); neuper@37906: print("a)\n"); neuper@37906: val e191a'="( x^^^2 + -1 * y^^^2 ) / ( x + y )"; neuper@37906: val e191a = the (rewrite_set thy' "rational_erls" false rls' e191a'); neuper@37926: val SOME (t,_) = rewrite_set thy' "rational_erls" false mp "((x + (-1) * y)*(x + y))/((1)*(x + y))"; neuper@37906: if t="(x ^^^ 2 + -1 * y ^^^ 2) / (x + y)"then() neuper@38031: else error "rationals.sml: e191a new behaviour"; neuper@37906: print("c)\n"); neuper@37906: val e191c'="( 9 * x^^^2 + -30 * x + 25 ) / ( 9 * x^^^2 + -25 )"; neuper@37906: val e191c = the (rewrite_set thy' "rational_erls" false rls' e191c'); neuper@37926: val SOME (t,_) = rewrite_set thy' "rational_erls" false mp "(((-5) + 3 * x)*((-5) + 3 * x))/((5 + 3 * x)*((-5) + 3 * x))"; neuper@37906: if t="(25 + ((-30) * x + 9 * x ^^^ 2)) / ((-25) + 9 * x ^^^ 2)"then() neuper@38031: else error "rationals.sml: 'e191c' new behaviour"; neuper@37906: neuper@37906: print("\n\nexample 192:\n"); neuper@37906: print("b)\n"); neuper@37906: val e192b'="( 7 * x^^^3 + -1 * x^^^2 * y ) / ( 7 * x * y^^^2 + -1 * y^^^3 )"; neuper@37906: val e192b = the (rewrite_set thy' "rational_erls" false rls' e192b'); neuper@37926: val SOME (t,_) = rewrite_set thy' "rational_erls" false mp "((x ^^^ 2)*(7 * x + (-1) * y))/((y ^^^ 2)*(7 * x + (-1) * y))"; neuper@37906: if t="(7 * x ^^^ 3 + -1 * (y * x ^^^ 2)) / (-1 * y ^^^ 3 + 7 * (x * y ^^^ 2))"then() neuper@37906: (*TERMORDER ~~~~~*) neuper@38031: else error "rationals.sml: 'e192b' new behaviour"; neuper@37906: neuper@37906: print("\n\nexample 193:\n"); neuper@37906: print("a)\n"); neuper@37906: val e193a'="( x^^^2 + -6 * x + 9 ) / ( x^^^2 + -9 )"; neuper@37906: val e193a = the (rewrite_set thy' "rational_erls" false rls' e193a'); neuper@37906: print("b)\n"); neuper@37906: val e193b'="( x^^^2 + -8 * x + 16 ) / ( 2 * x^^^2 + -32 )"; neuper@37906: val e193b = the (rewrite_set thy' "rational_erls" false rls' e193b'); neuper@37906: print("c)\n"); neuper@37906: val e193c'="( 2 * x + -50 * x^^^3 ) / ( 25 * x^^^2 + -10 * x + 1 )"; neuper@37926: val SOME(t,_) = rewrite_set thy' "rational_erls" false rls' e193c'; neuper@37906: --------------------------------15.10.02---*) neuper@37906: neuper@37906: neuper@37906: (*---------- WN: 10.9.02: neuper@37906: ML> val e204a = the (rewrite_set thy' "rational_erls" false rls' e204a'); neuper@37906: *** RATIONALS_STEP_CANCEL_EXCEPTION: Invalid fraction neuper@37906: print("\n\nexample 204:\n"); neuper@37906: print("a)\n"); neuper@37906: val e204a'="((5 * x) / 9) + ((3 * x) / 9) + (x / 9)"; neuper@37906: val e204a = the (rewrite_set thy' "rational_erls" false rls' e204a'); neuper@37906: print("b)\n"); neuper@37906: val e204b'="5 / x + -3 / x + -1 / x"; neuper@37906: val e204b = the (rewrite_set thy' "rational_erls" false rls' e204b'); neuper@37906: neuper@37906: print("\n\nexample 205:\n"); neuper@37906: print("a)\n"); neuper@37906: val e205a'="((4 * x + 7) / 8) + ((4 * x + 3) / 8)"; neuper@37906: val e205a = the (rewrite_set thy' "rational_erls" false rls' e205a'); neuper@37906: print("b)\n"); neuper@37906: val e205b'="((5 * x + 2) / 3) + ((-2 * x + 1) / 3)"; neuper@37906: val e205b = the (rewrite_set thy' "rational_erls" false rls' e205b'); neuper@37906: neuper@37906: print("\n\nexample 206:\n"); neuper@37906: print("a)\n"); neuper@37906: val e206a'="((5 * x + 4) / (2 * x + -1)) + ((9 * x + 5) / (2 * x + -1))"; neuper@37906: val e206a = the (rewrite_set thy' "rational_erls" false rls' e206a'); neuper@37906: print("b)\n"); neuper@37906: val e206b'="((17 * x + -23) / (5 * x + 4)) + ((-25 + -17 * x) / (5 * x + 4))"; neuper@37906: val e206b = the (rewrite_set thy' "rational_erls" false rls' e206b'); neuper@37906: neuper@37906: print("\n\nexample 207:\n"); neuper@37906: val e207'="((3 * x * y + 3 * y) / (x * y)) + ((5 * x * y + 7 * y) / (x * y)) + ((9 * x * y + -2 * y) / (x * y)) + ((x * y + 4 * y) / (x * y)) "; neuper@37906: val e207 = the (rewrite_set thy' "rational_erls" false rls' e207'); neuper@37906: neuper@37906: print("\n\nexample 208:\n"); neuper@37906: val e208'="((3 * x + 2) / (x + 2)) + ((5 * x + -1) / (x + 2)) + ((-7 * x + -3) / (x + 2)) + ((-1 * x + -3) / (x + 2)) "; neuper@37906: val e208 = the (rewrite_set thy' "rational_erls" false rls' e208'); neuper@37906: neuper@37906: print("\n\nexample 209:\n"); neuper@37906: val e209'="((3 * x + -7 * y + 3 * z) / (4)) + ((2 * x + 17 * y + 10 * z) / (4)) + ((-1 * x + 2 * y + z) / (4)) "; neuper@37906: val e209 = the (rewrite_set thy' "rational_erls" false rls' e209'); neuper@37906: neuper@37906: print("\n\nexample 210:\n"); neuper@37906: val e210'="((2 * x + 3 + -1 * x^^^2) / (5 * x)) + ((5 * x^^^2 + -2 * x + 1) / (5 * x)) + ((-3 * x^^^2 + -2 * x + 1) / (5 * x)) + ((-1 * x^^^2 + -3 * x + -5) / (5 * x)) "; neuper@37906: val e210 = the (rewrite_set thy' "rational_erls" false rls' e210'); neuper@37906: neuper@37906: print("\n\nexample 211:\n"); neuper@37906: print("a)\n"); neuper@37906: val e211a'="((b) / (a + -1 * b)) + ((-1 * a) / (a + -1 * b))"; neuper@37906: val e211a = the (rewrite_set thy' "rational_erls" false rls' e211a'); neuper@37906: print("b)\n"); neuper@37906: val e211b'="((b) / (b^^^2 + -1 * a^^^2)) + ((-1 * a) / (b^^^2 + -1 * a^^^2))"; neuper@37906: val e211b = the (rewrite_set thy' "rational_erls" false rls' e211b'); neuper@37906: neuper@37906: print("\n\nexample 212:\n"); neuper@37906: print("a)\n"); neuper@37906: val e212a'="((4) / (x)) + ((-3) / (y)) + -1"; neuper@37906: val e212a = the (rewrite_set thy' "rational_erls" false rls' e212a'); neuper@37906: print("b)\n"); neuper@37906: val e212b'="((4) / (x)) + ((-5) / (y)) + ((6) / (x*y))"; neuper@37906: val e212b = the (rewrite_set thy' "rational_erls" false rls' e212b'); neuper@37906: neuper@37906: print("\n\nexample 213:\n"); neuper@37906: print("a)\n"); neuper@37906: val e213a'="((5 * x) / (3 * y^^^2)) + ((19 * z) / (6 * x * y)) + ((-2 * x) / (3 * y^^^2)) + ((7 * y^^^2) / (6 * x^^^2)) "; neuper@37906: val e213a = the (rewrite_set thy' "rational_erls" false rls' e213a'); neuper@37906: print("b)\n"); neuper@37906: val e213b'="((2 * b) / (3 * a^^^2)) + ((3 * c) / (7 * a * b)) + ((4 * b) / (3 * a^^^2)) + ((3 * a) / (7 * b^^^2))"; neuper@37906: val e213b = the (rewrite_set thy' "rational_erls" false rls' e213b'); neuper@37906: neuper@37906: print("\n\nexample 214:\n"); neuper@37906: print("a)\n"); neuper@37906: val e214a'="((3 * x + 2 * y + 2 * z) / (4)) + ((-5 * x + -3 * y) / (3)) + ((x + y + -2 * z) / (2))"; neuper@37906: val e214a = the (rewrite_set thy' "rational_erls" false rls' e214a'); neuper@37906: print("b)\n"); neuper@37906: val e214b'="((5 * x + 2 * y + z) / (2)) + ((-7 * x + -3 * y) / (3)) + ((3 * x + 6 * y + -1 * z) / (12))"; neuper@37906: val e214b = the (rewrite_set thy' "rational_erls" false rls' e214b'); neuper@37906: neuper@37906: print("\n\nexample 216:\n"); neuper@37906: print("a)\n"); neuper@37906: val e216a'="((2 * b + 3 * c) / (a * c)) + ((3 * a + b) / (a * b)) + ((-2 * b^^^2 + -3 * a * c) / (a * b * c))"; neuper@37906: val e216a = the (rewrite_set thy' "rational_erls" false rls' e216a'); neuper@37906: print("b)\n"); neuper@37906: val e216b'="((2 * a + 3 * b) / (b * c)) + ((3 * c + a) / (a * c)) + ((-2 * a^^^2 + -3 * b * c) / (a * b * c))"; neuper@37906: val e216b = the (rewrite_set thy' "rational_erls" false rls' e216b'); neuper@37906: neuper@37906: print("\n\nexample 217:\n"); neuper@37906: val e217'="((z + -1) / (z)) + ((3 * z ^^^2 + -6 * z + 5) / (z^^^2)) + ((-4 * z^^^3 + 7 * z^^^2 + -5 * z + 5) / (z^^^3))"; neuper@37906: val e217 = the (rewrite_set thy' "rational_erls" false rls' e217'); neuper@37906: neuper@37906: print("\n\nexample 218:\n"); neuper@37906: val e218'="((9 * a^^^3 - 5 * a^^^2 + 2 * a + 8) / (108 * a^^^4)) + ((-5 * a + 3 * a^^^2 + 4) / (8 * a^^^3)) + ((-261 * a^^^3 + 19 * a^^^2 + -112 * a + 16) / (216 * a^^^4))"; neuper@37906: val e218 = the (rewrite_set thy' "rational_erls" false rls' e218'); neuper@37906: neuper@37906: print("\n\nexample 219:\n"); neuper@37906: print("a)\n"); neuper@37906: val e219a'="((1) / (y + 1)) + ((1) / (y + 2)) + ((1) / (y + 3))"; neuper@37906: val e219a = the (rewrite_set thy' "rational_erls" false rls' e219a'); neuper@37906: print("b)\n"); neuper@37906: val e219b'="((1) / (x + 1)) + ((1) / (x + 2)) + ((-2) / (x + 3))"; neuper@37906: val e219b = the (rewrite_set thy' "rational_erls" false rls' e219b'); neuper@37906: neuper@37906: print("\n\nexample 220:\n"); neuper@37906: print("a)\n"); neuper@37906: val e220a'="((17) / (5 * r + -2)) + ((-13) / (2 * r + 3)) + ((4) / (3 * r + -5))"; neuper@37906: val e220a = the (rewrite_set thy' "rational_erls" false rls' e220a'); neuper@37906: print("b)\n"); neuper@37906: val e220b'="((20 * a) / (a + -3)) + ((-19 * a) / (a + -4)) + ((a) / (a + -5))"; neuper@37906: val e220b = the (rewrite_set thy' "rational_erls" false rls' e220b'); neuper@37906: neuper@37906: print("\n\nexample 221:\n"); neuper@37906: print("a)\n"); neuper@37906: val e221a'="((a + b) / (a + -1 * b)) + ((a + -1 * b) / (a + b))"; neuper@37906: val e221a = the (rewrite_set thy' "rational_erls" false rls' e221a'); neuper@37906: print("b)\n"); neuper@37906: val e221b'="((x + -1 * y) / (x + y)) + ((x + y) / (x + -1 * y)) "; neuper@37906: val e221b = the (rewrite_set thy' "rational_erls" false rls' e221b'); neuper@37906: neuper@37906: print("\n\nexample 222:\n"); neuper@37906: print("a)\n"); neuper@37906: val e222a'="((1 + -1 * x) / (1 + x)) + ((-1 + -1 * x) / (1 + -1 * x)) + ((4 * x) / (1 + -1 * x^^^2))"; neuper@37906: val e222a = the (rewrite_set thy' "rational_erls" false rls' e222a'); neuper@37906: print("b)\n"); neuper@37906: val e222b'="((1 + x ) / (1 + -1 * x)) + ((-1 + x) / (1 + x)) + ((2 * x) / (1 + -1 * x^^^2))"; neuper@37906: val e222b = the (rewrite_set thy' "rational_erls" false rls' e222b'); neuper@37906: neuper@37906: print("\n\nexample 225:\n"); neuper@37906: print("a)\n"); neuper@37906: val e225a'="((6 * a) / (a^^^2 + -64)) + ((a + 2) / (2 * a + 16)) + ((-1) / (2))"; neuper@37906: val e225a = the (rewrite_set thy' "rational_erls" false rls' e225a'); neuper@37906: print("b)\n"); neuper@37906: val e225b'="((a + 2 ) / (2 * a + 12)) + ((4 * a) / (a^^^2 + -36)) + ((-1) / (2))"; neuper@37906: val e225b = the (rewrite_set thy' "rational_erls" false rls' e225b'); neuper@37906: neuper@37906: print("\n\nexample 226:\n"); neuper@37906: print("a)\n"); neuper@37906: val e226a'="((35 * z) / (49 * z^^^2 + -4)) + -1 + ((14 * z + -1) / (14 * z + 4)) "; neuper@37906: val e226a = the (rewrite_set thy' "rational_erls" false rls' e226a'); neuper@37906: print("b)\n"); neuper@37906: val e226b'="((45 * a * b) / (25 * a^^^2 + -9 * b^^^2)) + ((20 * a + 3 * b) / (10 * a + 6 * b)) + -2"; neuper@37906: val e226b = the (rewrite_set thy' "rational_erls" false rls' e226b'); neuper@37906: neuper@37906: print("\n\nexample 227:\n"); neuper@37906: print("a)\n"); neuper@37906: val e227a'="((6 * z + 11) / (6 * z + 14)) + ((9 * z ) / (9 * z^^^2 + -49)) + -1 "; neuper@37906: val e227a = the (rewrite_set thy' "rational_erls" false rls' e227a'); neuper@37906: print("b)\n"); neuper@37906: val e227b'="((16 * a + 37 * b) / (4 * a + 10 * b)) + ((6 * a * b) / (4 * a^^^2 + -25 * b^^^2)) + -4 "; neuper@37906: val e227b = the (rewrite_set thy' "rational_erls" false rls' e227b'); neuper@37906: neuper@37906: print("\n\nexample 228:\n"); neuper@37906: print("a)\n"); neuper@37906: val e228a'="((7 * a + 11) / (3 * a^^^2 + -3)) + ((-2 * a + -1) / (a^^^2 + -1 * a)) + ((-1) / (3 * a + 3))"; neuper@37906: val e228a = the (rewrite_set thy' "rational_erls" false rls' e228a'); neuper@37906: print("b)\n"); neuper@37906: val e228b'="((11 * z + 2 * b) / (4 * b * z + -8 * b^^^2)) + ((-8 * z) / (z^^^2 + -4 * b^^^2)) + ((-9 * z + -2 * b) / (4 * b * z + 8 * b^^^2))"; neuper@37906: val e228b = the (rewrite_set thy' "rational_erls" false rls' e228b'); neuper@37906: neuper@37906: neuper@37906: print("\n\nexample 229:\n"); neuper@37906: print("a)\n"); neuper@37906: val e229a'="((5 * x^^^2 + y) / (x + 2 * y)) + ((-8 * x^^^3 + 4 * x^^^2 * y + 3 * x * y) / (x^^^2 + -4 * y^^^2)) + ((3 * x^^^2 + -4 * y) / (x + -2 * y))"; neuper@37906: val e229a = the (rewrite_set thy' "rational_erls" false rls' e229a'); neuper@37906: print("b)\n"); neuper@37906: val e229b'="((7 * x^^^2 + y) / (x + 3 * y)) + ((-24 * x^^^2 * y + 5 * x * y + 21 * y^^^2) / (x^^^2 + -9 * y^^^2)) + ((4 * x^^^2 + -6 * y) / (x + -3 * y))"; neuper@37906: val e229b = the (rewrite_set thy' "rational_erls" false rls' e229b'); neuper@37906: neuper@37906: print("\n\nexample 230:\n"); neuper@37906: print("a)\n"); neuper@37906: val e230a'="((5 * x^^^2 + y) / (2 * x + y)) + ((-16 * x^^^3 + 2 * x^^^2 * y + 6 * x * y) / (4 * x^^^2 + -1 * y^^^2)) + ((3 * x^^^2 + -4 * y) / (2 * x + -1 * y))"; neuper@37906: val e230a = the (rewrite_set thy' "rational_erls" false rls' e230a'); neuper@37906: print("b)\n"); neuper@37906: val e230b'="((7 * x^^^2 + y) / (3 * x + y)) + ((-3 * x^^^3 + 15 * x * y + -7 * x^^^2 * y + 7 * y^^^2) / (9 * x^^^2 + -1 * y^^^2)) + ((4 * x^^^2 + -6 * y) / (3 * x + -1 * y))"; neuper@37906: val e230b = the (rewrite_set thy' "rational_erls" false rls' e230b'); neuper@37906: neuper@37906: print("\n\nexample 231:\n"); neuper@37906: print("a)\n"); neuper@37906: val e231a'="((2 * x + 5 * y) / (x)) + ((2 * x^^^3 + -5 * y^^^3 + 3 * x * y^^^2) / (x^^^3 + -2 * x^^^2 * y + x * y^^^2)) + ((-3 * x + -6 * y) / (x + -1 * y))"; neuper@37906: val e231a = the (rewrite_set thy' "rational_erls" false rls' e231a'); neuper@37906: print("b)\n"); neuper@37906: val e231b'="((6 * x + 2 * y) / (x)) + ((6 * x^^^2 * y + -4 * x * y^^^2 + -2 * y^^^3) / (x^^^3 + -2 * x^^^2 * y + x * y^^^2)) + ((-5 * x + -3 * y) / (x + -1 * y))"; neuper@37906: val e231b = the (rewrite_set thy' "rational_erls" false rls' e231b'); neuper@37906: neuper@37906: print("\n\nexample 232:\n"); neuper@37906: print("a)\n"); neuper@37906: val e232a'="((2 * x + 3 * y) / (x)) + ((4 * x^^^3 + -1 * x * y^^^2 + -3 * y^^^3) / (x^^^3 + -2 * x^^^2 * y + x * y^^^2)) + ((-5 * x + -6 * y) / (x + -1 * y))"; neuper@37906: val e232a = the (rewrite_set thy' "rational_erls" false rls' e232a'); neuper@37906: print("b)\n"); neuper@37906: val e232b'="((5 * x + 2 * y) / (x)) + ((2 * x^^^3 + -3 * x * y^^^2 + 3 * x^^^2 * y + -2 * y^^^3) / (x^^^3 + -2 * x^^^2 * y + x * y^^^2)) + ((-6 * x + -3 * y) / (x + -1 * y))"; neuper@37906: val e232b = the (rewrite_set thy' "rational_erls" false rls' e232b'); neuper@37906: neuper@37906: print("\n\nexample 233:\n"); neuper@37906: print("a)\n"); neuper@37906: val e233a'="((5 * x + 6 * y) / (x)) + ((5 * x * y^^^2 + -6 * y^^^3 + -2 * x^^^3 + 3 * x^^^2 * y) / (x^^^3 + -2 * x^^^2 * y + x * y^^^2)) + ((-2 * x + -3 * y) / (x + -1 * y))"; neuper@37906: val e233a = the (rewrite_set thy' "rational_erls" false rls' e233a'); neuper@37906: print("b)\n"); neuper@37906: val e233b'="((6 * x + 5 * y) / (x)) + ((4 * x^^^2 * y + 3 * x * y^^^2 + -5 * y^^^3 + -2 * x^^^3) / (x^^^3 + -2 * x^^^2 * y + x * y^^^2)) + ((-3 * x + -2 * y) / (x + -1 * y))"; neuper@37906: val e233b = the (rewrite_set thy' "rational_erls" false rls' e233b'); neuper@37906: neuper@37906: print("\n\nexample 234:\n"); neuper@37906: print("a)\n"); neuper@37906: val e234a'="((5 * a + b) / (2 * a * b + -2 * b^^^2)) + ((-3 * a + -1 * b) / (2 * a * b + 2 * b^^^2)) + ((-2 * a) / (a^^^2 + -1 * b^^^2))"; neuper@37906: val e234a = the (rewrite_set thy' "rational_erls" false rls' e234a'); neuper@37906: print("b)\n"); neuper@37906: val e234b'="((5 * a + 3 * b) / (6 * a * b + -18 * b^^^2)) + ((-3 * a + -3 * b) / (6 * a * b + 18 * b^^^2)) + ((-2 * a) / (a^^^2 + -9 * b^^^2)) "; neuper@37906: val e234b = the (rewrite_set thy' "rational_erls" false rls' e234b'); neuper@37906: neuper@37906: print("\n\nexample 235:\n"); neuper@37906: print("a)\n"); neuper@37906: val e235a'="((10 * x + 3 * y) / (12 * x * y + -18 * y^^^2)) + ((-6 * x + -3 * y) / (12 * x * y + 18 * y^^^2)) + ((-4 * x) / (4 * x^^^2 + -9 * y^^^2))"; neuper@37906: val e235a = the (rewrite_set thy' "rational_erls" false rls' e235a'); neuper@37906: print("b)\n"); neuper@37906: val e235b'="((8 * a + b) / (4 * a * b + -2 * b^^^2)) + ((-4 * a + -1 * b) / (4 * a * b + 2 * b^^^2)) + ((-2 * a) / (4 * a^^^2 + -1 * b^^^2)) "; neuper@37906: val e235b = the (rewrite_set thy' "rational_erls" false rls' e235b'); neuper@37906: neuper@37906: print("\n\nexample 236:\n"); neuper@37906: print("a)\n"); neuper@37906: val e236a'="((8 * a + 5 * b) / (20 * a * b + -50 * b^^^2)) + ((-4 * a + -5 * b) / (20 * a * b + 50 * b^^^2)) + ((-2 * a) / (4 * a^^^2 + -25 * b^^^2))"; neuper@37906: val e236a = the (rewrite_set thy' "rational_erls" false rls' e236a'); neuper@37906: print("b)\n"); neuper@37906: val e236b'="((24 * x + y) / (6 * x * y + -2 * y^^^2)) + ((-18 * x + -1 * y) / (6 * x * y + 2 * y^^^2)) + ((-15 * x) / (9 * x^^^2 + -1 * y^^^2)) "; neuper@37906: val e236b = the (rewrite_set thy' "rational_erls" false rls' e236b'); neuper@37906: neuper@37906: print("\n\nexample heuberger:\n"); neuper@37906: val eheu'="(x^^^4 + x * y + x^^^3 * y + y^^^2) / (x + 5 * x^^^2 + y + 5 * x * y + x^^^2 * y^^^3 + x * y^^^4)"; neuper@37906: val eheu = the (rewrite_set thy' "rational_erls" false rls' eheu'); neuper@37906: neuper@37906: print("\n\nexample stiefel:\n"); neuper@37906: val est1'="(7) / (-14) + (-2) / (4)"; neuper@37906: val est1 = the (rewrite_set thy' "rational_erls" false rls' est1'); neuper@37906: if est1 = ("(-1) / 1",[]) then () neuper@38031: else error "new behaviour in rationals.sml: est1'"; neuper@37906: -------------------------------------------------------------------------*) neuper@37906: neuper@37906: neuper@37906: (* neuper@37906: val t = (term_of o the o (parse thy)) neuper@37906: "(9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)"; neuper@37926: val SOME (t',_) = factor_expanded_ thy t; neuper@37906: term2str t'; neuper@37906: neuper@37906: "((-3) - x) * ((-3) + x) / (((-3) + x) * ((-3) + x))" neuper@37906: "(3 + x) * (3 - x) / ((3 - x) * (3 - x))" neuper@37906: *) neuper@37906: neuper@37906: neuper@37906: neuper@37906: (*WN.28.8.02: tests for the 'reverse-rewrite' functions: neuper@37906: these are defined in Rationals.ML and stored in neuper@37906: the 'reverse-ruleset' cancel*) neuper@37906: neuper@37906: (*the term for which reverse rewriting is demonstrated*) neuper@37906: val t = (term_of o the o (parse thy)) neuper@37906: "(9 - x ^^^ 2) / (9 + 6 * x + x ^^^ 2)"; neuper@37906: val Rrls {scr=Rfuns {init_state=ini,locate_rule=loc, neuper@37906: next_rule=nex,normal_form=nor,...},...} = cancel; neuper@37906: neuper@37906: (*normal_form produces the result in ONE step*) neuper@37926: val SOME (t',_) = nor t; neuper@37906: term2str t'; neuper@37906: neuper@37906: (*initialize the interpreter state used by the 'me'*) neuper@37906: val (t,_,revsets,_) = ini t; neuper@37906: neuper@37906: (*find the rule 'r' to apply to term 't'*) neuper@37926: val SOME r = nex revsets t; neuper@37906: (*val r = Thm ("sym_#mult_2_3","6 = 2 * 3") : rule*) neuper@37906: neuper@37906: (*check, if the rule 'r' applied by the user to 't' belongs to the ruleset; neuper@37906: if the rule is OK, the term resulting from applying the rule is returned,too; neuper@37906: there might be several rule applications inbetween, neuper@37906: which are listed after the thead in reverse order*) neuper@37906: val (r,(t,asm))::_ = loc revsets t r; neuper@37906: term2str t; neuper@37906: "(9 - x ^^^ 2) / (3 ^^^ 2 + 6 * x + x ^^^ 2)"; neuper@37906: neuper@37906: (*find the next rule to apply*) neuper@37926: val SOME r = nex revsets t; neuper@37906: (*val r = Thm ("sym_#power_3_2","9 = 3 ^^^ 2") : rule*) neuper@37906: neuper@37906: (*check the next rule*) neuper@37906: val (r,(t,asm))::_ = loc revsets t r; neuper@37906: term2str t; neuper@37906: "(3 ^^^ 2 - x ^^^ 2) / (3 ^^^ 2 + 6 * x + x ^^^ 2)"; neuper@37906: neuper@37906: (*find and check the next rules, rewrite*) neuper@37926: val SOME r = nex revsets t; neuper@37906: val (r,(t,asm))::_ = loc revsets t r; neuper@37906: term2str t; neuper@37906: "(3 ^^^ 2 - x ^^^ 2) / (3 ^^^ 2 + 2 * 3 * x + x ^^^ 2)"; neuper@37906: neuper@37926: val SOME r = nex revsets t; neuper@37906: val (r,(t,asm))::_ = loc revsets t r; neuper@37906: term2str t; neuper@37906: "(3 - x) * (3 + x) / (3 ^^^ 2 + 2 * 3 * x + x ^^^ 2)"; neuper@37906: neuper@37926: val SOME r = nex revsets t; neuper@37906: val (r,(t,asm))::_ = loc revsets t r; neuper@37906: term2str t; neuper@37906: "(3 - x) * (3 + x) / ((3 + x) * (3 + x))"; neuper@37906: neuper@37926: val SOME r = nex revsets t; neuper@37906: val (r,(t,asm))::_ = loc revsets t r; neuper@37906: val ss = term2str t; neuper@37906: if ss = "(3 - x) / (3 + x)" then () neuper@38031: else error "rational.sml: new behav. in rev-set cancel"; neuper@37906: terms2str asm; neuper@37906: neuper@37906: neuper@37906: neuper@37906: (*WN.11.9.02: the 'reverse-ruleset' cancel*) neuper@37906: neuper@37906: (*the term for which reverse rewriting is demonstrated*) neuper@37906: val t = (term_of o the o (parse thy)) neuper@37906: "(9 + (-1)*x^^^2) / (9 + ((-6)*x + x^^^2))"; neuper@37906: val Rrls {scr=Rfuns {init_state=ini,locate_rule=loc, neuper@37906: next_rule=nex,normal_form=nor,...},...} = cancel; neuper@37906: (*normal_form produces the result in ONE step*) neuper@37926: val SOME (t',_) = nor t; neuper@37906: term2str t'; neuper@37906: (*initialize the interpreter state used by the 'me'*) neuper@37906: val (t,_,revsets,_) = ini t; neuper@37906: (* neuper@37906: val [rs] = revsets; neuper@37906: filter_out (eq_Thms ["sym_real_add_zero_left", neuper@37906: "sym_real_mult_0", neuper@37906: "sym_real_mult_1"]) rs; neuper@37906: neuper@37906: 10.10.02: dieser Fall terminiert nicht (make_poly enth"alt zu viele rules) neuper@37926: val SOME r = nex revsets t; neuper@37906: val (r,(t,asm))::_ = loc revsets t r; neuper@37906: term2str t; neuper@37906: neuper@37926: val SOME r = nex revsets t; neuper@37906: val (r,(t,asm))::_ = loc revsets t r; neuper@37906: term2str t; neuper@37906: neuper@37906: ------ revset ---------------------------------------------------- neuper@37906: /// [Thm ("sym_real_add_zero_left","?z = 0 + ?z"), neuper@37906: /// Thm ("sym_real_mult_0","0 = 0 * ?z"), neuper@37906: ! Thm ("sym_#mult_2_(-3)","(-6) * x = 2 * ((-3) * x)"), neuper@37906: ! Thm ("sym_#add_(-3)_3","0 = (-3) + 3"), neuper@37906: neuper@37906: ? Thm ("sym_real_num_collect_assoc", neuper@37906: "[| ?l is_const; ?m is_const |] neuper@37906: ==> (?l + ?m) * ?n + ?k = ?l * ?n + (?m * ?n + ?k)"), neuper@37906: OK Thm ("sym_real_mult_2_assoc","2 * ?z1.0 + ?k = ?z1.0 + (?z1.0 + ?k)"), neuper@37906: OK Thm ("sym_real_add_left_commute","?y + (?x + ?z) = ?x + (?y + ?z)"), neuper@37906: /// Thm ("sym_real_mult_1","?z = 1 * ?z"), neuper@37906: ! Thm ("sym_#power_3_2","9 = 3 ^^^ 2"), neuper@37906: ! Thm ("sym_#mult_-1_-1","1 * x ^^^ 2 = -1 * (-1 * x ^^^ 2)"), neuper@37906: ! Thm ("sym_#mult_-1_3","(-3) * x = -1 * (3 * x)"), neuper@37906: OK Thm ("realpow_twoI","?r1 ^^^ 2 = ?r1 * ?r1" [.]), neuper@37906: OK Thm ("sym_real_add_assoc", neuper@37906: "?z1.0 + (?z2.0 + ?z3.0) = ?z1.0 + ?z2.0 + ?z3.0"), neuper@37906: OK Thm neuper@37906: ("sym_real_mult_assoc","?z1.0 * (?z2.0 * ?z3.0) = ?z1.0 * ?z2.0 * ?z3.0"), neuper@37906: OK Thm ("sym_real_mult_left_commute", neuper@37906: "?z2.0 * (?z1.0 * ?z3.0) = ?z1.0 * (?z2.0 * ?z3.0)"), neuper@37906: OK Thm ("sym_real_mult_commute","?w * ?z = ?z * ?w"), neuper@37906: ? Thm ("sym_real_add_mult_distrib2", neuper@37906: "?w * ?z1.0 + ?w * ?z2.0 = ?w * (?z1.0 + ?z2.0)"), neuper@37906: ? Thm ("sym_real_add_mult_distrib", neuper@37906: "?z1.0 * ?w + ?z2.0 * ?w = (?z1.0 + ?z2.0) * ?w"), neuper@37906: OK Thm ("real_mult_div_cancel2","?k ~= 0 ==> ?m * ?k / (?n * ?k) = ?m / ?n")] neuper@37906: -------- revset ---------------------------------------------------- neuper@37906: neuper@37906: val t = (term_of o the o (parse thy)) "(-6) * x"; neuper@37906: val t = (term_of o the o (parse thy)) neuper@37906: "(9 + (-1)*x^^^2) / (9 + ((-6)*x + x^^^2))"; neuper@37906: val thm = (mk_thm thy "(-6) * x = 2 * ((-3) * x)") neuper@37906: handle e => print_exn e; neuper@37926: val SOME (t',_) = rewrite_ thy e_rew_ord e_rls false thm t; neuper@37906: term2str t'; neuper@37906: ----------------------------------------------------------------------*) neuper@37906: neuper@37906: neuper@37906: neuper@37906: (* SK: Testbeispiele --- WN kopiert Rational.ML -> rational.sml----- neuper@37906: neuper@37906: val t1 = (term_of o the o (parse thy)) "((3 * x^^^2 + 6 *x + 3) / (2*x + 2))"; neuper@37926: val SOME (t1',rest)= cancel_ thy t1; neuper@37926: val SOME (t1'',_)= factor_out_gcd_ thy t1; neuper@37906: print(term2str t1'^" + Einschr\"ankung: "^term2str (hd(rest))); neuper@37906: term2str t1''; neuper@37906: neuper@37906: val t1 = (term_of o the o (parse thy)) "((-3 * x^^^2 + 6 *x - 3) / (2*x - 2))"; neuper@37926: val SOME (t1',_)= cancel_ thy t1; neuper@37926: val SOME (t1'',_)= factor_expanded_ thy t1; neuper@37906: term2str t1'; neuper@37906: term2str t1''; neuper@37906: neuper@37906: val t2 = (term_of o the o (parse thy)) "((x+ (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))"; neuper@37926: val SOME (t2',_) = add_fractions_ thy t2; neuper@37926: val SOME (t2'',_) = common_nominators_ thy t2; neuper@37906: term2str t2'; neuper@37906: term2str t2''; neuper@37906: neuper@37906: val t2 = (term_of o the o (parse thy)) "((x - 1) / (x + 1)) + ((x + 1) / (x - 1))"; neuper@37926: val SOME (t2',_) = add_expanded_frac_ thy t2; neuper@37926: val SOME (t2'',_) = common_expanded_nom_ thy t2; neuper@37906: term2str t2'; neuper@37906: term2str t2''; neuper@37906: neuper@37906: neuper@37906: val t3 = (term_of o the o (parse thy)) "((1) / (2*x + 2)) + ((1) / (2*x + (-2))) + ((1) / ( x^^^2 + (-1)))+((1) / (x^^^2 + (-2)*x + 1))"; neuper@37926: val SOME (t3',_) = common_nominators_ thy t3; neuper@37926: val SOME (t3'',_) = add_fractions_ thy t3; neuper@37906: (term2str t3'); neuper@37906: (term2str t3''); neuper@37906: neuper@37906: val t3 = (term_of o the o (parse thy)) "((1) / (2*x + 2)) + ((1) / (2*x - 2)) + ((1) / ( x^^^2 - 1))+((1) / (x^^^2 - 2 * x + 1))"; neuper@37926: val SOME (t3',_) = common_expanded_nom_ thy t3; neuper@37926: val SOME (t3'',_) = add_expanded_frac_ thy t3; neuper@37906: (term2str t3'); neuper@37906: (term2str t3''); neuper@37906: -------------------------------*) neuper@37906: neuper@37906: (* neuper@37926: val SOME(t4,t5) = norm_rational_ thy t3; neuper@37906: term2str t4; neuper@37906: term2str (hd(t5));*) neuper@37906: neuper@37906: (*val test1 = (term_of o the o (parse thy)) "1 - x^^^2 - 5 * x^^^5"; neuper@37906: val test2 = (term_of o the o (parse thy)) "1 + (-1) * x ^^^ 2 + (-5) * x ^^^ 5"; neuper@37906: val test2 = (term_of o the o (parse thy)) "1 - x"; neuper@37906: val test2 = (term_of o the o (parse thy)) "1 + (-1) * x"; neuper@37906: term2str(expanded2term(test1)); neuper@37906: term2str(term2expanded(test2)); *) neuper@37906: neuper@37906: neuper@37906: neuper@37906: (* WN kopiert 16.10.02 Rational.ML -> rational.sml-----vvv---*) neuper@37906: neuper@37906: val t=(term_of o the o (parse thy)) "(9 - x^^^2)/(9 - 6*x + x^^^2)"; neuper@37926: val SOME (t',_) = factout_ thy t; neuper@37926: val SOME (t'',_) = cancel_ thy t; neuper@37906: term2str t'; neuper@37906: term2str t''; neuper@37906: "(3 + x) * (3 - x) / ((3 - x) * (3 - x))"; neuper@37906: "(3 + x) / (3 - x)"; neuper@37906: neuper@37906: val t=(term_of o the o(parse thy)) neuper@37906: "(9 - x^^^2) / (9 - 6*x + x^^^2) + 1 / (3 - x)"; neuper@37926: val SOME (t',_) = common_nominator_ thy t; neuper@37926: val SOME (t'',_) = add_fraction_ thy t; neuper@37906: term2str t'; neuper@37906: term2str t''; neuper@37906: "(9 - x ^^^ 2) / ((3 - x) * (3 - x)) + 1 * (3 - x) / ((3 - x) * (3 - x))"; neuper@37906: "(4 + x) / (3 - x)"; neuper@37906: neuper@37906: (*WN.16.10.02 hinzugef"ugt -----vv---*) neuper@37906: val t=(term_of o the o(parse thy)) neuper@37906: "(9 - x^^^2) / (9 - 6*x + x^^^2) + 1"; neuper@37926: val SOME (t',_) = common_nominator_ thy t; neuper@37926: val SOME (t'',_) = add_fraction_ thy t; neuper@37906: term2str t'; neuper@37906: term2str t''; neuper@37906: "(9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2) +\ neuper@37906: \1 * (9 - 6 * x + x ^^^ 2) / (9 - 6 * x + x ^^^ 2)"; neuper@37906: "6 / (3 - x)"; neuper@37906: neuper@37906: val t=(term_of o the o(parse thy)) neuper@37906: "1 + (9 - x^^^2) / (9 - 6*x + x^^^2)"; neuper@37926: val SOME (t',_) = common_nominator_ thy t; neuper@37926: val SOME (t'',_) = add_fraction_ thy t; neuper@37906: term2str t'; neuper@37906: term2str t''; neuper@37906: "1 * (9 - 6 * x + x ^^^ 2) / (9 - 6 * x + x ^^^ 2) +\ neuper@37906: \(9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)"; neuper@37906: "6 / (3 - x)"; neuper@37906: (*WN.16.10.02 hinzugef"ugt -----^^---*) neuper@37906: neuper@37906: val t=(term_of o the o (parse thy)) neuper@37906: "(y^^^2 - x^^^2)/(y^^^2 - 2*y*x + x^^^2)"; neuper@37926: val SOME (t',_) = factout_ thy t; neuper@37926: val SOME (t'',_) = cancel_ thy t; neuper@37906: term2str t'; neuper@37906: term2str t''; neuper@37906: "(y + x) * (y - x) / ((y - x) * (y - x))"; neuper@37906: "(y + x) / (y - x)"; neuper@37906: neuper@37906: val t=(term_of o the o (parse thy)) neuper@37906: "(y^^^2 - x^^^2)/(y^^^2 - 2*y*x + x^^^2) + 1 / (y - x)"; neuper@37926: val SOME (t',_) = common_nominator_ thy t; neuper@37926: val SOME (t'',_) = add_fraction_ thy t; neuper@37906: term2str t'; neuper@37906: term2str t''; neuper@37906: "((-1) * x ^^^ 2 + y ^^^ 2) / (((-1) * x + y) * ((-1) * x + y)) +\ neuper@37906: \1 * ((-1) * x + y) / (((-1) * x + y) * ((-1) * x + y))"; neuper@37906: "((-1) - x - y) / (x - y)"; neuper@37906: (*WN.16.10.02 ^^^^^^^ Reihenfolge aus Angabe umgekehrt ?!*) neuper@37906: neuper@37906: val t=(term_of o the o (parse thy)) neuper@37906: "(x^^^2 - y^^^2)/(x^^^2 - 2*x*y + y^^^2) + 1 / (x - y)"; neuper@37926: val SOME (t',_) = common_nominator_ thy t; neuper@37926: val SOME (t'',_) = add_fraction_ thy t; neuper@37906: term2str t'; neuper@37906: term2str t''; neuper@37906: "((-1) * y ^^^ 2 + x ^^^ 2) / (((-1) * y + x) * ((-1) * y + x)) +\ neuper@37906: \1 * ((-1) * y + x) / (((-1) * y + x) * ((-1) * y + x))"; neuper@37906: "((-1) - y - x) / (y - x)"; neuper@37906: (*WN.16.10.02 ^^^^^^^ lexicographische Ordnung ?!*) neuper@37906: neuper@37906: val t=(term_of o the o (parse thy)) neuper@37906: "(y^^^2 - x^^^2)/(y^^^2 - 2*y*x + x^^^2)"; neuper@37926: val SOME (t',_) = norm_expanded_rat_ thy t; neuper@37906: term2str t'; neuper@37906: "(y + x) / (y - x)"; neuper@37926: (*val SOME (t'',_) = norm_rational_ thy t; neuper@37906: term2str t''; neuper@37906: *** RATIONALS_TERM2POLY_EXCEPTION: Invalid Polynomial neuper@37906: WN.16.10.02 ?!*) neuper@37906: neuper@37906: val t=(term_of o the o (parse thy)) neuper@37906: "(9 - x^^^2)/(9 - 6*x + x^^^2) + (1)/(3 + x)"; neuper@37926: val SOME (t',_) = norm_expanded_rat_ thy t; neuper@37906: term2str t'; neuper@37906: "(12 + 5 * x + x ^^^ 2) / (9 - x ^^^ 2)"; neuper@37926: (*val SOME (t'',_) = norm_rational_ thy t; neuper@37906: term2str t''; neuper@37906: *** RATIONALS_TERM2POLY_EXCEPTION: Invalid Polynomial neuper@37906: WN.16.10.02 ?!*) neuper@37906: neuper@37906: val t=(term_of o the o (parse thy)) neuper@37906: "(9 + (-1)* x^^^2)/(9 + (-1)* 6*x + x^^^2) + (1)/(3 + x)"; neuper@37926: val SOME (t',_) = norm_expanded_rat_ thy t; neuper@37926: val SOME (t'',_) = norm_rational_ thy t; neuper@37906: term2str t'; neuper@37906: term2str t''; neuper@37906: "(12 + 5 * x + x ^^^ 2) / (9 - x ^^^ 2)"; neuper@37906: "(12 + 5 * x + x ^^^ 2) / (9 + (-1) * x ^^^ 2)"; neuper@37906: (* WN kopiert 16.10.02 Rational.ML -> rational.sml-----^^^---*) neuper@37906: neuper@37906: neuper@37906: