Saturday, November 6, 2021

TI-92 Plus and TI-Nspire CX II: List Filters

TI-92 Plus and TI-Nspire CX II:  List Filters




For this particular post, I also have a TI-Nspire CX II CAS document which can be downloaded here:  https://drive.google.com/file/d/1Rm5vIWdUMg5OEyXi4VecNfuIGdiGRtan/view?usp=sharing


The functions are public and are available in the catalog.  Examples and syntax are included.  


The Filters


filters(list, criteria): filters out a list 

sumfilt(list, criteria): sum of selected elements of a list

avgfilt(list, criteria): arithmetic average of elements of a list

prdlist(list, criteria): product of selected elements of a list

dimfilt(list, criteria): returns a count of list elements that fit a criteria


This is similar to Excel functions filter, sumifs, averagefits, and countifs; there is no productifs in Excel.  


The criteria is a string, using x as a variable.  Examples:

"x<10": select elements less than 10

"x≥20": select elements greater than or equal to 20

"10<x and x<20": select elements between 10 and 20, not including 10 or 20

"10≤x and x≤20": select elements between 10 and 20, including 10 or 20


TI-92 Plus Functions: Filters


Note:  I am using the symbol [| for comment; in the program editor, select F2, option 9.  


TI-92 Plus Function:  filters


filters(list1,cr) 

Func

[| list, criteria string with x

[| EWS 2021-08-13

[| filter function

Local list2,d,i,t,x

{}→list2

dim(list1)→d

For i,1,d

expr(cr)|x=list1[i]→t

If t Then

augment(list2,{list1[i]})→list2

EndIf

EndFor

Return list2

EndFunc


TI-92 Plus Function: sumfilt


sumfilt(list1,cr) 

Func

[| list, criteria string with x

[| EWS 2021-08-14

[| sum-if filter function

Local list2,d,i,t,x

{}→list2

dim(list1)→d

For i,1,d

expr(cr)|x=list1[i]→t

If t Then

augment(list2,{list1[i]})→list2

EndIf

EndFor

Return sum(list2)

EndFunc


TI-92 Plus Function: avgfilt


avgfilt(list1,cr) 

Func

[| list, criteria string with x

[| EWS 2021-08-14

[| average-if filter function

Local list2,d,i,t,x

{}→list2

dim(list1)→d

For i,1,d

expr(cr)|x=list1[i]→t

If t Then

augment(list2,{list1[i]})→list2

EndIf

EndFor

Return sum(list2)/(dim(list2))

EndFunc


TI-92 Plus Function:  prdfilt


prdfilt(list1,cr) 

Func

[| list, criteria string with x

[| EWS 2021-08-14

[| product-if filter function

Local list2,d,i,t,x

{}→list2

dim(list1)→d

For i,1,d

expr(cr)|x=list1[i]→t

If t Then

augment(list2,{list1[i]})→list2

EndIf

EndFor

Return product(list2)

EndFunc


TI-92 Plus Function:  dimfilt


dimflt(list1,cr) 

Func

[| list, criteria string with x

[| EWS 2021-08-13

[| count-if filter function

Local list2,d,i,t,x

{}→list2

dim(list1)→d

For i,1,d

expr(cr)|x=list1[i]→t

If t Then

augment(list2,{list1[i]})→list2

EndIf

EndFor

Return dim(list2)

EndFunc


Examples:


list0 = {2,4,5,6,9,10,11,13,14,15,18}


filters(list0,"x≤10"):  {2,4,5,6,9}

filters(list0,"5≤x and x≤15"):  {5,6,9,10,11,13,14,15}


sumfilt(list0,"x≤10"):  36

sumfilt(list0,"5≤x and x≤15"):  83


avgfilt(list0,"x≤10"):  6

avgfilt(list0,"5≤x and x≤15"):  83/8


prdfilt(list0,"x≤10"):  21600

prdfilt(list0,"5≤x and x≤15"):  2700


dimfilt(list0,"x≤10"):  6

dimfilt(list0,"5≤x and x≤15"):  8


All original content copyright, © 2011-2021.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 


1 comment:

  1. Hi Eddie, what a coincidence; I was just planning to repair my old TI-92 II which has a bad contact on the mother board. So a warm the solder iron and repair it quickly to try your Saturday's list filter functions.

    I have nothing to change to enter all your codes in my TI-92 II, it is quite the same as the Ti 92+ version.

    But I am a so leasy guy that I spare a lot of typing efforts and also a few memory byte ; the core of all your filtered functions { 'sumfilt', 'avgfilt','prodfil','dimfilt', ... } are sharing the same exact code of the 'filters' function. So I found a shortcut:
    Moreover, you don't have to enter the criteria as a string. You just have to force it as string in the code of the 'filters' function:

    TI-92 II/Plus Function: filters
    ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨
    filters(list,cr)
    Func
    : @ list as a list , criteria as string or not with x
    : @ inspired from EWS 2021-08-13 "list filter function"
    : Local rslt,i,x
    : string(cr)→cr @ force as STRING
    : {}→rslt
    : For i,1,dim(list)
    : : If expr(cr)|x=list1[i]→t Then
    : : : augment(rslt,{list[i]})→rslt
    : : EndIf
    : EndFor
    : Return rslt
    EndFunc

    TI-92 II/Plus Function: sumfilt
    ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨
    sumfilt(list,cr)
    Func
    : Return sum(filters(list,cr))
    EndFunc

    TI-92 II/Plus Function: avgfilt
    ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨
    avgfilt(list,cr)
    Func
    : Return mean(filters(list,cr))
    EndFunc

    TI-92 II/Plus Function: prdfilt
    ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨
    prdfilt(list,cr)
    Func
    Return product(filters(list,cr))
    EndFunc

    TI-92 II/Plus Function: dimfilt
    ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨
    dimfïlt(list1,cr)
    Func
    : Return dim(filters(list,cr))
    EndFunc

    How cool is that ! As cool as reading your blog.

    Thanks Eddie.

    ReplyDelete

TI-84 Plus CE and CE Python 5.7 update

 TI-84 Plus CE and CE Python 5.7 update Texas Instruments has released software updates, 5.7, for both the TI-84 Plus CE and TI-84 Plus CE P...