Concurrent assignment to local variables - system-verilog

In the following assertion what will be the value of x if both subsequences end at the same time? Will it be indeterministic?
sequence s1;
int x;
((a ##[1:5] b, x = data1) or (d ##2 e, x = data2)) ##1 (data == x);
endsequence
if both subsequences (a ##[1:5] b) and (d ##2 e) match at the same time, what will be the value assigned to x?
Thanks.

Related

Holding greater or equal relation between two terms

H:count k (match d with
|nil=>nil
|s::l=>(s::firstn n l))
end <=
count 0 (match d with
|nil=>nil
|s::l=>(s::firstn n l))
end
Where n is natural number and d is list nat. From above H may i extract information that (s::firstn n l) contains more zeros than k.

COQ: How to use "<=" for Z and R in the same lemma?

Suppose I already defined floor (from R to Z). Now I want to prove that n <= x implies n <= floor(x), where n : Z, x : R.
I tried:
Lemma l: forall (n:Z) (x:R), (IZR n) <= x -> n <= (floor x).
but I'm getting the error The term n has type Z while it is expected to have type R.
How should I write this? Is there a way that I can use <= for Z and R simultaneously?
In order to override the default interpretation of a notation, you can open a notation scope locally using %key:
Lemma l : forall n x, (IZR n <= x)%R -> (n <= floor x)%Z.

How to compare two elements of list

I have a list with all elements equal to zero and the length of the list not equal to zero. I want to prove the following and compare both
(length l=?0)=false->
k < length l ->
(forall k, nth k l 0 = 0)->
1<=count 0 l.
(length l=?0)=false->
(forall k, nth k l 0 = 0) ->
(S n) < length l ->
count (S n) l = 0.
count (S n) l < count 0 l.
Fixpoint count (v:nat) (s:list nat) : nat :=
match s with
| [] => 0
| h :: t => (if beq_nat h v then 1 else 0) + (count v t) end.

Coq - Proving condition about elements of sequence in Ssreflect

I have a goal that looks like this:
x \in [seq (f v j) | j <- enum 'I_m & P v j] -> 0 < x
In the above, f is a definition generating a solution of an inequality depending on v, j and P v j is a predicate restricting j to indices which satisfy another inequality.
I have already proven that Goal : P v j -> (f v j > 0), but how can I use this to prove that it holds for any x in the sequence? I have found just a few relevant lemmas like nthP which introduce sequence manipulation, which I'm very unfamiliar with.
Thanks in advance!
You need to use the mapP lemma (that characterizes membership wrt map):
Lemma U m (P : rel 'I_m) f v x (hp : forall j, P v j -> f v j > 0) :
x \in [seq f v j | j <- enum 'I_m & P v j] -> 0 < x.
Proof. by case/mapP=> [y]; rewrite mem_filter; case/andP=> /hp ? _ ->. Qed.

Merging two small sequencies - algorithm

Prove that it is enough to make at most 5 comparisons in order to merge two sorted sequences of lengths 2 and 5.
Suppose the input arrays are [a b c d e] and [x y]
We start by trying to insert x into the larger array. We do binary search but we take a chance: We don't start in the middle but slightly to the left: We check x < b.
If we're lucky x falls in the left (smaller) part of the array and we can compare x < a to figure out if the result should start with x a or a x. We then have 3 comparisons left for y which is sufficient to do a binary search.
If we're unlucky x falls in the right (larger) part of the array. In other words x should be in c d e. We continue the binary search by checking x < d.
If we're lucky this is false, because we then know that the result starts with a b c d and we can then check x < e and y < e to figure out the order of the last three elements.
If this is true, we check x < c to figure out if the sequence should start with a b c x or a b x. We then have 2 comparisons left which is enough to do a binary search for y since we know that it should be to the right of x.
This is of course just an outline of a solution and not a formal proof. However, it can easily be transformed to a formal proof using Hoare logic. It would look as follows:
{ a ≤ b ≤ c ≤ d ≤ e ∧ x ≤ y }
if (x < b) {
{ a ≤ b ≤ c ≤ d ≤ e ∧ x ≤ y ∧ x < b }
if (x < a) {
...
} else {
...
}
} else {
{ a ≤ b ≤ c ≤ d ≤ e ∧ x ≤ y ∧ b ≤ x }
if (x < d) {
...
} else {
...
}
}