I've searched on the internet and most say just say that context free languages
are closed for union, concatenation, reversal, and Kleene Star. Are they also closed for set difference?
The context-free languages are not closed under set difference. One way to see this is to note that
the context-free languages are not closed under complementation,
the language Σ* is context-free, and
for any language L, the complement of L is given by Σ* - L.
Therefore, if the CFLs were closed under set difference, then they'd be closed under complementation... except that they aren't. :-)
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
As far as I know the main difference between declarative and imperative programming is the fact that in declarative programming you rather specify what the problem is, while in imperative programming you state exactly how to solve a problem.
However it is not entirely clear for me when to use one over another. Imagine you are imposed to solve a certain problem, according to which properties you decide to tackle this down declaratively (i.e using prolog) or imperatively (i.e using Java)? For what kind of problems would you prefer to use one over the other?
Imperative programming is closer to what the actual machine performs. This is a quite low level form of programming, and the more complex your application grows, the harder it will be for you to grasp all details at such a low level. On the plus side, being close to the machine, you can write quite performant code if you are good at that.
Declarative programming is more abstract and higher level: With comparatively little code, you can express quite sophisticated relationships in a way that can be more easily seen to be correct.
To see an important difference, compare for example pure Prolog with Java: Suppose I take away one of the rules in a Prolog program. I know a priori that this can make the program at most more specific: Some things that held previously may now no longer hold.
On the other hand, suppose I take away a statement in a Java program: Nothing much can be said about the effect in general. The program may even no longer compile.
So, changes in an imperative program can have very unforeseen effects, and are extremely hard to reason about, because there are few guarantees and invariants, and many things are implicit in some global state of the program. This makes imperative programming very error-prone.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Many contemporary languages allow two kinds of comments: one in which delimiters are used on both ends (multiple-line comments), and one in which a delimiter marks only the beginning of the comments (one-line comments). Discuss the advantages and disadvantages of each with respect to criteria (readability, writability, reliability, cost).
There's no right answer here, they differ in a personal or style-wise way of coding.
With both you have a easy to write/read comment. The comment may be as long as you want, but generally short and precise comments are better, otherwise you would only be rewriting code as comment.
//assings 10 to x will make everything happier // the code won't change (further reading)
x = 10
if (x == 10)
happy++
How did this comment helped future users?
With multiple lines, though, you can write a little text, but reading it would be a little extra work if you still had to read (and understand) the code.
It won't change how programmers will read them, but they sure help when you have more than one line of comment (like reference URL's) and don't want to start every line with a comment markup.
I, personally, like multiline code for a simple reason: it agroups logical parts together
//*assings 10 to x will make everything happier //the code is on
x = 10
if (x == 10)
happy++
//*/
Now I can easily turn the code betwen those comments on and off that part of the code (for testing, for instance) only by changing the first "/". It would be a advantage of multiline.
/*assings 10 to x will make everything happier // the code is off
x = 10
if (x == 10)
happy++
//*/
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
Is there a programming language in which any of the following:
a numeric literal next to a variable 3x, -0.5y
a numeric literal or numeric variable next to a parenthesized expression a(b+c+d) 2(x-y)
two adjacent parenthesized expressions (1+x)(1-x) (4a-5b)(1+4c)
is interpreted to mean a multiplication?
I can see the syntactical problems that this would cause, but I'm curious if any language has gone ahead and done it anyway.
TI-BASIC does it in certain circumstances. I believe that certain CAS oriented langauges do as well.
IIRC, Fortress has a "juxtaposition operator" that for numeric types is defined as multiplication.
Some high level languages, such Mathematica, are capable of dealing with symbols rather than plain vars. You can try to query Wolfram Alpha in a same fashion too, omitting the multiplication operator.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Isaac and Albert were excitedly describing the result of the Third Annual International Science
Fair Extravaganza in Sweden. There were three contestants, Louis, Rene, and Johannes. Isaac reported
that Louis won the fair, while Rene came in second. Albert, on the other hand, reported that Johannes
won the fair, while Louis came in second.
In fact, neither Isaac nor Albert had given a correct report of the results of the science fair. Each of them had given one correct statement and one false statement. What was the actual placing of the three contestants? Please base your solution to a Prolog program.
Well, i am beginner at prolog and i want to interpret such paragraphs into prolog code but i am not sure how to approach to this. Can you lead me about that?
We start by recording the statements of Isaac and Albert. 1 and 2 are used to identify the statements ("the first statement of Isaac..."), each list represents the participants in their order.
isaac(1,[louis,_,_]).
isaac(2,[_,rene,_]).
albert(1,[johannes,_,_]).
albert(2,[_,louis,_]).
Next we say who participated in the fair and that any answer should be a permutation of the three names. I'm working with SWI prolog, so permutation is a built-in predicate:
domain([louis,johannes,rene]).
valid(X):- domain(D), permutation(D,X).
Finally, we put everything together:
go(X) :- isaac(I,X),
albert(J,X),
valid(X),
\+ (isaac(K,X), dif(I,K)),
\+ (albert(L,X), dif(J,L)).
Two last lines ensure that only one claim of Isaac (Albert) is true.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I have a set of keys e.g (IENDKCAGI, RZRLBYBFH) and now I want to find the algorithm of it. I allready know the basics of cryptography but I don't know how to start reverse engeneering the algorithm.
I don't search a certain algorithm, I'm just interested how the process would look like.
cheers
EDIT: I don't want to crack any key!!! I buy the software I need!
I'm just interested in the approach of reengeneering a checksum from the result, thats my conceptual formulation, without knowing the algorythm. This topic is more theorethical, but in my opinion it has a certain relevancy also for stackoverflow
You can analyze it to some degree, at least enough to rule out several possibilities. You say you have a set of keys, and I'm not sure what you mean by that, so pretend for discussion that the left value is the plaintext and the right value is the encrypted equivalent.
You can determine that the left value has only one repeating character, "I", and that the right value has two, "R" and "B". From that you can rule out a simple substitution cipher, even one with characters rearranged.
Both values appear to have only characters in the range [A-Z] (a larger sample would help confirm), so you can rule out encryption techniques that yield binary results, like most block and stream ciphers. In fact, use of such a limited character set implies that it was designed for use by people rather than machines. That would imply a relatively simple cipher technique, but may also involve an additional key to which you do not have access.