The equality s.~r is equal to r.s on page 63. of Software Abstractions seems incorrect. I believe s.~r is equal to ~(r.~s) is the correct statement.
In this statement, s is a set, so ~s isn't a legal expression.
Related
what are Wildcard operators in system verilog? I have searched the net but there is some ambiguity.
Also are they synthesizable?
Answers for below?
4'b1010 ==? 4'b10x0
4'b10x0 ==? 4'b1010
It looks like you didn't search the IEEE 1800-2017 SystemVerilog LRM. Section 11.4.6 Wildcard equality operators defines this operator. A search would give many other examples like here.
Wildcard equality operators are intended to be synthesizable as long as the X appears on the RHS as a literal or constant expression. X's on the RHS are treated as don't care matches. X's on the LHS do not match anything and only used in simulation. The inside operator and the case inside conditional statement all use this asymmetric wildcard matching for synthesizable don't cares.
From section 5.5 of "IEEE Standard for Verilog Register Transfer Level Synthesis" IEEE Std 1364.1-2002 (1364 is the base specification that IEEE-1800 extended, and 1361.1 defined the synthesizable subset of 1364):
The value x may be used in case item expressions (may be mixed
with other expressions, such as 4'b01x0) in a casex statement to
imply a don't care value for synthesis.
As the Wildcard operator is an obvious extension of the casex expression, one would reasonably expect that it is intended to be synthesizable. I am not aware of an IEEE standard for 1800 that defines the synthesizable subset; or if this information is contained in the IEEE-1800 standard itself.
The late Stuart Sutherland proposed a list of synthesizable constructs for IEEE-1800 which included the Wildcard Equality, in his paper: https://sutherland-hdl.com/papers/2006-DVCon_SystemVerilog_synthesis_subset_paper.pdf
As a matter of practicality, the definitive way to check such a question is code up a small example using this construct, and feed it to the synthesis tool you are actually planning to use and see if you get warnings, errors, or working code!
I need to create UML diagrams for homework about a game ( called Downfall). I have to create it so that it works on any number (n) of player.
If this is an exact number that appears in multiple places of the diagram, should I use n or *? I would use it in multiplicity parameters and in size of array.
For example: There are n sides, and if there is a dial on a side, there has to be dial on each side at that position, so the dial has n-1 connected dials.
TL;DR
You can use a constant, like n. I would though recommend using a self-explanatory constant name like numberOfPlayers or at least noOfPlayers to make it obvious that it is always the same constant.
The name of the constant should be written without quotes (to distinguish it from strings, which are presented in double-quotes).
You can also use expression like n-1 as long as it evaluates to a non-negative Integer all the time.
Full explanation
Let's go by the UML specification. All section and figure references are from it.
1. Multiplicity definition (7.5.3.2)
The multiplicity is defined as lowerValue and upperValue.
The lower and upper bounds for the multiplicity of a MultiplicityElement are specified by ValueSpecifications (see Clause 8), which must evaluate to an Integer value for the lowerBound and an UnlimitedNatural value for the upperBound (see Clause 21 on Primitive Types)
2. ValueSpecification definition
ValueSpecification is defined as either LiteralSpecification (8.2) or Expression or OpaqueExpression (both described in 8.3).
LiteralSpecification is essentially just a number in the case interesting for us, so it is not what you need. But it is not the only option as www.admiraalit.nl suggests in his answer.
3. Expression definition (8.3.3.1)
An Expression is a mechanism to provide a value through some textual representation and eventually computation (I'm simplifying here). For instance:
An Expression is evaluated by first evaluating each of its operands and then performing the operation denoted by the Expression symbol to the resulting operand values
If you use a simple expression without operands, it simply becomes a constant that is a template for your model. So feel free to use a constant as a multiplicity value, as long as the constant evaluates to non-negative Integer (or UnlimitedNatural in case of an upper Limit).
It may even be an expression that changes its value over the lifecycle of the object however ensuring that this kind of multiplicity is met all the time might become challenging.
According to the UML specification, n is syntactically a valid multiplicity (see Ister's answer), but to make sure it is also semantically correct, you would have to define the meaning of n somewhere. Usually, n is not used as a multiplicity in UML diagrams.
I would advise you to use * in this case. If the minimum number of players is 2, you may use 2..*.
Additionally, you may use notes or constraints, e.g. { the number of connected dials is equal to the number of sides minus one }. You may also use a formal constraint language, like OCL.
Does WorksheetFunction.Or evaluate all arguments, or does it immediately return True once an argument evaluates to True?
The thing is, I am trying to check if a variable is numeric, and if it is, I want to check if it is less than 1. You can see it below:
If IsNumeric(lvl) Or lvl < 1 Then
Do sth...
End If
Described here, the Or operator in VBA evaluates all arguments and I get Type Mismatch Error when _lvl_ is not numeric. Does WorksheetFunction.Or behave the same?
Yes, WorksheetFunction.Or behaves the same.
The reason being, it is a regular function as far as VBA is concerned, so VBA will evaluate all arguments before passing them to the function. The function will not have a chance to perform lazy evaluation.
In order for lazy evaluation to kick in, the evaluation construct must be a part of the language syntax. VBA does not have it in its syntax, so it's not going to work when calling any function in any way.
I hope this won't end as philosophical question, but which of theese is the right result of (2^5^2)
Excel:
Matlab:
Wolfram|Alpha: http://www.wolframalpha.com/input/?i=2%5E5%5E2
33554432
I know I can add braces to get desired behavior, but I want to know why those Math softwares are implementing it differently?
In MATLAB operators of equal precedence are always evaluated left to right which explain the result you are seeing. The same is true with Excel.
In essence they are assuming that operations are always left associative. Wolfram alpha, as well as Mathematica define exp. as right associative which afaik is more 'correct' mathematically. In doubt use parenthesis.
I have an interesting question, but I'm not sure exactly how to phrase it...
Consider the lambda calculus. For a given lambda expression, there are several possible reduction orders. But some of these don't terminate, while others do.
In the lambda calculus, it turns out that there is one particular reduction order which is guaranteed to always terminate with an irreducible solution if one actually exists. It's called Normal Order.
I've written a simple logic solver. But the trouble is, the order in which it processes the constraints seems to have a huge effect on whether it finds any solutions or not. Basically, I'm wondering whether something like a normal order exists for my logic programming language. (Or wether it's impossible for a mere machine to deterministically solve this problem.)
So that's what I'm after. Presumably the answer critically depends on exactly what the "simple logic solver" is. So I will attempt to briefly describe it.
My program is closely based on the system of combinators in chapter 9 of The Fun of Programming (Jeremy Gibbons & Oege de Moor). The language has the following structure:
The input to the solver is a single predicate. Predicates may involve variables. The output from the solver is zero or more solutions. A solution is a set of variable assignments which make the predicate become true.
Variables hold expressions. An expression is an integer, a variable name, or a tuple of subexpressions.
There is an equality predicate, which compares expressions (not predicates) for equality. It is satisfied if substituting every (bound) variable with its value makes the two expressions identical. (In particular, every variable equals itself, bound or not.) This predicate is solved using unification.
There are also operators for AND and OR, which work in the obvious way. There is no NOT operator.
There is an "exists" operator, which essentially creates local variables.
The facility to define named predicates enables recursive looping.
One of the "interesting things" about logic programming is that once you write a named predicate, it typically works fowards and backwards (and sometimes even sideways). Canonical example: A predicate to concatinate two lists can also be used to split a list into all possible pairs.
But sometimes running a predicate backwards results in an infinite search, unless you rearrange the order of the terms. (E.g., swap the LHS and RHS of an AND or an OR somehwere.) I'm wondering whether there's some automated way to detect the best order to run the predicates in, to ensure prompt termination in all cases where the solution set is exactually finite.
Any suggestions?
Relevant paper, I think: http://www.cs.technion.ac.il/~shaulm/papers/abstracts/Ledeniov-1998-DCS.html
Also take a look at this: http://en.wikipedia.org/wiki/Constraint_logic_programming#Bottom-up_evaluation