Skip to content

Commit

Permalink
Implement weilHeight utility
Browse files Browse the repository at this point in the history
  • Loading branch information
frostburn committed Apr 30, 2024
1 parent 88395d8 commit 557bcad
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions documentation/BUILTIN.md
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,9 @@ Convert value to a boolean. Vectorizes over arrays.
### void()
Get rid of expression results. `void(++i)` increments the value but doesn't push anything onto the scale.

### weilHeight(*x*)
Calculate the Weil height of the interval. Natural logarithm of the maximum of numerator or denominator.

### wellTemperament(*commaFractions*, *comma = 81/80*, *down = 0*, *generator = 3/2*, *period = 2*)
Generate a well-temperament by cumulatively modifying the pure fifth `3/2` (or a given generator) by fractions of the syntonic/given comma.

Expand Down
9 changes: 9 additions & 0 deletions src/parser/__tests__/vector-broadcasting.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,4 +392,13 @@ describe('SonicWeave vector broadcasting', () => {
[-1, NaN],
]);
});

it('has a broadcasting Weil height', () => {
const ln5 = sw0D`weilHeight 3/5`;
expect(ln5.valueOf()).toBeCloseTo(Math.log(5));

const [ln2, ln3] = sw1D`[2, 3/2] weilHeight`;
expect(ln2.valueOf()).toBeCloseTo(Math.LN2);
expect(ln3.valueOf()).toBeCloseTo(Math.log(3));
});
});
4 changes: 4 additions & 0 deletions src/stdlib/prelude.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ riff oddLimitOf(x, equave = 2) {
const noEquaves = x ~% equave^(x dot %logarithmic(equave));
return numerator(noEquaves) max denominator(noEquaves);
}
riff weilHeight(x) {
"Calculate the Weil height of the interval. Natural logarithm of the maximum of numerator or denominator.";
return (tenneyHeight x ~+ log(labs x)) ~/ 2;
}
riff hypot(...args) {
"Calculate the square root of the sum of squares of the arguments.";
return sum(map(a => a ~^ 2, args)) ~/^ 2;
Expand Down

0 comments on commit 557bcad

Please sign in to comment.