!!!!! HISTORIQUE DE RESOLUTION
!!!!! pour EXERCICES d'ENCADREMENT (1  3) 
!!!!! EXERCICE 1 : grer conserver / inverser l'ordre

!if $cmd=reply and $status=waiting
 
!!!!! DETECTION D'ERREUR

!if $user=Valider

!if $action=3 
!!! interdire deux inverser consecutifs
   last=!item -1 of $histo
   !if $last=3
        error = $error dbleinv
   !else
       !if $[$lub*$glb]<0
           error = $error inverse
       !else
!!! interdire inversion de 0 <= a <= b et al.
           !if $symb!=< and ( $lub=0  or $glb=0 )
                error = $error inverse2
           !endif
       !endif
    !endif
!endif

!if  $action=4 and $fct=carre and $[$lub*$glb]<0
error = $error carre 
!endif

!if $action=5  and $lub<0
error = $error ensdef1
!endif

!if  $action=5 and $glb<0
error = $error ensdef2
!endif

!if  $mode=exo2 and $action=7 and ($glb2 < 0 or $glb<0)
  error = $error mult2ineg
 !endif

!!! ERROR SUR CHGNT ORDRE

!if ($action=1 or  $action=5) and $ordre=2
      error = $error ordre-croissant
!endif

!if $action=2
    !if ($ordre=1 and  $nombre<0) or ($ordre=2 and  $nombre>0)
      error = $error ordre-mult
    !endif
!endif
!if $action=3 and $ordre=1
       error = $error ordre-inv
!endif
!if $action=4
   !if  $mode!=exo3
       !if ($ordre=1 and $lub<0) or ($ordre=2 and $lub>=0)
           error = $error ordre-carre
       !endif
   !else
!!! exo3, action3 -> prendre les expo.
       !if $ordre=2 
           error = $error ordre-mono
       !endif
   !endif
!endif

!endif
!!! END DETECT ERRORS

!!!!! CREATION NOUVELLE INEGALITE
 
!if $user=Valider and $error=$empty

!!! noeval bloque les valuations  abusives (sinon risque de DL(8))
!!! noeval = 1 ds que l'exp contient ln, exp, sqrt, quotient
!!! type par dfaut 0 ; mis  1 aprs action 1 ou 6

newtyp=0

!if sqrt isin $nombre or ln isin $nombre or exp isin $nombre
noeval=1
!endif

!if $action=1 
    newtyp= 1
    newglb = $glb+$nombre
    newlub = $lub+$nombre
    !if $noeval = 1
     newvar = $var+$nombre
    !else
      newvar = !exec pari ($var + $nombre)
    !endif
 !endif  

!!!! dans multiplier / inverser parenthser ou non en fction de typ
!!!! NB : echec avec test de prsence de la string ( en premier char
!!!! NB : deux mult conscutives par nbre ngatifs pose pb affichage

!if $action=2
  !if $typ=0 
      newvar=$nombre*$var
  !else
      glb=($glb)
      lub=($lub)
      newvar=$nombre*($var)
  !endif
 !if $nombre > 0
    newglb=$nombre*$glb
    newlub=$nombre*$lub
 !else 
    newglb=$nombre*$lub
    newlub=$nombre*$glb
    newtyp=1
 !endif 

!endif

!!!! inverser quand les bornes sont non nulles et de meme signe

!if $action=3 and $[$lub*$glb]>0
    newglb =  1/($lub)
    newvar = 1/($var)
    newlub =  1/($glb)
 !endif  

!!!! inverser quand l'une des bornes est nulle 
!!!! NB : inegalites doivent tre strictes dans ce cas

!if $action=3 and $lub=0
    newglb =  1/($var)
    newvar = 1/($glb)
    newlub = 0
 !endif  
!if $action=3 and $glb=0
    newglb = 0 
    newvar = 1/($lub)
    newlub = 1/($var)
 !endif  

!!!! elever au carr quand les bornes sont positives

!if $action=4 and $fct=carre and $glb>=0 
    newglb = ($glb)^2
    newvar = ($var)^2
    newlub = ($lub)^2
 !endif  

!!!!! elever au carr quand les bornes sont ngatives

!if $action=4 and $fct=carre and $glb<0 and $lub<=0 
     newglb = ($lub)^2
     newlub = ($glb)^2
    newvar = ($var)^2
 !endif  

!!!! monter  l'exponentielle 
!if $action=4 and $fct=exp 
    newglb = exp($glb)
    newvar = exp($var)
    newlub = exp($lub)
 !endif  

!!!! passer  la racine carre / ln 

!if $action=5 and $frec=sqrt and $glb>=0 
    !if $glb!=1 and $glb!=0
      newglb = sqrt($glb)
      !else
     newglb = $glb
    !endif
    newvar = sqrt($var)
    !if $lub!=1 and $lub!=0
      newlub = sqrt($lub)
    !else
      newlub = $lub
    !endif
 !endif 
 
!if $action=5 and $frec=ln and $glb>0 
    !if $glb=1 
      newglb = 0
    !else
      newglb = ln($glb)
    !endif
    newvar = ln($var)
   !if $lub=1 
      newlub = 0
    !else
      newlub = ln($lub)
    !endif
 !endif  

!!!!!!!!!!! quand il y a deux ingalits 

!!!!! additionner deux ingalits
!!!! NB : pari calcule des dec.lim. avec somme de rac, ln, 
!!!! pari developpe les carrs 
!!!! evaluations bloques par noeval = 1

!if $action=6
    newtyp=1
    newglb = $glb+$glb2
    newlub = $lub+$lub2
    !if $noeval=0
         newvar = !exec pari $var + $var2
    !else
         newvar =  $var+$var2
    !endif   
!endif

!!!!! multiplier deux ingalits

!if $action=7
    newglb = $glb*$glb2
    newlub = $lub*$lub2
!!!    !if $noeval = 1
    newvar =  ($var)*($var2)
!!    tex1=!texmath $var
!!   tex2=!texmath $var2
!!    newtex=\left($tex1\right)\left($tex2\right)
!!!   !else
!!!     newvar = !exec pari  ($var)*($var2)
!!!    !endif
!endif

!!!! mettre  jour promptinegalites et lesinegalites
!!!! simplifier les  bornes si ce sont des valeurs entires
    valglb=$[$newglb]
    vallub=$[$newlub]
    !if $valglb!=NaN and . notin $valglb 
        newglb=$valglb
    !endif
    !if $vallub!=NaN and . notin $vallub 
        newlub=$vallub
    !endif
   histo = !append item $action to $histo 
   newineg =  $newglb , $newvar , $newtyp , $newlub 
   lesinegalites = $lesinegalites ; $newineg 
   promptinegalites = !append item  \($newglb) $symb \($newvar) $symb    \($newlub)  to $promptinegalites
    L=!itemcnt $promptinegalites
!!! par dfaut la dernire ingalit de la liste est choisie  
    choix=$L

!!! mode noeval aprs avoir cr  newineg. avec ln, exp, rac,quot
!if $noeval=0 and $action > 2
   noeval = 1
!endif

!endif

!endif