User:Frostburn/SonicWeave

Revision as of 11:49, 10 December 2023 by Frostburn (talk | contribs) (Sketch up to real logarithmic types.)

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.

Still very much a work in progress. Expect things to shift around as I design a parseable grammar.

Values

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.

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]\displaystyle{ \mathbb{B} \subset \mathbb{Z} \subset \mathbb{Q} \subset \mathrm{radical} \subset \mathbb{R} }[/math]

Type system

Values are dressed into types to implement domain-specific operator overloading and type-aware function overloading.

Rational linear types

[math]\displaystyle{ \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.

Radical linear types

[math]\displaystyle{ \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]\displaystyle{ \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.

Rational logarithmic types

[math]\displaystyle{ \begin{align} \mathrm{fjs} &\supset \{ \mathrm{P5}, \mathrm{M3}^5 \} \\ \mathrm{ji} &= \mathrm{fjs} \end{align} }[/math]

Radical logarithmic types

[math]\displaystyle{ \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]

Real logarithmic types

[math]\displaystyle{ \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.