!!!! QUERY CONDITIONS (Qconds)
!!!! EXO 2: good answers are necconds (necessary conditions, non TRUE)
!!! EXO3 : good answers are lesconds (sufficient non true conds)


goodrep=
goodcnt=0
!if $mode=2
    !if $defconds=$empty
          Qconds=$dummies
    !else
          Qconds=$defconds,$dummies
    !endif
    qcnt=!itemcnt $Qconds
    Qconds=!shuffle $Qconds
    !if $necconds=$empty
         goodrep=TRUE
         goodcnt=1
    !else
         !for i=1 to $qcnt
               cond=!item $i of $Qconds
               !if $cond isitemof $necconds
                   goodrep=$goodrep,$i
                  !advance goodcnt
               !else
                   !if $cond isitemof $trueconds
                       truerep=$truerep,$i
                    !endif
              !endif
          !next i
          goodrep=!item 2 to -1 of $goodrep
          truerep=!item 2 to -1 of $truerep
    !endif


!!!! EXO 3: good answers are lesconds (top of list b4 shuffle)
!!!! NB : lesconds, seconds may be empty
!else 
    scnt=!itemcnt $seconds
    ccnt=!itemcnt $lesconds
    Qconds=$lesconds,$seconds
!!!! add non redundant dummy conds 
     !for cond in $dummies
          !if $cond notitemof $Qconds
                 Qconds=!append item $cond to $Qconds
          !endif
     !next cond
    Qconds=!nonempty item $Qconds
    qcnt=!itemcnt $Qconds
!!! this bug if qcnt=1 (gives empty list)  : Qconds=!shuffle $Qconds 
    !if $qcnt>1
       Qconds=!shuffle $Qconds
    !endif
    !if $lesconds=$empty
         goodrep=TRUE
         goodcnt=1
    !else
        index=$wims_shuffle_order
        goodcnt=!itemcnt $lesconds
        !for j=1 to $goodcnt
             pos$(j)=!positionof item $j in $index
            goodrep=$goodrep,$(pos$(j))
        !next j
        !for i=1 to $qcnt
            cond=!item $i of $Qconds
            !if $cond isitemof $trueconds
                   truerep=$truerep,$i
            !endif
        !next i
        goodrep=!item 2 to -1 of $goodrep
        truerep=!item 2 to -1 of $truerep
    !endif
!endif

goodrep=!sort numeric item $goodrep
truerep=!sort numeric item $truerep

relations=geq,gt,eq,neq,leq,lt
trelations=\geq,>,=,\neq,\leq,<

!!!! PRINT lesconds  (ppconds)
ppconds=
!for cond in $lesconds
        row=!word 1 of $cond
        col=!word 2 of $cond
        rel=!word 3 of $cond
        nb=!word 4 of $cond
        pos=!positionof item $rel in $relations 
        trel=!item $pos of $trelations 
        texp=!word 1 of $(texs[$row;$col])
        ppconds=$ppconds, $texp $trel $nb 
!next cond
ppconds=!item 2 to -1 of $ppconds
!if $ppconds=$empty
    ppconds=TRUE
!endif

!!!! PRINT QCONDS  (ppQcons)
ppQconds=
!for cond in $Qconds
        row=!word 1 of $cond
        col=!word 2 of $cond
        rel=!word 3 of $cond
        pos=!positionof item $rel in $relations 
        trel=!item $pos of $trelations 
        nb=!word 4 of $cond
        texp=!word 1 of $(texs[$row;$col])
        ppQconds=$ppQconds, $texp $trel $nb 
!next cond
ppQconds=!item 2 to -1 of $ppQconds
