Public
Edited
Sep 8, 2023
Insert cell
Insert cell
Math.round(cent(3/2))
Insert cell
[3/2, 10/6].map(center)
Insert cell
Insert cell
ascendingMajorTonality =
[1/1,3/2,5/4,7/4]
Insert cell
ascendingMajorTonality.map(center)
Insert cell
ascendingMajorTonality.map(f)
Insert cell
amts = ascendingMajorTonality.map(f)
Insert cell
lcm(...amts.map(k => k.d))
Insert cell
lcm(1,2,3,4,5,6,)
Insert cell
[
{s: 1, n: 120, d: 60},
{s: 1, n: 90, d: 60},
{s: 1, n: 80, d: 60},
{s: 1, n: 75, d: 60},
{s: 1, n: 72, d: 60},
].map(f)
Insert cell
F(1,1)
.gcd(3,2)
.gcd(5,4)
.gcd(7,4)
.gcd(7,5)
Insert cell
F(1,1).abs()
Insert cell
F(3,2).mul(2/4)
Insert cell
F(5,4).mul(4/4)
Insert cell
amts.map(k => k.d)
Insert cell
F(1/2)
Insert cell
Insert cell
F(3,2).mul(F(3,2))
Insert cell
F(3,1).div(4,1)
Insert cell
F(12,9)
Insert cell
Insert cell
F(9,8).mul(10,9)
// to get Just Major Third
// sum the Major Wholetone (frequency ratio 9/8) and the Minor Wholetone (10/9)
Insert cell
F(2,1).mul(6,7)
// to get Septimal Major Sixth
// subtract a Sub-minor Third In from the Octave
Insert cell
F(12,7).mul(4/5)
// to get Septimal Sixth
// subtract the Just Major Third (frequency ratios 12/7 × 4/5) to get the dissonance 48/35
Insert cell
F(4,3).mul(8,9).mul(8,9)
// the interval “left over” when two Pythagorean Wholetones (frequency ratios 9/8 × 9/8 = 81/64)
// are subtracted from a pure Fourth (4/3)
Insert cell
Insert cell
Insert cell
Insert cell
// options are mirrored; e.g.
// 2 equal-sized sections divides the whole as 1:1, and its mirror: hence 1 option
// 3 -> 1:2, and its its mirror 2:1: hence 1 option
// 4 -> 1:3, 2:2 and their mirrors: hence 2 options
// 5 -> 1:4, 2:3, and their mirrors: hence 2 options
// 6 -> 1:5, 2:4, 3:3, and their mirrors: hence 3 options
// 7 -> 1:6, 2:5, 3:4, and their mirrors: hence 3 options
// 8 -> 1:7, 2:6, 3:5, 4:4, and their mirrors: hence 4 options
// 9 -> 1:8, 2:7, 3:6, 4:5, and their mirrors: hence 4 options
// 10 -> 1:9, 2:8, 3:7, 4:6, 5:5, and their mirrors: hence 4 options
Inputs.table(
d3
.range(1,11)
.map(
(harmonic) => {
const options = (harmonic/2)|0;
const lengths = aap(harmonic);
return ({
harmonic,
options,
lengths: lengths.map(([n,d]) => n + "/" + d).join(", "),
frequencies: lengths.map(([d, n]) => [n, d]),
})
}
),
// {width:36*9}
)
Insert cell
d3.range(1, 10/2+1).map((d) => [d, (10 - d)])
Insert cell
aap = n => d3.range(1, ((n / 2)|0)+1)
.map((d) => [d, n])
Insert cell
aap(10)
Insert cell
Insert cell
[
(1**2 + 1**2) ** (1/2),
(2 ** (1/2) + 1) ** .5,
]
Insert cell
Insert cell
center = R.pipe(
cent,
Math.round,
)
Insert cell
Insert cell
syntonicComma = F(9,8).div(10,9)
Insert cell
Insert cell
Insert cell
array_primeFactors = primeFactors(integer)
Insert cell
numbers = d3.dsvFormat(":").parse("24:27:30:32:36:40:45:48").columns.map(Number)
Insert cell
primes = numbers.map(primeFactors)
Insert cell
primes.map(powers)
Insert cell
powers = (list) => list.reduce((map, val) => {map[val] = (map[val] || 0) + 1; return map}, {} );
Insert cell
{
var size = array_primeFactors.length;
var result_1 = '', result_2 = '';
var power = 1;
var use_power = false;
var times = '';

// Display result no.1;
result_1 = array_primeFactors[size-1].toString().concat(result_1);
for(let i= size-2; i>=0; i--){
result_1 = array_primeFactors[i].toString().concat(' × ',result_1);
}

// Display result no.2;
for(let i= size-1; i>=0; i--){
if(array_primeFactors[i]==array_primeFactors[i-1]){
power += 1;
use_power = true;
} else {
if(power==1) {power="";} // We don't display "^1"
if(result_2 != '') { times = ' × ';} // Condition is fulfilled to add the times (×) symbol.
result_2 = array_primeFactors[i].toString().concat('<sup>',power,'</sup>',times,result_2);
power = 1; // Reinitialize power to 1
}
}
if(size>1){
return html`<i>n</i>
= ${integer}
= ${use_power == false? ` ${result_1}.` : `${result_1}
= ${result_2}.` }
`;
}
else{
return html `${integer} is prime.<br/>`;
}
}
Insert cell
// See also:
// https://stackoverflow.com/questions/39899072/how-can-i-find-the-prime-factors-of-an-integer-in-javascript
//
// Find the prime factors of the natural number 'n'
function primeFactors(n) {

if (n<2) { return [n]; } // For n = 0 or n = 1, we return an array with only one row: [n]

const factors = [];
let divisor = 2;

while (n >= 2) {
if (n % divisor == 0) {
factors.push(divisor);
n = n / divisor;
} else {
divisor++;
}
}
return factors;
}
Insert cell
f = (args) => F(args)
Insert cell
trans0 = FileAttachment("20-trans-0.png").image({width:640})
Insert cell
Insert cell
unison = F(1)
Insert cell
octave = unison.mul(2)
Insert cell
C = unison
Insert cell
C2 = octave
Insert cell
P5 = F(3,2)
Insert cell
G = P5
Insert cell
Insert cell
D = G.div(P4)
Insert cell
G.mul(P5).div(2)
Insert cell
A = D.mul(P5)
Insert cell
P4 = F(4,3)
Insert cell
Fnote = // F is:
C2.div(P5) // P5 down from C2, or
Insert cell
C.mul(P4).compare(Fnote) === 0
Insert cell
lcm(8,9,15,8)
Insert cell
Insert cell
F = require('fraction.js@4.0/fraction.js')
Insert cell
import {lcm} from "@martien/math-helpers"
Insert cell
// import {cent} from "@martien/cent"
import {M} from "@martien/music"
Insert cell
cent = M.cent
Insert cell
R = require("ramda")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more