# APPLICATIONS OF QUANTUM ANNEALING TO MUSIC THEORY

Institute of Theoretical and Applied Informatics, Polish Academy of Sciences
Ludmila Botelho
"...might compose elaborate and scientific pieces of music of any degree of complexity or extent"

# Quantum annealing

Proposition: Find the minimum energy in a landscape

• Ground state = optimal solution

$$H(t) = \left(1-\frac{t}{T}\right)H_0+ \frac{t}{T}H_P$$

• Different from gate based

$$H_P = - \sum_{i > j} J_{ij}s_i s_j - \sum _i h_is_i,$$

$$H(t) = \left(1-\frac{t}{T}\right)H_0+ \frac{t}{T}H_P$$

- Can be encoded in Binary Values

# Ising model

• Mathematical model to describe magnetization

$$s_i \in \{-1,+1\}$$

# NP-hard!

$$s_i \leftrightarrow x_i = \frac{1-s_i}{2}$$

$$x_i \in\{0,1\}$$

$$y=x^TQx$$

• Penalty Method

$$\text{min } y=f(x)$$

$$\text{subject to: } x_1 +x_2 + x_3= 1$$

$$\text{min }y=f(x)+P\left(\sum_{i=1}^3 x_i -1\right)^2$$

Binary variables

Constants

4

1

rest

measure

Durations

2

Pitches

C

D

A

E

G

F

B

C

# Music Generation

x_{i,j} = \begin{cases}% 1 & \text{note at position $i$ is $j$,}\\ 0 & \text{otherwise.} \end{cases}

$$\sum_{j \in P} x_{i,j} = 1$$

How to define the binary variables?

$$\left ( 1- \sum_{j \in P} x_{i,j} \right )^2$$

• Pitches

$$x_{i,C} + x_{i+1,D} \leq 1$$

$$x_{i,C} + x_{i+1,C} + x_{i+2,C} \leq 2$$

$$P=\{p_1,p_2,\dots,p_k \}$$

$$x_{i,j}$$ for $$i \in [n]$$ and $$j \in P$$

$$P=\{\mathtt{C}, \mathtt{D}, \mathtt{E}, \mathtt{G}\}$$

# Melody Generation

Optimization

$$-\sum_{ \substack{i\in [n-1] \\ j,j' \in P}} W_{j,j'} x_{i,j} x_{i+1,j'}$$

weights

Exemple: Ode to Joy excerpt

$$W_{F\#4,E4} = 2,$$

$$W_{F\#4,F\#4} = 2,$$

$$W_{F\#4,G4} = 1$$

# melody Generation

$$\sum_{\substack{i \in [n] \\ j \in D}} d(j)y_{i,j} = L$$

• Duration of notes
y_{i,j} = \begin{cases}% 1 & \text{note at position $i$ has duration $j$,}\\ 0 & \text{otherwise.} \end{cases}

# Rhythm Generation

$$\sum_{j \in D} y_{i,j} = 1$$

$$D = \{1,2,3,4\}$$

$$j \in D$$

# Harmonization

x_{i,j} = \begin{cases}% 1 & \text{chord at position $i$ contains note $j$,}\\ 0 & \text{otherwise.} \end{cases}

$$\sum_{j \in P} x_{i,j} = 3$$

$$(1-x_{i,p_{i_j}})$$

G

E

D

G

B

B

G

Boléro (Ravel, Maurice)

Monophonic

Polyphonic

# Music is complex

• Phrase Identification

Huang, Jiun-Long, Shih-Chuan Chiu, and Man-Kwan Shan. "Towards an automatic music arrangement framework using score reduction." ACM Transactions on Multimedia Computing, Communications, and Applications (TOMM) 8.1 (2012): 1-23.

• Phrase Identification

# QUBO Formulation

• Variables and objective function
• Entropy

- Pitch and rhythm

- Maximize information

$$x_{ij} =\begin{cases}1,& \text{j'th phrase of track i is selected}\\ 0, & \text{otherwise.}\end{cases}$$

$$- \sum_{i=1}^N\sum_{j=1}^{P_i} e(p_{ij})x_{ij}$$

$$E(s) = - \sum_{i=1}^N P(x_i)\ln P(x_i)$$

# QUBO Formulation

• Constraints

$$x_{ij} = 1 \iff m_{ik}=1 k \in S_{ij}$$

$$\sum_{i=1}^N m_{ik} = M \ \ \text{for} \ \ k=1,\dots,K$$

Set of measures in phrase $$j$$ of $$i$$’th track

Number of measures

Number of tracks after reduction

• Similar to fixed interval scheduling

binary variable

# Future work

• Compatibility between selected phrases

- Dissonance criteria

• Track support for selected phrase

Guitar: 4 octaves

Piano: 8 octaves

By ludmilaasb

• 255