Skip to content

Commit 5d19a72

Browse files
committed
refactor: streamline Set serialization and improve condition expression documentation
1 parent d2eca2f commit 5d19a72

File tree

3 files changed

+7
-50
lines changed

3 files changed

+7
-50
lines changed

src/compute-engine/latex-syntax/dictionary/definitions-sets.ts

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -594,34 +594,7 @@ function serializeSet(
594594
const h = operator(expr);
595595
if (!h) return '';
596596

597-
//
598-
// `Set`
599-
//
600-
if (h === 'Set') {
601-
if (nops(expr) === 0) return '\\emptyset';
602-
603-
//
604-
// 1/ First variant: ["Set", <set | predicate>, ["Condition"]]
605-
//
606-
if (nops(expr) === 2 && operator(operand(expr, 2)) === 'Condition') {
607-
return joinLatex([
608-
'\\left\\lbrace',
609-
serializer.serialize(operand(expr, 1)),
610-
'\\middle\\mid',
611-
serializer.serialize(operand(expr, 2)),
612-
'\\right\\rbrace',
613-
]);
614-
}
615-
616-
//
617-
// 2/ 2nd variant: ["Set", ...<sequence>]
618-
//
619-
return joinLatex([
620-
'\\left\\lbrace',
621-
...operands(expr).map((x) => serializer.serialize(x) + ' ,'),
622-
'\\right\\rbrace',
623-
]);
624-
}
597+
// Note: `Set` serialization is handled by the matchfix entry's inline serializer.
625598

626599
//
627600
// Multiple

src/compute-engine/library/control-structures.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ export const CONTROL_STRUCTURES_LIBRARY: SymbolDefinitions[] = [
2727
evaluate: evaluateBlock,
2828
},
2929

30-
// A condition expression tests for one or more conditions of an expression
31-
// ['Condition', value, "positive"]
30+
// A condition expression tests for one or more conditions of an expression.
31+
// Two forms:
32+
// ['Condition', value, "positive"] — tests value against named condition(s)
33+
// ['Condition', predicate] — set-builder predicate (e.g. x > 0)
3234
Condition: {
3335
description: 'Test whether a value satisfies one or more conditions.',
3436
lazy: true,
35-
signature: '(value, symbol) -> boolean',
37+
signature: '(expression, symbol?) -> boolean',
3638
evaluate: ([value, conds], { engine }) => {
3739
let conditions: string[] = [];
3840
if (isSymbol(conds)) {

test/compute-engine/latex-syntax/sets.test.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ describe('SERIALIZING SETS', () => {
2525
});
2626

2727
test('Complement', () => {
28-
expect(latex(['Complement', 'A'])).toMatchInlineSnapshot(
29-
`A^\\complement`
30-
);
28+
expect(latex(['Complement', 'A'])).toMatchInlineSnapshot(`A^\\complement`);
3129
});
3230

3331
// test('Range', () => {});
@@ -718,10 +716,6 @@ describe('SET BUILDER NOTATION', () => {
718716
x,
719717
0,
720718
],
721-
[
722-
Error,
723-
missing,
724-
],
725719
],
726720
]
727721
`);
@@ -744,10 +738,6 @@ describe('SET BUILDER NOTATION', () => {
744738
x,
745739
0,
746740
],
747-
[
748-
Error,
749-
missing,
750-
],
751741
],
752742
]
753743
`);
@@ -767,10 +757,6 @@ describe('SET BUILDER NOTATION', () => {
767757
x,
768758
0,
769759
],
770-
[
771-
Error,
772-
missing,
773-
],
774760
],
775761
]
776762
`);
@@ -790,10 +776,6 @@ describe('SET BUILDER NOTATION', () => {
790776
x,
791777
0,
792778
],
793-
[
794-
Error,
795-
missing,
796-
],
797779
],
798780
]
799781
`);

0 commit comments

Comments
 (0)