Skip to content

Solvability requirement for non-Real if-equations #3779

@HansOlsson

Description

@HansOlsson

Separated out from: #3763

Consider:

model A
  Boolean b=time<2;
  Integer i, j;
equation 
  if b then
    i=2;
  else
    j=4;
  end if;
  i+j=5;
end A;

This illustrates that equation for non-Real shouldn't only require that the variables are in "almost solved form", but also if-equations with non-evaluable conditions must have the same variables in "almost solved form" in order to easily handle the equation.

The problem is exactly how to formulate the requirement.

model B
  Boolean b=time<2;
  Integer i, j, k, m;
equation 
  k=2;
  m=4;
  if b then
    j=k+m;
  else
    j=4-m;
  end if;
  j=i+5;
end B;

Doesn't have the same set of variables solvable in all branches, but it has a set of variables (j,m) solvable in all branches. (If the last equation were j=i*2+5 the overall system wouldn't be solvable, but that is a global check, not a local one.)

One simple approach to handle if-equations is to merge the branches to construct if-expressions. That cannot be done uniquely here as it would either be j=if b then k+m else 4-m; or m=if b then j-k else 4+j;, but it is not possible to have both j and m in almost solved form in the same merged equation.

If there are multiple equations with multiple variables it may even be difficult to find all possibilities.

So, it seems quite complicated.

One simple restriction would be to restrict them even further and state that for non-Real equation in non-evaluable if-equations there must appear unique variables in the left-hand-sides of the equations in all branches, as the "almost solved form" was primarily to handle connection-sums and similar cases that aren't needed inside if-equations. If that is too restrictive we can later extend it.

Note that this is just for non-Real equations, excluding e.g., j=x*0.5;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions