Debian Codegraph @

texmf-dist/doc/latex/pas-cours/macro-calculs.tex

raw
1 % environnement "ifactors" : decomposition en produit de facteurs premiers
2
3 \begin{VerbatimOut}{pascours-ifactors.cxx}
4 maple_mode(0);
5 n:=read("n.val");
6 F:=ifactors(n);
7 l:=size(F);
8 T:="";
9 c:=0;
10 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++; };
11 Sortie:=fopen("pascours-ifactors.tex");
12 fprint(Sortie,Unquoted,T);
13 fclose(Sortie);
14 \end{VerbatimOut}
15
16 \newenvironment*{ifactors}
17 {\VerbatimEnvironment\begin{VerbatimOut}{n.val}}
18 {\end{VerbatimOut}
19 \immediate\write18{giac <pascours-ifactors.cxx}
20 \ensuremath{\input{pascours-ifactors.tex}}
21 }
22
23 % environnement "ifactorstable"
24
25 \begin{VerbatimOut}{pascours-ifactorstable.cxx}
26 maple_mode(0);
27 n:=read("n.val");
28 F:=ifactors(n);
29 l:=size(F);
30 for (k:=0;k<l;k:=k+2){ L[k/2]:=F[k]; };
31 T:="\\begin{tabular}{r|l}";
32 k:=0;
33 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]; }; };
34 T:=T+"1 & \\\\\\end{tabular}";
35 Sortie:=fopen("pascours-ifactorstable.tex");
36 fprint(Sortie,Unquoted,T);
37 fclose(Sortie);
38 \end{VerbatimOut}
39
40 \newenvironment*{ifactorstable}
41 {\VerbatimEnvironment\begin{VerbatimOut}{n.val}}
42 {\end{VerbatimOut}
43 \immediate\write18{giac <pascours-ifactorstable.cxx}
44 \input{pascours-ifactorstable.tex}
45 }
46
47 % environnement "fracsimplify"
48
49 \begin{VerbatimOut}{pascours-fracsimplify.cxx}
50 maple_mode(0);
51 L:=read("n.val");
52 n:=L[0];
53 d:=L[1];
54 s:=ratnormal(n/d);
55 T:="\\ensuremath{\\frac{\\numprint{"+n+"}}{\\numprint{"+d+"}}="+latex(s)+"}";
56 Sortie:=fopen("pascours-fracsimplify.tex");
57 fprint(Sortie,Unquoted,T);
58 fclose(Sortie);
59 \end{VerbatimOut}
60
61 \newenvironment*{fracsimplify}
62 {\VerbatimEnvironment\begin{VerbatimOut}{n.val}}
63 {\end{VerbatimOut}
64 \immediate\write18{giac <pascours-fracsimplify.cxx}
65 \input{pascours-fracsimplify.tex}
66 }
67
68 % environnement "exprsimplify"
69
70 \begin{VerbatimOut}{pascours-exprsimplify.cxx}
71 maple_mode(0);
72 expression:=read("n.val");
73 s:=simplifier(expression);
74 T:="\\ensuremath{\\StrSubstitute{"+s+"}{*}{}}";
75 Sortie:=fopen("pascours-exprsimplify.tex");
76 fprint(Sortie,Unquoted,T);
77 fclose(Sortie);
78 \end{VerbatimOut}
79
80 \newenvironment*{exprsimplify}
81 {\VerbatimEnvironment\begin{VerbatimOut}{n.val}}
82 {\end{VerbatimOut}
83 \immediate\write18{giac <pascours-exprsimplify.cxx}
84 \input{pascours-exprsimplify.tex}
85 }
86
87 % Commande "graphsuite"
88
89 \define@cmdkey [PAS] {graphsuite} {xmin}{}
90 \define@cmdkey [PAS] {graphsuite} {xmax}{}
91 \define@cmdkey [PAS] {graphsuite} {ymin}{}
92 \define@cmdkey [PAS] {graphsuite} {ymax}{}
93 \define@cmdkey [PAS] {graphsuite} {gridcolor}{}
94 \define@cmdkey [PAS] {graphsuite} {gridstyle}{}
95 \define@cmdkey [PAS] {graphsuite} {gridxstep}{}
96 \define@cmdkey [PAS] {graphsuite} {gridystep}{}
97 \define@cmdkey [PAS] {graphsuite} {colorfunction}{}
98 \define@cmdkey [PAS] {graphsuite} {function}{}
99 \define@cmdkey [PAS] {graphsuite} {u}{}
100 \define@cmdkey [PAS] {graphsuite} {nmax}{}
101 \define@cmdkey [PAS] {graphsuite} {colorconstruction}{}
102 \define@cmdkey [PAS] {graphsuite} {styleconstruction}{}
103 \define@boolkey[PAS] {graphsuite} {grid}[true]{}
104 \define@boolkey[PAS] {graphsuite} {nograd}[true]{}
105
106 \presetkeys [PAS] {graphsuite} {%
107 gridcolor=gray,%
108 gridstyle=dotted,%
109 gridxstep=1,%
110 gridystep=1,%
111 grid=false,%
112 nograd=false,%
113 colorfunction=black,%
114 colorconstruction=green!50!black,%
115 nmax=5,%
116 styleconstruction=dotted,%
117 }{}
118
119 \newcommand*{\graphsuite}[1][]
120 {
121 \setkeys[PAS]{graphsuite}{#1}
122 \begin{tikzpicture}[>=latex,declare function={f(\x)=\cmdPAS@graphsuite@function;}]
123 \ifPAS@graphsuite@grid
124 \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);
125 \fi
126 \draw[thick,->] (\cmdPAS@graphsuite@xmin,0) -- (\cmdPAS@graphsuite@xmax,0);
127 \draw[thick,->] (0,\cmdPAS@graphsuite@ymin) -- (0,\cmdPAS@graphsuite@ymax);
128 \pgfmathparse{\cmdPAS@graphsuite@xmax-1}\let\xmaxgrad\pgfmathresult
129 \pgfmathparse{\cmdPAS@graphsuite@ymax-1}\let\ymaxgrad\pgfmathresult
130 \foreach \x in {\cmdPAS@graphsuite@xmin,...,\xmaxgrad}
131 {
132 \ifnum\x=0
133 \else
134 \draw[thick] (\x,0.1) -- (\x,-0.1) node[below] {\x};
135 \fi
136 }
137 \foreach \y in {\cmdPAS@graphsuite@ymin,...,\ymaxgrad}
138 {
139 \ifnum\y=0
140 \else
141 \draw[thick] (0.1,\y) -- (-0.1,\y) node[left] {\y};
142 \fi
143 }
144 \clip (\cmdPAS@graphsuite@xmin,\cmdPAS@graphsuite@ymin) rectangle (\cmdPAS@graphsuite@xmax,\cmdPAS@graphsuite@ymax);
145 \ifnum\cmdPAS@graphsuite@xmin<\cmdPAS@graphsuite@ymin
146 \let\min\cmdPAS@graphsuite@xmin
147 \else
148 \let\min\cmdPAS@graphsuite@ymin
149 \fi
150 \ifnum\cmdPAS@graphsuite@xmax<\cmdPAS@graphsuite@ymax
151 \let\max\cmdPAS@graphsuite@ymax
152 \else
153 \let\max\cmdPAS@graphsuite@xmax
154 \fi
155 \draw (\min,\min) -- (\max,\max);
156 \draw[color=\cmdPAS@graphsuite@colorfunction] plot[domain=\cmdPAS@graphsuite@xmin:\cmdPAS@graphsuite@xmax,samples=100] (\x,{f(\x)});
157 % Début de la construction
158 \global\let\x\cmdPAS@graphsuite@u
159 \draw[style=\cmdPAS@graphsuite@styleconstruction,color=\cmdPAS@graphsuite@colorconstruction] (\x,0) -- (\x,{f(\x)});
160 \global\let\xant\x\pgfmathparse{f(\x)}\global\let\x\pgfmathresult
161 \foreach \f in {1,...,\cmdPAS@graphsuite@nmax}
162 {
163 \draw[style=\cmdPAS@graphsuite@styleconstruction,color=\cmdPAS@graphsuite@colorconstruction] (\xant,\x) -- (\x,\x) -- (\x,{f(\x)});
164 \global\let\xant\x\pgfmathparse{f(\x)}\global\let\x\pgfmathresult
165 }
166 \end{tikzpicture}
167 }
168
169 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
170 % %%%%%%Environnement xcas
171
172 \newcommand{\executGiac}[1]{
173 \ifwindows
174 \immediate\write18{giac #1 }
175 \else
176 \immediate\write18{giac <#1 }
177 \fi }
178
179 \begin{VerbatimOut}{xcas.in}
180 maple_mode(0);
181 Sortie:=fopen("xcas.tex");
182 read("xcas.out");
183 Resultat:=cat(latex(ans()));
184 fprint(Sortie,Unquoted,Resultat);
185 fclose(Sortie);
186 \end{VerbatimOut}
187
188
189 \newenvironment{xcas}
190 {\VerbatimEnvironment\begin{VerbatimOut}{xcas.out}}
191 {\end{VerbatimOut}
192 \executGiac{xcas.in}
193 \input{xcas.tex}
194 }