Index: Compiler/BackEnd/BackendDAEOptimize.mo
===================================================================
--- Compiler/BackEnd/BackendDAEOptimize.mo	(revision None)
+++ Compiler/BackEnd/BackendDAEOptimize.mo	(revision None)
@@ -411,5 +411,5 @@
 algorithm
   (_,_,repl,_,_) := inTpl;
-  (eqns,_) := BackendVarTransform.replaceEquations({eqn},repl,NONE());
+  (eqns,_) := BackendVarTransform.replaceEquations({eqn},repl,SOME(BackendVarTransform.skipPreChangeEdgeOperator));
   // print("Check Equations:\n"); BackendDump.dumpEqns(eqns);
   outTpl := List.fold(eqns,removeSimpleEquationsFastFinder1,inTpl);
@@ -819,5 +819,5 @@
       list<BackendDAE.Var> vars1,vars2,varsa,vars;
       list<Integer> ilst1,ilst2,ilsta,ilst;
-      Boolean varskn1,varskn2,varskn;
+      Boolean varskn1,varskn2,varskn,time1,time2,time_;
       DAE.Exp e;
       DAE.Type ty;
@@ -826,11 +826,11 @@
           print("Found Alias " +& ComponentReference.printComponentRefStr(cr1) +& " = " +& ComponentReference.printComponentRefStr(cr2) +& " Negate:" +& boolString(negate) +& ".\n");
         // get Variables
-        (vars1,ilst1,varskn1) =  getVars(cr1,syst,shared);
-        (vars2,ilst2,varskn2) =  getVars(cr2,syst,shared);
+        (vars1,ilst1,varskn1,time1) =  getVars(cr1,syst,shared);
+        (vars2,ilst2,varskn2,time2) =  getVars(cr2,syst,shared);
         // select Alias
-        (varsa,ilsta,vars,ilst,varskn,e) = selectAliasNew1(vars1,ilst1,varskn1,e1,vars2,ilst2,varskn2,e2);
+        (varsa,ilsta,vars,ilst,varskn,time_,e) = selectAliasNew1(vars1,ilst1,varskn1,time1,e1,vars2,ilst2,varskn2,time2,e2);
         // merge Attributes, move Alias, set Attributes to Var
       then
-        selectAliasNew2(varsa,ilsta,vars,ilst,varskn,negate,e,source,inTpl);  
+        selectAliasNew2(varsa,ilsta,vars,ilst,varskn,time_,negate,e,source,inTpl);  
     case(_,_,_,_,_,_,true,(syst,shared,_,_,_))
       equation
@@ -848,4 +848,5 @@
   input list<Integer> ilst;
   input Boolean varskn;
+  input Boolean time_;
   input Boolean negate;
   input DAE.Exp e;
@@ -854,5 +855,5 @@
   output tuple<BackendDAE.EqSystem,BackendDAE.Shared,BackendVarTransform.VariableReplacements,list<BackendDAE.Equation>,Boolean> outTpl;
 algorithm
-  outTpl := match(varsa,ilsta,vars,ilst,varskn,negate,e,source,inTpl)
+  outTpl := match(varsa,ilsta,vars,ilst,varskn,time_,negate,e,source,inTpl)
     local
       BackendDAE.EqSystem syst;
@@ -867,7 +868,20 @@
       list<Integer> ialst,ilst1;
       list<BackendDAE.Var> valst,vlst;
-    case ({},_,{},_,_,_,_,_,_)
+    case ({},_,{},_,_,_,_,_,_,_)
       then inTpl;      
-    case ((av as BackendDAE.VAR(varName=acr))::valst,ia::ialst,(v as BackendDAE.VAR(varName=cr))::vlst,i::ilst1,_,_,_,_,(syst,shared,repl,eqns,_))
+    // case for time
+    case ((av as BackendDAE.VAR(varName=acr))::valst,ia::ialst,_,_,_,true,_,_,_,(syst,shared,repl,eqns,_))
+      equation
+        cre = Expression.crefExp(DAE.CREF_IDENT("time",DAE.T_REAL_DEFAULT,{}));
+        cre = Debug.bcallret1(negate,Expression.negate,cre,cre);
+        Debug.fcall(Flags.DEBUG_ALIAS,BackendDump.debugStrCrefStrExpStr,("Alias Equation ",acr," = ",cre," found (3).\n"));
+        // store changed var
+        shared = handleAliasVar(av,cre,source,shared);
+        (syst,_) = BackendVariable.removeVarDAE(ia,syst);
+        // add to replacements
+        repl = BackendVarTransform.addReplacement(repl, acr, cre,SOME(BackendVarTransform.skipPreChangeEdgeOperator)); 
+       then
+        selectAliasNew2(valst,ialst,vars,ilst,varskn,time_,negate,e,source,(syst,shared,repl,eqns,true));
+    case ((av as BackendDAE.VAR(varName=acr))::valst,ia::ialst,(v as BackendDAE.VAR(varName=cr))::vlst,i::ilst1,_,_,_,_,_,(syst,shared,repl,eqns,_))
       equation
         cre = Expression.crefExp(cr);
@@ -882,7 +896,7 @@
         (syst,_) = BackendVariable.removeVarDAE(ia,syst);
         // add to replacements
-        repl = BackendVarTransform.addReplacement(repl, cr, cre,NONE()); 
+        repl = BackendVarTransform.addReplacement(repl, acr, cre,SOME(BackendVarTransform.skipPreChangeEdgeOperator)); 
        then
-        selectAliasNew2(valst,ialst,vlst,ilst1,varskn,negate,e,source,(syst,shared,repl,eqns,true));
+        selectAliasNew2(valst,ialst,vlst,ilst1,varskn,time_,negate,e,source,(syst,shared,repl,eqns,true));
   end match;
 end selectAliasNew2;
@@ -927,8 +941,10 @@
   input list<Integer> ilst1;
   input Boolean varskn1;
+  input Boolean time1;
   input DAE.Exp e1;
   input list<BackendDAE.Var> vars2;
   input list<Integer> ilst2;
   input Boolean varskn2;
+  input Boolean time2;
   input DAE.Exp e2;
   output list<BackendDAE.Var> varsa;
@@ -937,21 +953,22 @@
   output list<Integer> ilst;
   output Boolean varskn;
+  output Boolean time_;
   output DAE.Exp e;
 algorithm
-  (varsa,ilsta,vars,ilst,varskn,e) := match(vars1,ilst1,varskn1,e1,vars2,ilst2,varskn2,e2)
+  (varsa,ilsta,vars,ilst,varskn,time_,e) := match(vars1,ilst1,varskn1,time1,e1,vars2,ilst2,varskn2,time2,e2)
     local 
       Boolean b1,b2;
     // parameter - parameter should never happen
-    case(_,_,true,_,_,_,true,_)
+    case(_,_,true,_,_,_,_,true,_,_)
       then fail();
-    case(_,_,true,_,_,_,false,_)
+    case(_,_,true,_,_,_,_,false,_,_)
       equation
         true = List.mapAllValueBool(vars2,replaceableAliasNew,true);
-      then (vars2,ilst2,vars1,ilst1,varskn1,e1);
-    case(_,_,false,_,_,_,true,_)
+      then (vars2,ilst2,vars1,ilst1,varskn1,time1,e1);
+    case(_,_,false,_,_,_,_,true,_,_)
       equation
         true = List.mapAllValueBool(vars1,replaceableAliasNew,true);
-      then (vars1,ilst1,vars2,ilst2,varskn1,e2);
-    case(_,_,false,_,_,_,false,_)
+      then (vars1,ilst1,vars2,ilst2,varskn2,time2,e2);
+    case(_,_,false,_,_,_,_,false,_,_)
       equation
         b1 = List.mapAllValueBool(vars1,replaceableAliasNew,true);
@@ -959,5 +976,5 @@
         (varsa,ilsta,vars,ilst,varskn,e) = selectAliasNew1_1(b1,vars1,ilst1,varskn1,e1,b2,vars2,ilst2,varskn2,e2);
       then
-        (varsa,ilsta,vars,ilst,varskn,e);
+        (varsa,ilsta,vars,ilst,varskn,false,e);
   end match;
 end selectAliasNew1;
@@ -993,10 +1010,10 @@
         i2 = List.fold(il2,intAdd,0);
         b = intGt(i2,i1);
-        ((varsa,ilsta,vars,ilst,varskn,e)) = Util.if_(b,(vars2,ilst2,vars1,ilst1,varskn1,e1),(vars1,ilst1,vars2,ilst2,varskn1,e2));       
+        ((varsa,ilsta,vars,ilst,varskn,e)) = Util.if_(b,(vars2,ilst2,vars1,ilst1,varskn1,e1),(vars1,ilst1,vars2,ilst2,varskn2,e2));       
       then (varsa,ilsta,vars,ilst,varskn,e);
     case(false,_,_,_,_,true,_,_,_,_)
       then (vars2,ilst2,vars1,ilst1,varskn1,e1);
     case(true,_,_,_,_,false,_,_,_,_)
-      then (vars1,ilst1,vars2,ilst2,varskn1,e2);
+      then (vars1,ilst1,vars2,ilst2,varskn2,e2);
   end match;
 end selectAliasNew1_1;
@@ -1035,16 +1052,20 @@
   output list<Integer> oIndexs;
   output Boolean varskn;
-algorithm
-  (oVars,oIndexs,varskn) := matchcontinue(cr,syst,shared)
+  output Boolean time_;
+algorithm
+  (oVars,oIndexs,varskn,time_) := matchcontinue(cr,syst,shared)
+    case (DAE.CREF_IDENT(ident = "time",subscriptLst = {}),_,_)
+      then
+        ({},{},true,true);
     case (_,_,_)
       equation
         (oVars as _::_,oIndexs) = BackendVariable.getVarDAE(cr,syst);
       then
-        (oVars,oIndexs,false);
+        (oVars,oIndexs,false,false);
     case (_,_,_)
       equation
         (oVars as _::_,oIndexs) = BackendVariable.getVarShared(cr,shared);
       then
-        (oVars,oIndexs,true);
+        (oVars,oIndexs,true,false);
   end matchcontinue;
 end getVars;
@@ -1215,5 +1236,4 @@
       DAE.Exp cre,es;
       list<DAE.ComponentRef> crlst;
-      list<Integer> ilst;
       BackendDAE.Var v;
       Integer i;
@@ -1294,5 +1314,5 @@
         Debug.fcall(Flags.DEBUG_ALIAS,BackendDump.debugStrCrefStrExpStr,("Self Generated Var ",cr," = ",exp," found (1).\n"));
         // add to replacements
-        repl = BackendVarTransform.addReplacement(repl, cr, exp,NONE());
+        repl = BackendVarTransform.addReplacement(repl, cr, exp,SOME(BackendVarTransform.skipPreChangeEdgeOperator));
         // remove var from vars        
         (syst,_) = BackendVariable.removeVarDAE(i,syst);        
@@ -1319,5 +1339,5 @@
         (syst,_) = BackendVariable.removeVarDAE(i,syst);
         // add to replacements
-        repl = BackendVarTransform.addReplacement(repl, cr, exp,NONE());
+        repl = BackendVarTransform.addReplacement(repl, cr, exp,SOME(BackendVarTransform.skipPreChangeEdgeOperator));
         repl = Debug.bcallret3(bs,BackendVarTransform.addDerConstRepl,cr,DAE.RCONST(0.0),repl,repl);
       then
@@ -1341,5 +1361,5 @@
         shared = BackendVariable.addKnVarDAE(v,shared);
         // add to replacements if constant
-        repl = Debug.bcallret4(constExp,BackendVarTransform.addReplacement,repl, cr, exp,NONE(),repl);
+        repl = Debug.bcallret4(constExp,BackendVarTransform.addReplacement,repl, cr, exp,SOME(BackendVarTransform.skipPreChangeEdgeOperator),repl);
         // if state der(var) has to replaced to 0
       then
@@ -1391,5 +1411,5 @@
         shared = BackendVariable.addKnVarDAE(v, ishared);
         // update Replacements
-        repl_1 = BackendVarTransform.addReplacement(repl, cr, exp,NONE());        
+        repl_1 = BackendVarTransform.addReplacement(repl, cr, exp,SOME(BackendVarTransform.skipPreChangeEdgeOperator));        
       then (BackendDAE.EQSYSTEM(ordvars1,eqns,m,mT,matching),shared,repl_1,iEqns);
     // a = b alias
@@ -1400,5 +1420,5 @@
         shared = BackendVariable.addAliasVarDAE(v, ishared);
         // update Replacements
-        repl_1 = BackendVarTransform.addReplacement(repl, cr, exp,NONE());
+        repl_1 = BackendVarTransform.addReplacement(repl, cr, exp,SOME(BackendVarTransform.skipPreChangeEdgeOperator));
       then (BackendDAE.EQSYSTEM(ordvars1,eqns,m,mT,matching),shared,repl_1,iEqns);
     // a = der(b) der replacement
@@ -1411,5 +1431,5 @@
         (ordvars1,v) = BackendVariable.removeVar(i,ordvars);
         // update Replacements
-        repl_1 = BackendVarTransform.addReplacement(repl, cr, exp,NONE());        
+        repl_1 = BackendVarTransform.addReplacement(repl, cr, exp,SOME(BackendVarTransform.skipPreChangeEdgeOperator));        
       then (BackendDAE.EQSYSTEM(ordvars1,eqns,m,mT,matching),ishared,repl_1,iEqns);        
   end match;
@@ -1613,5 +1633,5 @@
         pos_1 = pos-1;
         eqn = BackendDAEUtil.equationNth(eqns,pos_1);
-        ({eqn},_) = BackendVarTransform.replaceEquations({eqn}, repl,NONE());
+        ({eqn},_) = BackendVarTransform.replaceEquations({eqn}, repl,SOME(BackendVarTransform.skipPreChangeEdgeOperator));
         varlst = BackendEquation.equationVars(eqn,vars);
         ((vareqns,(syst1,shared1,repl_1,derrepl_1,dereqnarray,meqns1,b))) = removeSimpleEquationsPastFinder1((pos,varlst,compflag,mark,eqn,(syst,shared,repl,derrepl,dereqnarray,meqns,b)));
@@ -1856,5 +1876,5 @@
         shared1 = BackendVariable.addKnVarDAE(v, shared);
         // update Replacements
-        repl_1 = BackendVarTransform.addReplacement(repl, cr, exp,NONE());
+        repl_1 = BackendVarTransform.addReplacement(repl, cr, exp,SOME(BackendVarTransform.skipPreChangeEdgeOperator));
       then (vareqns,BackendDAE.EQSYSTEM(ordvars1,eqns,m,SOME(mT),matching),shared1,repl_1,inDerrepl,iDereqnarray,pos::meqns);
     // Alias a = b 
@@ -1867,5 +1887,5 @@
         shared1 = BackendVariable.addAliasVarDAE(v, shared);
         // update Replacements
-        repl_1 = BackendVarTransform.addReplacement(repl, cr, exp,NONE());
+        repl_1 = BackendVarTransform.addReplacement(repl, cr, exp,SOME(BackendVarTransform.skipPreChangeEdgeOperator));
         // update Assignments
         matching = updateAliasMatching(matching,i,pos);
@@ -1897,5 +1917,5 @@
         (ordvars1,v) = BackendVariable.removeVar(i,ordvars);
         // update Replacements
-        repl_1 = BackendVarTransform.addReplacement(repl, cr, exp,NONE());
+        repl_1 = BackendVarTransform.addReplacement(repl, cr, exp,SOME(BackendVarTransform.skipPreChangeEdgeOperator));
         // update Assignments
         matching = updateAliasMatching(matching,i,pos);
@@ -2451,5 +2471,5 @@
       BackendDAE.Variables ordvars,knvars,exobj,knvars1;
       BackendDAE.Variables aliasVars;      
-      BackendDAE.EquationArray remeqns,inieqns,inieqns1,remeqns1;
+      BackendDAE.EquationArray remeqns,inieqns,remeqns1;
       array<DAE.Constraint> constrs;
       array<DAE.ClassAttributes> clsAttrs;
@@ -2468,16 +2488,15 @@
     case (true,BackendDAE.DAE(systs,BackendDAE.SHARED(knvars,exobj,aliasVars,inieqns,remeqns,constrs,clsAttrs,cache,env,funcTree,BackendDAE.EVENT_INFO(whenClauseLst,zeroCrossingLst,sampleLst,relationsLst,numberOfRealtions),eoc,btp,symjacs)),_)
       equation
-        // replace moved vars in knvars,ineqns,remeqns
+        // replace moved vars in knvars,remeqns
         (aliasVars,(_,varlst)) = BackendVariable.traverseBackendDAEVarsWithUpdate(aliasVars,replaceAliasVarTraverser,(repl,{}));
         aliasVars = List.fold(varlst,fixAliasConstBindings,aliasVars);
         (knvars1,_) = BackendVariable.traverseBackendDAEVarsWithUpdate(knvars,replaceVarTraverser,repl);
-        (inieqns1,_) = BackendEquation.traverseBackendDAEEqnsWithUpdate(inieqns,replaceEquationTraverser,repl);
         (remeqns1,_) = BackendEquation.traverseBackendDAEEqnsWithUpdate(remeqns,replaceEquationTraverser,repl);
-        (whenClauseLst1,_) = BackendVarTransform.replaceWhenClauses(whenClauseLst, repl, NONE());
+        (whenClauseLst1,_) = BackendVarTransform.replaceWhenClauses(whenClauseLst, repl, SOME(BackendVarTransform.skipPreChangeEdgeOperator));
         systs1 = removeSimpleEquationsShared1(systs,{},repl);
         // remove asserts with condition=true from removed equations
         remeqns1 = BackendDAEUtil.listEquation(List.select(BackendDAEUtil.equationList(remeqns1),assertWithCondTrue));
       then 
-        BackendDAE.DAE(systs1,BackendDAE.SHARED(knvars1,exobj,aliasVars,inieqns1,remeqns1,constrs,clsAttrs,cache,env,funcTree,BackendDAE.EVENT_INFO(whenClauseLst1,zeroCrossingLst,sampleLst,relationsLst,numberOfRealtions),eoc,btp,symjacs));
+        BackendDAE.DAE(systs1,BackendDAE.SHARED(knvars1,exobj,aliasVars,inieqns,remeqns1,constrs,clsAttrs,cache,env,funcTree,BackendDAE.EVENT_INFO(whenClauseLst1,zeroCrossingLst,sampleLst,relationsLst,numberOfRealtions),eoc,btp,symjacs));
   end match;
 end removeSimpleEquationsShared;
@@ -10114,13 +10133,13 @@
     matchcontinue(isyst,sharedChanged)
     local
-      BackendDAE.Variables orderedVars "orderedVars ; ordered Variables, only states and alg. vars" ;
-      BackendDAE.EquationArray orderedEqs "orderedEqs ; ordered Equations" ;
+      BackendDAE.Variables orderedVars,knvars,aliasvars;
+      BackendDAE.EquationArray orderedEqs;
       Option<BackendDAE.IncidenceMatrix> m;
       Option<BackendDAE.IncidenceMatrixT> mT;
       BackendDAE.Matching matching;
       BackendDAE.Shared shared;
-    case (BackendDAE.EQSYSTEM(orderedVars,orderedEqs,m,mT,matching),(shared, _))
-      equation
-        ((_,true)) = BackendDAEUtil.traverseBackendDAEExpsEqnsWithUpdate(orderedEqs,traversersimplifyTimeIndepFuncCalls,(BackendVariable.daeKnVars(shared),false));
+    case (BackendDAE.EQSYSTEM(orderedVars,orderedEqs,m,mT,matching),(shared as BackendDAE.SHARED(knownVars = knvars,aliasVars = aliasvars), _))
+      equation
+        ((_,_,true)) = BackendDAEUtil.traverseBackendDAEExpsEqnsWithUpdate(orderedEqs,traversersimplifyTimeIndepFuncCalls,(knvars,aliasvars,false));
       then
         (BackendDAE.EQSYSTEM(orderedVars,orderedEqs,m,mT,matching),(shared,true));
@@ -10132,9 +10151,9 @@
 protected function traversersimplifyTimeIndepFuncCalls "function traversersimplifyTimeIndepFuncCalls
   author: Frenkel TUD 2012-06"
-  input tuple<DAE.Exp,tuple<BackendDAE.Variables,Boolean>> itpl;
-  output tuple<DAE.Exp,tuple<BackendDAE.Variables,Boolean>> outTpl;
+  input tuple<DAE.Exp,tuple<BackendDAE.Variables,BackendDAE.Variables,Boolean>> itpl;
+  output tuple<DAE.Exp,tuple<BackendDAE.Variables,BackendDAE.Variables,Boolean>> outTpl;
 protected
   DAE.Exp e;
-  tuple<BackendDAE.Variables,Boolean> tpl;
+  tuple<BackendDAE.Variables,BackendDAE.Variables,Boolean> tpl;
 algorithm
   (e,tpl) := itpl;
@@ -10144,39 +10163,96 @@
 protected function traverserExpsimplifyTimeIndepFuncCalls "function traverserExpsimplifyTimeIndepFuncCalls
   author: Frenkel TUD 2012-06"
-  input tuple<DAE.Exp,tuple<BackendDAE.Variables,Boolean>> tpl;
-  output tuple<DAE.Exp,tuple<BackendDAE.Variables,Boolean>> outTpl;
+  input tuple<DAE.Exp,tuple<BackendDAE.Variables,BackendDAE.Variables,Boolean>> tpl;
+  output tuple<DAE.Exp,tuple<BackendDAE.Variables,BackendDAE.Variables,Boolean>> outTpl;
 algorithm
   outTpl := matchcontinue(tpl)
     local
-      BackendDAE.Variables vars;
+      BackendDAE.Variables knvars,aliasvars;
       DAE.Type tp;
       DAE.Exp e,zero;
       DAE.ComponentRef cr;
       BackendDAE.Var var;
-    case((DAE.CALL(path=Absyn.IDENT(name = "der"),expLst={DAE.CREF(componentRef=cr,ty=tp)}),(vars,_)))
-      equation
-        (var::{},_) = BackendVariable.getVar(cr, vars);
+      DAE.CallAttributes attr;
+    case((e as DAE.CALL(path=Absyn.IDENT(name = "der"),expLst={DAE.CREF(componentRef=cr,ty=tp)}),(knvars,aliasvars,_)))
+      equation
+        (var::{},_) = BackendVariable.getVar(cr, knvars);
         false = BackendVariable.isVarOnTopLevelAndInput(var);
         (zero,_) = Expression.makeZeroExpression(Expression.arrayDimension(tp));
       then 
-        ((zero,(vars,true)));
-    case((DAE.CALL(path=Absyn.IDENT(name = "pre"),expLst={e as DAE.CREF(componentRef=cr,ty=tp)}),(vars,_)))
-      equation
-        (_::{},_) = BackendVariable.getVar(cr, vars);
-      then
-        ((e,(vars,true)));
-    case((DAE.CALL(path=Absyn.IDENT(name = "change"),expLst={e as DAE.CREF(componentRef=cr,ty=tp)}),(vars,_)))
-      equation
-        (_::{},_) = BackendVariable.getVar(cr, vars);
+        ((zero,(knvars,aliasvars,true)));
+    case((DAE.CALL(path=Absyn.IDENT(name = "pre"),expLst={e as DAE.CREF(componentRef=cr)}),(knvars,aliasvars,_)))
+      equation
+        (_::{},_) = BackendVariable.getVar(cr, knvars);
+      then
+        ((e,(knvars,aliasvars,true)));
+    case((e as DAE.CALL(path=Absyn.IDENT(name = "pre"),expLst={DAE.CREF(componentRef=cr,ty=tp)},attr=attr),(knvars,aliasvars,_)))
+      equation
+        (var::{},_) = BackendVariable.getVar(cr, aliasvars);
+        (cr,_) = BackendVariable.getAlias(var);
+        e = simplifyTimeIndepFuncCallsGetAliasExp(DAE.CALL(Absyn.IDENT("pre"),{DAE.CREF(cr,tp)},attr),knvars);
       then 
-        ((DAE.BCONST(false),(vars,true)));
-    case((DAE.CALL(path=Absyn.IDENT(name = "edge"),expLst={e as DAE.CREF(componentRef=cr,ty=tp)}),(vars,_)))
-      equation
-        (_::{},_) = BackendVariable.getVar(cr, vars);
-      then
-        ((DAE.BCONST(false),(vars,true)));
+        ((e,(knvars,aliasvars,true)));
+    case((DAE.CALL(path=Absyn.IDENT(name = "change"),expLst={e as DAE.CREF(componentRef=cr,ty=tp)}),(knvars,aliasvars,_)))
+      equation
+        (_::{},_) = BackendVariable.getVar(cr, knvars);
+        zero = Expression.arrayFill(Expression.arrayDimension(tp),DAE.BCONST(false));
+      then 
+        ((zero,(knvars,aliasvars,true)));
+    case((DAE.CALL(path=Absyn.IDENT(name = "change"),expLst={e as DAE.CREF(componentRef=cr,ty=tp)},attr=attr),(knvars,aliasvars,_)))
+      equation
+        (var::{},_) = BackendVariable.getVar(cr, aliasvars);
+        (cr,_) = BackendVariable.getAlias(var);
+        e = simplifyTimeIndepFuncCallsGetAliasExp(DAE.CALL(Absyn.IDENT("change"),{DAE.CREF(cr,tp)},attr),knvars);
+      then 
+        ((e,(knvars,aliasvars,true)));
+    case((DAE.CALL(path=Absyn.IDENT(name = "edge"),expLst={e as DAE.CREF(componentRef=cr,ty=tp)}),(knvars,aliasvars,_)))
+      equation
+        (_::{},_) = BackendVariable.getVar(cr, knvars);
+        zero = Expression.arrayFill(Expression.arrayDimension(tp),DAE.BCONST(false));
+      then
+        ((zero,(knvars,aliasvars,true)));
+    case((DAE.CALL(path=Absyn.IDENT(name = "edge"),expLst={e as DAE.CREF(componentRef=cr,ty=tp)},attr=attr),(knvars,aliasvars,_)))
+      equation
+        (var::{},_) = BackendVariable.getVar(cr, aliasvars);
+        (cr,_) = BackendVariable.getAlias(var);
+        e = simplifyTimeIndepFuncCallsGetAliasExp(DAE.CALL(Absyn.IDENT("edge"),{DAE.CREF(cr,tp)},attr),knvars);
+      then 
+        ((e,(knvars,aliasvars,true)));
     case _ then tpl;
   end matchcontinue;
 end traverserExpsimplifyTimeIndepFuncCalls;
+
+protected function simplifyTimeIndepFuncCallsGetAliasExp
+  input DAE.Exp inE;
+  input BackendDAE.Variables knvars;
+  output DAE.Exp outE; 
+algorithm
+  outE := matchcontinue(inE,knvars)
+    local      
+      DAE.ComponentRef cr;
+      DAE.Exp e;
+      DAE.Type tp;
+    case (DAE.CALL(path=Absyn.IDENT(name = "pre"),expLst={e as DAE.CREF(componentRef=cr)}),_)
+      equation
+        (_::{},_) = BackendVariable.getVar(cr, knvars);
+      then
+        e;
+    case(DAE.CALL(path=Absyn.IDENT(name = "change"),expLst={DAE.CREF(componentRef=cr,ty=tp)}),_)
+      equation
+        (_::{},_) = BackendVariable.getVar(cr, knvars);
+        e = Expression.arrayFill(Expression.arrayDimension(tp),DAE.BCONST(false));
+      then 
+        e;
+    case(DAE.CALL(path=Absyn.IDENT(name = "edge"),expLst={DAE.CREF(componentRef=cr,ty=tp)}),_)
+      equation
+        (_::{},_) = BackendVariable.getVar(cr, knvars);
+        e = Expression.arrayFill(Expression.arrayDimension(tp),DAE.BCONST(false));
+      then 
+        e;
+    else
+      then
+        inE;
+  end matchcontinue;
+end simplifyTimeIndepFuncCallsGetAliasExp;
 
 protected function simplifyTimeIndepFuncCallsShared "function simplifyTimeIndepFuncCallsShared
@@ -10206,6 +10282,5 @@
     case (BackendDAE.DAE(systs,BackendDAE.SHARED(knvars,exobj,aliasVars,inieqns,remeqns,constrs,clsAttrs,cache,env,funcTree,eventInfo,eoc,btp,symjacs)))
       equation
-        _ = BackendDAEUtil.traverseBackendDAEExpsEqnsWithUpdate(inieqns,traversersimplifyTimeIndepFuncCalls,(knvars,false));
-        _ = BackendDAEUtil.traverseBackendDAEExpsEqnsWithUpdate(remeqns,traversersimplifyTimeIndepFuncCalls,(knvars,false));
+        _ = BackendDAEUtil.traverseBackendDAEExpsEqnsWithUpdate(remeqns,traversersimplifyTimeIndepFuncCalls,(knvars,aliasVars,false));
       then 
         BackendDAE.DAE(systs,BackendDAE.SHARED(knvars,exobj,aliasVars,inieqns,remeqns,constrs,clsAttrs,cache,env,funcTree,eventInfo,eoc,btp,symjacs));
Index: Compiler/BackEnd/BackendDAEUtil.mo
===================================================================
--- Compiler/BackEnd/BackendDAEUtil.mo	(revision None)
+++ Compiler/BackEnd/BackendDAEUtil.mo	(revision None)
@@ -9141,5 +9141,5 @@
   output BackendDAE.BackendDAE outInitDAE;
 algorithm
-  (outDAE, outInitDAE) := match(inDAE)
+  (outDAE, outInitDAE) := matchcontinue(inDAE)
     local
       BackendDAE.EqSystems systs;
@@ -9154,4 +9154,10 @@
       array<DAE.Constraint> constraints;
       array<DAE.ClassAttributes> classAttrs;
+      
+    case (_)
+      equation
+        false = Flags.isSet(Flags.SOLVE_INITIAL_SYSTEM);
+      then
+        (inDAE,inDAE);      
       
     case(BackendDAE.DAE(systs, BackendDAE.SHARED(knownVars=knvars,
@@ -9203,5 +9209,5 @@
       initdae = solveInitialSystem1(vars, eqns, inDAE, initdae);
     then(inDAE, initdae);
-  end match;
+  end matchcontinue;
 end solveInitialSystem;
 
Index: Compiler/BackEnd/BackendVariable.mo
===================================================================
--- Compiler/BackEnd/BackendVariable.mo	(revision None)
+++ Compiler/BackEnd/BackendVariable.mo	(revision None)
@@ -2019,4 +2019,49 @@
 end varSortFunc;
 
+
+public function getAlias
+" function getAlias
+  autor: Frenkel TUD 2012-11
+  returns the original Varname of an AliasVar"
+  input BackendDAE.Var inVar;
+  output DAE.ComponentRef outCr;
+  output Boolean negated;
+protected
+  DAE.Exp e; 
+algorithm
+  e := varBindExp(inVar);
+  (outCr,negated) := getAlias1(e);
+end getAlias;
+
+protected function getAlias1
+  input DAE.Exp inExp;
+  output DAE.ComponentRef outCr;
+  output Boolean negated;
+algorithm
+  (outCr,negated) :=
+  match (inExp)
+    local
+      DAE.ComponentRef name;
+      Absyn.Path fname;
+    
+    case DAE.CREF(componentRef=name) then (name,false);
+    case DAE.UNARY(operator=DAE.UMINUS(_),exp=DAE.CREF(componentRef=name)) then (name,true);
+    case DAE.UNARY(operator=DAE.UMINUS_ARR(_),exp=DAE.CREF(componentRef=name)) then (name,true);
+    case DAE.LUNARY(operator=DAE.NOT(_),exp=DAE.CREF(componentRef=name)) then (name,true);
+    case DAE.CALL(path=Absyn.IDENT(name = "der"), expLst={DAE.CREF(componentRef=name)})
+      equation
+        name = ComponentReference.crefPrefixDer(name);
+      then (name,false);
+    case DAE.UNARY(operator=DAE.UMINUS(_),exp=DAE.CALL(path=Absyn.IDENT(name = "der"), expLst={DAE.CREF(componentRef=name)}))
+      equation
+       name = ComponentReference.crefPrefixDer(name);
+    then (name,true);
+    case DAE.UNARY(operator=DAE.UMINUS_ARR(_),exp=DAE.CALL(path=Absyn.IDENT(name = "der"), expLst={DAE.CREF(componentRef=name)}))
+      equation
+       name = ComponentReference.crefPrefixDer(name);
+    then (name,true);
+  end match;
+end getAlias1;
+
 /* =======================================================
  *
@@ -2228,4 +2273,11 @@
   BackendDAE.SHARED(knownVars = vars) := shared;
 end daeKnVars;
+
+public function daeAliasVars
+  input BackendDAE.Shared shared;
+  output BackendDAE.Variables vars;
+algorithm
+  BackendDAE.SHARED(aliasVars = vars) := shared;
+end daeAliasVars;
 
 public function varsSize "function: varsSize
Index: Compiler/BackEnd/ExpressionSolve.mo
===================================================================
--- Compiler/BackEnd/ExpressionSolve.mo	(revision None)
+++ Compiler/BackEnd/ExpressionSolve.mo	(revision None)
@@ -376,5 +376,5 @@
         (rhs,asserts);
         
-    // a^b = f(..) -> a = sign(pre(a))*(f(...)^(1/b))   
+    // a^b = f(..) -> a = sign(pre(a))*(f(...)^(1/b))
     case (_,_,DAE.CREF(componentRef = cr),_)
       equation
Index: Compiler/BackEnd/SimCodeUtil.mo
===================================================================
--- Compiler/BackEnd/SimCodeUtil.mo	(revision None)
+++ Compiler/BackEnd/SimCodeUtil.mo	(revision None)
@@ -1812,5 +1812,5 @@
       Integer n_h,maxDelayedExpIndex, uniqueEqIndex, numberofNonLinearSys, numberofEqns, numberOfInitialEquations, numberOfInitialAlgorithms;
       list<SimCode.HelpVarInfo> helpVarInfo;
-      BackendDAE.BackendDAE dlow,dlow2;
+      BackendDAE.BackendDAE dlow,dlow2,initDAE;
       DAE.FunctionTree functionTree;
       BackendDAE.SymbolicJacobians symJacs;
@@ -1863,4 +1863,10 @@
          //Debug.fcall(Flags.CPP_VAR,print, "is that Cpp? : " +& Dump.printBoolStr(ifcpp) +& "\n");
         cname = Absyn.pathStringNoQual(class_);
+
+        // generate initalsystem
+        (_, initDAE) = BackendDAEUtil.solveInitialSystem(dlow);
+        
+        // replace pre(alias) in time-equations
+        dlow = BackendDAEOptimize.simplifyTimeIndepFuncCalls(dlow);
        
         // check if the Sytems has states
@@ -1887,5 +1893,5 @@
         
         // initialization stuff
-        (residuals, initialEquations, numberOfInitialEquations, numberOfInitialAlgorithms, uniqueEqIndex, tempvars, useSymbolicInitialization) = createInitialResiduals(dlow2, uniqueEqIndex, {}, helpVarInfo);
+        (residuals, initialEquations, numberOfInitialEquations, numberOfInitialAlgorithms, uniqueEqIndex, tempvars, useSymbolicInitialization) = createInitialResiduals(dlow2, initDAE, uniqueEqIndex, {}, helpVarInfo);
         (jacG, uniqueEqIndex) = createInitialMatrices(dlow2, uniqueEqIndex);
  
@@ -6405,4 +6411,5 @@
   This function generates all initial_residuals."
   input BackendDAE.BackendDAE inDAE;
+  input BackendDAE.BackendDAE inInitDAE;
   input Integer iuniqueEqIndex;
   input list<SimCode.SimVar> itempvars;
@@ -6416,5 +6423,6 @@
   output Boolean useSymbolicInitialization;
 algorithm
-  (outResiduals, outInitialEqns, outNumberOfInitialEquations, outNumberOfInitialAlgorithms, ouniqueEqIndex, otempvars, useSymbolicInitialization) := matchcontinue(inDAE, iuniqueEqIndex, itempvars, helpVarInfo)
+  (outResiduals, outInitialEqns, outNumberOfInitialEquations, outNumberOfInitialAlgorithms, ouniqueEqIndex, otempvars, useSymbolicInitialization) := 
+  matchcontinue(inDAE, inInitDAE, iuniqueEqIndex, itempvars, helpVarInfo)
     local
       BackendDAE.EqSystems eqs;
@@ -6432,12 +6440,10 @@
       
     // try to solve the inital system symbolical.
-    case (_, _, _, _) equation
-      true = Flags.isSet(Flags.SOLVE_INITIAL_SYSTEM);
-    
-      // generate initalsystem
-      (_, BackendDAE.DAE(systs, 
+    case (_, BackendDAE.DAE(systs, 
                          shared as BackendDAE.SHARED(knownVars=knvars,
                                                      aliasVars=aliasVars,
-                                                     removedEqs=removedEqs))) = BackendDAEUtil.solveInitialSystem(inDAE);
+                                                     removedEqs=removedEqs)),  _, _, _) equation
+      true = Flags.isSet(Flags.SOLVE_INITIAL_SYSTEM);
+
       // generate equations from the solved systems
       (uniqueEqIndex, _, _, allEquations, tempvars) = createEquationsForSystems(systs, shared, helpVarInfo, iuniqueEqIndex, {}, {}, {}, itempvars);
@@ -6457,5 +6463,5 @@
     then (residual_equations, allEquations, numberOfInitialEquations, numberOfInitialAlgorithms, uniqueEqIndex, tempvars, true);
     
-    case (_, _, _, _) equation
+    case (_, _, _, _, _) equation
       (initialEqs_lst, numberOfInitialEquations, numberOfInitialAlgorithms) = BackendDAEOptimize.collectInitialEquations(inDAE);
       (residual_equations, uniqueEqIndex, tempvars) = createNonlinearResidualEquations(initialEqs_lst, iuniqueEqIndex, itempvars);
Index: Compiler/FrontEnd/ExpressionSimplify.mo
===================================================================
--- Compiler/FrontEnd/ExpressionSimplify.mo	(revision None)
+++ Compiler/FrontEnd/ExpressionSimplify.mo	(revision None)
@@ -249,4 +249,14 @@
       then
         ((e,(true,options)));
+    case ((DAE.CALL(path=Absyn.IDENT("change"), expLst={e}), (b, options)))
+      equation
+        ((e,_)) = Expression.traverseExp(e,changeCref,false);
+      then
+        ((e,(true,options)));
+    case ((DAE.CALL(path=Absyn.IDENT("edge"), expLst={e}), (b, options)))
+      equation
+        ((e,_)) = Expression.traverseExp(e,edgeCref,false);
+      then
+        ((e,(true,options)));
         
     // normal call 
@@ -412,4 +422,32 @@
   end match;
 end preCref;
+
+protected function changeCref
+  input tuple<DAE.Exp,Boolean> iExp;
+  output tuple<DAE.Exp,Boolean> oExp;
+algorithm
+  oExp := match(iExp)
+    local
+      DAE.Exp e;
+      Boolean b;
+      DAE.Type ty;
+    case ((e as DAE.CREF(ty=ty),_)) then ((DAE.CALL(Absyn.IDENT("change"),{e},DAE.CALL_ATTR(ty,false,true,DAE.NO_INLINE(),DAE.NO_TAIL())),true));
+    else then iExp;
+  end match;
+end changeCref;
+
+protected function edgeCref
+  input tuple<DAE.Exp,Boolean> iExp;
+  output tuple<DAE.Exp,Boolean> oExp;
+algorithm
+  oExp := match(iExp)
+    local
+      DAE.Exp e;
+      Boolean b;
+      DAE.Type ty;
+    case ((e as DAE.CREF(ty=ty),_)) then ((DAE.CALL(Absyn.IDENT("edge"),{e},DAE.CALL_ATTR(ty,false,true,DAE.NO_INLINE(),DAE.NO_TAIL())),true));
+    else then iExp;
+  end match;
+end edgeCref;
 
 public function simplify1
Index: Compiler/Util/Flags.mo
===================================================================
--- Compiler/Util/Flags.mo	(revision None)
+++ Compiler/Util/Flags.mo	(revision None)
@@ -616,5 +616,4 @@
 //    "countOperations",
     "removeUnusedFunctions",
-    "simplifyTimeIndepFuncCalls",
     "inputDerivativesUsed",
     "detectJacobianSparsePattern",
@@ -641,5 +640,5 @@
     ("collapseIndependentBlocks", Util.gettext("Collapses all equation systems back into one big system again (undo partitionIndependentBlocks)")),
     ("removeUnusedFunctions", Util.gettext("removed all unused functions from functionTree")),
-    ("simplifyTimeIndepFuncCalls", Util.gettext("simplifies time independent built in function calls like pre(param) -> param, der(param) -> 0.0, change(param) -> false, edge(param) -> false")),
+//    ("simplifyTimeIndepFuncCalls", Util.gettext("simplifies time independent built in function calls like pre(param) -> param, der(param) -> 0.0, change(param) -> false, edge(param) -> false")),
     ("inputDerivativesUsed", Util.gettext("checks if derivatives of inputs are need to calculate the model.")),
     ("simplifysemiLinear", Util.gettext("simplifies calls to semiLinear")),
