Page 1 sur 1

subsop command

Publié : dim. janv. 05, 2020 9:49 pm
par compsystems
hello

A valuable improvement in the subsop command is that it allows you to accept a criterion or rule.

Code : Tout sélectionner

subsop( set[ 0, 1, 2, 3, 4 ], 2 = sqrt(2)+1 ) [enter] [0,1,sqrt(2)+1,3,4]
subsop( set[ 1,2,3,4,5,6,7,9,10,11,12 ], odd='NULL' ) [enter]  set[2,4,6,8,10,12]  
subsop( set[ 1,2,3,4,5,6,7,9,10,11,12 ], even='NULL' ) [enter] set[1,3,5,7,9,11]
map( lambda x: ifte(odd(x),'NULL',x), set[ 1,2,3,4,5,6,7,9,10,11,12 ]) It does not work, returns [seq[],2,seq[],4,seq[],6,seq[],seq[],10,seq[],12]
apply(lambda x: ifte(even(x),'NULL',x), set[ 1,2,3,4,5,6,7,9,10,11,12 ]) It does not work, returns [1,seq[],3,seq[],5,seq[],7,9,seq[],11,seq[]]

Re: subsop command

Publié : mar. janv. 07, 2020 7:26 pm
par parisse
There is a command to do something similar, it's name is select.

Re: subsop command

Publié : mer. janv. 08, 2020 6:41 pm
par compsystems
Select works very on
select( lambda x: ifte(odd(x),'NULL',x), set[ 1,2,3,4,5,6,7,9,10,11,12 ]) [enter] retuns set[2,4,6,10,12]
select( lambda x: ifte(even(x),'NULL',x), set[ 1,2,3,4,5,6,7,9,10,11,12 ]) [enter] retuns set[1,3,5,7,9,11]

but not on:

select( lambda x,y: ifte(x<y,true, false),[1, 2, 3], [-1, 4, 0]) or
select( lambda x,y: ifte(x<y,true, false),[[1, 2, 3], [-1, 4, 0]], matrix) expectes [false, true, false]

I want to replicate the maxima MAP cmd behavior to XCAS

maxima
map(lambda ([a, b], is (x < y)), [1, 2, 3], [-1, 4, 0]); [enter] retuns [false, true, false]