User:Frostburn/SonicWeave: Difference between revisions

Frostburn (talk | contribs)
Expand type hierarchy but leave TODOs for obscure types.
Frostburn (talk | contribs)
Expand on rational frequencies and define relative to absolute conversion.
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
This is my second attempt at creating a a Domain Specific Language (DSL) called ''SonicWeave'' for manipulating frequencies, ratios and pitches in Scale Workshop 3.
This is a description of the design philosophy behind the Domain Specific Language (DSL) called ''SonicWeave'' for manipulating frequencies, ratios and pitches in Scale Workshop 3.


Still very much a work in progress. Expect things to shift around as I design a parseable grammar.
== Units as vectors ==
== Values ==
Let's first establish that it makes sense to talk about quantities as vectors. We can choose a basis consisting of the exponents of the second, the metre and the kilogram. Now we can plot Hertz at -1 on the exponents-of-second axis, Newton at coordinates (-2, 1, 1) and Pascal at coordinates (-2, -1, 1).
Values consist of strings, functions and extended time monzos which combine a rational time exponent, rational prime exponents, a multiplicative rational residual and a catch-all real cents offset.
[[File:Units-as-vectors.png|thumb|Hertz, Newton and Pascal plotted on a basis consisting of the exponents of SI base units.]]
== Domains ==
Theres a linear domain where 3/2 + 3/2 means 3 (as a ratio of two frequencies) and a logarithmic domain where 3\2 + 3\2 means 8 (as a ratio of two frequencies).
== Tiers ==
Types are organized into tiers consisting of booleans, integers, rationals, radicals (i.e. rationals raised to rational powers) and reals.


<math>
== Rational frequencies as vectors ==
\mathbb{B} \subset \mathbb{Z} \subset \mathbb{Q} \subset \mathrm{radical} \subset \mathbb{R}
When dealing with musical data we mostly care about frequencies measured in Hertz. To represent frequencies other than 1 Hz we need more basis vectors and by the [[Wikipedia:Fundamental theorem of arithmetic|fundamental theorem of arithmetic]] we can choose the exponents of prime numbers to get a vector representation of any rational multiple of 1 Hz.
</math>
== Type system ==
Values are dressed into types to implement domain-specific operator overloading and type-aware function overloading.
=== Rational linear types ===
<math>
\begin{align}
\mathrm{boolean} &= \mathbb{B} = \{0, 1\} \\
\mathrm{integer} &= \mathbb{Z} \supset \{1, 2, 3, 4\} \\
\mathrm{fraction} &\supset \{3/2, 5/3\} \\
\mathrm{decimal} &\supset \{(1.2), (1.4), (1,5)\} \\
\mathrm{rational} &= \mathbb{Q} = \mathrm{integer} \cup \mathrm{fraction} \cup \mathrm{decimal}
\end{align}
</math>


Note: Decimals require surrounding parenthesis when using a decimal dot but may be entered plain when using a decimal comma.
Using the basis of (the exponents of) the second, prime 2 and prime 3 we can plot 1 Hz at (-1, 0, 0), 2 Hz at (-1, 1, 0), 3 Hz at (-1, 0, 1) and 4/3 Hz at (-1, 2, -1). [TODO: image]


=== Radical linear types ===
To make sense of vector addition we say that objects in this space represent the frequency you get at the intersection of the line from origin and the Hertz plane e.g. the sum of 9 Hz and 4 Hz is 36 Hz² and represent the frequency 6 Hz i.e. the geometric average of 9 Hz and 4 Hz. This is one part of what the '''ablog''' (short for ''absolute logarithmic'') function in SonicWeave does. [TODO: image]
<math>
\begin{align}
\mathrm{radicalExpression} &\supset \{\sqrt{3}, 2^\frac{5}{3}\} \\
\mathrm{radical} &= \mathrm{rational} \cup \mathrm{radicalExpression}
\end{align}
</math>
=== Real linear types ===
<math>
\begin{align}
\mathrm{integer!} &\supset \{69!, 420!\} \\
\mathrm{decimal!} &\supset \{(3.14159!), (2.718!)\} \\
\mathrm{real} &= \mathbb{R} = \mathrm{radical} \cup \mathrm{integer!} \cup \mathrm{decimal!}
\end{align}
</math>


Note: Real linear types are mostly an artifact of the catch-all property extended time monzos. Not recommended for everyday use.
This works for everything except for objects with 0 as the exponent of the second. These objects form the relative echelon in Sonic Weave where the conversion from linear factors to logarithmic pitch is handled by the '''logarithmic''' function. In this document we notate it using a right-facing arrow:
=== Rational logarithmic types ===
<math>
\begin{align}
\mathrm{fjs} &\supset \{ \mathrm{P5}, \mathrm{M3}^5 \} \\
\mathrm{ji} &= \mathrm{fjs}
\end{align}
</math>
=== Radical logarithmic types ===
<math>
\begin{align}
\mathrm{nedo} &\supset \{ 5\backslash 7, 7\backslash 12 \} \\
\mathrm{nedji} &\supset \{ 7\backslash 13<3>, 1\backslash 3<5/3> \} \\
\mathrm{cents} &\supset \{.5, 1.955, 100., c \} \\
\mathrm{monzo} &\supset \{[-4, 4, -1>, [1/2, 1/3> \} \\
\mathrm{xfjs} &\supset \{\mathrm{n3}, \mathrm{m4.5}\} \\
\mathrm{pitch} &= \mathrm{ji} \cup \mathrm{nedo} \cup \mathrm{nedji} \cup \mathrm{cents} \cup \mathrm{monzo} \cup \mathrm{xfjs}
\end{align}
</math>
=== Radical co-logarithmic types ===
<math>
\begin{align}
\mathrm{jorp} &= \{€\} \\
\mathrm{warts} &\supset \{5@, 17c@, [email protected]/5, b13@\} \\
\mathrm{val} &\supset \{<12, 19, 28]\} \\
\mathrm{copitch} &= \mathrm{jorp} \cup \mathrm{warts} \cup \mathrm{val}
\end{align}
</math>
=== Real logarithmic types ===
<math>
\begin{align}
\mathrm{cents!} &\supset \{.777!, 1901.955!, 69.!, c!\} \\
\mathrm{freePitch} &= \mathrm{pitch} \cup \mathrm{cents!}
\end{align}
</math>
 
Similarly, the free pitch type is unlikely to be relevant in day-to-day use of SW3.
 
=== Real co-logarithmic types ===
<math>
\begin{align}
\mathrm{jorp!} &= \{€!\} \\
\mathrm{freeCopitch} &= \{x * €!, x \in \mathbb{R}\}
\end{align}
</math>


Note: Completionism is an illness.
<math>\overrightarrow{2^x 3^y 5^z \ldots} \mapsto x e_2 + y e_3 + z e_5 + \ldots, x, y, z, \ldots \in \mathbb{Q}</math>
 
=== Linear unit quantities ===
<math>
\begin{align}
\mathrm{second} &= \{s\} \\
\mathrm{hertz} &= \{Hz\}
\end{align}
</math>
 
=== Rational linear quantities ===
<math>
\mathrm{rationalTime} = \{p * s^q, p \in \mathbb{Q}, q \in \mathbb{Q} \}
</math>
 
Note: Decimal numbers do not require parenthesis when implicitly multiplying unit quantities e.g. "261.6 Hz" is a valid expression.
 
=== Radical linear quantities ===
<math>
\mathrm{radicalTime} = \{p * s^q, p \in \mathrm{radical}, q \in \mathbb{Q} \}
</math>
 
=== Real linear quantities ===
<math>
\mathrm{realTime} = \{p * s^q, p \in \mathbb{R}, q \in \mathbb{Q} \}
</math>
 
=== Rational logarithmic quantities ===
<math>
\begin{align}
\mathrm{afjs} &\supset \{\mathrm{C4}, \mathrm{E5}^5\} \\
\mathrm{aji} &= \mathrm{afjs}
\end{align}
</math>
 
=== Rational co-logarithmic quantities ===
TODO
 
=== Radical logarithmic quantities ===
<math>
\begin{align}
\mathrm{axfjs} &\supset \{\mathrm{C½♭4}, \mathrm{\alpha 3}\} \\
\mathrm{acents} &= \{ac\} \\
\mathrm{apitch} &= \mathrm{aji} \cup \mathrm{axfjs} \cup \mathrm{acents}
\end{align}
</math>


=== Radical co-logarithmic quantities ===
''Relative logarithmic'' vector addition is the same as multiplication of the represented ''linear'' values.
TODO


=== Real logarithmic quantities ===
<math>\overrightarrow{a} + \overrightarrow{b} = \overrightarrow{a b}</math>
TODO


=== Real co-logarithmic quantities ===
=== Conversion from relative to absolute ===
TODO
The second part of '''ablog''' requires a unison frequency declaration like <code>1/1 = 440 Hz</code>. In this document we denote <math>e_0 = \overrightarrow{1 Hz}</math> and the declared unison frequency as <math>e_0'</math> e.g <math>e_0' = \overrightarrow{440 Hz}</math>


Note: Make it stop.
''Relative logarithmic'' values are converted to ''absolute logarithmic'' frequencies simply by adding <math>e_0'</math>. e.g. '''ablog(logarithmic(81/55))''' is


=== Domain types ===
<math>
<math>
\begin{align}
\overrightarrow{\frac{81}{55}} + e_0' = (4 e_3 - e_5 - e_{11}) + (3 e_2 + e_5 + e_{11} + e_0) = 3 e_2 + 4 e_3 + e_0 = \overrightarrow{648 Hz}
\mathrm{linear} &= \ldots \\
\mathrm{logarithmic} &= \ldots \\
\end{align}
</math>
</math>