UPPAAL Verification Error- Index value is out of range - deadlock

I am using Uppaal for system verification. The simulation is running perfectly fine but when I verify by using this property A[] not deadlock it is giving me the following error:
_The successors of this state are not well defined.
Index value 3 is out of range. Array length = 3, Element size = 1 in line 1 of go3[id]?_
What could have gone wrong there?

If your array has a length of 3 the index needs to be 0, 1, or 2. That's why index value 3 is out of range. Make sure your index is never bigger than arraylength-1.

Related

Julia Inconsistent bounds check for slices

I was writing some code that makes use of array views and slices, but encountered some inconsistencies.
Why does the following not cause an exception:
a = [1,2]
#show a[3:end]
#show a[4:end]
The above all return empty arrays as expected
But this causes a BoundsError
a = [1,2]
#show a[2:3]
Why is the first index of the slice allowed to be larger than the size of the array itself, but Julia seems to have a problem with the last index being larger than the size?
Julia version: 1.3.1
x[c:end] is syntax for getindex(x, UnitRange(c, lastindex(x))).
Any range a:b with a > b is empty. Indexing an array with an empty range will result in an empty array by definition of getindex.
You index an array with an empty range in your first set of examples. In your second set of examples, you index with an out-of-bounds range, which errors as expected.

Irregular error warning: RuntimeWarning: invalid value encountered in double_scalars

My code contains some random steps and exponential expression (monotonic expression), which needs to find its root at the end. The "RuntimeWarning: invalid value encountered in double_scalars" appeared occasionally. For example, 3 or 2 times it appeared when I run 5 times. Could you tell me what's going on here? PS: each time I can get the result, but it's just the warning makes me confused.
There are two possible way to solve it, depends on your data.
1.
As you are handling some huge number and exceed the limit of double
To solve this, the method is actually quite mathematical.
First, if and only if (T_data[runs][0])*(np.exp(-(x)*(T_data[runs][1]))) is always smaller than 1.7976931348623157e+308.
As a*e^(-x*b) = e(ln(a)-xb)
Thus, (T_data[runs][0])*(np.exp(-(x)*(T_data[runs][1]))) = np.exp(T_data[runs][0]-(x)*(T_data[runs][1]))
Use np.exp(np.log(T_data[runs][0])-(x)*(T_data[runs][1])) instead.
2.
However, as you said you get the result everytime, it is possible that (T_data[runs][0])*(np.exp(-(x)*(T_data[runs][1]))) is approaching zero, which is too small that double can no longer hold but cause no harm to save as 0.
And you should change your code like this to avoid the warning.
temp = (x)*(T_data[runs][1])) > 709 ? 0 : np.exp(-(x)*(T_data[runs][1]))
exponential += (T_data[runs][0]) * temp
## As ln(1.7976931348623157e+308) ~= 709.78

Prolog Recursion Length Count

This might be a simple / basic problem but I am having troubles grasping the logic.
I want to calculate the length of the list, using recursion.
Imagine having a list [a,b,c,d] for this problem.
We have a basic clause, and a recursive clause as can be seen below.
The basic clause always deals with the most basic problem, in this case an empty list. The recursive clause tries to solve the problem for size N-1 of the list.
listLength([],0).
listLength([Head|Tail], Count):-
listLength(Tail, PartialCount),
Count is PartialCount+1.
Now, my question is the following:
Let's look at this piece of code:
listLength(Tail, PartialCount)
The program will keep on running until the Tail is empty, which will then pass to listLength([],0).
for which PartialCount becomes equal to 0.
Then, the program continues to Count is PartialCount+1. and Count becomes equal to 1.
Then the program starts backtracking to the other "unsolved" lengths.
First it starts with [d], since this was the last element that it tried to solve, now PartialCount becomes 1, and this is what I don't understand.
How come PartialCount suddenly becomes "1", which makes Count equal to 2 afterwards, since in the program, there is no indiciation of re-defining the PartialCount.
The program also backtracks to [c,d], which makes Partial Count equal to 2, and so forth.
Can someone explain how this happens? As far as I know, PartialCount is set to "0" in the listLength([],0] example, but I don't know how its value gets updated?
I see thatCount gets updated, but not PartialCount
There is a separate PartialCount in each recursive call. It's like local variables versus global. Local variable masks global variable with the same name. The local variable in the deepest nesting masks the ones outside it.
ADDITION: Here is what happens:
Call [a,b,c,d]
Call [b,c,d]
Call [c,d]
Call [d]
Call []
Success (first clause): Count = 0, no ParticalCount
Success (2nd clause): PartialCount = 0, Count = 1
Success (2nd clause): PartialCount = 1, Count = 2
Success (2nd clause): PartialCount = 2, Count = 3
Success (2nd clause): PartialCount = 3, Count = 4

Converting virtual address to page table entry

I am reading Modern Operating Systems 3rd Edition by A.S Tanenbaum, and I've come to the chapter on virtual memory management. I've been stuck on a part for some time now, and I can't get my head around it. Either, it's a typo in the book, or I have misunderstood something.
Suppose we have a multi-level page table with two levels, where we map 32-bit virtual addresses to physical memory frames.
The fields for the page tables and the offset is
10 | 10 | 12
meaning we have a top level page table with 1024 entries, and a page size of 4096 bytes or 4KB. Entry 0 of the top level page table points to the text segment page table, entry 1 to the data segment, and the 1023 entry to the stack page table.
This is quoted from the book:
As an example, consider the 32-bit virtual address 0x00403004
(4,206,596 decimal), which is 12,292 bytes into the data. This virtual
address corresponds to PT 1 = 1, PT2 = 2, and Offset = 4. The MMU
first uses PT1 to index into the top-level page table and obtain entry
1, which corresponds to addresses 4M to 8M. It then uses PT2 to index
into the second-level page table just found and extract entry 3, which
corresponds to addresses 12288 to 16383 within its 4M chunk (i.e.,
absolute addresses 4,206,592 to 4,210,687).
When I translate the address to binary, I get 0000000001|0000000011|000000000100 which for me corresponds to PT1 = 1, PT2 = 3, Offset = 4.
Am I missing something, or is this a typo in the book stating PT2 = 2, when it actually should be PT2 = 3? As the text later says, the MMU uses the PT2 index to extract entry 3.
Where does the "12,292 bytes into the data" come from? How is that derived from the virtual address? I understand it has something to do with the offset, but I can't figure out how it's done. As far as I have understood, the physical address is derived as a combination of the frame number from the second page table, and the offset. I see that the 12,292 is a result of 3*4096+4 (PT2 entry * page size + offset). Is this correct?
1) I think this is a typo indeed, as 0000000001|0000000011|000000000100 binary = 4,206,596 decimal
2) The response is in the previous paragraph of the book :
Entry 0 of the top-level page table points to the page table for the program text, entry 1 points to the page table for the data, and entry 1023 points to the page table for the stack
So he is just saying that 0000000001|0000000011|000000000100 corresponds to 0000000011|000000000100 into the data. Indeed 0000000001 corresponds to the data in the top level page table, and 0000000011|000000000100 binary = 12,292 decimal.
I didn't finish converting to binary out of despair and a little bit laziness but its clearer now thanks to you. Seeing it made things much more clear.
it is a typo as the previous answerer stated. its without a doubt (Check US 4th edition)
"12,292 bytes into the data" comes from substracting 222 (4MB) (Toplevel Page table entry size=4MB) from 4206596
TLDR: 4206596 - 222 (4MB) = 12,292

Decrypting a Caesar's Cypher Trouble

I have been stumped on this for a long time and I was wondering if anyone can help me out. How could I write a program that would calculate the shift value of an encrypted Caesar's Cypher file in C++? My assignment is to take each lower case letter and calculate how many times each is used, then find the most frequent character. I know I can do that with a map of char and int. But then I would have to go back to that letter to change it to the letter 'e'. With maps there's no way to search back through values. I think the only way is a vector of vectors but I wouldn't know how to find the letter again with those either. Does anyone know a better way or how could I use vectors to accomplish this?
You can go like this.
First read whole file in a buffer.
Create map with char key and int value. with all alphabets and values 0
Loop over whole buffer till end incrementing value in map by 1 for each character. Also maintain max variable storing key ha of character having maximum value.
At end of loop max variable will point to e.
Subtracting 4 from max will give you shift value for this cipher. If it comes negative then you can add 26. (As this calculation in in mod 26)
All you need is a vector of size 26 (one for each character) where A has index 0 and Z has index 25.
Go through the ciphertext and in the vector increase the value for the specified character index.
When you've gone through all the ciphertext then go through the vector and check for the highest value. This is probably the character E.
Now you take the index and subtract with 4 (index of E).
This yields the shift value.
Let's say 20 has the highest count then your shift value is 16.

Resources