@@ -50,6 +50,7 @@ module DAELow:
5050
5151
5252 datatype Equation = EQUATION of Exp.Exp * Exp.Exp
53+ | SOLVED_EQUATION of Exp.ComponentRef * Exp.Exp
5354 | ALGORITHM of int (* index in algorithms*) *
5455 Exp.Exp list *(*inputs CREF or der(CREF)*)
5556 Exp.Exp list(*outputs CREF or der(CREF)*)
@@ -439,10 +440,16 @@ relation equation_str: Equation => string =
439440
440441 rule Exp.print_exp_str e1 => s1 &
441442 Exp.print_exp_str e2 => s2 &
442- Util.string_append_list([s1,"= ",s2]) => res
443+ Util.string_append_list([s1," = ",s2]) => res
443444 --------------------
444445 equation_str(EQUATION(e1,e2)) => res
445446
447+ rule Exp.print_component_ref_str cr => s1 &
448+ Exp.print_exp_str e2 => s2 &
449+ Util.string_append_list([s1," := ",s2]) => res
450+ --------------------
451+ equation_str(SOLVED_EQUATION(cr,e2)) => res
452+
446453 rule int_string(i) => is &
447454 Util.string_append_list(["Algorithm no: ",is,"\n"]) => res
448455 ----------------------------------------------------------
@@ -468,11 +475,12 @@ relation remove_simple_equations: (Variables, (* vars *)
468475 => (eqns',seqns,movedvars',vartransf) &
469476 (*VarTransform.dump_replacements(vartransf) => () &*)
470477 VarTransform.replace_equations(eqns',vartransf) => eqns'' &
478+ VarTransform.replace_equations(seqns,vartransf) => seqns' &
471479 move_variables(vars,knvars,movedvars')=> (vars',knvars')
472480 (*& print_vars_statistics(vars',knvars')*)
473481 -------------------------------------
474482 remove_simple_equations(vars,knvars,eqns,reqns,states)
475- => (vars',knvars',eqns'',seqns)
483+ => (vars',knvars',eqns'',seqns' )
476484
477485 rule print "-remove_simple_equations failed\n"
478486 ------------------------
@@ -509,6 +517,7 @@ relation remove_simple_equations2: (Equation list, (* all equations*)
509517
510518 rule (* cr1 is state and cr2 not, remove equation and cr2*)
511519 simple_equation(e) => (cr1,cr2) &
520+ typeof_equation(e) => t &
512521 VarTransform.apply_replacements(repl,cr1,cr2) => (cr1,cr2) &
513522 tree_get(states,cr1) => _ &
514523 not VarTransform.get_replacement(repl,cr2) => _ &
@@ -519,10 +528,11 @@ relation remove_simple_equations2: (Equation list, (* all equations*)
519528 => (eqns',seqns',mvars'',repl'')
520529 --------------------------------------------------
521530 remove_simple_equations2(e::eqns,vars,knvars,mvars,states,repl)
522- => (eqns',e ::seqns',mvars'',repl'')
531+ => (eqns',SOLVED_EQUATION(cr2,Exp.CREF(cr1,t)) ::seqns',mvars'',repl'')
523532
524533 rule (* as above but swapped args.*)
525534 simple_equation(e) => (cr2,cr1) &
535+ typeof_equation(e) => t &
526536 VarTransform.apply_replacements(repl,cr1,cr2) => (cr1,cr2) &
527537 tree_get(states,cr1) => _ &
528538 VarTransform.add_replacement(repl,cr2,cr1) => repl' &
@@ -532,10 +542,11 @@ relation remove_simple_equations2: (Equation list, (* all equations*)
532542 => (eqns',seqns',mvars'',repl'')
533543 --------------------------------------------------
534544 remove_simple_equations2(e::eqns,vars,knvars,mvars,states,repl)
535- => (eqns',e ::seqns',mvars'',repl'')
545+ => (eqns',SOLVED_EQUATION(cr2,Exp.CREF(cr1,t)) ::seqns',mvars'',repl'')
536546
537547 rule (* cr1 variable, cr2 constant, remove equation and cr1 *)
538548 simple_equation(e) => (cr1,cr2) &
549+ typeof_equation(e) => t &
539550 VarTransform.apply_replacements(repl,cr1,cr2) => (cr1,cr2) &
540551 is_variable(cr1,vars,knvars) &
541552 not is_variable(cr2,vars,knvars) &
@@ -546,10 +557,11 @@ relation remove_simple_equations2: (Equation list, (* all equations*)
546557 => (eqns',seqns',mvars'',repl'')
547558 --------------------------------------------------
548559 remove_simple_equations2(e::eqns,vars,knvars,mvars,states,repl)
549- => (eqns',e ::seqns',mvars'',repl'')
560+ => (eqns',SOLVED_EQUATION(cr1,Exp.CREF(cr2,t)) ::seqns',mvars'',repl'')
550561
551562 rule (* same as above but swapped args *)
552563 simple_equation(e) => (cr2,cr1) &
564+ typeof_equation(e) => t &
553565 VarTransform.apply_replacements(repl,cr1,cr2) => (cr1,cr2) &
554566 is_variable(cr1,vars,knvars) &
555567 not is_variable(cr2,vars,knvars) &
@@ -560,11 +572,12 @@ relation remove_simple_equations2: (Equation list, (* all equations*)
560572 => (eqns',seqns',mvars'',repl'')
561573 --------------------------------------------------
562574 remove_simple_equations2(e::eqns,vars,knvars,mvars,states,repl)
563- => (eqns',e ::seqns',mvars'',repl'')
575+ => (eqns',SOLVED_EQUATION(cr1,Exp.CREF(cr2,t)) ::seqns',mvars'',repl'')
564576
565577
566578 rule (* None are states, but variables, remove equation *)
567579 simple_equation(e) => (cr1,cr2) &
580+ typeof_equation(e) => t &
568581 VarTransform.apply_replacements(repl,cr1,cr2) => (cr1,cr2) &
569582 not tree_get(states,cr1) => _ &
570583 not tree_get(states,cr2) => _ &
@@ -577,7 +590,7 @@ relation remove_simple_equations2: (Equation list, (* all equations*)
577590 => (eqns',seqns',mvars'',repl'')
578591 --------------------------------------------------
579592 remove_simple_equations2(e::eqns,vars,knvars,mvars,states,repl)
580- => (eqns',e ::seqns',mvars'',repl'')
593+ => (eqns',SOLVED_EQUATION(cr1,Exp.CREF(cr2,t)) ::seqns',mvars'',repl'')
581594
582595 rule (* Not a simple variable, check rest*)
583596 remove_simple_equations2(eqns,vars,knvars,mvars,states,repl)
@@ -587,6 +600,21 @@ relation remove_simple_equations2: (Equation list, (* all equations*)
587600 => (e::eqns',seqns',mvars',repl')
588601end
589602
603+ (** relation typeof_equation
604+ ** Returns the Exp.Type of an equation
605+ **)
606+ relation typeof_equation: (Equation) => Exp.Type =
607+
608+ rule Exp.typeof(e) => t
609+ -------------------
610+ typeof_equation(EQUATION(e,_)) => t
611+
612+ rule Exp.typeof(e) => t
613+ -------------------
614+ typeof_equation(SOLVED_EQUATION(_,e)) => t
615+ end
616+
617+
590618(** relation: move_variables
591619 ** This relation takes the two variable lists of a dae (states+alg) and known vars
592620 ** and moves a set of variables from the first to the second set.
0 commit comments