How to disable 'experimental' warning? - vala

I love chained relational feature (e.g. 0 < a < b that replaces 0 < a && a < b) ... but the feature is experimental currently. How to disable/ignore 'experimental' warning?

Pass --enable-experimental to valac.

Related

How to replace an observation in a attribute table using if-then conditional statement in ARC GIS Pro

I have an attribute table with a column that has many observations below a chemical detection limit - 0.005. Since these are not valid measurements, I would like to replace all values in the field under 0.005 with the value 0.0025. So: if observation < 0.005 then replace with 0.0025.
I am not familiar with python coding but using calculate field I have tried (unsuccessfully) to reclassify values to another value using:
def Reclass(arg):
if arg is < 0.005:
return 0.0025
This worked. Choose Python in the dropdown:
def r(fld):
if fld is None or fld >= 0.005:
return fld
elif fld < 0.005:
return 0.0025

QuickSort Sortorder

I'm trying to implement quicksort for my library based on this post Delphi : Sorted List
I am not 100% sure how to implement a sort order ascending/descending into this.
Do I just switch the comperator in if Lo<=Hi then begin and until Lo>Hi;?
I admit I don't quite understand this.
You only need to reverse the comparison in these two lines
while List[Lo] < Mid do Inc(Lo) ;
while List[Hi] > Mid do Dec(Hi) ;
So make that
while List[Lo] > Mid do Inc(Lo) ;
while List[Hi] < Mid do Dec(Hi) ;

Why does Dafny think there might be a problem with this precondition when using a ghost variable?

Let's say I have the following class:
class Testing {
ghost var myGhostVar: int;
method Init()
modifies this
ensures this.myGhostVar == -1
{
this.myGhostVar := -1;
assert this.myGhostVar == -1;
}
method MyTestingMethod(list: array<int>, t: int)
modifies this
requires list.Length > 1
requires this.myGhostVar == -1
requires t == -1
ensures MyPredicate(list, myGhostVar)
ensures this.myGhostVar < list.Length
{
this.Init();
assert this.myGhostVar < 0;
assert list.Length > 0;
assert this.myGhostVar < list.Length;
}
predicate MyPredicate(list: array<int>, startIndex: int)
requires startIndex < list.Length
{
true
}
}
For some reason, Dafny say that the call to MyPredicate(...) might not hold. But if I instead use t as the argument instead of myGhostVar; Dafny has no complaints.
Both have the same requires predicate which makes it all a bit confusing. Is it something that I am missing when using ghost variables?
It's not an issue with ghost variables - you could check and see that you'd have the same issue if you removed the ghost keyword.
The issue is that to call MyPredicate(list, myGhostVar), you need to satisfy the pre-condition, which here would be myGhostVar < list.Length.
You actually have this condition in your ensures clause, which is great!
ensures MyPredicate(list, myGhostVar)
ensures this.myGhostVar < list.Length
But your call to MyPredicate is before the condition you need. Try flipping around the order:
ensures this.myGhostVar < list.Length
ensures MyPredicate(list, myGhostVar)
And you should see that Dafny stops complaining.
In general, Dafny will try to prove that the pre-conditions within an ensures clauses hold using the previous ensures clauses.
Both have the same requires predicate which makes it all a bit confusing. Is it something that I am missing when using ghost variables?
Here, I think you're asking about the clauses
requires this.myGhostVar == -1
requires t == -1
and wondering why it can't use the this.myGhostVar == -1 pre-condition to prove this.myGhostVar < list.Length.
The answer is that the this.myGhostVar == -1 is a pre-condition, meaning Dafny knows that it holds on entry, but the value of this.myGhostVar might change during the execution of the method. So that doesn't help Dafny when checking the post-condition.
Note that Dafny doesn't look at the body of its methods when checking the well-formedness of its post-conditions. For that purpose, Dafny only knows what you tell it in the method signature.

How to fix JavaCC/jjTree error 'The code of method jjMoveNfa_0(int, int) is exceeding the 65535 bytes limit'

I'm writing a file parser using JavaCC/jjTree parser generator (https://javacc.org/)
Since the files to be parsed contain lots of data in a non-standard way (meaning: no CSV etc.) defining the grammar for the parser generator leads to lots and lots of TOKEN definitions.
At some point the automatically generated code for the "TokenManager" exceeds the limit of 65.535 bytes in the method "private int jjMoveNfa_0(int startState, int curPos)".
So my question is: how can one pass a parameter (or convince the JavaCC/jjTree code generator by any other means) to generate code, which does no break the limits?
I faced the the same problem. The reason was the definition of my tokens.
I had a lot of the following definitions:
< MY_TOKEN : "MY_TOKEN" | "TOKEN_VARIANT1" | "TOKEN_VARIANT2" | "TOKEN_VARIANT3" >
So I need to use in parser statement only
< MY_TOKEN >
Solution:
Split the definition into:
< MY_TOKEN : "MY_TOKEN">
| < TOKEN_VARIANT1 : "TOKEN_VARIANT1" >
| < TOKEN_VARIANT2 : "TOKEN_VARIANT2" >
| < TOKEN_VARIANT3 : "TOKEN_VARIANT3" >
Change parser definition into
< MY_TOKEN > | < TOKEN_VARIANT1 > | < TOKEN_VARIANT2 > | < TOKEN_VARIANT3>

Why this Dafny example verification fails?

This is an example to learn Dafny.
method test5(x:array<int>,y:array<int>,n:int)
requires 0<=n
requires 0< x.Length
requires 0< y.Length
requires x[0]==y[0];
requires (x[0]>=0 ==> y[0]>=0)
requires (y[0]>= 0 ==> x[0]>= 0)
requires (x[0]+y[0]==0 || x[0]+y[0]>0);
modifies y;
modifies x;
ensures (x[0]==y[0]);
ensures (x[0]>0 ==> y[0]>0)
ensures (y[0] > 0 ==> x[0] > 0)
ensures (x[0]+y[0]==0 || x[0]+y[0]>0)
{ if (x[0]>0)
{x[0]:=x[0]- 1;
y[0]:=y[0]- 1;
}
}
Why does the verification fails?
Can Dafny show a counterexample?
Yes, you can get a counterexample. If you're using Visual Studio, simply click on the red circle where the error is. This brings up the Verification Debugger. If you're using VS Code, then press F7 (see https://marketplace.visualstudio.com/items?itemName=correctnessLab.dafny-vscode). That will reverify your program and show you some information from the counterexample.
In your case, these counterexamples show x and y as being equal and with x[0]==y[0]==1 initially. Indeed, starting from that initial state, test5 will not establish its declared postcondition.
Rustan

Resources