Write a regular expression that defines a simple musical score. Notes are repres
ID: 3672987 • Letter: W
Question
Write a regular expression that defines a simple musical score. Notes are represented by their duration, immediately followed by the frequency and then optionally a sharp,"#", or a flat, "b" The frequency is specified by the capital letters A..G. The frequency letter "R" represents a rest or no sound. A rest never has a sharp or flat. The duration is a number representing the inverse of the time per bar. A quarter note is represented as "4", and eight note as an "8". The possible values are 1, 2, 4, 8 and 16. There can be one or more spaces between the notes. Write a Deterministic Finite State Automata (DFA) for two of the above languages. This should be a circle and arrow diagram with the edges labeled with the input symbol. Using any programming language you like, write a program to implement one of the DFAs defined above. Your program should read in a string and then display "accepted" or "not accepted" based on whether the input string conforms to the language specification.Explanation / Answer
(1)Some preliminaries:
There is a growing body of work in the philosophy of music and musical aesthetics that has considered the various ways that music can be meaningful: music as representational (that is, musical depictions of persons, places, processes, or events); musical as quasi-linguistic reference (as when a musical figure underscores the presence of a character in a film or opera), and most especially, music as emotionally expressive. Here I will focus on the last topic, for I believe it will be useful for researchers in music perception and cognition to avail themselves of the distinctions that aestheticians have worked out regarding the musical expression of emotion.Now we often say that music is "expressive," or that a performer plays with great expression, but what exactly do we mean? There are at least two things one may be saying. First, one may be praising a performer for their musical sensitivity, that he or she has a keen sense of just how a passage is supposed to be played. Such praise is often couched in terms of the performer's "musicality" (in statements that border on the oxymoronic, as when one says that a performer plays the music very musically). Such praise may also be couched in terms of expression--i.e., that a performer plays "expressively." I have little to say about these attributions, save that they are often linked to the second thing one often means when speaking of the music or a performance being expressive: an expressive piece or performance is one that recognizably embodies a particular emotion, and indeed may cause a sympathetic emotional response in the listener. Thus if one plays "expressively," this means that the music's particular emotional qualities--its sadness, gaiety, exuberance, and so forth, are amply conveyed by the performer.
Before we discuss those emotional qualities a number of other preliminary remarks are in order. When we speak of the expressive properties of music, these are distinct from the expressive properties of sound. Sounds may be loud, shrill, acoustically rough or smooth, and so forth. These acoustic qualities have expressive correlates and may trigger emotional responses, and of course one cannot have music without sound. But musical expression is more than this: it requires the attention to the music qua music, rather than as mere sounds. The opening "O Fortuna" of Carmina Burana may shock (and indeed scare) the listener due to its sudden loudness (especially when the bass drum starts whacking away), but this shock isn't a musical effect--we get the same reaction when we here a sudden "bang" at a fireworks display or when a car backfires. By contrast, in hearing the opening of Mozart's 40th symphony as having a quality of restless melancholy, one attends to both the musical syntax and its sonic embodiment.
Another caveat: as Hanslick has noted, at times a musical work may arouse feelings in the listener through ad-hoc associations. In other words, one must be on guard for the "they're playing our song" phenomenon. These associative properties may be quite strong, and can operate in marked contrast to the innate expressive qualities of a given piece, as in the paradigmatic case of a happy piece that arouses sadness because it reminds the listener of a lost love or deceased friend. As will be noted in some detail below, context plays a pivotal role, and here context can include not only genre, but extra-musical information such as lyrics, the image track of a film score, and literary programs. I take it, however, that a primary interest for researchers in the perception and cognition of musical expression will be in the intrinsic expressive properties of the music itself.
Finally, in philosophical discussions of meaning and expression, there is usually what might be called "the inter-subjective agreement requirement." Here is an example from visual art. If I show you a picture of a man on a horse, and you and everyone else says "that's a man on a horse," this confirms that the picture is a successful representation of a man and a horse. Moreover, I don't have to give you any cues or hints regarding its representational subject. By the same token, in order for a piece of music to be "an expression of emotion X" there must be broad consensus among listeners that the music expresses X, a consensus arrived at without any extra-musical prompting. One problem for accounts of musical expression is that such inter-subjective agreement often does not happen: one listener says a given piece is an expression of anger, while another says it expresses hate, another jealousy, and yet another of sinister passion. What emotion does this piece express? While anger, hate, jealousy, and sinister passion are related emotions, the piece nonetheless fails to individuate any one of them in particular. Musical expression is plastic enough so that the same passage might be expressive of a wide variety of emotional states. It is for this reason that context plays such a crucial role in the individuation of musical expressions of emotion.
Simple Emotions, Higher Emotions, and Moods
In the late 19th century Eduard Hanslick famously denied that music had any ability to express emotions, and many 20th century aestheticians (and composers, most notably Stravinsky) held this to be true. Why would one take up such a counter-intuitive view? Well, philosophers often take up counter-intuitive views, and if you are a philosopher, there are two problems to be surmounted if one wants to claim that a piece of music expresses a particular emotion. The first is the "who" problem: whose emotion is being expressed? Emotions are felt by living, sentient creatures, and as Malcolm Budd has noted, "It cannot be literally true that [a piece of] music embodies emotion, for it is not a living body" (Budd, Music and the Emotions, p. 37). One is thus tempted to claim that a piece of music is an expression of its composer's emotion. But when one examines the compositional history of most works this claim also falls apart, for composers often write sad music, for example, even when they feel no particular sadness (as in the case of Funeral March from of Beethoven's "Eroica" symphony). Nor are they in the throes of sadness during the entire course of composing a piece of music, since the compositional process may last weeks, months, or even years (see, for example, the Adagio Mesto movement of Brahms' trio for horn, violin, and piano, which is purported to be an elegy to his mother). Thus if pieces of music are expressions of emotion, they are disembodied, and usually disconnected from any particular "emotional cause" in the life of their composer.
If not the composer, then perhaps a musical expression of emotion is related to the emotional life of the listener, that is, if I feel emotion X when listening to a piece, then I might say that the piece expresses X by arousing that feeling in me when I listen to it. But as has often been noted, a piece of music need not arouse an emotion in order to be expressive of that emotion--if, for example, on a particular occaision when I listened to the Funeral March from Beethoven's "Eroica" Symphony and it did not happen to make me sad, it does not follow that on that day the Funeral March was not expressive of sadness. We will return to the role of expressive music in arousing the listener's emotions in a moment, but there is another problem involved when we feel an emotion.
In contrast to the "who" problem, there is also "why" problem: why do we feel a particular emotion? Emotions typically require what are referred to in philosophical parlance as intentional objects, that is, particular people or events that play a causal role in triggering an emotional state. Thus we are jealous of a particular person, frustrated at a particular state of affairs, feel grief at the death of a particular friend or relative, and so forth. One does not, for example, feel "jealous" in general (though one may have a disposition toward jealousy). So in many putative cases of musical expression, what is problematic is that, for example, while the music seems angry, it is not clear just what the listener ought to be angry about, if she is to sympathetically feel anger when listeneing.
Not all emotions are like anger, jealousy and frustration, as some do not always require intentional objects. While one can be sad due to particular event, one also can be generally sad, for example, and such sadness is not dependent upon any particular person, state of affairs, and so forth. As Colin Radford has pointed out, "not all emotions, or occasions of emotion are rational, i.e., they are not informed by, explained and justified by appropriate beliefs [that is, intentional objects]" ("Muddy Waters," p. 249). Radford also explicitly acknowledges that "we naturally call such feelings 'moods.'" ("Muddy Waters," p. 250). Thus there is a distinction between higher emotions (which require an intentional object) and simple emotions and moods which may/do not.
There is now general consensus that music can express moods and simple emotions, contra Hanslick. Some aestheticians, most notably Jerrold Levinson, have claimed that in some music contexts music can do more, in that it is capable of mimicking the characteristic "look and feel" of at least some of the higher emotions (see Music, Art, and Metaphysics, chapter 14).
How music expresses emotions:
But just how does music express simple emotions? There are two main points of view on this question. The first, developed (and much defended) by Peter Kivy, is known in philosophical circles as "cognitivism" or "cognitivist" theories of musical expression. The second, one with a long historical pedigree, can be termed "emotivist" or "arousal" theories of musical expression. Taking up the cognitivist charge, Kivy has repeatedly denied that music really arouses what he has termed the "garden varieties" or real-world instances of sadness, happiness, anger, and other simple emotions in the listener (though music may move the listener through its sheer beauty). For even simple emotions, when fully aroused, usually relate to an intentional object. Thus if we say that a piece of music makes us sad or angry, what exactly are we sad or angry about--the music? ("that damn Symphonie Pathetique!") or its composer? ("that damn Tchaikovsky!"). And has already been noted, a piece that seems expressive of happiness may actually trigger sadness due to extra-musical associations.
For the cognitivist, the expressive properties of music are properties intrinsic to the music, and not, to quote Kivy, "dispositions to arouse emotions in [the] listener" ("Feeling the Musical Emotions," p. 1). Kivy takes this position from O. K. Bouwsma, but he also acknowledges psychological antecedents for this view, in particular Charles Hartshorne's The Philosophy and Psychology of Sensation (1934), and Kivy cites Hartshorne observation that 'Thus the "gaiety" of yellow (the peculiar highly specific gaiety) is in the yellowness of the yellow' (see ibid., note 2, p. 1). In making this move, one allows that music that is expressive of sadness need not make the listener sad.
How exactly does music then express emotions if not by arousing them in the listener? Here Kivy, Levinson, and many others would agree with this explanation given by Malcom Budd (who takes this view in large part from the music psychologist Caroll Pratt): "music can be agitated, restless, triumphant, or calm since it can possess the character of the bodily movements which are involved in the moods and emotions that are given these names" (Music and the Emotions, p. 47). Likewise Kivy develops a "physiognomy of musical expression" and thus claims that music is expressive of these basic emotions by its resemblance to human utterance and behavior. Music thus distills certain aspects of human expressive behavior, especially that of the voice, and renders those aspects into dynamic musical shapes.. Levinson's claim that music can express some higher emotions (such as hope) is based on the claim that some higher emotions have characteristic physiognomies that can be musically portrayed (see ibid.).Note, however, on this view that in order for the contours of a musical phrase to express an emotion, one must recognize that this "musical utterance and behavior" is akin to other, non-musical utterances and behaviors. Thus musical expression is mediated through our understanding of social behavior in general, and what might be termed a knowledge of "social musical behavior" in particular. It is for this reason that one may mistake musical expressions in an alien musical culture, not because we do not know the musical language, but perhaps primarily because we do not know the normative social behaviors onto which the musical gestures may be mapped.
To sum up so far: the "cognitivist" theory of emotional expression in music says that a piece of music expresses emotion E if a suitably grounded listener is able to recognize correspondences between musical gesture(s) and human social behavior(s) that are the outward manifestations of particular emotional states. Note that she need not assume that this emotion was felt by the composer (or is felt by the performer), nor does the listener have to experience that emotion while listening.
(2) Deterministic finite automaton
An example of a deterministic finite automaton that accepts only binary numbers that are multiples of 3. The state S0 is both the start state and an accept state.
In theory of computation, a branch of theoretical computer science, a deterministic finite automaton (DFA)—also known as deterministic finite state machine—is a finite state machine that accepts/rejects finite strings of symbols and only produces a unique computation (or run) of the automaton for each input string. 'Deterministic' refers to the uniqueness of the computation. In search of simplest models to capture the finite state machines, McCulloch and Pitts were among the first researchers to introduce a concept similar to finite automaton in 1943.
The figure illustrates a deterministic finite automaton using a state diagram. In the automaton, there are three states: S0, S1, and S2(denoted graphically by circles). The automaton takes a finite sequence of 0s and 1s as input. For each state, there is a transition arrow leading out to a next state for both 0 and 1. Upon reading a symbol, a DFA jumps deterministically from a state to another by following the transition arrow. For example, if the automaton is currently in state S0 and current input symbol is 1 then it deterministically jumps to state S1. A DFA has a start state (denoted graphically by an arrow coming in from nowhere) where computations begin, and a set of accept states (denoted graphically by a double circle) which help define when a computation is successful.
A DFA is defined as an abstract mathematical concept, but is often implemented in hardware and software for solving various specific problems. For example, a DFA can model software that decides whether or not online user-input such as email addresses are valid.[4] (see: finite state machine for more practical examples).
DFAs recognize exactly the set of regular languages[1] which are, among other things, useful for doing lexical analysis and pattern matching. DFAs can be built fromnondeterministic finite automata (NFAs) using the powerset construction method.
A deterministic finite automaton M is a 5-tuple, (Q, , , q0, F), consisting of
Let w = a1a2 ... an be a string over the alphabet . The automaton M accepts the string w if a sequence of states, r0,r1, ..., rn, exists in Q with the following conditions:
In words, the first condition says that the machine starts in the start state q0. The second condition says that given each character of string w, the machine will transition from state to state according to the transition function . The last condition says that the machine accepts w if the last input of w causes the machine to halt in one of the accepting states. Otherwise, it is said that the automaton rejects the string. The set of strings that M accepts is the language recognized by M and this language is denoted by L(M).
A deterministic finite automaton without accept states and without a starting state is known as a transition system or semiautomaton.
For more comprehensive introduction of the formal definition see automata theory.
Complete and incomplete deterministic finite automata
According to the above definition, deterministic finite automata are always complete: they define a transition for each state and each input symbol.
While this is the most common definition, some authors use the term deterministic finite automaton for a slightly different notion: an automaton that defines at most one transition for each state and each input symbol; the transition function is allowed to be partial. When no transition is defined, such an automaton halts.
Example
The following example is of a DFA M, with a binary alphabet, which requires that the input contains an even number of 0s.
The state diagram for M
M = (Q, , , q0, F) where
0
1
S1
S2
S1
S2
S1
S2
The state S1 represents that there has been an even number of 0s in the input so far, while S2 signifies an odd number. A 1 in the input does not change the state of the automaton. When the input ends, the state will show whether the input contained an even number of 0s or not. If the input did contain an even number of 0s, M will finish in stateS1, an accepting state, so the input string will be accepted.
The language recognized by M is the regular language given by the regular expression (1 + 0 (1*) 0)*, where "*" is the Kleene star, e.g., 1* denotes any non-negative number (possibly zero) of symbols "1".
(3) Generally DFA's are used to check, whether given string is present in a certain language. e.g _ab1c is present in the Language of variables in C.
void assignPointerValuesInPairs(int index)
{
/*comments is an ArrayList
before marking start hotpointer = -1
after marking start hotpointer = 0
after marking end hotpointer is resetted to -1*/
switch(currentState)
{
case 2: /*q2*/
comments.add(/*mark start*/);
hotPointer = 0;
break;
case 0: /*On initial state q0*/
switch(hotPointer)
{
case 0: //If I am in end of comment.
comments.add(/*mark end*/);
hotPointer = -1; //Resetting the hotPointer.
break;
case -1: /*Already in q1 only*/
/*Do nothing*/
}
}
}
0
1
S1
S2
S1
S2
S1
S2
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.