An expression tree of
1. Operators: AND/OR
2. Operands: class Operand(id: int, value: boolean)
Need to get the minimal number of false operand ids, whose values needs to be true to make complete expression tree evaluation to be true.
Related
What is the difference between objectid(), hash(), pointer() and pointer_from_objref() in Julia?
What is the operator that compares with === ?
julia> L1 = [1,2,3];
julia> L2 = L1;
julia> L3 = copy(L1);
julia> objectid(L1), objectid(L2), objectid(L3)
(0xac55c2b098913d98, 0xac55c2b098913d98, 0xbdee7946bbc068f0)
julia> hash(L1), hash(L2), hash(L3)
(0xecc5186e7be222c6, 0xecc5186e7be222c6, 0xecc5186e7be222c6)
julia> pointer_from_objref(L1), pointer_from_objref(L2), pointer_from_objref(L3)
(Ptr{Nothing} #0x00007f6888141e40, Ptr{Nothing} #0x00007f6888141e40, Ptr{Nothing} #0x00007f68881438f0)
julia> pointer(L1), pointer(L2), pointer(L3)
(Ptr{Int64} #0x00007f6888141e80, Ptr{Int64} #0x00007f6888141e80, Ptr{Int64} #0x00007f6888143930)
From the documentation:
objectid(x)
Get a hash value for x based on object identity. objectid(x)==objectid(y) if x === y.
hash(x[, h::UInt])
Compute an integer hash code such that isequal(x,y) implies hash(x)==hash(y).
pointer_from_objref(x)
Get the memory address of a Julia object as a Ptr.
pointer(array [, index])
Get the native address of an array or string, optionally at a given location index.
pointer works on arrays and strings and pointer(x) returns Ptr{X} where X is a type stored in x (a corner case is standard strings in base where it is UInt8 although eltype of String is Char). This gives you a pointer where data is stored; two different objects can have the pointer compare with == as true, e.g. with x=[1] and y=reinterpret(UInt8, x) you will get pointer(x) == pointer(y) (although those pointers have different types);
pointer_from_objref works on any mutable object and returns Ptr{Nothing}. For arrays and strings this is not the same as pointer because arrays/strings also have some metadata that is stored before the actual data.
objectid - as the documentation says is a hash that is based on the rule that if two objects x and y have a property that x===y is true then they should have the same objectid (the actual implementation is a bit complex to cover the x===y rule correctly - for instance s1 = "12" and s2 = "12" will most likely have a different value returned by pointer but since s1 === s2 then objectid will return the same value on them;
hash is a standard hash value that is based on isequal not on ===. This means e.g. that two arrays x=[1] and y=[1] will have the same hash (as they have the same contents and compare as equal using isequal) but have different objectid because they are not identical when compared using ===
=== means a comparison testing if objects passed to it are undistinguishable. The simple rule to use in most cases is that it is:
objects have the same values for immutable objects
objects have the same memory location for mutable objects
(the last rule is a bit tricky as e.g. two strings s1="12" and s2="12" compare as equal using === because they are immutable, but actually they are distinguishable using pointer function)
So as you can see the rules are a bit complex to ensure that in common cases users get what they expect.
I can't figure out which is the result of set operation of extensible constraints in ASN.1, like below:
A ::= INTEGER ( (1..64, ..., 100..128) INTERSECTION (1..32, ..., 33..120) )
B ::= INTEGER ( (1..64, ..., 100..128) UNION (1..32, ..., 33..120) )
C ::= INTEGER (1..64, ..., 100..128) (1..32, ..., 33..120)
What's the resultant constraint of these types?
Any help is appreciated.
The first two definitions are invalid since the ... can only occur at the topmost level, not nested inside multiple parentheses, so A and B are invalid definitions. See ITU-T X.680 clause 50.1 and 50.5.
C is also technically invalid since the value 120 is not within the base range of 1..64 for the "parent type". If you change the 120 to 64, then the effective constraint is as follows:
C ::= INTEGER (1..32, ..., 33..64)
ITU-T X.680 clause 50.10 has the following:
50.10 If a subtype constraint is serially applied to a parent type which is extensible through the application of an extensible constraint, value notation used within it shall not reference values that are not in the extension root of the parent type. The result of the second (serially applied) constraint is defined to be the same as if the constraint had been applied to the parent type without its extension marker and possible extension additions.
Simple question. I tried searching, by googling for less than and greater than signs doesn't return great results.
My guess is that <> is basically equivalent to not equals. So, the below expression would be false if x is null or an empty string, and true otherwise?
if x <> ""
This would also return True if a value is contained in the entity listed. This is commonly used to look for quesrystring or form elements that may or may not have been supplied:
If Request("someFieldName") <> "" Then
' Field was provided and has a value, so use the field value
Else
' Field was either empty or not provided, in which case use something else
End If
Hope this helps.
So, the below expression would be false if x is null or an empty string, and true otherwise?
Not exactly. There are few function to verify value:
IsNull(expression)
IsNull returns True if expression is Null, that is, it contains no
valid data; otherwise, IsNull returns False. If expression consists of
more than one variable, Null in any constituent variable causes True
to be returned for the entire expression.
The Null value indicates that the variable contains no valid data.
Null is not the same as Empty, which indicates that a variable has not
yet been initialized. It is also not the same as a zero-length string
(""), which is sometimes referred to as a null string.
IsEmpty(expression)
The expression argument can be any expression. However, because
IsEmpty is used to determine if individual variables are initialized,
the expression argument is most often a single variable name.
IsEmpty returns True if the variable is uninitialized, or is
explicitly set to Empty; otherwise, it returns False. False is always
returned if expression contains more than one variable.
Other good function
VarType(varname)
Returns a value indicating the subtype of a variable.
Use Windows Script 5.6 Documentation from http://www.microsoft.com/en-us/download/details.aspx?id=2764
While working on a project in Dr. Scheme, I initialized a variable as null as follows:
(define var null)
How can I do this in R5RS?
In Scheme, the conventional placeholder for "invalid" is #f, the false object. You can test for it using not.
(There is a null? procedure in Scheme that checks whether the object is the empty list, (). However, that should only be used for list contexts, and not as an "invalid" placeholder. Note that not only returns true for #f, and null? only returns true for (); be careful not to mix the two up.)
I have an Ocaml function that is giving me errors.
What I am trying to do:
Recursively create a List of random numbers (0-2) of size "limit".
Here's what I have:
let rec carDoorNumbers = fun limit ->
match limit with
| [1] -> Random.int 3
| [] -> Random.int 3 :: carDoorNumbers (limit-1);;
I am getting this error:
Error: This expression has type 'a list
but an expression was expected of type int
Think about what your function has to do: given a limit, you have to create a list of numbers. So your type is something like carDoorNumbers : int -> int list.
Looking at that, it seems you have two errors. First, you're matching limit (which should be an int) against a list pattern. [1] -> ... matches a list containing only the element 1 and [] matches the empty list; you really want to match against the number 1 and any other number n.
The second error is that you return two different types in your match statement. Remember that you are supposed to be returning a list. In the first case, you are returning Random.int 3, which is an int rather than an int list. What you really want to return here is something like [Random.int 3].
The error you got is a little confusing. Since the first thing you returned was an int, it expects your second thing to also be an int. However, your second case was actually correct: you do return an int list! However, the compiler does not know what you meant, so its error is backwards; rather than changing the int list to an int, you need to change the int to an int list.
Your match expression treats limit like a list. Both [1] and [] are lists. That's what the compiler is telling you. But it seems limit should be an integer.
To match an integer, just use an integer constant. No square brackets.
(As a side comment, you might want to be sure the function works well when you pass it 0.)