Cette source est entièrement OO, elle permet de dessiner une équation écrite sous la forme RPN
On peut calculer toute sortes de choses grace notation ! même si la source ne vous interesse pas, si vous ne conaissez pas, renseignez vous sur le RPN, c'est vraiment pratique !
fonctionalitée : le calcul de dérivées, la conversion en notation classique, affichage d'equations, et d'autres trucs sympas...
Cette notation est utilisée sur quelques calculatrices HP et sur des langages interprétés.
Source / Exemple :
<?php
/*
Une fonction et deux classes :
-une classe Pile
-une classe RNP (reverse polish notation)
-une fonction qui permet de savoir si une ligne est un commentaire ou non.
La classe RPN permet d'afficher des �quations sous forme d'images. On peut
lui faire faire des additions, des multiplications, des soustractions, des
divisions, des racines carr�es, des exposants, des carr�s ou des fonctions.
Pour effectuer une fonction, il faut mettre f puis la fin de la fonction.
Cette classe peut aussi faire des calculs, mais cette fois ci, elle ne
permet pas d'effectuer autant de choses... Elle permet juste de faire des
�quations classiques : avec les op�rateurs de sommes, de quotients,
de diff�rences et de produits. On peut aussi calculer une racine carr�e.
On peut aussi convertire cette notation vers une notation classique.
function isval($a){
if ($a==='')
return false;
else
return true;
}
function lignecode($line)
{
//Ceci sert pour savoir si une ligne est un commentaire ou non...
if (preg_match('/^\s*?#.*?/',$line)) return false;
if (preg_match('/^\s*?$/',$line)) return false;
return true;
}
class Pile{
//constructeur
public function Pile()
{
$this->length=0;
$this->pile=array();
}
//permet d'empiler une valeur
public function empile($val)
{
$this->length++;
$this->pile[$this->length]=$val;
}
//permet de d�piler une valeur
public function depile()
{
$this->length--;
if ($this->length>=0){
return $this->pile[$this->length+1];
}else{
trigger_error('Sortie de pile !', E_USER_NOTICE);
//throw new Meserreurs();
}
}
//renvoi la hauteur de la pile
public function gethauteur()
{
return $this->length;
}
//renvoi un �l�ment de la pile
public function get($nbr)
{
return $this->pile[$nbr];
}
//deffinit un �l�ment de la pile
public function set($nbr, $val)
{
$this->pile[$nbr]=$val;
}
//renvoi le tableau de la pile
public function getpile()
{
return $this->pile;
}
private $pile; //data
private $length; //taille
}
class RPN extends Pile{
/*
Cette classe permet de g�rer plein de choses en rapport avec la RPN :
Reverse Polish Notation
On peut convertire une "formule, relation ou autre chose bizare" sous
forme classique, on peut aussi afficher � l'�cran la formule sous
forme d'une image (les quotients seront plac�s sous formes de fractions,
les racines carr�es seront dessin�es ... les signes pour tout, et il existe,
les symboles d'ensembles, les signes de sommes ect...)
On peut aussi calculer une valeur sous cette forme.
//constructeur
public function RPN($str)
{
$this->str=$str;
Pile::Pile();
$this->parse=false;
//echo $str;
}
public function to_nn(){
/*
Conversion vers la notation classique.
On a aussi besoin ici d'une gestion de parenth�ses, donc la pile doit �tre g�r�e par tableaux...
if (!$this->parse)$this->parse();
list($usec, $sec) = explode(' ', microtime());
$start=$sec+$usec;
foreach ($this->tab as $val)
{
switch ($val)
{
case '+':
list($a, $c, $d)=Pile::depile();
list($b, $c, $d)=Pile::depile();
Pile::empile(array($a.' + '.$b, true, true));
break;
case '-':
list($b, $c1, $d)=Pile::depile();
list($a, $c, $d)=Pile::depile();
if (!$c1){
Pile::empile(array($a.' - '.$b, true, true));
}else{
Pile::empile(array($a.' - ( '.$b.' )', true, true));
}
break;
case '*':
list($a, $c1, $d1)=Pile::depile();
list($b, $c2, $d2)=Pile::depile();
if ($c1 && !$c2)
Pile::empile(array('('.$a.') * '.$b, false, true));
else if (!$c1 && $c2)
Pile::empile(array($a.' * ('.$b.')', false, true));
else if (!$c1 && !$c2)
Pile::empile(array($a.' * '.$b, false, true));
else
Pile::empile(array('('.$a.') * ('.$b.')', false, true));
break;
case '/':
list($b, $c2, $d2)=Pile::depile();
list($a, $c1, $d1)=Pile::depile();
if ($d1 && !$d2)
Pile::empile(array('('.$a.') / '.$b, false, true));
else if (!$d1 && $d2)
Pile::empile(array($a.' / ('.$b.')', false, true));
else if (!$d1 && !$d2)
Pile::empile(array($a.' / '.$b, false, true));
else
Pile::empile(array('('.$a.') / ('.$b.')', false, true));
break;
case '�':
list($a, $c, $d)=Pile::depile();
if ($c)
Pile::empile(array('('.$a.') � ', false, false));
else
Pile::empile(array($a.' � ', false, false));
break;
case '=':
list($a, $c, $d)=Pile::depile();
list($b, $c, $d)=Pile::depile();
Pile::empile(array($a.' = '.$b, false, false));
break;
default:
Pile::empile(array($val, false, false));
break;
}
}
//calcule le temps de calcul....
list($a, $c, $d)=Pile::depile();
list($usec, $sec) = explode(' ', microtime());
$this->times['conv']=(int)(($sec+$usec-$start)*100000);
$this->times['conv']=(float)$this->times['conv']/100;
return $a;
}
public function getvalue()
{
/*
Je ne me suis pas attard� sur cette fonction, elle est tr�s simple � modifier,
je vous en laisse le soin...
if (!$this->parse)$this->parse();
list($usec, $sec) = explode(' ', microtime());
$start=$sec+$usec;
foreach ($this->tab as $val)
{
if (intval($val))
{
Pile::empile(intval($val));
}
else if (floatval($val))
{
Pile::empile(floatval($val));
}
else
{
switch ($val)
{
/*
Pour ajouter des fonctions, c'est tr�s simple :
function � deux arguments :
case 'mafonction':
Pile::empile(traitefonction(Pile::depile(),Pile::depile());
//ou traitefonction est la fonction appel�e...
break;
function � un argument :
case 'mafonction':
Pile::empile(traitefonction(Pile::depile());
//ou traitefonction est la fonction appel�e...
break;
case '+':
Pile::empile(Pile::depile()+Pile::depile());
break;
case '-':
Pile::empile(-Pile::depile()+Pile::depile());
break;
case '*':
Pile::empile(Pile::depile()*Pile::depile());
break;
case '/':
Pile::empile(1/Pile::depile()*Pile::depile());
break;
case 'sqrt':
Pile::empile(sqrt(Pile::depile()));
break;
case '^':
$b=Pile::depile();
$a=Pile::depile();
Pile::empile($a^$b);
break;
}
}
}
//calcule le temps de calcul....
list($usec, $sec) = explode(' ', microtime());
$this->times['calc']=(int)(($sec+$usec-$start)*100000);
$this->times['calc']=(float)$this->times['calc']/100;
return (Pile::gethauteur()===1)?Pile::depile():false;
}
public function getimage($name=false, $type='png', $transparent=true, $border=false, $font_size=5,
$background_r=255, $background_v=255, $background_b=255,
$txt_r=0, $txt_v=0, $txt_b=0, $rapport=1.2
)
{
/*
Cette fonction permet d'avoir une image de la relation / formule / �quation /
tas de chiffres et de lettres dont l'utilit�e, le nom ou qualifiquatif m'�chapent.
if (!$this->parse)
$this->parse();
$text_width = imagefontwidth($font_size);
$text_height = imagefontheight($font_size);
list($usec, $sec) = explode(' ', microtime());
$start=$sec+$usec;
foreach ($this->tab as $val)
{
switch ($val)
{
/*
L'ajout de fonctions est ici l�g�rement diff�rente :
on peut trouver ici des choses � trois arguments : congruance par exemple...
list($a, $p)=Pile::depile(); pour avoir dans $a l'image, et dans $p
le fait qu'on ai besoin de parenth�ses ou non...
Pile::empile(array($c, false)); pour empiler et dire qu'on n'a pas
besoin de parenth�ses si on multiplie le r�sultat...
Pour dire qu'on a besoin de parenth�ses, on remplace le false par true...
Comme vous l'aurez surement compris, la modification des images se fait par GD.
Methodes g�r�es :
- ssi (si et seulement si : signe : <=>)
- implique (implication : le donc : signe =>)
- > (plus grand que)
- < (plus petit que)
- >= (plus grand ou �gal)
- <= (plus petit ou �gal)
- lim (limite d'expression)
- integrale (intgrale d'expression)
- = (�galit�)
- != difference
- + (additions)
- - (soustraction)
- / (division, toujours sous forme de fraction)
- * (multiplication)
- ^ (exposant)
- infinit+ (plus l'infinit)
- infinit- (moins l'infinit)
- | (valeur absolue)
- � (carr�)
- sqrt (racine carr�e)
- rationnel (l'ensemble des nombres qui peuvent s'exprimer sous forme
de fractions de nombres relatifs)
- real (l'ensemble des r�els)
- reel (idem)
- naturel (l'ensemble des nombres naturels)
- relatif (l'ensemble des nombres relatifs)
- complexe (l'ensemble des nombres complexes)
- appartient (inclu un nombre ou un point dans un ensemble)
- includans (inclu un ensemble dans un autre ensemble)
- !appartient (n'inclu pas un nombre ou un point dans un ensemble)
- !includans (n'inclu pas un ensemble dans un autre ensemble)
- () (ajoute des parenth�ses inutiles)
- base (on met : a0 a1 a2 .... ai i n base pour mettre le chiffre �gal
� a0+ a1*n+ a2*n^2+ a3*n^3 ... +ai*n^i)
- enter (retour � la ligne)
- vect (met sous la forme d'un vecteur)
- [] (les ensembles de nombres : ensemble � intervals ouberts)
- ][ (ensemble � intervals ferm�s)
- [[ (ensemble � interval ferm� � droite et ouvert � gauche)
- ]] (ensemble � interval ferm� � ouvert et ouvert � droite)
- ilexiste (le signe il existe : un E � l'envers)
- quelquesoit (le signe quelque soit, ou pour tout : un A � l'envers)
les parenth�ses sont (normalement) ajout�s automatiquement
- pour taper une fonction, tapez fsin par exemple
(le nom de la fonction, mais commen�ant par f...)
- si vous voulez taper la lettre f, tapez \f.
- somme (le symbole de somme) on tape termes de la somme,
variable, valeur de d�part, valeur de fin, somme.
- indice par exemple : la suite U indice n. on met : U n indice...
�a facilite beaucoup de choses.
- matrice : exemple : 1 2 3 4 2 2 matrice...
en g�n�ral : elements x y matrice affiche une matrice de x * y elements
- parmi : Cnk ou k parmi n : le nombre d'ensemble � k �l�ments
dans un ensemble � n �l�ment.
- ^vect : produit vectoriel
- couleur : met le texte d'une autre couleur ex : r v b couleur
case '.':
list($b, $pb)=Pile::depile();
list($a, $pa)=Pile::depile();
$ax=imagesX($a);
$ay=imagesY($a);
$bx=imagesX($b);
$by=imagesY($b);
$c=imagecreate($ax+$bx+$text_width, max($ay, $by));
$background_color = imagecolorallocate($c,
$background_r, $background_v, $background_b);
$text_color = imageColorAllocate ($c, $txt_r, $txt_v, $txt_b);
imagecopy($c, $a,
0,0,
0, 0,
$ax, $ay);
imagecopy($c, $b,
$ax+$text_width, 0,
0,0,
$bx, $by);
imagestring($c, $font_size,
$ax,
intval((max($ay, $by)-$text_height)/2),
'.', $text_color);
Pile::empile(array($c, false, NULL));
imagedestroy($a);
imagedestroy($b);
break;
case 'inv':
$a=Pile::depile();
$b=Pile::depile();
Pile::empile($a);
Pile::empile($b);
break;
case 'hstrike':
list($a)=Pile::depile();
$xa=imagesX($a);
$ya=imagesY($a);
//imageline($a, 0, intval($ya/2)-1, $xa, intval($ya/2)-1, $text_color);
imageline($a, 0, intval($ya/2), $xa, intval($ya/2), $text_color);
//imageline($a, 0, intval($ya/2)+1, $xa, intval($ya/2)+1, $text_color);
Pile::empile(array($a, false, NULL));
break;
case 'vstrike':
list($a)=Pile::depile();
$xa=imagesX($a);
$ya=imagesY($a);
imageline($a, intval($xa/2), 0, intval($xa/2), $ya, $text_color);
Pile::empile(array($a, false, NULL));
break;
case 'couleur':
list($a, $pa,$txt_b)=Pile::depile();
list($a, $pa,$txt_v)=Pile::depile();
list($a, $pa,$txt_r)=Pile::depile();
list($a, $b, $c)=Pile::depile();
$text_color = imageColorAllocate ($a, $txt_r, $txt_v, $txt_b);
Pile::empile(array($a, $b, $c));
break;
case 'parmi':
list($a, $pa)=Pile::depile();
list($b, $pb)=Pile::depile();
$ax=imagesX($a);
$ay=imagesY($a);
$bx=imagesX($b);
$by=imagesY($b);
$x = max($ax, $bx)+30;
$y = $ay + $by + 5;
$c=imagecreate($x, $y);
$background_color = imagecolorallocate($c,
$background_r, $background_v, $background_b);
$text_color = imageColorAllocate ($c, $txt_r, $txt_v, $txt_b);
imagearc($c,
30, intval($y/2),
30, intval($y*8/10),
90, 270, $text_color);
imagecopy($c, $a,
30,0,
0, 0,
$ax, $ay);
imagecopy($c, $b,
30, $y-$by,
0,0,
$bx, $by);
Pile::empile(array($c, false, NULL));
imagedestroy($a);
imagedestroy($b);
break;
case '^vect':
list($b, $pb)=Pile::depile();
list($a, $pa)=Pile::depile();
$ax=imagesX($a);
$ay=imagesY($a);
$bx=imagesX($b);
$by=imagesY($b);
$c=imagecreate($ax+$bx+$text_width, max($ay, $by));
$background_color = imagecolorallocate($c,
$background_r, $background_v, $background_b);
$text_color = imageColorAllocate ($c, $txt_r, $txt_v, $txt_b);
imagecopy($c, $a,
0,0,
0, 0,
$ax, $ay);
imagecopy($c, $b,
$ax+$text_width, 0,
0,0,
$bx, $by);
imagestring($c, $font_size,
$ax,
max($ay, $by)-$text_height,
'^', $text_color);
Pile::empile(array($c, false, NULL));
imagedestroy($a);
imagedestroy($b);
break;
case 'matrice':
list($a, $pa, $y)=Pile::depile();
list($b, $pb, $x)=Pile::depile();
imagedestroy($a);
imagedestroy($b);
$images=array();
$x=intval($x);
$y=intval($y);
$mx=array(); //le max cumul� d'abscisse sur une colone...
$my=array(); //le max cumul� en y sur une ligne...
$p=array();
for ($i=0;$i<$x;$i++){ $mx[$i]=0; }
for ($i=0;$i<$y;$i++){ $my[$i]=0; }
for ($i=$y-1;$i>=0;$i--){
$images[$i]=array();
$sy[$i]=array();
$sx[$i]=array();
$p[$i]=array();
for ($j=$x-1;$j>=0;$j--){
list($images[$i][$j], $p[$i][$j])=Pile::depile();
}
}
for ($i=0;$i<$y;$i++){
for ($j=0;$j<$x;$j++){
$ax=imagesx($images[$i][$j]);
$ay=imagesy($images[$i][$j]);
//si un jours, on veut forcer les parenth�ses...
/*if ($p[$i][$j]){
$i=imagecreate($ax+20,$ay);
imagecopy($i, $images[$i][$j],
10, 0,
0,0,
$ax,$ay);
imagearc($i,
10, intval($ay/2),
10, $ay,
90, 270, $text_color);
imagearc($i,
$ax-10, intval($ay/2),
10, $ay,
270, 90, $text_color);
imagedestroy($images[$i][$j]);
$images[$i][$j]=$i;
$ax+=20;
}*/
$sy[$i][$j]=$ay;
$sx[$i][$j]=$ax;
if ($mx[$j]<$sx[$i][$j]){
$mx[$j]=$sx[$i][$j];
}
if ($my[$i]<$sy[$i][$j]){
$my[$i]=$sy[$i][$j];
}
}
}
for ($i=1;$i<$x;$i++){ $mx[$i]+=$mx[$i-1]+$text_width; }
for ($i=1;$i<$y;$i++){ $my[$i]+=$my[$i-1]; }
/*print_r($my);
print_r($mx);
print_r($sy);
print_r($sx);*/
$a=imagecreate($mx[$x-1]+20, $my[$y-1]);
$background_color = imagecolorallocate($a,
$background_r, $background_v, $background_b);
$text_color = imageColorAllocate ($a, $txt_r, $txt_v, $txt_b);
for ($i=0;$i<$y;$i++){
for ($j=0;$j<$x;$j++){
imagecopy($a, $images[$i][$j],
10+$mx[$j]-$sx[$i][$j], $my[$i]-$sy[$i][$j],
0, 0,
$sx[$i][$j], $sy[$i][$j]);
if ($j!=$x-1){
imagestring ($a, $font_size,
10+$mx[$j],
$my[$i]-$text_height,
';', $text_color);
}
imagedestroy($images[$i][$j]);
}
}
imagearc($a,
10, intval($my[$y-1]/2),
10, $my[$y-1],
90, 270, $text_color);
imagearc($a,
$mx[$x-1]+10, intval($my[$y-1]/2),
10, $my[$y-1],
270, 90, $text_color);
Pile::empile(array($a, false, NULL));
break;
case 'indice':
list($a, $pa)=Pile::depile(); //indice
list($b, $pb)=Pile::depile(); //expression
$ax=imagesX($a);
$ay=imagesY($a);
$bx=imagesX($b);
$by=imagesY($b);
$e=imagecreate (intval($bx*$rapport+$ax), intval($by*$rapport+$ay/2));
$background_color = imagecolorallocate($e,
$background_r, $background_v, $background_b);
ImageCopyResized($e,$b,0,0,0,0,intval($bx*$rapport),intval($by*$rapport),$bx, $by);
$background_color = imagecolorallocate($e,
$background_r, $background_v, $background_b);
imagecopy($e, $a,
intval($bx*$rapport), intval($by*$rapport-$ay/2),
0, 0,
$ax, $ay);
Pile::empile(array($e, false, NULL));
imagedestroy($a);
imagedestroy($b);
break;
case 'somme':
list($a, $pa)=Pile::depile(); //limite superieure
list($b, $pb)=Pile::depile(); //limite inferieure
list($c, $pc)=Pile::depile(); //variable
list($d, $pd)=Pile::depile(); //termes de la somme
$ax=imagesX($a);
$ay=imagesY($a);
$bx=imagesX($b);
$by=imagesY($b);
$cx=imagesX($c);
$cy=imagesY($c);
$dx=imagesX($d);
$dy=imagesY($d);
$e=imagecreate (intval($dx*$rapport), intval($dy*$rapport));
ImageCopyResized($e,$d,0,0,0,0,intval($dx*$rapport),intval($dy*$rapport),$dx, $dy);
$background_color = imagecolorallocate($d,
$background_r, $background_v, $background_b);
$dx=intval($rapport*$dx);
$dy=intval($rapport*$dy);
$x=$dx+max(15, $ax, $bx+$cx+5)+5;
$y=max(30+max($by,$cy)+$ay, $dy);
$f=imageCreate($x, $y);
$background_color = imageColorAllocate($f,
$background_r, $background_v, $background_b);
$text_color = imageColorAllocate ($f, $txt_r, $txt_v, $txt_b);
imagecopy($f, $a,
0, 0,
0, 0,
$ax, $ay);
imagecopy($f, $c,
0, $y-max($by, $cy),
0, 0,
$cx, $cy);
//le signe =
imageline($f,
$cx, $y-intval(max($by, $cy)/2)-1,
$cx+5, $y-intval(max($by, $cy)/2)-1,
$text_color);
imageline($f,
$cx, $y-intval(max($by, $cy)/2)+2,
$cx+5, $y-intval(max($by, $cy)/2)+2,
$text_color);
//le signe somme
imageline($f,
1, $y-max($cy, $by),
15, $y-max($cy, $by),
$text_color);
imageline($f,
1, $ay,
15, $ay,
$text_color);
imageline($f,
1, $ay,
8, $ay+intval(($y-max($cy, $by)-$ay)/2),
$text_color);
imageline($f,
1, $y-max($cy, $by),
8, $ay+intval(($y-max($cy, $by)-$ay)/2),
$text_color);
imagecopy($f, $b,
$cx+5, $y-max($by, $cy),
0, 0,
$bx, $by);
imagecopy($f, $e,
$x-$dx, intval(($y-$dy)/2),
0, 0,
$dx, $dy);
Pile::empile(array($f, false, NULL));
imagedestroy($a);
imagedestroy($b);
imagedestroy($c);
imagedestroy($d);
imagedestroy($e);
break;
case 'quelquesoit':
list($a)=Pile::depile();
$ax=imagesX($a);
$ay=imagesY($a);
$imageX=$ax+10;
$imageY=$ay;
$c=imageCreate($imageX, $imageY);
$background_color = imageColorAllocate($c,
$background_r, $background_v, $background_b);
$text_color = imageColorAllocate ($c, $txt_r, $txt_v, $txt_b);
imagecopy($c, $a,
10,intval(($imageY-$ay)/2),
0, 0,
$ax, $ay);
imageline($c, 0, 0, 5, $imageY-1, $text_color);
imageline($c, 10, 0, 5, $imageY-1, $text_color);
imageline($c, 3, intval($imageY/2), 7, intval($imageY/2), $text_color);
Pile::empile(array($c, false, NULL));
imagedestroy($a);
break;
case 'ilexiste':
list($a)=Pile::depile();
$ax=imagesX($a);
$ay=imagesY($a);
$imageX=$ax+15;
$imageY=$ay;
$c=imageCreate($imageX, $imageY);
$background_color = imageColorAllocate($c,
$background_r, $background_v, $background_b);
$text_color = imageColorAllocate ($c, $txt_r, $txt_v, $txt_b);
imagecopy($c, $a,
15,intval(($imageY-$ay)/2),
0, 0,
$ax, $ay);
imageline($c, 10, 0, 10, $imageY-1, $text_color);
imageline($c, 10, $imageY-1, 0, $imageY-1, $text_color);
imageline($c, 10, 0, 0, 0, $text_color);
imageline($c, 3, intval($imageY/2), 10, intval($imageY/2), $text_color);
Pile::empile(array($c, false, NULL));
imagedestroy($a);
break;
case '[]':
list($a)=Pile::depile();
list($b)=Pile::depile();
$ax=imagesX($a);
$ay=imagesY($a);
$bx=imagesX($b);
$by=imagesY($b);
$imageX=$ax+$bx+5+$text_width;
$imageY=max($ay, $by);
$c=imageCreate($imageX, $imageY);
$background_color = imageColorAllocate($c,
$background_r, $background_v, $background_b);
$text_color = imageColorAllocate ($c, $txt_r, $txt_v, $txt_b);
imagecopy($c, $a,
5,intval(($imageY-$ay)/2),
0, 0,
$ax, $ay);
imagecopy($c, $b,
$ax+$text_width,intval(($imageY-$by)/2),
0, 0,
$bx, $by);
imagestring ($c, $font_size,
$ax + intval($text_width/2), intval(($imageY-$text_height)/2), ',', $text_color);
imageline($c, 0, 0, 0, $imageY-1, $text_color);
imageline($c, 0, $imageY-1, 5, $imageY-1, $text_color);
imageline($c, 0, 0, 5, 0, $text_color);
imageline($c, $imageX-1, 0, $imageX-1, $imageY-1, $text_color);
imageline($c, $imageX-1, $imageY-1, $imageX-6, $imageY-1, $text_color);
imageline($c, $imageX-1, 0, $imageX-6, 0, $text_color);
Pile::empile(array($c, false, NULL));
imagedestroy($a);
imagedestroy($b);
break;
case ']]':
list($a)=Pile::depile();
list($b)=Pile::depile();
$ax=imagesX($a);
$ay=imagesY($a);
$bx=imagesX($b);
$by=imagesY($b);
$imageX=$ax+$bx+5+$text_width;
$imageY=max($ay, $by);
$c=imageCreate($imageX, $imageY);
$background_color = imageColorAllocate($c,
$background_r, $background_v, $background_b);
$text_color = imageColorAllocate ($c, $txt_r, $txt_v, $txt_b);
imagecopy($c, $a,
5,intval(($imageY-$ay)/2),
0, 0,
$ax, $ay);
imagecopy($c, $b,
$ax+$text_width,intval(($imageY-$by)/2),
0, 0,
$bx, $by);
imagestring ($c, $font_size,
$ax + intval($text_width/2), intval(($imageY-$text_height)/2), ',', $text_color);
imageline($c, 5, 0, 5, $imageY-1, $text_color);
imageline($c, 0, $imageY-1, 5, $imageY-1, $text_color);
imageline($c, 0, 0, 5, 0, $text_color);
imageline($c, $imageX-1, 0, $imageX-1, $imageY-1, $text_color);
imageline($c, $imageX-1, $imageY-1, $imageX-6, $imageY-1, $text_color);
imageline($c, $imageX-1, 0, $imageX-6, 0, $text_color);
Pile::empile(array($c, false, NULL));
imagedestroy($a);
imagedestroy($b);
break;
case '[[':
list($a)=Pile::depile();
list($b)=Pile::depile();
$ax=imagesX($a);
$ay=imagesY($a);
$bx=imagesX($b);
$by=imagesY($b);
$imageX=$ax+$bx+5+$text_width;
$imageY=max($ay, $by);
$c=imageCreate($imageX, $imageY);
$background_color = imageColorAllocate($c,
$background_r, $background_v, $background_b);
$text_color = imageColorAllocate ($c, $txt_r, $txt_v, $txt_b);
imagecopy($c, $a,
5,intval(($imageY-$ay)/2),
0, 0,
$ax, $ay);
imagecopy($c, $b,
$ax+$text_width,intval(($imageY-$by)/2),
0, 0,
$bx, $by);
imagestring ($c, $font_size,
$ax + intval($text_width/2), intval(($imageY-$text_height)/2), ',', $text_color);
imageline($c, 0, 0, 0, $imageY-1, $text_color);
imageline($c, 0, $imageY-1, 5, $imageY-1, $text_color);
imageline($c, 0, 0, 5, 0, $text_color);
imageline($c, $imageX-6, 0, $imageX-6, $imageY-1, $text_color);
imageline($c, $imageX-1, $imageY-1, $imageX-6, $imageY-1, $text_color);
imageline($c, $imageX-1, 0, $imageX-6, 0, $text_color);
Pile::empile(array($c, false, NULL));
imagedestroy($a);
imagedestroy($b);
break;
case '][':
list($a)=Pile::depile();
list($b)=Pile::depile();
$ax=imagesX($a);
$ay=imagesY($a);
$bx=imagesX($b);
$by=imagesY($b);
$imageX=$ax+$bx+$text_width+5;
$imageY=max($ay, $by);
$c=imageCreate($imageX, $imageY);
$background_color = imageColorAllocate($c,
$background_r, $background_v, $background_b);
$text_color = imageColorAllocate ($c, $txt_r, $txt_v, $txt_b);
imagecopy($c, $a,
5,intval(($imageY-$ay)/2),
0, 0,
$ax, $ay);
imagecopy($c, $b,
$ax+$text_width,intval(($imageY-$by)/2),
0, 0,
$bx, $by);
imagestring ($c, $font_size,
$ax + intval($text_width/2), intval(($imageY-$text_height)/2), ',', $text_color);
imageline($c, 5, 0, 5, $imageY-1, $text_color);
imageline($c, 0, $imageY-1, 5, $imageY-1, $text_color);
imageline($c, 0, 0, 5, 0, $text_color);
imageline($c, $imageX-6, 0, $imageX-6, $imageY-1, $text_color);
imageline($c, $imageX-1, $imageY-1, $imageX-6, $imageY-1, $text_color);
imageline($c, $imageX-1, 0, $imageX-6, 0, $text_color);
Pile::empile(array($c, false, NULL));
imagedestroy($a);
imagedestroy($b);
break;
case 'vect':
list($a)=Pile::depile();
$ax=imagesX($a);
$ay=imagesY($a);
$b=imageCreate($ax, $ay+6);
$background_color = imageColorAllocate($b,
$background_r, $background_v, $background_b);
$text_color = imageColorAllocate ($b, $txt_r, $txt_v, $txt_b);
imagecopy($b, $a,
0,6,
0, 0,
$ax, $ay);
imageline($b,
0, 3, $ax, 3,
$text_color);
imageline($b,
$ax-3, 0, $ax, 3,
$text_color);
imageline($b,
$ax-3, 6, $ax, 3,
$text_color);
Pile::empile(array($b, false, NULL));
imagedestroy($a);
break;
case 'enter':
list($a)=Pile::depile();
list($b)=Pile::depile();
$ax=imagesX($a);
$ay=imagesY($a);
$bx=imagesX($b);
$by=imagesY($b);
$imageX=max($ax, $bx);
$imageY=$ay+$by+10;
$c=imageCreate($imageX, $imageY);
$background_color = imageColorAllocate($c,
$background_r, $background_v, $background_b);
$text_color = imageColorAllocate ($c, $txt_r, $txt_v, $txt_b);
imagecopy($c, $a,
intval(($imageX-$ax)/2),0,
0, 0,
$ax, $ay);
imagecopy($c, $b,
intval(($imageX-$bx)/2),$ay+10,
0, 0,
$bx, $by);
Pile::empile(array($c, false, NULL));
imagedestroy($a);
imagedestroy($b);
break;
case 'base':
list($b, $p)=Pile::depile();
list($a, $p, $v)=Pile::depile();
imagedestroy($a);
$a=array();
$p=array();
$imageX=imagesX($b);
$imageY=0;
$ax=array();
$ay=array();
for ($i=0;$i<$v;$i++){
list($a[$i], $p[$i])=Pile::depile(); //expression
$ax[$i]=imagesX($a[$i]);
$ay[$i]=imagesY($a[$i]);
$imageX+=$ax[$i]+2+(($p[$i])?10:0);
$imageY=max($ay[$i], $imageY);
}
$by=imagesY($b);
$imageY+=$by;
//echo $v, ' ', $imageY, ' ', $imageX;
$c=imageCreate($imageX, $imageY);
$background_color = imageColorAllocate($c,
$background_r, $background_v, $background_b);
$text_color = imageColorAllocate ($c, $txt_r, $txt_v, $txt_b);
$x=0;
for ($i=0;$i<$v;$i++){
imagecopy($c, $a[$i],
$x, intval(($imageY+$by-$ay[$i])/2),
0, 0,
$ax[$i], $ay[$i]);
if ($p[$i]){
//les parenth�ses
imagearc($c,
$x, intval(($imageY+$by)/2),
10, $ay[$i],
90, 270, $text_color);
imagearc($c,
$x+$ax[$i]-5, intval(($imageY+$by)/2),
10, $ay[$i],
270, 90, $text_color);
}
$x+=$ax[$i];
}
imagecopy($c, $b,
$x+5, 0,
0, 0,
$bx, $by);
imageline($c,
0, $by,
$imageX, $by,
$text_color);
Pile::empile(array($c, false, NULL));
for ($i=0;$i<$v;$i++){
imagedestroy($a[$i]);
}
break;
case '()':
list($a, $p1)=Pile::depile(); //expression
$ax=imagesX($a);
$ay=imagesY($a);
$b=imageCreate ($ax+30, $ay+10);
$background_color = imageColorAllocate($b,
$background_r, $background_v, $background_b);
$text_color = imageColorAllocate ($b, $txt_r, $txt_v, $txt_b);
imagecopy($b, $a,
15, 5,
0, 0,
$ax, $ay);
//les parenth�ses
imagearc($b,
10, intval($ay/2),
10, $ay+10,
90, 270, $text_color);
imagearc($b,
$ax+20, intval($ay/2),
10, $ay+10,
270, 90, $text_color);
Pile::empile(array($b, false, NULL));
imagedestroy($a);
break;
case ',':
list($a, $p1)=Pile::depile(); //limite
list($b, $p2)=Pile::depile(); //variable
$ax=imagesX($a);
$ay=imagesY($a);
$bx=imagesX($b);
$by=imagesY($b);
$imageY=max($ay, $by);
$imageX=$ax + $bx + $text_width*3;
$c=imageCreate ($imageX, $imageY);
$background_color = imageColorAllocate($c,
$background_r, $background_v, $background_b);
$text_color = imageColorAllocate ($c, $txt_r, $txt_v, $txt_b);
//on copie les images
imagecopy($c, $a,
0, $imageY-intval(($imageY+$ay)/2),
0, 0,
$ax, $ay);
imagecopy($c, $b,
$ax + $text_width*3, $imageY-intval(($imageY+$by)/2),
0, 0,
$bx, $by);
imagestring ($c, $font_size,
$ax + $text_width, intval(($imageY-$text_height)/2), ',', $text_color);
//on empile les images
Pile::empile(array($c, false, NULL));
//on supprime les images utilis�es
imagedestroy($a);
imagedestroy($b);
break;
case 'appartient':
list($a, $p1)=Pile::depile(); //limite
list($b, $p2)=Pile::depile(); //variable
$ax=imagesX($a);
$ay=imagesY($a);
$bx=imagesX($b);
$by=imagesY($b);
$imageY=max($ay, $by);
$imageX=$ax + $bx + 30;
$c=imageCreate ($imageX, $imageY);
$background_color = imageColorAllocate($c,
$background_r, $background_v, $background_b);
$text_color = imageColorAllocate ($c, $txt_r, $txt_v, $txt_b);
//on copie les images
imagecopy($c, $a,
0, $imageY-intval($imageY+$ay)/2,
0, 0,
$ax, $ay);
imagecopy($c, $b,
$ax+30, $imageY-intval($imageY+$by)/2,
0, 0,
$bx, $by);
//la barre au centre
imageline($c,
$ax+5, intval($imageY/2),
$ax+20, intval($imageY/2),
$text_color);
imagearc($c, $ax+15, intval($imageY/2), 20, 10, 60, 300, $text_color);
//on empile les images
Pile::empile(array($c, false, NULL));
//on supprime les images utilis�es
imagedestroy($a);
imagedestroy($b);
break;
case '!appartient':
list($a, $p1)=Pile::depile(); //limite
list($b, $p2)=Pile::depile(); //variable
$ax=imagesX($a);
$ay=imagesY($a);
$bx=imagesX($b);
$by=imagesY($b);
$imageY=max($ay, $by);
$imageX=$ax + $bx + 30;
$c=imageCreate ($imageX, $imageY);
$background_color = imageColorAllocate($c,
$background_r, $background_v, $background_b);
$text_color = imageColorAllocate ($c, $txt_r, $txt_v, $txt_b);
//on copie les images
imagecopy($c, $a,
0, $imageY-intval($imageY+$ay)/2,
0, 0,
$ax, $ay);
imagecopy($c, $b,
$ax+30, $imageY-intval($imageY+$by)/2,
0, 0,
$bx, $by);
//la barre au centre
imageline($c,
$ax+5, intval($imageY/2),
$ax+20, intval($imageY/2),
$text_color);
imageline($c,
$ax+5,intval($imageY/2)-10,
$ax+20,intval($imageY/2)+10,
$text_color);
imagearc($c, $ax+15, intval($imageY/2), 20, 10, 60, 300, $text_color);
//on empile les images
Pile::empile(array($c, false, NULL));
//on supprime les images utilis�es
imagedestroy($a);
imagedestroy($b);
break;
case 'includans':
list($a, $p1)=Pile::depile(); //limite
list($b, $p2)=Pile::depile(); //variable
$ax=imagesX($a);
$ay=imagesY($a);
$bx=imagesX($b);
$by=imagesY($b);
$imageY=max($ay, $by);
$imageX=$ax + $bx + 30;
$c=imageCreate ($imageX, $imageY);
$background_color = imageColorAllocate($c,
$background_r, $background_v, $background_b);
$text_color = imageColorAllocate ($c, $txt_r, $txt_v, $txt_b);
//on copie les images
imagecopy($c, $a,
0, $imageY-intval($imageY+$ay)/2,
0, 0,
$ax, $ay);
imagecopy($c, $b,
$ax+30, $imageY-intval($imageY+$by)/2,
0, 0,
$bx, $by);
imagearc($c, $ax+15, intval($imageY/2), 20, 10, 60, 300, $text_color);
//on empile les images
Pile::empile(array($c, false, NULL));
//on supprime les images utilis�es
imagedestroy($a);
imagedestroy($b);
break;
case '!includans':
list($a, $p1)=Pile::depile(); //limite
list($b, $p2)=Pile::depile(); //variable
$ax=imagesX($a);
$ay=imagesY($a);
$bx=imagesX($b);
$by=imagesY($b);
$imageY=max($ay, $by);
$imageX=$ax + $bx + 30;
$c=imageCreate ($imageX, $imageY);
$background_color = imageColorAllocate($c,
$background_r, $background_v, $background_b);
$text_color = imageColorAllocate ($c, $txt_r, $txt_v, $txt_b);
//on copie les images
imagecopy($c, $a,
0, $imageY-intval($imageY+$ay)/2,
0, 0,
$ax, $ay);
imagecopy($c, $b,
$ax+30, $imageY-intval($imageY+$by)/2,
0, 0,
$bx, $by);
imagearc($c, $ax+15, intval($imageY/2), 20, 10, 60, 300, $text_color);
imageline($c,
$ax+10,intval($imageY/2)-10,
$ax+15,intval($imageY/2)+10,
$text_color);
//on empile les images
Pile::empile(array($c, false, NULL));
//on supprime les images utilis�es
imagedestroy($a);
imagedestroy($b);
break;
case 'rationnel':
$a=imageCreate (20,20);
$background_color = imageColorAllocate($a,
$background_r, $background_v, $background_b);
$text_color = imageColorAllocate ($a, $txt_r, $txt_v, $txt_b);
imageline($a,
5,5,
5,15,
$text_color);
imageline($a,
15,15,
19,19,
$text_color);
imageEllipse($a, 10, 10, 20, 20, $text_color);
Pile::empile(array($a, false, NULL));
break;
case 'complexe':
$a=imageCreate (20,20);
$background_color = imageColorAllocate($a,
$background_r, $background_v, $background_b);
$text_color = imageColorAllocate ($a, $txt_r, $txt_v, $txt_b);
imageline($a,
5,5,
5,15,
$text_color);
imagearc($a, 10,10, 20, 20, 110, 280, $text_color);
Pile::empile(array($a, false, NULL));
break;
case 'naturel':
$a=imageCreate (20,20);
$background_color = imageColorAllocate($a,
$background_r, $background_v, $background_b);
$text_color = imageColorAllocate ($a, $txt_r, $txt_v, $txt_b);
imageline($a,
0,20,
0,0,
$text_color);
imageline($a,
0,0,
19,20,
$text_color);
imageline($a,
19,20,
19,0,
$text_color);
imageline($a,
3,3,
3,20,
$text_color);
Pile::empile(array($a, false, NULL));
break;
case 'relatif':
$a=imageCreate (20,20);
$background_color = imageColorAllocate($a,
$background_r, $background_v, $background_b);
$text_color = imageColorAllocate ($a, $txt_r, $txt_v, $txt_b);
imageline($a,
0,0,
19,0,
$text_color);
imageline($a,
19,0,
3,19,
$text_color);
imageline($a,
0,19,
19,19,
$text_color);
imageline($a,
16,0,
0,19,
$text_color);
Pile::empile(array($a, false, NULL));
break;
case 'real':
case 'reel':
$a=imageCreate (10,20);
$background_color = imageColorAllocate($a,
$background_r, $background_v, $background_b);
$text_color = imageColorAllocate ($a, $txt_r, $txt_v, $txt_b);
imageline($a,
0,0,
0,19,
$text_color);
imageline($a,
3,0,
3,19,
$text_color);
imageline($a,
3,10,
9,20,
$text_color);
imageline($a,
0,0,
5,0,
$text_color);
imagearc($a, 6, 5, 8, 11, 280, 110, $text_color);
Pile::empile(array($a, false, NULL));
break;
case 'ssi':
list($a, $p1)=Pile::depile(); //limite
list($b, $p2)=Pile::depile(); //variable
$ax=imagesX($a);
$ay=imagesY($a);
$bx=imagesX($b);
$by=imagesY($b);
$imageY=max($ay, $by);
$imageX=$ax + $bx + 30;
$c=imageCreate ($imageX, $imageY);
$background_color = imageColorAllocate($c,
$background_r, $background_v, $background_b);
$text_color = imageColorAllocate ($c, $txt_r, $txt_v, $txt_b);
//on copie les images
imagecopy($c, $a,
0, $imageY-intval($imageY+$ay)/2,
0, 0,
$ax, $ay);
imagecopy($c, $b,
$ax+30, $imageY-intval($imageY+$by)/2,
0, 0,
$bx, $by);
//le =
imageline($c,
$ax+5, intval($imageY/2)+2,
$ax+25, intval($imageY/2)+2,
$text_color);
imageline($c,
$ax+5, intval($imageY/2)-2,
$ax+25, intval($imageY/2)-2,
$text_color);
//les fleches
imageline($c,
$ax, intval($imageY/2),
$ax+5, intval($imageY/2)-5,
$text_color);
imageline($c,
$ax, intval($imageY/2),
$ax+5, intval($imageY/2)+5,
$text_color);
imageline($c,
$ax+25, intval($imageY/2)-5,
$ax+30, intval($imageY/2),
$text_color);
imageline($c,
$ax+25, intval($imageY/2)+5,
$ax+30, intval($imageY/2),
$text_color);
//on empile les images
Pile::empile(array($c, false, NULL));
//on supprime les images utilis�es
imagedestroy($a);
imagedestroy($b);
break;
case 'implique':
list($a, $p1)=Pile::depile(); //limite
list($b, $p2)=Pile::depile(); //variable
$ax=imagesX($a);
$ay=imagesY($a);
$bx=imagesX($b);
$by=imagesY($b);
$imageY=max($ay, $by);
$imageX=$ax + $bx + 30;
$c=imageCreate ($imageX, $imageY);
$background_color = imageColorAllocate($c,
$background_r, $background_v, $background_b);
$text_color = imageColorAllocate ($c, $txt_r, $txt_v, $txt_b);
//on copie les images
imagecopy($c, $a,
0, $imageY-intval($imageY+$ay)/2,
0, 0,
$ax, $ay);
imagecopy($c, $b,
$ax+30, $imageY-intval($imageY+$by)/2,
0, 0,
$bx, $by);
//le =
imageline($c,
$ax+5, intval($imageY/2)+2,
$ax+25, intval($imageY/2)+2,
$text_color);
imageline($c,
$ax+5, intval($imageY/2)-2,
$ax+25, intval($imageY/2)-2,
$text_color);
//les fleches
imageline($c,
$ax+25, intval($imageY/2)-5,
$ax+30, intval($imageY/2),
$text_color);
imageline($c,
$ax+25, intval($imageY/2)+5,
$ax+30, intval($imageY/2),
$text_color);
//on empile les images
Pile::empile(array($c, false, NULL));
//on supprime les images utilis�es
imagedestroy($a);
imagedestroy($b);
break;
case '<':
list($a, $p1)=Pile::depile(); //limite
list($b, $p2)=Pile::depile(); //variable
$ax=imagesX($a);
$ay=imagesY($a);
$bx=imagesX($b);
$by=imagesY($b);
$imageY=max($ay, $by);
$imageX=$ax + $bx + 20;
$c=imageCreate ($imageX, $imageY);
$background_color = imageColorAllocate($c,
$background_r, $background_v, $background_b);
$text_color = imageColorAllocate ($c, $txt_r, $txt_v, $txt_b);
imagecopy($c, $a,
0, $imageY-intval($imageY+$ay)/2,
0, 0,
$ax, $ay);
imagecopy($c, $b,
$ax+20, $imageY-intval($imageY+$by)/2,
0, 0,
$bx, $by);
imageline($c,
$ax+20, intval($imageY/2)-5,
$ax, intval($imageY/2),
$text_color);
imageline($c,
$ax+20, intval($imageY/2)+5,
$ax, intval($imageY/2),
$text_color);
Pile::empile(array($c, false, NULL));
imagedestroy($a);
imagedestroy($b);
break;
case '>':
list($a, $p1)=Pile::depile(); //limite
list($b, $p2)=Pile::depile(); //variable
$ax=imagesX($a);
$ay=imagesY($a);
$bx=imagesX($b);
$by=imagesY($b);
$imageY=max($ay, $by);
$imageX=$ax + $bx + 20;
$c=imageCreate ($imageX, $imageY);
$background_color = imageColorAllocate($c,
$background_r, $background_v, $background_b);
$text_color = imageColorAllocate ($c, $txt_r, $txt_v, $txt_b);
imagecopy($c, $a,
0, $imageY-intval($imageY+$ay)/2,
0, 0,
$ax, $ay);
imagecopy($c, $b,
$ax+20, $imageY-intval($imageY+$by)/2,
0, 0,
$bx, $by);
imageline($c,
$ax, intval($imageY/2)-5,
$ax+20, intval($imageY/2),
$text_color);
imageline($c,
$ax, intval($imageY/2)+5,
$ax+20, intval($imageY/2),
$text_color);
Pile::empile(array($c, false, NULL));
imagedestroy($a);
imagedestroy($b);
break;
case '<=':
list($a, $p1)=Pile::depile(); //limite
list($b, $p2)=Pile::depile(); //variable
$ax=imagesX($a);
$ay=imagesY($a);
$bx=imagesX($b);
$by=imagesY($b);
$imageY=max($ay, $by);
$imageX=$ax + $bx + 20;
$c=imageCreate ($imageX, $imageY);
$background_color = imageColorAllocate($c,
$background_r, $background_v, $background_b);
$text_color = imageColorAllocate ($c, $txt_r, $txt_v, $txt_b);
imagecopy($c, $a,
0, $imageY-intval($imageY+$ay)/2,
0, 0,
$ax, $ay);
imagecopy($c, $b,
$ax+20, $imageY-intval($imageY+$by)/2,
0, 0,
$bx, $by);
imageline($c,
$ax+20, intval($imageY/2)-5,
$ax, intval($imageY/2),
$text_color);
imageline($c,
$ax+20, intval($imageY/2)+5,
$ax, intval($imageY/2),
$text_color);
//la double barre
imageline($c,
$ax+20, intval($imageY/2)+7,
$ax, intval($imageY/2)+2,
$text_color);
Pile::empile(array($c, false, NULL));
imagedestroy($a);
imagedestroy($b);
break;
case '>=':
list($a, $p1)=Pile::depile(); //limite
list($b, $p2)=Pile::depile(); //variable
$ax=imagesX($a);
$ay=imagesY($a);
$bx=imagesX($b);
$by=imagesY($b);
$imageY=max($ay, $by);
$imageX=$ax + $bx + 20;
$c=imageCreate ($imageX, $imageY);
$background_color = imageColorAllocate($c,
$background_r, $background_v, $background_b);
$text_color = imageColorAllocate ($c, $txt_r, $txt_v, $txt_b);
imagecopy($c, $a,
0, $imageY-intval($imageY+$ay)/2,
0, 0,
$ax, $ay);
imagecopy($c, $b,
$ax+20, $imageY-intval($imageY+$by)/2,
0, 0,
$bx, $by);
//le signe
imageline($c,
$ax, intval($imageY/2)-5,
$ax+20, intval($imageY/2),
$text_color);
imageline($c,
$ax, intval($imageY/2)+5,
$ax+20, intval($imageY/2),
$text_color);
//la double barre
imageline($c,
$ax, intval($imageY/2)+7,
$ax+20, intval($imageY/2)+2,
$text_color);
Pile::empile(array($c, false, NULL));
imagedestroy($a);
imagedestroy($b);
break;
case 'lim':
list($a, $p1)=Pile::depile(); //limite
list($b, $p2)=Pile::depile(); //variable
list($c, $p3)=Pile::depile(); //expression
$ax=imagesX($a);
$ay=imagesY($a);
$bx=imagesX($b);
$by=imagesY($b);
$cx=imagesX($c);
$cy=imagesY($c);
$e=imagecreate (intval($cx*$rapport), intval($cy*$rapport));
ImageCopyResized($e,$c,0,0,0,0,intval($cx*$rapport),intval($cy*$rapport),$cx, $cy);
$background_color = imagecolorallocate($c,
$background_r, $background_v, $background_b);
$cx=intval($rapport*$cx);
$cy=intval($rapport*$cy);
$imageY=max($ay, $by) + $cy + 10;
$imageX=max($ax + $bx + 20, $cx + 10 + 4 * $text_width );
$d=imageCreate ($imageX, $imageY);
$background_color = imageColorAllocate($d,
$background_r, $background_v, $background_b);
$text_color = imageColorAllocate ($d, $txt_r, $txt_v, $txt_b);
imagecopy($d, $e,
4*$text_width, 0,
0, 0,
$cx, $cy);
imagecopy($d, $a,
$ax+20, $imageY-intval(($imageY-$cy+$ay)/2),
0, 0,
$ax, $ay);
imagecopy($d, $b,
0, $imageY-intval(($imageY-$cy+$by)/2),
0, 0,
$bx, $by);
imageline($d,
$bx, $imageY-intval(($imageY-$cy)/2),
$bx+20, $imageY-intval(($imageY-$cy)/2),
$text_color);
imageline($d,
$bx+15, $imageY-intval(($imageY-$cy)/2)+5,
$bx+20, $imageY-intval(($imageY-$cy)/2),
$text_color);
imageline($d,
$bx+15, $imageY-intval(($imageY-$cy)/2)-5,
$bx+20, $imageY-intval(($imageY-$cy)/2),
$text_color);
imagestring ($d, $font_size,
0, intval($cy/2-$text_height/2), 'Lim', $text_color);
Pile::empile(array($d, false, NULL));
imagedestroy($a);
imagedestroy($b);
imagedestroy($c);
imagedestroy($e);
break;
case 'infinit+':
$a=imageCreate (40,10);
$background_color = imageColorAllocate($a,
$background_r, $background_v, $background_b);
$text_color = imageColorAllocate ($a, $txt_r, $txt_v, $txt_b);
imageEllipse($a, 17, 5, 14, 10, $text_color);
imageEllipse($a, 32, 5, 16, 10, $text_color);
imageline($a, 0,5,10,5, $text_color);
imageline($a, 5,0,5,10, $text_color);
Pile::empile(array($a, false, NULL));
break;
case 'infinit-':
$a=imageCreate (40,10);
$background_color = imageColorAllocate($a,
$background_r, $background_v, $background_b);
$text_color = imageColorAllocate ($a, $txt_r, $txt_v, $txt_b);
imageEllipse($a, 17, 5, 14, 10, $text_color);
imageEllipse($a, 32, 5, 16, 10, $text_color);
imageline($a, 0,5,10,5, $text_color);
Pile::empile(array($a, false, NULL));
break;
case 'integrale':
list($a, $p1)=Pile::depile(); //borne 2
list($b, $p2)=Pile::depile(); //borne 1
list($c, $p3)=Pile::depile(); //dx
list($d, $p4)=Pile::depile(); //la fonction
$ax=imagesX($a);
$ay=imagesY($a);
$bx=imagesX($b);
$by=imagesY($b);
$cx=imagesX($c);
$cy=imagesY($c);
$dx=imagesX($d);
$dy=imagesY($d);
$f=imagecreate ($dx*2, $dy*2);
ImageCopyResized($f,$d,0,0,0,0,$dx*2,$dy*2,$dx, $dy);
$background_color = imagecolorallocate($f,
$background_r, $background_v, $background_b);
$dx=2*$dx;
$dy=2*$dy;
$imageX=max($ax, $bx)+$cx+$dx+$text_width*2+35;
$imageY=max($ay+$by+10, $cy,$dy)+10;
$e=imageCreate ($imageX, $imageY);
$background_color = imageColorAllocate($e,
$background_r, $background_v, $background_b);
$text_color = imageColorAllocate ($e, $txt_r, $txt_v, $txt_b);
imagecopy($e, $b,
20, 5,
0, 0,
$bx, $by);
imagecopy($e, $a,
20, $imageY-5-$ay,
0, 0,
$ax, $ay);
imagecopy($e, $f,
max($ax, $bx)+25, intval(($imageY-$dy)/2),
0, 0,
$dx, $dy);
imagecopy($e, $c,
max($ax, $bx)+30+$dx, intval(($imageY-$cy)/2),
0, 0,
$cx, $cy);
if ($p4){
imagearc($e,
max($ax, $bx)+25, intval($imageY/2),
5, intval($dy/2)+10,
90, 270, $text_color);
imagearc($e,
max($ax, $bx)+25+$dx, intval($imageY/2),
5, intval($dy/2)+10,
270, 90, $text_color);
}
if ($p2){
imagearc($e,
20, 5+intval($by/2),
5, 5+intval($by/2),
90, 270, $text_color);
imagearc($e,
20+$bx, 5+intval($by/2),
5, 5+intval($by/2),
270, 90, $text_color);
}
if ($p1){
imagearc($e,
20, $imageY-5-intval($ay/2),
5, 5+intval($ay/2),
90, 270, $text_color);
imagearc($e,
20+$ax, $imageY-5-intval($ay/2),
5, 5+intval($ay/2),
270, 90, $text_color);
}
//le signe de l'int�grale
imageline($e, 10, 5, 10, $imageY-6, $text_color);
//le coin haut
imageline($e, 10, 5, 15, 0, $text_color);
imageline($e, 20, 0, 15, 0, $text_color);
//le second coin
imageline($e, 10, $imageY-6, 5, $imageY-1, $text_color);
imageline($e, 5, $imageY-1, 0, $imageY-1, $text_color);
Pile::empile(array($e, false, NULL));
imagedestroy($a);
imagedestroy($b);
imagedestroy($c);
imagedestroy($d);
imagedestroy($f);
break;
case '|':
//on prends le module ou la valeur absolue (la distance � l'origine...)
list($a, $p)=Pile::depile();
$ax=imagesx($a);
$ay=imagesy($a);
$y=$ay+11;
$x=$ax+10;
$c=imagecreate ($x, $y);
$background_color = imagecolorallocate($c,
$background_r, $background_v, $background_b);
$text_color = imagecolorallocate ($c, $txt_r, $txt_v, $txt_b);
imagecopy($c, $a,
7, 7,
0, 0,
$ax, $ay);
imageline($c, 0, 0, 0, $y, $text_color);
imageline($c, $x-2, 0, $x-2, $y, $text_color);
Pile::empile(array($c, false, NULL));
imagedestroy($a);
break;
case '�':
//on �l�ve au carr�
list($a, $pa)=Pile::depile();
$ax=imagesx($a);
$ay=imagesy($a);
$y=$ay+6;
$p=(int)$ay/4;
$x=$ax+$text_width*2+$p*2;
$c=imagecreate ($x, $y);
$background_color = imagecolorallocate($c,
$background_r, $background_v, $background_b);
$text_color = imagecolorallocate ($c, $txt_r, $txt_v, $txt_b);
imagecopy($c, $a,
$p, 5,
0, 0,
$ax, $ay);
if ($pa){
imagearc($c, $p, $y/2, $p, $ay-5, 90, 270, $text_color);
imagearc($c, $ax+$p, $y/2, $p, $ay-5, 270, 90, $text_color);
}
imagestring ($c, $font_size-3, $x-$text_width*2,
0, '2', $text_color);
Pile::empile(array($c, false, NULL));
imagedestroy($a);
break;
case 'sqrt':
//on prend la racine
list($a, $p)=Pile::depile();
$ax=imagesx($a);
$ay=imagesy($a);
$r=$ax/15;
if ($r<4) $r=4;
$x=$ax+$r*2+2;
$y=$ay+1;
$c=imagecreate ($x, $y);
$background_color = imagecolorallocate($c,
$background_r, $background_v, $background_b);
$text_color = imagecolorallocate ($c, $txt_r, $txt_v, $txt_b);
imagecopy($c, $a,
$r*2, 1,
0, 0,
$ax, $ay);
imageline($c, 0, 0, $r, $ay-1, $text_color);
imageline($c, $r, $ay-1, $r*2, 1, $text_color);
imageline($c, $r*2, 1, $x-1, 1, $text_color);
imageline($c, $x-1, 1, $x-1, 5, $text_color);
Pile::empile(array($c, false, NULL));
imagedestroy($a);
break;
case '^':
//On effectue un exposant
list($b, $p1)=Pile::depile();
list($a, $p2)=Pile::depile();
$ax=imagesx($a);
$ay=imagesy($a);
$c=imagecreate (intval($ax*$rapport), intval($ay*$rapport));
ImageCopyResized($c,$a,0,0,0,0,$ax*$rapport,intval($ay*$rapport),$ax, $ay);
$background_color = imagecolorallocate($c,
$background_r, $background_v, $background_b);
$ax=intval($rapport*$ax);
$ay=intval($rapport*$ay);
$bx=imagesx($b);
$by=imagesy($b);
//on calcule les dimensions de la nouvelle image
$y=$ay+$by/2;
$ap=intval($ay/4);
$bp=intval($by/4);
$x=$ax+$bx+2*$ap+2*$bp;
//on cr� la nouvelle image
$d=imagecreate ($x, $y);
$background_color = imagecolorallocate($d,
$background_r, $background_v, $background_b);
$text_color = imagecolorallocate ($d, $txt_r, $txt_v, $txt_b);
//on copie le nombre
imagecopy($d, $c,
$ap*1.5, $by/2,
0, 0,
$ax, $ay);
//on copie l'exposant
imagecopy($d, $b,
$x-$bx-5, 0,
0, 0,
$bx, $by);
//on ajoute des parenth�ses � l'�xposant
if ($p2){
imagearc($d,
$ap, $by/2+$ay/2, $ap, $ay-5,
90, 270, $text_color);
imagearc($d,
$ax+$ap*2, $by/2+$ay/2, $ap, $ay-5,
270, 90, $text_color);
}
//on ajoute les parenth�ses pour le premier membre
if ($p1){
imagearc($d, $x-5, $by/2, $bp, $by-5, 270, 90, $text_color);
imagearc($d, $x-$bx-6, $by/2, $bp, $by-5, 90, 270, $text_color);
}
//on trace le signe
/*imagestring ($d, $font_size, $ax+$ap*2,
$by/2, '^', $text_color);
Pile::empile(array($d, false, NULL));
imagedestroy($a);
imagedestroy($b);
imagedestroy($c);
break;
case '+':
//on effectue une somme
list($b, $p)=Pile::depile();
list($a, $p)=Pile::depile();
$ax=imagesx($a);
$ay=imagesy($a);
$bx=imagesx($b);
$by=imagesy($b);
$y=max($ay, $by);
$x=$ax+$bx+$text_width;
$c=imagecreate ($x, $y);
$background_color = imagecolorallocate($c,
$background_r, $background_v, $background_b);
$text_color = imagecolorallocate ($c, $txt_r, $txt_v, $txt_b);
imagecopy($c, $a,
0, intval(($y-$ay)/2),
0, 0,
$ax, $ay);
imagecopy($c, $b,
$x-$bx, intval(($y-$by)/2),
0, 0,
$bx, $by);
imagestring ($c, $font_size, $ax,
intval(($y-$text_height)/2), '+', $text_color);
Pile::empile(array($c, true, NULL));
imagedestroy($a);
imagedestroy($b);
break;
case '-':
//on effectue une diff�rence
list($b, $p2)=Pile::depile();
list($a, $p)=Pile::depile();
$ax=imagesx($a);
$ay=imagesy($a);
if ($p2==true)
$p=(int)$y/4;
else
$p=0;
$bx=imagesx($b);
$by=imagesy($b);
$y=max($ay, $by);
$x=$ax+$bx+$text_width*2+2*$p;
$c=imagecreate ($x, $y);
$background_color = imagecolorallocate($c,
$background_r, $background_v, $background_b);
$text_color = imagecolorallocate ($c, $txt_r, $txt_v, $txt_b);
imagecopy($c, $a,
0, intval(($y-$ay)/2),
0, 0,
$ax, $ay);
imagecopy($c, $b,
$x-$bx-$p, intval(($y-$by)/2),
0, 0,
$bx, $by);
if ($p2==true){
imagearc($c, $x-$p, $y/2, $p, $y-5, 270, 90, $text_color);
imagearc($c, $x-$bx-$p, $y/2, $p, $y-5, 90, 270, $text_color);
}
imagestring ($c, $font_size, $ax+$text_width/2,
intval(($y-$text_height)/2), '-', $text_color);
Pile::empile(array($c, true, NULL));
imagedestroy($a);
imagedestroy($b);
break;
case '*':
//on effectue un produit
list($b, $p2)=Pile::depile();
list($a, $p1)=Pile::depile();
$ax=imagesx($a);
$ay=imagesy($a);
$bx=imagesx($b);
$by=imagesy($b);
$y=max($ay, $by);
$p=(int)$y/4;
$x=$ax+$bx+(($p1)?2:0+($p2)?2:0)*$p+$text_width*2+5;
$c=imagecreate ($x, $y);
$background_color = imagecolorallocate($c,
$background_r, $background_v, $background_b);
$text_color = imagecolorallocate ($c, $txt_r, $txt_v, $txt_b);
imagecopy($c, $a,
5, intval(($y-$ay)/2),
0, 0,
$ax, $ay);
imagecopy($c, $b,
$x-$bx-5, intval(($y-$by)/2),
0, 0,
$bx, $by);
if ($p2==true){
imagearc($c, $x-$p, $y/2, $p, $y-5, 270, 90, $text_color);
imagearc($c, $x-$bx-$p, $y/2, $p, $y-5, 90, 270, $text_color);
}
if ($p1==true){
imagearc($c, $x-$bx-3*$p, $y/2, $p, $y-5, 270, 90, $text_color);
imagearc($c, $p/2, $y/2, $p, $y-5, 90, 270, $text_color);
}
if (!$p1 && !$p2){
imagestring ($c, $font_size, $ax+$text_width,
intval(($y-$text_height)/2), '*', $text_color);
}
Pile::empile(array($c, false, NULL));
imagedestroy($a);
imagedestroy($b);
break;
case '/':
//on effectue une division
list($b, $p)=Pile::depile();
list($a, $p)=Pile::depile();
$ax=imagesx($a);
$ay=imagesy($a);
$bx=imagesx($b);
$by=imagesy($b);
$y=$ay+$by+2;
$x=max($ax, $bx)+$y/5;
$c=imagecreate ($x, $y);
$background_color = imagecolorallocate($c,
$background_r, $background_v, $background_b);
$text_color = imagecolorallocate ($c, $txt_r, $txt_v, $txt_b);
imagecopy($c, $a,
intval(($x-$ax)/2), 0,
0, 0,
$ax, $ay);
imagecopy($c, $b,
intval(($x-$bx)/2), $ay+1,
0, 0,
$bx, $by);
imageline($c, 0, $ay, $x, $ay, $text_color);
Pile::empile(array($c, false, NULL));
imagedestroy($a);
imagedestroy($b);
break;
case '=':
//on d�clare une �galit�e
list($b, $p)=Pile::depile();
list($a, $p)=Pile::depile();
$ax=imagesx($a);
$ay=imagesy($a);
$bx=imagesx($b);
$by=imagesy($b);
$y=max($ay, $by);
$x=$ax+$bx+15;
$c=imagecreate ($x, $y);
$background_color = imagecolorallocate($c,
$background_r, $background_v, $background_b);
$text_color = imagecolorallocate ($c, $txt_r, $txt_v, $txt_b);
imagecopy($c, $a,
0, intval(($y-$ay)/2),
0, 0,
$ax, $ay);
imagecopy($c, $b,
$x-$bx, intval(($y-$by)/2),
0, 0,
$bx, $by);
imageline($c,
$ax+2, intval($y/2)-2,
$ax+12, intval($y/2)-2,
$text_color);
imageline($c,
$ax+2, intval($y/2)+2,
$ax+12, intval($y/2)+2,
$text_color);
Pile::empile(array($c, false, NULL));
imagedestroy($a);
imagedestroy($b);
break;
case '!=':
//on d�clare une �galit�e
list($b, $p)=Pile::depile();
list($a, $p)=Pile::depile();
$ax=imagesx($a);
$ay=imagesy($a);
$bx=imagesx($b);
$by=imagesy($b);
$y=max($ay, $by);
$x=$ax+$bx+15;
$c=imagecreate ($x, $y);
$background_color = imagecolorallocate($c,
$background_r, $background_v, $background_b);
$text_color = imagecolorallocate ($c, $txt_r, $txt_v, $txt_b);
imagecopy($c, $a,
0, intval(($y-$ay)/2),
0, 0,
$ax, $ay);
imagecopy($c, $b,
$x-$bx, intval(($y-$by)/2),
0, 0,
$bx, $by);
imageline($c,
$ax+2, intval($y/2)-2,
$ax+12, intval($y/2)-2,
$text_color);
imageline($c,
$ax+2, intval($y/2)+2,
$ax+12, intval($y/2)+2,
$text_color);
imageline($c,
$ax+5, intval($y/2)+3,
$ax+7, intval($y/2)-3,
$text_color);
Pile::empile(array($c, false, NULL));
imagedestroy($a);
imagedestroy($b);
break;
default:
if ($val{0}==='f'){
//on applique une fonction au d�rnier �l�ment
list($a, $p1)=Pile::depile();
$ax=imagesx($a);
$ay=imagesy($a);
$y=$ay;
$p=(int)$y/4;
$x=$ax+2*$p+$text_width*(strlen($val)-1);
$c=imagecreate ($x, $y);
$background_color = imagecolorallocate($c,
$background_r, $background_v, $background_b);
$text_color = imagecolorallocate ($c, $txt_r, $txt_v, $txt_b);
imagecopy($c, $a,
$x-$ax-$p, intval(($y-$ay)/2),
0, 0,
$ax, $ay);
imagestring ($c, $font_size, 0,
intval(($y-$text_height)/2), substr($val, 1), $text_color);
imagearc($c, $x-$p, $y/2, $p, $y-5, 270, 90, $text_color);
imagearc($c, $x-$ax-$p, $y/2, $p, $y-5, 90, 270, $text_color);
Pile::empile(array($c, false, NULL));
imagedestroy($a);
}else{
if ($val{0}==='\\'){
$val=substr($val, 1);
}
//on empile
$im = imagecreate ($text_width*strlen($val)+3, $text_height+2);
if ($im===NULL)return false;
$background_color = imagecolorallocate ($im,
$background_r, $background_v, $background_b);
$text_color = imagecolorallocate ($im, $txt_r, $txt_v, $txt_b);
imagestring ($im, $font_size, 2, 1, $val, $text_color);
Pile::empile(array($im, false, $val));
}
break;
}
}
//print_r(Pile::getpile());
//On affiche une bordure si besoin
list($im, $a)=Pile::depile();
if ($transparent){
// $tr = imagecolorat($im, 0, 0);
$tr = imagecolortransparent($im, $background_color);
}
if ($border===true)
{
$x=imagesx($im);
$y=imagesy($im);
$c=imagecreate ($x+10, $y+10);
$background_color = imagecolorallocate($c,
$background_r, $background_v, $background_b);
$text_color = imagecolorallocate ($c, $txt_r, $txt_v, $txt_b);
imagecopy($c, $im,
5, 5,
0, 0,
$x, $y);
$y=$y+9;
$x=$x+9;
imageline($c, 0, 0, $x, 0, $text_color);
imageline($c, $x, 0, $x, $y, $text_color);
imageline($c, $x, $y, 0, $y, $text_color);
imageline($c, 0, $y, 0, 0, $text_color);
imagedestroy($im);
$im=&$c;
}
//calcule le temps d'affichage
list($usec, $sec) = explode(' ', microtime());
$this->times['aff']=(int)(($sec+$usec-$start)*100000);
$this->times['aff']=(float)$this->times['aff']/100;
//imageantialias($im,true);
/*
En fonction des param�tres, on affiche l'image, on la renvoi, ou on
l'enregistre selon son type.
if ($name===NULL)
{
header('Content-type: image/'.$type);
eval('image'.$type.'($im);');
}
else if ($name===false)
return $im;
else
eval('image'.$type.'($im, "'.$name.'");');
}
public function getstring(){
return $this->str;
}
private function parse(){
/*
cette fonction parse la chaine
La chaine transmise peut �tre consid�r�e comme un code source : certains font
des interpr�teurs sur le m�me principe...
On s�l�ctionne les lignes, on enl�ves les commentaires, et on s�l�ctionne chaque
instruction par un explode qui enl�ve les s�parateurs.
On filtre ensuite le tableau pour enlever les cases vides.
//date
list($usec, $sec) = explode(' ', microtime());
$start=$sec+$usec;
$this->parse=true;
$tab=explode('
', $this->str);
$tab=implode(' ', array_filter($tab, 'lignecode'));
$tab1=array();
$tab1=array_merge(preg_split('/\s/',$tab), $tab1);
$tab1=array_filter($tab1,'isval');
$this->tab=$tab1;
//calcule le temps de parsing....
list($usec, $sec) = explode(' ', microtime());
$this->times['parse']=(int)(($sec+$usec-$start)*100000);
$this->times['parse']=(float)$this->times['parse']/100;
}
public function gettimes(){
/*
Cette fonction sert si un jour j'ai � faire des fonctions genre progeval,
ou bien prog_interprete...
j'aurais des fonctions qui permetront d�ja de faire des choses pour faciliter l'optimisation...
unit�e : mili seconde
type de nombres : float � deux chiffres apr�s la virgule, de toute fa�on,
apr�s cette limite, on n'a pas d'informations sur la charge de l'ordinateur
sur le moment pour pouvoir dire que c'�tait vraiment repr�sentatif...
return array($this->times);
}
public function calc_derive(){
if (!$this->parse)$this->parse();
list($usec, $sec) = explode(' ', microtime());
$start=$sec+$usec;
foreach ($this->tab as $val)
{
switch ($val)
{
case '+':
list($b, $bp, $bpd, $bd, $bdp, $bdpd)=Pile::depile();
list($a, $ap, $apd, $ad, $adp, $adpd)=Pile::depile();
Pile::empile(array($a.' + '.$b, true, true, $ad.' + '.$bd, true, true));
break;
case '-':
list($b, $bp, $bpd, $bd, $bdp, $bdpd)=Pile::depile();
list($a, $ap, $apd, $ad, $adp, $adpd)=Pile::depile();
Pile::empile(array($a.' + '.$b, true, true, $ad.' + '.$bd, true, true));
if (!$bp){
if (!$bdp){
Pile::empile(
array(
$a.' - '.$b, true, true,
$ad.' - '.$bd, true, true));
}else{
Pile::empile(
array(
$a.' - ( '.$b.' )', true,
true, $ad.' - ( '.$bd.' )', true, true));
}
}else{
if (!$bdp){
Pile::empile(
array(
$a.' - '.$b, true, true,
$ad.' - '.$bd, true, true));
}else{
Pile::empile(
array(
$a.' - ( '.$b.' )', true, true,
$ad.' - ( '.$bd.' )', true, true));
}
}
break;
case '*':
list($b, $bp, $bpd, $bd, $bdp, $bdpd)=Pile::depile();
list($a, $ap, $apd, $ad, $adp, $adpd)=Pile::depile();
if ($adp && !$bp && !$bdp && !$ap)
$d='( '.$ad.' ) * '.$b.' + '.$bd.' * '.$a;
else if (!$adp && $bp && !$bdp && !$ap)
$d=$ad.' * ( '.$b.' ) + '.$bd.' * '.$a;
else if (!$adp && !$bp && $bdp && !$ap)
$d=$ad.' * '.$b.' + ( '.$bd.' ) * '.$a;
else if (!$adp && !$bp && !$bdp && !$ap)
$d=$ad.' * '.$b.' + '.$bd.' * ( '.$a.' )';
else if ($adp && $bp && !$bdp && !$ap)
$d='( '.$ad.' ) * ( '.$b.' ) + '.$bd.' * '.$a;
else if ($adp && !$bp && $bdp && !$ap)
$d='( '.$ad.' ) * '.$b.' + ( '.$bd.' ) * '.$a;
else if ($adp && !$bp && !$bdp && $ap)
$d='( '.$ad.' ) * '.$b.' + '.$bd.' * ( '.$a.' )';
else if (!$adp && $bp && $bdp && !$ap)
$d=$ad.' * ( '.$b.' ) + ( '.$bd.' ) * '.$a.' )';
else if (!$adp && $bp && !$bdp && $ap)
$d=$ad.' * ( '.$b.' ) + '.$bd.' * ( '.$a.' )';
else if (!$adp && !$bp && $bdp && $ap)
$d=$ad.' * '.$b.' + ( '.$bd.' ) * ( '.$a.' )';
else if ($adp && $bp && $bdp && !$ap)
$d='( '.$ad.' ) * ( '.$b.' ) + ('.$bd.') * '.$a;
else if ($adp && $bp && !$bdp && $ap)
$d='( '.$ad.' ) * ( '.$b.' ) + '.$bd.' * ( '.$a.' )';
else if ($adp && !$bp && $bdp && $ap)
$d='( '.$ad.' ) * '.$b.' + ( '.$bd.' ) * ( '.$a.' )';
else if (!$adp && $bp && $bdp && $ap)
$d=$ad.' * ( '.$b.' ) + ( '.$bd.' ) * ( '.$a.' )';
else if ($adp && $bp && $bdp && $ap)
$d='( '.$ad.' ) * ( '.$b.' ) + ( '.$bd.' ) * ( '.$a.' )';
else
$d=$ad.' * '.$b.' + '.$bd.' * '.$a;
if ($c1 && !$c2)
Pile::empile(
array('('.$a.') * '.$b, false, true, $d, true, true));
else if (!$c1 && $c2)
Pile::empile(
array($a.' * ('.$b.')', false, true, $d, true, true));
else if (!$c1 && !$c2)
Pile::empile(
array($a.' * '.$b, false, true, $d, true, true));
else
Pile::empile(
array('('.$a.') * ('.$b.')', false, true, $d, true, true));
break;
case '/':
list($b, $bp, $bpd, $bd, $bdp, $bdpd)=Pile::depile();
list($a, $ap, $apd, $ad, $adp, $adpd)=Pile::depile();
if ($c2){
if ($adp && !$bp && !$bdp && !$ap)
$d='( ( '.$ad.' ) * '.$b.' - '.$bd.
' * '.$a.' ) / ( ( '.$b.' ) � )';
else if (!$adp && $bp && !$bdp && !$ap)
$d='( '.$ad.' * ( '.$b.' ) - '.$bd.' * '.$a.
' ) / ( ( '.$b.' ) � )';
else if (!$adp && !$bp && $bdp && !$ap)
$d='( '.$ad.' * '.$b.' - ( '.$bd.' ) * '.$a.
' ) / ( ( '.$b.' ) � )';
else if (!$adp && !$bp && !$bdp && !$ap)
$d='( '.$ad.' * '.$b.' - '.$bd.' * ( '.$a.
' ) ) / ( ( '.$b.' ) � )';
else if ($adp && $bp && !$bdp && !$ap)
$d='( ( '.$ad.' ) * ( '.$b.' ) - '.$bd.' * '.
$a.' ) / ( ( '.$b.' ) � )';
else if ($adp && !$bp && $bdp && !$ap)
$d='( ( '.$ad.' ) * '.$b.' - ( '.$bd.' ) * '.
$a.' ) / ( ( '.$b.' ) � )';
else if ($adp && !$bp && !$bdp && $ap)
$d='( ( '.$ad.' ) * '.$b.' - '.$bd.' * ( '.
$a.' ) ) / ( ( '.$b.' ) � )';
else if (!$adp && $bp && $bdp && !$ap)
$d='( '.$ad.' * ( '.$b.' ) - ( '.$bd.' ) * '.
$a.' ) / ( ( '.$b.' ) � )';
else if (!$adp && $bp && !$bdp && $ap)
$d='( '.$ad.' * ( '.$b.' ) - '.$bd.' * ( '.
$a.' ) ) / ( ( '.$b.' ) � )';
else if (!$adp && !$bp && $bdp && $ap)
$d='( '.$ad.' * '.$b.' - ( '.$bd.' ) * ( '.
$a.' ) ) / ( ( '.$b.' ) � )';
else if ($adp && $bp && $bdp && !$ap)
$d='( ( '.$ad.' ) * ( '.$b.' ) - ('.$bd.') * '.
$a.' ) / ( ( '.$b.' ) � )';
else if ($adp && $bp && !$bdp && $ap)
$d='( ( '.$ad.' ) * ( '.$b.' ) - '.$bd.' * ( '.
$a.' ) ) / ( ( '.$b.' ) � )';
else if ($adp && !$bp && $bdp && $ap)
$d='( ( '.$ad.' ) * '.$b.' - ( '.$bd.' ) * ( '.
$a.' ) ) / ( ( '.$b.' ) � )';
else if (!$adp && $bp && $bdp && $ap)
$d='( '.$ad.' * ( '.$b.' ) - ( '.$bd.' ) * ( '.
$a.' ) ) / ( ( '.$b.' ) � )';
else if ($adp && $bp && $bdp && $ap)
$d='( ( '.$ad.' ) * ( '.$b.' ) - ( '.$bd.
' ) * ( '.$a.' ) ) / ( ( '.$b.' ) � )';
else
$d='( '.$ad.' * '.$b.' - '.$bd.' * '.$a.
' ) / ( ( '.$b.' ) � )';
}else{
if ($adp && !$bp && !$bdp && !$ap)
$d='( ( '.$ad.' ) * '.$b.' - '.$bd.' * '.
$a.' ) / ( '.$b.' � )';
else if (!$adp && $bp && !$bdp && !$ap)
$d='( '.$ad.' * ( '.$b.' ) - '.$bd.' * '.
$a.' ) / ( '.$b.' � )';
else if (!$adp && !$bp && $bdp && !$ap)
$d='( '.$ad.' * '.$b.' - ( '.$bd.' ) * '.$a.
' ) / ( '.$b.' � )';
else if (!$adp && !$bp && !$bdp && !$ap)
$d='( '.$ad.' * '.$b.' - '.$bd.' * ( '.$a.
' ) ) / ( '.$b.' � )';
else if ($adp && $bp && !$bdp && !$ap)
$d='( ( '.$ad.' ) * ( '.$b.' ) - '.$bd.' * '.$a.
' ) / ( '.$b.' � )';
else if ($adp && !$bp && $bdp && !$ap)
$d='( ( '.$ad.' ) * '.$b.' - ( '.$bd.' ) * '.
$a.' ) / ( '.$b.' � )';
else if ($adp && !$bp && !$bdp && $ap)
$d='( ( '.$ad.' ) * '.$b.' - '.$bd.' * ( '
.$a.' ) ) / ( '.$b.' � )';
else if (!$adp && $bp && $bdp && !$ap)
$d='( '.$ad.' * ( '.$b.' ) - ( '.$bd.' ) * '.
$a.' ) / ( '.$b.' � )';
else if (!$adp && $bp && !$bdp && $ap)
$d='( '.$ad.' * ( '.$b.' ) - '.$bd.' * ( '.
$a.' ) ) / ( '.$b.' � )';
else if (!$adp && !$bp && $bdp && $ap)
$d='( '.$ad.' * '.$b.' - ( '.$bd.' ) * ( '.
$a.' ) ) / ( '.$b.' � )';
else if ($adp && $bp && $bdp && !$ap)
$d='( ( '.$ad.' ) * ( '.$b.' ) - ('.$bd.') * '.
$a.' ) / ( '.$b.' � )';
else if ($adp && $bp && !$bdp && $ap)
$d='( ( '.$ad.' ) * ( '.$b.' ) - '.$bd.' * ('.
$a.') ) / ( '.$b.' � )';
else if ($adp && !$bp && $bdp && $ap)
$d='( ( '.$ad.' ) * '.$b.' - ( '.$bd.' ) * ( '.
$a.' ) ) / ( '.$b.' � )';
else if (!$adp && $bp && $bdp && $ap)
$d='( '.$ad.' * ( '.$b.' ) - ( '.$bd.' ) * ( '.
$a.' ) ) / ( '.$b.' � )';
else if ($adp && $bp && $bdp && $ap)
$d='( ( '.$ad.' ) * ( '.$b.' ) - ( '.$bd.' ) * ( '
.$a.' ) ) / ( '.$b.' � )';
else
$d='( '.$ad.' * '.$b.' - '.$bd.' * '.$a.' ) / ( '.$b.' � )';
}
if ($apd && !$bpd)
Pile::empile(array('('.$a.') / '.$b, false, true, $d, false, true));
else if (!$apd && $bpd)
Pile::empile(array($a.' / ('.$b.')', false, true, $d, false, true));
else if (!$apd && !$bpd)
Pile::empile(array($a.' / '.$b, false, true, $d, false, true));
else
Pile::empile(
array('('.$a.') / ('.$b.')', false, true, $d, false, true));
break;
case '�':
list($a, $ap, $apd, $ad, $adp, $adpd)=Pile::depile();
if ($ap)
Pile::empile(
array(
'( '.$a.' ) � ', false, false,
'2 ( '.$a.' )', false, false));
else
Pile::empile(
array(
$a.' � ', false, false,
'2 * '.$a.' ', false, false));
break;
case '^':
list($b, $bp, $bpd, $bd, $bdp, $bdpd)=Pile::depile();
list($a, $ap, $apd, $ad, $adp, $adpd)=Pile::depile();
if ($ap && $bp)
Pile::empile(
array(
'( '.$a.' ) ^ ( '.$b.' ) ',
false, false,
'( '.$b.') * ( '.$a.' ) ^ ( '.$b.' - 1 )',
false, false));
else if ($ap)
Pile::empile(
array(
'( '.$a.' ) ^ '.$b, false, false,
$b.' ( '.$a.' ) ^ ( '.$b.' - 1 )', false, false));
else if ($bp)
Pile::empile(
array(
$a.' ^ ( '.$b.' )', false, false,
'( '.$b.') '.$a.' ^ ( '.$b.' - 1 )', false, false));
else
Pile::empile(
array(
$a.' ^ '.$b, false, false,
$b.' * '.$a.' ^ ( '.$b.' - 1 )', false, false));
break;
case 'x':
Pile::empile(array($val, false, false, '1', false, false));
break;
default:
Pile::empile(array($val, false, false, '0', false, false));
break;
}
}
//calcule le temps de calcul....
list($a, $ap, $apd, $ad, $adp, $adpd)=Pile::depile();
list($usec, $sec) = explode(' ', microtime());
$this->times['derive']=(int)(($sec+$usec-$start)*100000);
$this->times['derive']=(float)$this->times['derive']/100;
return $ad;
}
private $tab;
private $str;
private $parse;
private $times;
}
//exemple d'�quations
/*
$a=new RPN('
#Image de produit remarquables
#x 1 + x 1 - * y =
#y b a x * + =
#a b - a b + / a b - a b - * a b + a b - * / = a b - � a � b � - / =
#x a + 4 / fcos � x a + 4 / fsin � + 1 =
#za zb * | za | zb | * =
#y 2.722 x ^ =
#3 1 2 + -
reel c appartient
reel b appartient
reel a appartient
c t b * t � a * + + dt x 0 integrale x infinit+ lim infinit- =
0 a <= ssi , , ,
n i ^ ai *
... +
n 2 ^ a2 * +
n 1 ^ a1 * +
n 0 ^ a0 * +
a0 a1 a2 ... ai 5 n base =
enter
#conversions de 42 dans diff�rentes bases
2 4 2 10 base A 2 2 16 base 0 1 0 1 0 1 0 0 8 2 base = =
enter
#relation de chales
AB vect BC vect + AC vect =
enter
0 1 [] 0 1 ][ includans
enter
0 1 0 1 !includans
enter
a 1 > a 0 > implique
enter
a b > ilexiste a quelquesoit
enter
#la deffinition d'une limite finie en plus l'infini
l b - l b + ][ \f(c) appartient
a c > quelquesoit ,
real a appartient ilexiste ,
real b appartient quelquesoit ,
');
//echo $a->getstring();
//$a->getvalue();
//$a->parse();
$a->getimage(NULL);
//print_r($a->gettimes());
//print_r($a->to_nn());
//echo $a->calc_derive();
?>
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.