Simple basic verification problem in uppal - verification

I'm struggling with some simple verification. I have automata and value x like this:
automata2
When x at the start is different from 0 then E<> x !=0 is satisfied, but when x = 0, then its not satisfied and E<> x == 0 and A<> x == 0 are satisfied.
But I would like to get a not satisfied for E<> x !=0 even when x is different from 0 at the start.
What should I change? How does that verify-er works exactly? Empty path, when nothing was executed is a correct path too? And the Set of all possibly paths contains this empty path as well?

The initial state is a state like any other, thus if x is 0 in the initial state, then all paths starting in this state will eventually be in a state where x = 0 holds. If you want to check if x = 0 in any other state, you need to exclude the initial state in the query. For instance E<> x=0 and not line1.S0.

Related

Does `if` work only in combination with `else` in Series.apply(lambda x)?

I'm getting a SyntaxError for:
housing['Lot Area'].apply(lambda x: x + 50000 if x > 20000)
When I add else, the code runs fine:
housing['Lot Area'].apply(lambda x: x + 50000 if x > 20000 else x)
Does if only work in combination with else here? I'd like to increment x with 50000 only if x > 20000 -- otherwise I'd like x to remain unchanged. I find the else part a bit redundant here. Besides the first question before, is there any way to write this code without the else part?
Base on your description , even apply is not need here
housing.loc[housing['Lot Area']>20000,'Lot Area']+=50000
Comment from Alex :
if the if statement resolves to False for a value, then apply() doesn't return and just lets the value in the Series as it is
you're getting a SyntaxError because you are typing invalid syntax. the ternary operator must be used like
expression if bool else other_expression

Why is my conditional expression != ignored?

Here's my Fibonacci code using python 3.5
z = 0
x = 0
y = 1
while z != 317811:
x = x + y
z = x
print (z)
y = x + y
z = y
print (z)
I am wondering why this prints to infinity when setting the condition to
z != 317811
but works when it is below this number like
z != 196418
or a number greater than this like
z!= 514229
I tried a different approach (z <= 317811) but it prints up to 514229.
Thank you for your time.
KD
You're only testing alternate Fibonnaci numbers as the stopping condition: 317811 is getting missed.
One fix would be to test both x and y.
this is just logical problem
you are printing two
z != 317811
for this condition
"z"
is updated twice once in first z assignment i.e z = x
but "z" again get updated at second assignment z = y and then "z" is not sutisfying the condition(z != 317811) and not equal to 317811 but it is now 514229
Note: it will always work for number being printed at the second steps as this value of Z will be compared in while condition in loop
You are increasing z value twice a loop, but only checking once.
What actually is happening is that z is increasing with the fibonacci serie. Last values of z are:
196418
317811
514229
But you are only checking the stop condition once every two assignment. In this case you are checking that 196418 != 317811 and 514229 != 317811, thus never matching it.
One possible fix could be to test if z != 317811 after the first print. Even if in this case I would prefer testing "<" instead of "!="

Counter intuitive meaning of < ANY & >ANY logic operators in SQL

ANY intuitively means: anything that matches in the set.
However, I found out it, it doesn't behave as expected in two cases:
x > ANY(...) The value must be greater than the smallest value in
the list to evaluate to TRUE.
x < ANY(...) The value must be
smaller than the biggest value in the list to evaluate to TRUE
(Source)
In other words, the entire result of sub-query introduced by ANY has to be compared to x, which runs counter to meaning of ANY.
Why is it so, or I am just misunderstanding the semantics of <ANY & >ANY operators ?
x > ANY(...) The value must be greater than the smallest value in the list to evaluate to TRUE.
x < ANY (...) The value must be smaller than the biggest value in the list to evaluate to TRUE
Both of the above statements assert the Algorithm that oracle might using for comparison. for example.
select * from X where id > Any ( 1 , 2 , 3 , 4 , 5 )
in above code can be drill down as
id > 1 OR id > 2 OR id > 3 and so on..
so only id > 1 will assert it true. (Algo Optimization) Same way they did it for x < ANY (...)
x > ANY(...) The value must be greater than the smallest value in the list to evaluate to TRUE
This is stating a consequence. It may take some thinking about. x may be greater than every value in the list, and it will still return TRUE. The opposite may be easier to understand:
x > ANY(...) will be FALSE if the value is less than or equal to the smallest value in the list, because it must also be less than or equal to all other members of the list
Or yet another way:
x > ANY(...) will be true if there is at least one value in the list, y say, that x is greater than. If there are a set of such y values, the smallest value in the list must logically be one member of that set.

How to choose a range for a loop based upon the answers of a previous loop?

I'm sorry the title is so confusingly worded, but it's hard to condense this problem down to a few words.
I'm trying to find the minimum value of a specific equation. At first I'm looping through the equation, which for our purposes here can be something like y = .245x^3-.67x^2+5x+12. I want to design a loop where the "steps" through the loop get smaller and smaller.
For example, the first time it loops through, it uses a step of 1. I will get about 30 values. What I need help on is how do I Use the three smallest values I receive from this first loop?
Here's an example of the values I might get from the first loop: (I should note this isn't supposed to be actual code at all. It's just a brief description of what's happening)
loop from x = 1 to 8 with step 1
results:
x = 1 -> y = 30
x = 2 -> y = 28
x = 3 -> y = 25
x = 4 -> y = 21
x = 5 -> y = 18
x = 6 -> y = 22
x = 7 -> y = 27
x = 8 -> y = 33
I want something that can detect the lowest three values and create a loop. From theses results, the values of x that get the smallest three results for y are x = 4, 5, and 6.
So my "guess" at this point would be x = 5. To get a better "guess" I'd like a loop that now does:
loop from x = 4 to x = 6 with step .5
I could keep this pattern going until I get an absurdly accurate guess for the minimum value of x.
Does anybody know of a way I can do this? I know the values I'm going to get are going to be able to be modeled by a parabola opening up, so this format will definitely work. I was thinking that the values could be put into a column. It wouldn't be hard to make something that returns the smallest value for y in that column, and the corresponding x-value.
If I'm being too vague, just let me know, and I can answer any questions you might have.
nice question. Here's at least a start for what I think you should do for this:
Sub findMin()
Dim lowest As Integer
Dim middle As Integer
Dim highest As Integer
lowest = 999
middle = 999
hightest = 999
Dim i As Integer
i = 1
Do While i < 9
If (retVal(i) < retVal(lowest)) Then
highest = middle
middle = lowest
lowest = i
Else
If (retVal(i) < retVal(middle)) Then
highest = middle
middle = i
Else
If (retVal(i) < retVal(highest)) Then
highest = i
End If
End If
End If
i = i + 1
Loop
End Sub
Function retVal(num As Integer) As Double
retVal = 0.245 * Math.Sqr(num) * num - 0.67 * Math.Sqr(num) + 5 * num + 12
End Function
What I've done here is set three Integers as your three Min values: lowest, middle, and highest. You loop through the values you're plugging into the formula (here, the retVal function) and comparing the return value of retVal (hence the name) to the values of retVal(lowest), retVal(middle), and retVal(highest), replacing them as necessary. I'm just beginning with VBA so what I've done likely isn't very elegant, but it does at least identify the Integers that result in the lowest values of the function. You may have to play around with the values of lowest, middle, and highest a bit to make it work. I know this isn't EXACTLY what you're looking for, but it's something along the lines of what I think you should do.
There is no trivial way to approach this unless the problem domain is narrowed.
The example polynomial given in fact has no minimum, which is readily determined by observing y'>0 (hence, y is always increasing WRT x).
Given the wide interpretation of
[an] equation, which for our purposes here can be something like y =
.245x^3-.67x^2+5x+12
many conditions need to be checked, even assuming the domain is limited to polynomials.
The polynomial order is significant, and the order determines what conditions are necessary to check for how many solutions are possible, or whether any solution is possible at all.
Without taking this complexity into account, an iterative approach could yield an incorrect solution due to underflow error, or an unfortunate choice of iteration steps or bounds.
I'm not trying to be hard here, I think your idea is neat. In practice it is more complicated than you think.

Not Equal to This OR That in Lua

I am trying to verify that a variable is NOT equal to either this or that. I tried using the following codes, but neither works:
if x ~=(0 or 1) then
print( "X must be equal to 1 or 0" )
return
end
if x ~= 0 or 1 then
print( "X must be equal to 1 or 0" )
return
end
Is there a way to do this?
Your problem stems from a misunderstanding of the or operator that is common to people learning programming languages like this. Yes, your immediate problem can be solved by writing x ~= 0 and x ~= 1, but I'll go into a little more detail about why your attempted solution doesn't work.
When you read x ~=(0 or 1) or x ~= 0 or 1 it's natural to parse this as you would the sentence "x is not equal to zero or one". In the ordinary understanding of that statement, "x" is the subject, "is not equal to" is the predicate or verb phrase, and "zero or one" is the object, a set of possibilities joined by a conjunction. You apply the subject with the verb to each item in the set.
However, Lua does not parse this based on the rules of English grammar, it parses it in binary comparisons of two elements based on its order of operations. Each operator has a precedence which determines the order in which it will be evaluated. or has a lower precedence than ~=, just as addition in mathematics has a lower precedence than multiplication. Everything has a lower precedence than parentheses.
As a result, when evaluating x ~=(0 or 1), the interpreter will first compute 0 or 1 (because of the parentheses) and then x ~= the result of the first computation, and in the second example, it will compute x ~= 0 and then apply the result of that computation to or 1.
The logical operator or "returns its first argument if this value is different from nil and false; otherwise, or returns its second argument". The relational operator ~= is the inverse of the equality operator ==; it returns true if its arguments are different types (x is a number, right?), and otherwise compares its arguments normally.
Using these rules, x ~=(0 or 1) will decompose to x ~= 0 (after applying the or operator) and this will return 'true' if x is anything other than 0, including 1, which is undesirable. The other form, x ~= 0 or 1 will first evaluate x ~= 0 (which may return true or false, depending on the value of x). Then, it will decompose to one of false or 1 or true or 1. In the first case, the statement will return 1, and in the second case, the statement will return true. Because control structures in Lua only consider nil and false to be false, and anything else to be true, this will always enter the if statement, which is not what you want either.
There is no way that you can use binary operators like those provided in programming languages to compare a single variable to a list of values. Instead, you need to compare the variable to each value one by one. There are a few ways to do this. The simplest way is to use De Morgan's laws to express the statement 'not one or zero' (which can't be evaluated with binary operators) as 'not one and not zero', which can trivially be written with binary operators:
if x ~= 1 and x ~= 0 then
print( "X must be equal to 1 or 0" )
return
end
Alternatively, you can use a loop to check these values:
local x_is_ok = false
for i = 0,1 do
if x == i then
x_is_ok = true
end
end
if not x_is_ok then
print( "X must be equal to 1 or 0" )
return
end
Finally, you could use relational operators to check a range and then test that x was an integer in the range (you don't want 0.5, right?)
if not (x >= 0 and x <= 1 and math.floor(x) == x) then
print( "X must be equal to 1 or 0" )
return
end
Note that I wrote x >= 0 and x <= 1. If you understood the above explanation, you should now be able to explain why I didn't write 0 <= x <= 1, and what this erroneous expression would return!
For testing only two values, I'd personally do this:
if x ~= 0 and x ~= 1 then
print( "X must be equal to 1 or 0" )
return
end
If you need to test against more than two values, I'd stuff your choices in a table acting like a set, like so:
choices = {[0]=true, [1]=true, [3]=true, [5]=true, [7]=true, [11]=true}
if not choices[x] then
print("x must be in the first six prime numbers")
return
end
x ~= 0 or 1 is the same as ((x ~= 0) or 1)
x ~=(0 or 1) is the same as (x ~= 0).
try something like this instead.
function isNot0Or1(x)
return (x ~= 0 and x ~= 1)
end
print( isNot0Or1(-1) == true )
print( isNot0Or1(0) == false )
print( isNot0Or1(1) == false )