subsop command

Messages in english

Modérateur : xcasadmin

compsystems
Messages : 554
Inscription : sam. févr. 04, 2017 11:34 pm
Localisation : Colombia
Contact :

subsop command

Message par compsystems » dim. janv. 05, 2020 9:49 pm

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[]]
Dernière modification par compsystems le mer. janv. 08, 2020 6:46 pm, modifié 1 fois.

parisse
Messages : 5731
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: subsop command

Message par parisse » mar. janv. 07, 2020 7:26 pm

There is a command to do something similar, it's name is select.

compsystems
Messages : 554
Inscription : sam. févr. 04, 2017 11:34 pm
Localisation : Colombia
Contact :

Re: subsop command

Message par compsystems » mer. janv. 08, 2020 6:41 pm

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]

Répondre