CodeTools[ProgramAnalysis]
IsLoopInvariant
verify if a condition is an invariant of a loop
Calling Sequence
Parameters
Description
Examples
Compatibility
IsLoopInvariant(loop, candinv, knowninv, invarianttype = invtype)
loop
-
WhileLoop
candinv
boolean function of polynomial relations; candidate invariant to verify
knowninv
(optional) boolean function in polynomial relations; known invariant of loop
invtype
(optional) one of either plain (default), inductive or absolute ; type of invariant check to perform
This command checks if candinv is an invariant of the WhileLoop loop, returning true if it is and false if it is not.
If any additional invariants of loop are known, they can be given using the optional argument knowninv. The known invariants are used to create weaker candidate invariants from candinv by forming the conjunction of knowninv and candinv.
Boolean functions are used to represent candinv and knowninv. If boolean operators were used, the relations will evaluate prematurely to true or false. In the case of absolute invariants, only a single polynomial equation or an And of polynomial equations are supported.
The value of invtype determines what kind of invariant test is being conducted. By default, it will be checked if candinv is a plain invariant of loop when invtype is plain. It can also be verified if candinv is an inductive or absolute invariant when invtype is inductive or absolute.
with⁡CodeToolsProgramAnalysis:
The following procedure computes the nth Fibonacci number:
Fibonacci := proc(n) local x, y, t; x := 0; y := 1; t := 0; while (y <= n) do t := y; y := x + y; x := t; end do: return x: end proc;
Fibonacci ≔ procnlocalx,y,t;x ≔ 0;y ≔ 1;t ≔ 0;whiley<=ndot ≔ y;y ≔ x+y;x ≔ tend do;returnxend proc
Construct the WhileLoop data structure:
loop≔CreateLoop⁡Fibonacci
loop≔Record⁡WhileLoop,variables=t,x,y,parameters=n,initialization=0,0,1,transitions=,y,y,x+y,guard=y≤n,precondition=,postcondition=,returnvalue=x
Check whether or not −x4−2⁢x3⁢y+x2⁢y2+2⁢y3⁢x−y4+1=0 is an absolute invariant of loop:
IsLoopInvariant⁡loop,1+x2⁢y2−2⁢x3⁢y+2⁢y3⁢x−y4−x4=0,invarianttype=absolute
true
The CodeTools[ProgramAnalysis][IsLoopInvariant] command was introduced in Maple 2016.
For more information on Maple 2016 changes, see Updates in Maple 2016.
See Also
CodeTools[ProgramAnalysis][LoopInvariant]
CodeTools[ProgramAnalysis][VerifyLoop]
CodeTools[ProgramAnalysis][CreateLoop]
Download Help Document