@@ -164,7 +164,8 @@ describe('SUM parsing', () => {
164164 } ) ;
165165
166166 test ( 'parsing of summation with element in List' , ( ) => {
167- // [1,5] is parsed as a List, not a Range
167+ // [1,5] is parsed as a List (parsing unchanged), but evaluated as Range
168+ // See EL-1: 2-element integer Lists are treated as Range in Element context
168169 expect ( ce . parse ( `\\sum_{n \\in [1,5]}n` ) ) . toMatchInlineSnapshot (
169170 `["Sum", "n", ["Element", "n", ["List", 1, 5]]]`
170171 ) ;
@@ -284,9 +285,15 @@ describe('SUM with Element indexing set', () => {
284285 ) . toMatchInlineSnapshot ( `14` ) ;
285286 } ) ;
286287
287- test ( 'sum over List' , ( ) => {
288- // [1,5] parses as a List, not Range - evaluates to 1+5=6
289- expect ( evaluate ( `\\sum_{n \\in [1,5]}n` ) ) . toMatchInlineSnapshot ( `6` ) ;
288+ test ( 'sum over List bracket notation' , ( ) => {
289+ // EL-1: [1,5] is now treated as Range(1,5) in Element context
290+ // so \sum_{n \in [1,5]}n = 1+2+3+4+5 = 15
291+ expect ( evaluate ( `\\sum_{n \\in [1,5]}n` ) ) . toMatchInlineSnapshot ( `15` ) ;
292+ } ) ;
293+
294+ test ( 'sum over List bracket notation with formula' , ( ) => {
295+ // [1,4] treated as Range(1,4), sum of squares: 1+4+9+16 = 30
296+ expect ( evaluate ( `\\sum_{n \\in [1,4]}n^2` ) ) . toMatchInlineSnapshot ( `30` ) ;
290297 } ) ;
291298
292299 test ( 'sum over Range via box' , ( ) => {
@@ -326,6 +333,53 @@ describe('SUM with Element indexing set', () => {
326333 const reparsed = ce . parse ( latex ) ;
327334 expect ( reparsed . json ) . toEqual ( parsed . json ) ;
328335 } ) ;
336+
337+ // EL-6: Interval support with Open/Closed boundaries
338+ test ( 'sum over closed Interval via box' , ( ) => {
339+ // Closed interval [1, 5] → iterates 1, 2, 3, 4, 5
340+ const expr = ce . box ( [ 'Sum' , 'n' , [ 'Element' , 'n' , [ 'Interval' , 1 , 5 ] ] ] ) ;
341+ expect ( expr . evaluate ( ) . json ) . toBe ( 15 ) ;
342+ } ) ;
343+
344+ test ( 'sum over half-open Interval (open start) via box' , ( ) => {
345+ // Interval (0, 5] → iterates 1, 2, 3, 4, 5
346+ const expr = ce . box ( [
347+ 'Sum' ,
348+ 'n' ,
349+ [ 'Element' , 'n' , [ 'Interval' , [ 'Open' , 0 ] , 5 ] ] ,
350+ ] ) ;
351+ expect ( expr . evaluate ( ) . json ) . toBe ( 15 ) ;
352+ } ) ;
353+
354+ test ( 'sum over half-open Interval (open end) via box' , ( ) => {
355+ // Interval [1, 6) → iterates 1, 2, 3, 4, 5
356+ const expr = ce . box ( [
357+ 'Sum' ,
358+ 'n' ,
359+ [ 'Element' , 'n' , [ 'Interval' , 1 , [ 'Open' , 6 ] ] ] ,
360+ ] ) ;
361+ expect ( expr . evaluate ( ) . json ) . toBe ( 15 ) ;
362+ } ) ;
363+
364+ test ( 'sum over open Interval via box' , ( ) => {
365+ // Interval (0, 6) → iterates 1, 2, 3, 4, 5
366+ const expr = ce . box ( [
367+ 'Sum' ,
368+ 'n' ,
369+ [ 'Element' , 'n' , [ 'Interval' , [ 'Open' , 0 ] , [ 'Open' , 6 ] ] ] ,
370+ ] ) ;
371+ expect ( expr . evaluate ( ) . json ) . toBe ( 15 ) ;
372+ } ) ;
373+
374+ test ( 'product over Interval via box' , ( ) => {
375+ // Interval [1, 4] → iterates 1, 2, 3, 4
376+ const expr = ce . box ( [
377+ 'Product' ,
378+ 'k' ,
379+ [ 'Element' , 'k' , [ 'Interval' , 1 , 4 ] ] ,
380+ ] ) ;
381+ expect ( expr . evaluate ( ) . json ) . toBe ( 24 ) ; // 1*2*3*4 = 24
382+ } ) ;
329383} ) ;
330384
331385describe ( 'PRODUCT' , ( ) => {
0 commit comments