491 |
491 |
492 |
492 |
493 "--------- inform [rational,simplification] ----------------------"; |
493 "--------- inform [rational,simplification] ----------------------"; |
494 "--------- inform [rational,simplification] ----------------------"; |
494 "--------- inform [rational,simplification] ----------------------"; |
495 "--------- inform [rational,simplification] ----------------------"; |
495 "--------- inform [rational,simplification] ----------------------"; |
496 states:=[]; |
496 states := []; |
497 CalcTree [(["Term (4/x - 3/y - 1)", "normalform N"], |
497 CalcTree [(["Term (a * x / (b * x) + c * x / (d * x) + e / f)", "normalform N"], |
498 ("Rational",["rational","simplification"], |
498 ("Rational", ["rational", "simplification"], ["simplification", "of_rationals"]))]; |
499 ["simplification","of_rationals"]))]; |
|
500 Iterator 1; moveActiveRoot 1; |
499 Iterator 1; moveActiveRoot 1; |
501 autoCalculate 1 CompleteCalcHead; |
500 autoCalculate 1 CompleteCalcHead; |
|
501 |
|
502 "--- (-1) give a preview on the calculation without any input"; |
|
503 (* |
|
504 autoCalculate 1 CompleteCalc; |
|
505 val ((pt, p), _) = get_calc 1; |
|
506 show_pt pt; |
|
507 [ |
|
508 (([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)), |
|
509 (([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f), |
|
510 (([1], Res), a / b + c / d + e / f), <--- (1) input arbitrary |
|
511 (([2], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)), |
|
512 (([3], Res), (a * (d * f) + b * (c * f) + b * (d * e)) / (b * (d * f))), |
|
513 (([4], Res), (a * d * f + b * c * f + b * d * e) / (b * d * f)), <--- (2) input next |
|
514 (([], Res), (a * d * f + b * c * f + b * d * e) / (b * d * f))] <--- (3) is also final result |
|
515 EXAMPLE NOT OPTIMAL |
|
516 *) |
|
517 "--- (0) user input as the *first* step does not work, thus impdo at least 1 step"; |
502 autoCalculate 1 (Step 1); |
518 autoCalculate 1 (Step 1); |
503 autoCalculate 1 (Step 1); |
519 autoCalculate 1 (Step 1); |
|
520 val ((pt, p), _) = get_calc 1; |
|
521 (*show_pt pt; |
|
522 [ |
|
523 (([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)), |
|
524 (([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f), |
|
525 (([1], Res), a / b + c / d + e / f)] |
|
526 *) |
|
527 "--- (1) input an arbitrary next formula"; |
|
528 appendFormula 1 "((a * d) + (c * b)) / (b * d) + e / f"; |
|
529 val ((pt, p), _) = get_calc 1; |
|
530 (*show_pt pt; |
|
531 [ |
|
532 (([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)), |
|
533 (([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f), |
|
534 (([1], Res), a / b + c / d + e / f), |
|
535 (([2,1], Frm), a / b + c / d + e / f), |
|
536 (([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)), |
|
537 (([2,2], Res), (a * d + c * b) / (b * d) + e / f), |
|
538 (([2], Res), (a * d + c * b) / (b * d) + e / f)] |
|
539 *) |
|
540 val ((pt,p),_) = get_calc 1; |
|
541 if p = ([2], Res) andalso (length o children o (get_nd pt)) (fst p) = 2 then () |
|
542 else error ("inform.sml: [rational,simplification] 1"); |
|
543 |
|
544 "--- (2) input the next formula that would be presented by mat-engine"; |
|
545 (* generate a preview: |
504 autoCalculate 1 (Step 1); |
546 autoCalculate 1 (Step 1); |
505 autoCalculate 1 (Step 1); |
547 val ((pt, p), _) = get_calc 1; |
506 "--- input the next formula that _should_ be presented by mat-engine"; |
548 show_pt pt; |
507 appendFormula 1 "(4 * y + -3 * x) / (x * y) + -1"; |
549 [ |
508 val ((pt,p),_) = get_calc 1; |
550 (([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)), |
|
551 (([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f), |
|
552 (([1], Res), a / b + c / d + e / f), |
|
553 (([2,1], Frm), a / b + c / d + e / f), |
|
554 (([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)), |
|
555 (([2,2], Res), (a * d + c * b) / (b * d) + e / f), |
|
556 (([2], Res), (a * d + c * b) / (b * d) + e / f), |
|
557 (([3], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f))] <--- input this |
|
558 *) |
|
559 appendFormula 1 "(b * d * e + b * c * f + a * d * f) / (b * d * f)"; |
|
560 val ((pt, p), _) = get_calc 1; |
|
561 (*show_pt pt; |
|
562 [ |
|
563 (([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)), |
|
564 (([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f), |
|
565 (([1], Res), a / b + c / d + e / f), |
|
566 (([2,1], Frm), a / b + c / d + e / f), |
|
567 (([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)), |
|
568 (([2,2], Res), (a * d + c * b) / (b * d) + e / f), |
|
569 (([2], Res), (a * d + c * b) / (b * d) + e / f), |
|
570 (([3], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f))] |
|
571 *) |
|
572 if p = ([3], Res) andalso (length o children o (get_nd pt)) (fst p) = 0 then () |
|
573 else error ("inform.sml: [rational,simplification] 2"); |
|
574 |
|
575 "--- (3) input the exact final result"; |
|
576 appendFormula 1 "(b * d * e + b * c * f + a * d * f) / (b * d * f)"; |
|
577 val ((pt, p), _) = get_calc 1; |
|
578 (*show_pt pt; |
|
579 [ |
|
580 (([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)), |
|
581 (([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f), |
|
582 (([1], Res), a / b + c / d + e / f), |
|
583 (([2,1], Frm), a / b + c / d + e / f), |
|
584 (([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)), |
|
585 (([2,2], Res), (a * d + c * b) / (b * d) + e / f), |
|
586 (([2], Res), (a * d + c * b) / (b * d) + e / f), |
|
587 (([3], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)), |
|
588 (([4,1], Frm), (b * d * e + b * c * f + a * d * f) / (b * d * f)), |
|
589 (([4,1], Res), (a * (d * f) + b * (c * f) + b * (d * e)) / (b * (d * f))), |
|
590 (([4,2], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)), |
|
591 (([4], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f))] |
|
592 *) |
509 if p = ([4], Res) andalso (length o children o (get_nd pt)) (fst p) = 2 then () |
593 if p = ([4], Res) andalso (length o children o (get_nd pt)) (fst p) = 2 then () |
510 else error ("inform.sml: [rational,simplification] 1"); |
|
511 |
|
512 "--- input the next formula that would be presented by mat-engine"; |
|
513 (*autoCalculate 1 (Step 1);*) |
|
514 appendFormula 1 "(4 * y + -3 * x + -1 * (x * y)) / (x * y)"; |
|
515 val ((pt,p),_) = get_calc 1; |
|
516 if p = ([5], Res) andalso (length o children o (get_nd pt)) (fst p) = 0 then () |
|
517 else error ("inform.sml: [rational,simplification] 2"); |
|
518 |
|
519 "--- input the exact final result";(*TODO: Exception- LIST "last_elem" raised*) |
|
520 appendFormula 1 "(-3 * x + 4 * y + -1 * x * y) / (x * y)"; |
|
521 val ((pt,p),_) = get_calc 1; |
|
522 if p = ([6], Res) andalso (length o children o (get_nd pt)) (fst p) = 2 then () |
|
523 else error ("inform.sml: [rational,simplification] 3"); |
594 else error ("inform.sml: [rational,simplification] 3"); |
524 show_pt pt; |
595 |
|
596 "--- (4) finish the calculation + check the postcondition (in the future)"; |
|
597 autoCalculate 1 CompleteCalc; |
|
598 val ((pt, p), _) = get_calc 1; |
|
599 val (t, asm) = get_obj g_result pt []; |
|
600 if term2str t = "(a * d * f + b * c * f + b * d * e) / (b * d * f)" andalso |
|
601 terms2str asm = "[\"b * d * f ~= 0\",\"d ~= 0\",\"b ~= 0\"," ^ |
|
602 "\"a * x / (b * x) + c * x / (d * x) + e / f is_ratpolyexp\"]" |
|
603 then () else error "inform [rational,simplification] changed at end"; |
|
604 (*show_pt pt; |
|
605 [ |
|
606 (([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)), |
|
607 (([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f), |
|
608 (([1], Res), a / b + c / d + e / f), |
|
609 (([2,1], Frm), a / b + c / d + e / f), |
|
610 (([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)), |
|
611 (([2,2], Res), (a * d + c * b) / (b * d) + e / f), |
|
612 (([2], Res), (a * d + c * b) / (b * d) + e / f), |
|
613 (([3], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)), |
|
614 (([4,1], Frm), (b * d * e + b * c * f + a * d * f) / (b * d * f)), |
|
615 (([4,1], Res), (a * (d * f) + b * (c * f) + b * (d * e)) / (b * (d * f))), |
|
616 (([4,2], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)), |
|
617 (([4], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)), |
|
618 (([5], Res), (a * (d * f) + b * (c * f) + b * (d * e)) / (b * (d * f))), |
|
619 (([6], Res), (a * d * f + b * c * f + b * d * e) / (b * d * f)), |
|
620 (([], Res), (a * d * f + b * c * f + b * d * e) / (b * d * f))] |
|
621 *) |
525 |
622 |
526 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------"; |
623 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------"; |
527 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------"; |
624 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------"; |
528 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------"; |
625 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------"; |
529 val t = str2term "Diff (x^^^2 + x + 1, x)"; |
626 val t = str2term "Diff (x^^^2 + x + 1, x)"; |