(* ::Package:: *)

(************************************************************************)
(* This file was generated automatically by the Mathematica front end.  *)
(* It contains Initialization cells from a Notebook file, which         *)
(* typically will have the same name as this file except ending in      *)
(* ".nb" instead of ".m".                                               *)
(*                                                                      *)
(* This file is intended to be loaded into the Mathematica kernel using *)
(* the package loading commands Get or Needs.  Doing so is equivalent   *)
(* to using the Evaluate Initialization Cells menu command in the front *)
(* end.                                                                 *)
(*                                                                      *)
(* DO NOT EDIT THIS FILE.  This entire file is regenerated              *)
(* automatically each time the parent Notebook file is saved in the     *)
(* Mathematica front end.  Any changes you make to this file will be    *)
(* overwritten.                                                         *)
(************************************************************************)



(*   par Marcel D\[EAcute]l\[EGrave]ze   *)


 BeginPackage["EtudeFct`"]


restreins::usage=
	"restreins[cond] rajoute la condition cond[x] \[AGrave] l'ensemble de d\[EAcute]finition."


tv::usage=
	"tv[f] donne le tableau de variations de la fonction f."


Ntv::usage=
	"Ntv[f] donne le tableau de variations de la fonction f."


valAbs::usage=
	"valAbs[x] donne la valeur absolue de x."


indicGT::usage=
"indicGT[a][x] est la fonction indicatrice de l'intervalle ]a; \[Infinity][\n(non d\[EAcute]finie en x=a)."


indicLT::usage=
"indicLT[b][x] est la fonction indicatrice de l'intervalle ]-\[Infinity], b[\n(non d\[EAcute]finie en x=b)."


indicGTLT::usage=
"indicGTLT[a,b][x] est la fonction indicatrice de l'intervalle ]a, b[\n(non d\[EAcute]finie en x=a et x=b)."


Begin["`Private`"]


<<Tableaux`


Off[General::"spell1"]


Off[Reduce::"ratnz"]


valAbs[t_]=Sqrt[t^2];


indicGT[a_][t_]=1/2+valAbs[t-a]/(2(t-a));


indicLT[b_][t_]=1/2-valAbs[t-b]/(2(t-b));


indicGTLT[a_,b_][t_]=indicGT[a][t]*indicLT[b][t]


ordonne[e_]:=If[Head[e]===Or,Sort[e,(#1[[2]]<#2[[2]])&],e]


simpl[k_]:=Reduce[Simplify[k],x,Reals]


afficheExpr[k_]:=HoldForm[k]/.{True->"x\[Element]\[DoubleStruckCapitalR]",False->"x\[Element]{}",x->"x"}


restreins[cond_/; Not[Head[cond]===Symbol \[Or] Head[cond]===Function]]:=(Print["L'argument de restreins doit \[EHat]tre une fonction bool\[EAcute]enne, par exemple"];
	Print["cond[x_] = (0\[LessEqual]x\[LessEqual]1);    restreins[cond]"])


restreins[cond_]:=(restriction=cond[x]; afficheExpr[restriction])


afficheSgn[{n_, z_, p_}]:=afficheTableau[{"n\[EAcute]gatif pour","nul pour", "positif pour"},None,{{afficheExpr[simpl[n]]},{afficheExpr[ordonne[simpl[z]]]},{afficheExpr[simpl[p]]}}]


ensDef[fct_]:=Reduce[restriction\[And]((fct[x]<0 )\[Or]( fct[x]>=0)), x, Reals]


zeros[fct_]:=Reduce[restriction\[And](fct[x]==0),x ,Reals]


valX[e_]:=Simplify[
If[Head[e]===Or,Apply[List,e],e]/.Equal[x,vx_]->vx
];


sgn[fct_]:={Reduce[restriction\[And](fct[x]<0),x,Reals],
zeros[fct],
Reduce[restriction\[And](fct[x]>0),x,Reals]}


ensDefD1[fct_]:=(ensDef[fct])\[And](ensDef[fct']);


ensDefD2[fct_]:=(ensDef[fct])\[And](ensDef[fct'])\[And](ensDef[fct''])


zerosD1[fct_]:=Reduce[ensDef[fct]\[And](fct'[x]==0),x,Reals]


zerosD2[fct_]:=Reduce[ensDefD1[fct]\[And](fct''[x]==0),x,Reals]


sgnD1[fct_]:={Reduce[ensDef[fct]\[And](fct'[x]<0),x,Reals],
zerosD1[fct],
Reduce[ensDef[fct]\[And](fct'[x]>0),x,Reals]}


sgnD2[fct_]:={Reduce[ensDefD1[fct]\[And]fct''[x]<0,x,Reals],
zerosD2[fct],
Reduce[ensDefD1[fct]\[And](fct''[x]>0),x,Reals]}


asAffPlus[fct_]:=  Print["Du c\[OHat]t\[EAcute] +\[Infinity], fonction non d\[EAcute]finie."]/;(ensDef[fct]/.x->10^99)=!=True;


asAffPlus[fct_]:=Module[{a, b,t},a=Limit[fct[t]/t,t->\[Infinity]];b=Limit[fct[t]-a*t,t->\[Infinity]];
If[a===0, If[NumericQ[b],Print["Du c\[OHat]t\[EAcute] +\[Infinity], asymptote horizontale y= ",b],Print["Du c\[OHat]t\[EAcute] +\[Infinity], direction asymptotique nulle et f(x)\[LongRightArrow] ",b]],If[NumericQ[a],
If[NumericQ[b],  Print["Du c\[OHat]t\[EAcute] +\[Infinity], asymptote affine y = (",a,")x +(",b,")"],   Print["Du c\[OHat]t\[EAcute] +\[Infinity], pas d'asymptote affine (direction asymptotique = ",a,")"]],  Print["Du c\[OHat]t\[EAcute] +\[Infinity], pas d'asymptote affine."]] ]]


asAffMoins[fct_]:=  Print["Du c\[OHat]t\[EAcute] -\[Infinity], fonction non d\[EAcute]finie."]/;(ensDef[fct]/.x->-10^99)=!=True;


asAffMoins[fct_]:=Module[{a, b,t},a=Limit[fct[t]/t,t->-\[Infinity]];b=Limit[fct[t]-a*t,t->-\[Infinity]];
If[a===0, If[NumericQ[b],Print["Du c\[OHat]t\[EAcute] -\[Infinity], asymptote horizontale y= ",b],Print["Du c\[OHat]t\[EAcute] -\[Infinity], direction asymptotique nulle et f(x)\[LongRightArrow] ",b]],If[NumericQ[a],
If[NumericQ[b],  Print["Du c\[OHat]t\[EAcute] -\[Infinity], asymptote affine y = (",a,")x +(",b,")"],   Print["Du c\[OHat]t\[EAcute] -\[Infinity], pas d'asymptote affine (direction asymptotique = ",a,")"]],  Print["Du c\[OHat]t\[EAcute] -\[Infinity], pas d'asymptote affine."] ]]]


NasAffPlus[fct_]:=  Print["Du c\[OHat]t\[EAcute] +\[Infinity], fonction non d\[EAcute]finie."]/;(ensDef[fct]/.x->10^99)=!=True;


NasAffPlus[fct_]:=Module[{a, b,t},a=Limit[fct[t]/t,t->\[Infinity]];b=Limit[fct[t]-a*t,t->\[Infinity]];
If[a===0, If[NumericQ[b],Print["Du c\[OHat]t\[EAcute] +\[Infinity], asymptote horizontale y= ",N[b]],Print["Du c\[OHat]t\[EAcute] +\[Infinity], direction asymptotique nulle et f(x)\[LongRightArrow] ",N[b]]],If[NumericQ[a],
If[NumericQ[b],  Print["Du c\[OHat]t\[EAcute] +\[Infinity], asymptote affine y = (",N[a],")x +(",N[b],")"],   Print["Du c\[OHat]t\[EAcute] +\[Infinity], pas d'asymptote affine (direction asymptotique = ",N[a],")"]],  Print["Du c\[OHat]t\[EAcute] +\[Infinity], pas d'asymptote affine."] ]]]


NasAffMoins[fct_]:=  Print["Du c\[OHat]t\[EAcute] -\[Infinity], fonction non d\[EAcute]finie."]/;(ensDef[fct]/.x->-10^99)=!=True;


NasAffMoins[fct_]:=Module[{a, b,t},a=Limit[fct[t]/t,t->-\[Infinity]];b=Limit[fct[t]-a*t,t->-\[Infinity]];
If[a===0, If[NumericQ[b],Print["Du c\[OHat]t\[EAcute] -\[Infinity], asymptote horizontale y= ",N[b]],Print["Du c\[OHat]t\[EAcute] -\[Infinity], direction asymptotique nulle et f(x)\[LongRightArrow] ",N[b]]],If[NumericQ[a],
If[NumericQ[b],  Print["Du c\[OHat]t\[EAcute] -\[Infinity], asymptote affine y = (",N[a],")x +(",N[b],")"],
   Print["Du c\[OHat]t\[EAcute] -\[Infinity], pas d'asymptote affine (direction asymptotique = ",N[a],")"]],  Print["Du c\[OHat]t\[EAcute] -\[Infinity], pas d'asymptote affine."] ]]]


extr[fct_]:=Module[{z=zerosD1[fct]},"Aucun"/;z==False]


extr[fct_]:=Module[{z=zerosD1[fct]},{"x\[Element]\[DoubleStruckCapitalR]", "f(\[DoubleStruckCapitalR])"}/;z==True]


extr[fct_]:=Module[{z=valX[zerosD1[fct]]},If[Head[z]===List,
z=Sort[z,LessEqual];Transpose[{z, Simplify[fct[z]]}], 
{{z, fct[z]}}]]


afficheExtr[e_List/;Not[FreeQ[e,x]]\[And]Length[Dimensions[e]]===1]:=Print["Candidat(s) extremum(s) : ",{ e[[1]],"f(%)"}/.x->"x"]


afficheExtr[e_List/;Not[FreeQ[e,x]]\[And]Length[Dimensions[e]]===2]:=Print["Candidat(s) extremum(s) : ",Table[{ e[[k,1]],"f(%)"}/.x->"x",{k,1,Length[e]}]]


afficheExtr[e_]:=Print["Candidat(s) extremum(s) : ", e]


pi[fct_]:=Module[{z=zerosD2[fct]},"Aucun"/;z==False]


pi[fct_]:=Module[{z=zerosD2[fct]},{"x\[Element]\[DoubleStruckCapitalR]", "f(\[DoubleStruckCapitalR])"}/;z==True]


pi[fct_]:=Module[{z=valX[zerosD2[fct]]},If[Head[z]===List,
z=Sort[z,LessEqual];Transpose[{z, Simplify[fct[z]]}],
{ {z,fct[z]}}]]


affichePi[e_List/;Not[FreeQ[e,x]]\[And]Length[Dimensions[e]]===1]:=Print["Candidat(s) point(s) d'inflexion : ",{ e[[1]],"f(%)"}/.x->"x"]


affichePi[e_List/;Not[FreeQ[e,x]]\[And]Length[Dimensions[e]]===2]:=Print["Candidat(s) points(s) d'inflexion: ",Table[{ e[[k,1]],"f(%)"}/.x->"x",{k,1,Length[e]}]]


affichePi[e_]:=Print["Candidat(s) points(s) d'inflexion : ", e]


tv[fct_]:=(
Print["Ensemble de d\[EAcute]finition de f : ",afficheExpr[simpl[ensDef[fct]]]];
		Print["f(x) = ",afficheExpr[Factor[fct[x]]]];
		Print["Signe(f(x)) : ",afficheSgn[sgn[fct]]];
                    Print["f'(x) = ",afficheExpr[Factor[fct'[x]]]];
                  Print["Signe(f'(x)) : ", afficheSgn[sgnD1[fct]]];
                  Print["f''(x) = ",afficheExpr[Factor[fct''[x]]]];
                  Print["Signe(f''(x)) : ",  afficheSgn[sgnD2[fct]]];
                 afficheExtr[extr[fct]];
                  affichePi[ pi[fct]];
                 asAffPlus[fct];
                asAffMoins[fct]);


Ntv[fct_]:=(
Print["Ensemble de d\[EAcute]finition de f : ",afficheExpr[N[simpl[ensDef[fct]]]]];
		Print["f(x) = ",afficheExpr[Factor[N[fct[x]]]]];
		Print["Signe(f(x)) : ",afficheSgn[N[sgn[fct]]]];
                    Print["f'(x) = ",afficheExpr[Factor[N[fct'[x]]]]];
                  Print["Signe(f'(x)) : ", afficheSgn[N[sgnD1[fct]]]];
                  Print["f''(x) = ",afficheExpr[Factor[N[fct''[x]]]]];
                  Print["Signe(f''(x)) : ",  afficheSgn[N[sgnD2[fct]]]];
                  afficheExtr[ N[extr[fct]]];
                 affichePi[ N[pi[fct]]];
                NasAffPlus[fct];
                NasAffMoins[fct]);


On[General::"spell1"]


restriction=True;


End[]


EndPackage[]
