We explore the use of quantum computational methods in narrative generation through the construction of QuNL, a declarative language for describing subjective elements in narrative construction in quantum computational terms and QuNE a special-purpose interpreter for executing QuNL programs on a classical computer..
- QuNL (Quantum Narrative Language)
QuNL allows the user to specify four types of computational entities: Basis, Protagonist, Ethos and Praxis.
Basis. Each basis provides a reference frame for representing the protagonist states with regards to two opposing qualities. For example wealth@hero can be defined as a basis that corresponds to a 2D coordinate system with an x-vector called ‘rich’ with value [cos(30.0), sin(30.0)] and a y-vector called ‘poor’ with value [cos(120.0), sin(120.0)] where the angle values are in degrees. The following QuNL statement describes all this information (currently QuNL expects all numerical values to be in floating point format X.X):
Basis wealth@hero <- rich [cos(30.0), sin(30.0)] poor [cos(120.0), sin(120.0)];
Figure 1: Anatomy of a Basis statement in QuNL.
In addition, a Basis can be defined with respect to an already defined basis as in:
Basis health@hero <- healthy sick #Angle 10.0 #WithRespectTo wealth@hero;
In this statement a new basis ‘health@hero’ is defined consisting of an x-vector named ‘healthy’ and a y-vector called ‘sick’ each of which forms a 10 degree angle with the corresponding x- and y- vectors of the ‘wealth@hero’ basis. The #Angle and #WithRespectTo keywords are used to indicate the relative angle and the reference basis respectively.
In QuNL we can refer to any of the two unit vectors of a Basis with the expression:
For example, the expression sick(health@hero) refers to the ‘sick’ vector of the ‘health@hero’ basis.
Protagonist. Each protagonist describes the initial state of a story character. For example, the statement:
Protagonist hero <- #Amplitude [cos(45.0), sin(45.0)] #WithRespectTo health@hero;
describes the initial state of a protagonist named ‘hero’ as a unit vector with value [cos(45.0), sin(45.0)] in the coordinate system defined by Basis ‘health@hero’. Figure 2 describes the anatomy of a Protagonist statement.
Figure 2: Anatomy of a Protagonist statement.
Ethos. A set of qualities that a protagonist seeks to achieve as closely as possible (‘ethos’ is hellenic for the guiding beliefs of a person) . For example, the statement:
Ethos hero <- rich(wealth@hero) healthy(health@hero);
denotes that the protagonist ‘hero’ seeks to move his state as close as possible to the positions of the vectors ‘rich’ of basis ‘wealth@hero’ and ‘healthy’ of basis ‘health@hero’. Figure 3 describes the structure of Ethos statements.
Figure 3: Anatomy of an Ethos statement.
Praxis. A Praxis statement represents the subjective imprint of an action (‘praxis’ is hellenic for ‘action’) that a protagonist may use in order to achieve the qualities in his Ethos. A Praxis statement may contain variables which in QuNL are denoted as identifiers beginning with ‘?’. The following statement defines a Praxis named ‘Steal’.
Praxis Steal <-
#Actors (?subject != ?object)
?p <- Prob ?subject = evil(morality@?subject)
?p > 0.7
?h <- Prob ?object = rich(wealth@?subject)
?h > 0.9
(Entangle [?subject ?object] [?p*?h]
Each Praxis statement contains three fields, #Actors, #Context and #Effects.. The #Actors field contains statements defining the actors taking part in the Praxis and constraining the values of the Praxis variables independent of the context in which the Praxis can be executed. For example in the case of the Steal action above the #Actors statements denote that the subject of the action (referred to by the built-in Praxis variable ?subject) should be different from the person to which the object is directed to (referred to by the built-in Praxis variable ?object).
The #Context field contains a set of statements that describe the context under which the action can take place. Since the context can be quite general the types of statements that can be supported in this field can be quite extensive. At its current version QuNL supports the computation of the probabilities of a superposition observed to have a particular value represented with the Prob command. For example the statement:
?p <- Prob ?subject = evil(morality@?subject)
computes the probability with which the superposition of the protagonist state bound to the value of the variable ?subject can be found through measurement to be equal to the vector ‘evil’ of the basis ‘morality@?subject’ where again the variable ?subject is appropriately bound. The value of this probability is then assigned to the variable ?p. The context of the particular Steal action then indicates that in order for this action to be considered for execution the prospective thief has to think of himself as being primarily evil (with a probability >0.7) and he also has to think of the victim as being rich (with a probability >0.9).
In addition the Praxis context can contain a Metro statement (‘metro’ is hellenic for measure). A Metro statement causes a measurement of a stte in a given basis. For example, the statement
?decision <- Metro #State hero #WithRespectTo romance
will cause a measurement of the state ‘hero’ in the basis ‘romance’. The result of the measurement will be the name of the unit vector of the basis ‘romance’ in which the superposition ‘hero’ will collapse. This result will be stored in the variable ‘?decision’.
Furthermore, the context of a Praxis statement can contain statements comparing various values through the use of the usual operators ‘>’, ‘<‘, ‘=’, ‘>=’, ‘<=’, ‘!=’. It can also contain special functions such as the Random() function which generates a random number between 0 and 1.
Finally, the #Effects field describes the effect of this action according to the persons involved in it. In the current QuNL version Praxis can have three effects:
- Create entanglements between various protagonist states.
- Transform one or more superpositions.
- Stop narrative generation because a final resolution for the story has been found.
Entanglements are established using the Entangle statement. This statement takes three arguments each one enclosed in brackets () that describe how the states (e.g. ?subject and ?object) in its first argument will be correlated. The second argument of this statement defines the probability P with which the correlation described in its third argument can be established through measurement. Finally, the third argument describes the pair of unit vectors of two bases (e.g. A and B) in which the values of the entangled states will collapse after measurement with probability P. Then the probability of the ?subject and ?object states collapsing on the other pair of unit vectors of bases A and B is 1-P and is computed automatically by the system. For example in the following Entangle statement:
(Entangle [?subject ?object] [?p*?h]
P = ?p*?h, A = wealth@?subject, B = wealth@?object and the statement establishes the following entanglement relation between the ?subject and ?object states:
(?p*?h)*|rich(wealth@?subject) poor(wealth@?object)> + (1-?p*?h)*|poor(wealth@?subject) rich(wealth@?object)>
As a result when this entanglement is resolved through measurement then with a (?p*?h) probability stealing will succeed and the thief (?subject) will think of himself as rich while the victim (?object) will think of himself as poor or with a (1-?p*?h) probability stealing will fail and the thief will think of himself as poor and the victim will think that he remains rich.
Superposition transformations take place through the Transform statement. This statement takes three arguments each one enclosed in a pair of brackets (). The first one denotes the state that will be transformed while the second argument defines the probability with which the transformed state will be measured to be identical with the vector of the basis described by its third argument. For example the following Self-Employ action (in which the subject attempts to work for himself if he thinks he is sufficiently poor) will result in transforming the superposition of the ?subject into one in which the probability that he thinks that he is poor is cut by half.:
Praxis Self-Employ <-
#Actors (?subject = ?object)
?p <- Prob ?subject = poor(wealth@?subject)
?p < 0.6
(Transform ?subject [?p/2.0] [poor(wealth@?subject)])
A Stop statement is trigerred by a Praxis that causes narrative generation to finish. It takes a variable set of arguments that correspond to the text that will be displayed at the and of the story. For example the statement
(Stop this is the end)
will result in terminating the narrative generation process with the statement ‘** End Of Story ** this is the end’. Note that narrative generation terminates either through the execution a Stop statement of if the interpreter(see below) finds no applicable actions for the protagonists.
QuNL allows comments in the program code, Each comment line should be preceded with the ‘//’ characters.
- QuNE (Quantum Narrative Engine)
QuNE is our online interpreter for QuNL that can be found here. The user interface for QuNE consists of two windows: User Input and QuNE Output. The User Input window allows the user to input one of more QuNL statements. The statements are sent to the interpreter by pressing the ‘Send QuNL command’ button. The output of the interpreter is displayed in the QuNE Output window.
Apart from QuNL statements, QuNE accepts three commands (all QuNE commands begin with ‘:’) :show, :run and :clear. The ‘:show‘ command displays the current contents of the symbol table used by the interpreter.
The ‘:run’ command instructs the interpreter to start constructing the narrative by iteratively executing the Praxis statements given by the user. Each iterative execution is noted as a plot cycle in the interpreter output. Currently, the interpreter runs each program for a maximum of 20 plot cycles.
Finally, the ‘:clear‘ command clears the contents of the QuNE symbol table.
An example QuNL program describing the setup for a short love story between a girl and two contenders the hero and antihero can be found here. Another example based on the ‘Continuity of the Parks’ novel by J. Cortázar can be found here. To run any of the examples paste the QuNL code in the User Input window and press the ‘Send QuNL command’ button. Then type ‘:run’ at the User Input window. The program output will appear at the QuNE Output window. If you want to run the example again or another example then type ‘:clear’ in the User Input window, paste again the text and use the ‘run’ command as before. Enjoy!