summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/pas-cours/latex/macro-calculs.tex
blob: f41f3e81f6083bd858c98e9a5a451ba97b910a83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
% environnement "ifactors" : decomposition en produit de facteurs premiers

\begin{VerbatimOut}{pascours-ifactors.cxx}
maple_mode(0);
n:=read("n.val");
F:=ifactors(n);
l:=size(F);
T:="";
c:=0;
for (k:=0;k<l;k:=k+2) { if c!=0 then T:=T+"\\times"; end_if T:=T+F[k]+"^{"+F[k+1]+"}"; c++; };
Sortie:=fopen("pascours-ifactors.tex");
fprint(Sortie,Unquoted,T);
fclose(Sortie);
\end{VerbatimOut}
  
\newenvironment*{ifactors}
{\VerbatimEnvironment\begin{VerbatimOut}{n.val}}
{\end{VerbatimOut}
\immediate\write18{giac <pascours-ifactors.cxx}
\ensuremath{\input{pascours-ifactors.tex}}
}

% environnement "ifactorstable"

\begin{VerbatimOut}{pascours-ifactorstable.cxx}
maple_mode(0);
n:=read("n.val");
F:=ifactors(n);
l:=size(F);
for (k:=0;k<l;k:=k+2){ L[k/2]:=F[k]; }; 
T:="\\begin{tabular}{r|l}";
k:=0;
while (n!=1) { T:=T+n+"&"; if (irem(n,L[k])==0) { T:=T+L[k]+"\\\\"; n:=n/L[k]; } else { k:=k+1; T:=T+L[k]+"\\\\"; n:=n/L[k]; };  };
T:=T+"1 & \\\\\\end{tabular}";
Sortie:=fopen("pascours-ifactorstable.tex");
fprint(Sortie,Unquoted,T);
fclose(Sortie);
\end{VerbatimOut}
  
\newenvironment*{ifactorstable}
{\VerbatimEnvironment\begin{VerbatimOut}{n.val}}
{\end{VerbatimOut}
\immediate\write18{giac <pascours-ifactorstable.cxx}
\input{pascours-ifactorstable.tex}
}

% environnement "fracsimplify"

\begin{VerbatimOut}{pascours-fracsimplify.cxx}
maple_mode(0);
L:=read("n.val");
n:=L[0];
d:=L[1];
s:=ratnormal(n/d);
T:="\\ensuremath{\\frac{\\numprint{"+n+"}}{\\numprint{"+d+"}}="+latex(s)+"}";
Sortie:=fopen("pascours-fracsimplify.tex");
fprint(Sortie,Unquoted,T);
fclose(Sortie);
\end{VerbatimOut}
  
\newenvironment*{fracsimplify}
{\VerbatimEnvironment\begin{VerbatimOut}{n.val}}
{\end{VerbatimOut}
\immediate\write18{giac <pascours-fracsimplify.cxx}
\input{pascours-fracsimplify.tex}
}

% environnement "exprsimplify"

\begin{VerbatimOut}{pascours-exprsimplify.cxx}
maple_mode(0);
expression:=read("n.val");
s:=simplifier(expression);
T:="\\ensuremath{\\StrSubstitute{"+s+"}{*}{}}";
Sortie:=fopen("pascours-exprsimplify.tex");
fprint(Sortie,Unquoted,T);
fclose(Sortie);
\end{VerbatimOut}
  
\newenvironment*{exprsimplify}
{\VerbatimEnvironment\begin{VerbatimOut}{n.val}}
{\end{VerbatimOut}
\immediate\write18{giac <pascours-exprsimplify.cxx}
\input{pascours-exprsimplify.tex}
}

% Commande "graphsuite"

\define@cmdkey [PAS] {graphsuite} {xmin}{}
\define@cmdkey [PAS] {graphsuite} {xmax}{}
\define@cmdkey [PAS] {graphsuite} {ymin}{}
\define@cmdkey [PAS] {graphsuite} {ymax}{}
\define@cmdkey [PAS] {graphsuite} {gridcolor}{}
\define@cmdkey [PAS] {graphsuite} {gridstyle}{}
\define@cmdkey [PAS] {graphsuite} {gridxstep}{}
\define@cmdkey [PAS] {graphsuite} {gridystep}{}
\define@cmdkey [PAS] {graphsuite} {colorfunction}{}
\define@cmdkey [PAS] {graphsuite} {function}{}
\define@cmdkey [PAS] {graphsuite} {u}{}
\define@cmdkey [PAS] {graphsuite} {nmax}{}
\define@cmdkey [PAS] {graphsuite} {colorconstruction}{}
\define@cmdkey [PAS] {graphsuite} {styleconstruction}{}
\define@boolkey[PAS] {graphsuite} {grid}[true]{} 
\define@boolkey[PAS] {graphsuite} {nograd}[true]{} 

\presetkeys    [PAS] {graphsuite} {%
									gridcolor=gray,%
									gridstyle=dotted,%
									gridxstep=1,%
									gridystep=1,%
									grid=false,%
									nograd=false,%
									colorfunction=black,%
									colorconstruction=green!50!black,%
									nmax=5,%
									styleconstruction=dotted,%
									}{}

\newcommand*{\graphsuite}[1][]
{
	\setkeys[PAS]{graphsuite}{#1}
	\begin{tikzpicture}[>=latex,declare function={f(\x)=\cmdPAS@graphsuite@function;}]
		\ifPAS@graphsuite@grid
			\draw[color=\cmdPAS@graphsuite@gridcolor,style=\cmdPAS@graphsuite@gridstyle] (\cmdPAS@graphsuite@xmin,\cmdPAS@graphsuite@ymin) grid[xstep=\cmdPAS@graphsuite@gridxstep,ystep=\cmdPAS@graphsuite@gridystep] (\cmdPAS@graphsuite@xmax,\cmdPAS@graphsuite@ymax);
		\fi
		\draw[thick,->] (\cmdPAS@graphsuite@xmin,0) -- (\cmdPAS@graphsuite@xmax,0);
		\draw[thick,->] (0,\cmdPAS@graphsuite@ymin) -- (0,\cmdPAS@graphsuite@ymax);
		\pgfmathparse{\cmdPAS@graphsuite@xmax-1}\let\xmaxgrad\pgfmathresult
		\pgfmathparse{\cmdPAS@graphsuite@ymax-1}\let\ymaxgrad\pgfmathresult
		\foreach \x in {\cmdPAS@graphsuite@xmin,...,\xmaxgrad}
		{
			\ifnum\x=0
			\else
			\draw[thick] (\x,0.1) -- (\x,-0.1) node[below] {\x};
			\fi
		}
		\foreach \y in {\cmdPAS@graphsuite@ymin,...,\ymaxgrad}
		{
			\ifnum\y=0
			\else
			\draw[thick] (0.1,\y) -- (-0.1,\y) node[left] {\y};
			\fi
		}
		\clip (\cmdPAS@graphsuite@xmin,\cmdPAS@graphsuite@ymin) rectangle (\cmdPAS@graphsuite@xmax,\cmdPAS@graphsuite@ymax);
		\ifnum\cmdPAS@graphsuite@xmin<\cmdPAS@graphsuite@ymin
			\let\min\cmdPAS@graphsuite@xmin
		\else
			\let\min\cmdPAS@graphsuite@ymin
		\fi
		\ifnum\cmdPAS@graphsuite@xmax<\cmdPAS@graphsuite@ymax
			\let\max\cmdPAS@graphsuite@ymax
		\else
			\let\max\cmdPAS@graphsuite@xmax
		\fi
		\draw (\min,\min) -- (\max,\max);
		\draw[color=\cmdPAS@graphsuite@colorfunction] plot[domain=\cmdPAS@graphsuite@xmin:\cmdPAS@graphsuite@xmax,samples=100] (\x,{f(\x)});
		% Début de la construction
		\global\let\x\cmdPAS@graphsuite@u
		\draw[style=\cmdPAS@graphsuite@styleconstruction,color=\cmdPAS@graphsuite@colorconstruction] (\x,0) -- (\x,{f(\x)});
		\global\let\xant\x\pgfmathparse{f(\x)}\global\let\x\pgfmathresult
		\foreach \f in {1,...,\cmdPAS@graphsuite@nmax}
		{	
			\draw[style=\cmdPAS@graphsuite@styleconstruction,color=\cmdPAS@graphsuite@colorconstruction] (\xant,\x) -- (\x,\x) -- (\x,{f(\x)});
			\global\let\xant\x\pgfmathparse{f(\x)}\global\let\x\pgfmathresult
		}
	\end{tikzpicture}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%Environnement xcas

\newcommand{\executGiac}[1]{
    \ifwindows
    \immediate\write18{giac  #1 }
    \else
    \immediate\write18{giac  <#1 }
    \fi }

    \begin{VerbatimOut}{xcas.in}
    maple_mode(0);
    Sortie:=fopen("xcas.tex");
    read("xcas.out");
    Resultat:=cat(latex(ans()));
    fprint(Sortie,Unquoted,Resultat);
    fclose(Sortie);
    \end{VerbatimOut}
    

    \newenvironment{xcas}
    {\VerbatimEnvironment\begin{VerbatimOut}{xcas.out}}
    {\end{VerbatimOut}
               \executGiac{xcas.in}
               \input{xcas.tex}
    }