From 62b7145f2761bd92d5c89864c8dedc6ff647fd31 Mon Sep 17 00:00:00 2001 From: Lumi Pakkanen Date: Sun, 9 Jun 2024 16:42:30 +0300 Subject: [PATCH] Simplify linear quantities in parallelotope ref #344 --- src/parser/__tests__/stdlib.spec.ts | 18 ++++++++++++++++++ src/stdlib/prelude.ts | 6 ++++++ 2 files changed, 24 insertions(+) diff --git a/src/parser/__tests__/stdlib.spec.ts b/src/parser/__tests__/stdlib.spec.ts index db854926..16a3056a 100644 --- a/src/parser/__tests__/stdlib.spec.ts +++ b/src/parser/__tests__/stdlib.spec.ts @@ -1576,4 +1576,22 @@ describe('SonicWeave standard library', () => { '2 blue', ]); }); + + it('has reasonable default formatting for a parallellotope', () => { + const scale = expand('parallelotope([3/2, 7/81], [5, 1], [0, 0], 2/1)'); + expect(scale).toEqual([ + '28/27', + '9/8', + '7/6', + '81/64', + '21/16', + '112/81', + '3/2', + '14/9', + '27/16', + '7/4', + '243/128', + '2/1', + ]); + }); }); diff --git a/src/stdlib/prelude.ts b/src/stdlib/prelude.ts index 0c512d7f..b79690a1 100644 --- a/src/stdlib/prelude.ts +++ b/src/stdlib/prelude.ts @@ -513,6 +513,12 @@ riff parallelotope(basis, ups = niente, downs = niente, equave = 2, basisSizeHin axis ~tns~ ££; } + (* It's too hard to keep track of good formatting during tensoring. Simplify non-unison linears. *) + const l = isLinear($) + if (l) + l[0] = false + $[l] = simplify $[l] + if (basisSizeHints == niente and equaveSizeHint == niente) return sort($ ~rdc equave);