Debian Codegraph @

texmf-dist/tex/generic/pgfplots/oldpgfcompatib/pgfplotsoldpgfsupp_leq.code.tex

raw
1 % ======================================================
2 % compatibility with PGF 3.0.1a
3 % ======================================================
4 %
5 %%% This file is a copy of some part of PGF/Tikz.
6 %%% It has been copied here to provide :
7 %%% - compatibility with older PGF versions
8 %%% - availability of PGF contributions by Christian Feuersaenger
9 %%% which are necessary or helpful for pgfplots.
10 %%%
11 %%% It contains a couple of patches such that selected changes which
12 %%% are also part of PGF/TikZ (and can be found in the development
13 %%% version of PGF/TikZ) are available within pgfplots.
14 %%%
15 %%% this file contains solvers which have been written by Christian Feuersaenger (primarily, but not only, for pgfplots)
16
17 % Solves a linear equation system of size 2x2 using gauss elimination.
18 %
19 % It employs TeX register arithmetics to do so.
20 % #1: should contain 4 sets of braces with matrix entries,
21 % {<a11>}{<a12>}
22 % {<a21>}{<a22>}
23 % where each entry should be a number without unit.
24 % It is acceptable if '#1' is a macro which expands to the expected
25 % format.
26 % #2: should contain 2 sets of braces with the right-hand-side,
27 % {<r1>}{<r2>}
28 % where each entry should be a number without unit.
29 % It is acceptable if '#2' is a macro which expands to the expected
30 % format.
31 %
32 % It will assign \pgfmathresult to contain two sets of braces with the
33 % result.
34 %
35 % Example:
36 % \pgfutilsolvetwotwoleq{
37 % {0.24}{1}
38 % {-0.97}{0}
39 % }{
40 % {-7}
41 % {18}
42 % }
43 % -> yields \pgfmathresult={−18.55618}{−2.54642}
44 %
45 % The algorithm employs column pivotisation.
46 %
47 % If the matrix is singular, the routine will return {}.
48 \def\pgfutilsolvetwotwoleq#1#2{%
49 \begingroup
50 \dimendef\aa=0
51 \dimendef\ab=1
52 \dimendef\ba=2
53 \dimendef\bb=3
54 \dimendef\ra=4
55 \dimendef\rb=5
56 \dimendef\tmpa=6
57 \dimendef\tmpb=7
58 \edef\pgf@temp{#1}%
59 \expandafter\pgfutilsolvetwotwoleq@A\pgf@temp
60 \edef\pgf@temp{#2}%
61 \expandafter\pgfutilsolvetwotwoleq@r\pgf@temp
62 %
63 \pgfutilsolvetwotwoleq@ifislarger\aa\ba{%
64 % identity "permutation":
65 \def\Pa{a}%
66 \def\Pb{b}%
67 }{%
68 % permutation matrix: switch rows!
69 \def\Pa{b}%
70 \def\Pb{a}%
71 }%
72 % \pivot := 1/aa
73 \tmpa=\csname m\Pa a\endcsname pt %
74 \ifdim\tmpa<0pt \tmpa=-\tmpa\fi
75 \ifdim\tmpa<0.0001pt
76 % singular matrix!
77 \let\pgfmathresult=\pgfutil@empty
78 \else
79 \pgfmathreciprocal@
80 {\csname m\Pa a\endcsname}%
81 \let\pivot=\pgfmathresult
82 %
83 % \factor := 1/aa * ba
84 \csname \Pb a\endcsname=\pivot\csname \Pb a\endcsname
85 \edef\factor{\expandafter\pgf@sys@tonumber\csname \Pb a\endcsname}%
86 %
87 % bb -= ba/aa * ab
88 \tmpa=-\factor\csname \Pa b\endcsname
89 \advance\csname \Pb b\endcsname by\tmpa
90 %
91 % rb -= ba/aa * ra
92 \tmpa=-\factor\csname r\Pa\endcsname
93 \advance\csname r\Pb\endcsname by\tmpa
94 %
95 \tmpa=\csname \Pb b\endcsname%
96 \ifdim\tmpa<0pt \tmpa=-\tmpa\fi
97 \ifdim\tmpa<0.0001pt
98 % singular matrix!
99 \let\pgfmathresult=\pgfutil@empty
100 \else
101 % xb := rb / bb (the modified rb and modified bb!)
102 \pgfmathdivide@
103 {\expandafter\pgf@sys@tonumber\csname r\Pb\endcsname}
104 {\expandafter\pgf@sys@tonumber\csname \Pb b\endcsname}%
105 \expandafter\let\csname pgfmathresult\Pb\endcsname=\pgfmathresult
106 %
107 % ra := ra - xb * ab
108 \tmpa=\csname pgfmathresult\Pb\endcsname\csname \Pa b\endcsname
109 \advance\csname r\Pa\endcsname by-\tmpa
110 %
111 % xa := 1/aa * ra (the modified ra!)
112 \tmpa=\pivot\csname r\Pa\endcsname
113 \expandafter\edef\csname pgfmathresult\Pa\endcsname{\pgf@sys@tonumber\tmpa}%
114 %
115 \edef\pgfmathresult{%
116 {\csname pgfmathresult\Pa\endcsname}%
117 {\csname pgfmathresult\Pb\endcsname}%
118 }%
119 \fi
120 \fi
121 \pgfmath@smuggleone\pgfmathresult
122 \endgroup
123 }%
124
125 \def\pgfutilsolvetwotwoleq@ifislarger#1#2#3#4{%
126 \tmpa=#1
127 \ifdim\tmpa<0pt
128 \multiply\tmpa by-1
129 \fi
130 \tmpb=#2
131 \ifdim\tmpb<0pt
132 \multiply\tmpb by-1
133 \fi
134 \ifdim\tmpa>\tmpb
135 #3%
136 \else
137 #4%
138 \fi
139 }%
140
141 \def\pgfutilsolvetwotwoleqfloat@ifislarger#1#2#3#4{%
142 \pgfmathfloatabs@{#1}\let\tmpa=\pgfmathresult
143 \pgfmathfloatabs@{#2}\let\tmpb=\pgfmathresult
144 \pgfmathfloatlessthan@{\tmpb}{\tmpa}%
145 \ifpgfmathfloatcomparison
146 #3%
147 \else
148 #4%
149 \fi
150 }%
151 \def\pgfutilsolvetwotwoleq@A#1#2#3#4{%
152 \def\maa{#1}\def\mab{#2}%
153 \def\mba{#3}\def\mbb{#3}%
154 \aa=#1pt \ab=#2pt
155 \ba=#3pt \bb=#4pt
156 }
157 \def\pgfutilsolvetwotwoleq@r#1#2{%
158 \ra=#1pt \rb=#2pt
159 }%
160 \def\pgfutilsolvetwotwoleqfloat@A#1#2#3#4{%
161 \pgfmathfloatparsenumber{#1}\let\maa=\pgfmathresult
162 \pgfmathfloatparsenumber{#2}\let\mab=\pgfmathresult
163 \pgfmathfloatparsenumber{#3}\let\mba=\pgfmathresult
164 \pgfmathfloatparsenumber{#4}\let\mbb=\pgfmathresult
165 }
166 \def\pgfutilsolvetwotwoleqfloat@r#1#2{%
167 \pgfmathfloatparsenumber{#1}\let\ra=\pgfmathresult
168 \pgfmathfloatparsenumber{#2}\let\rb=\pgfmathresult
169 }%
170
171 % Same as \pgfutilsolvetwotwoleq, but using floating point
172 % arithmetics. The return value is still in fixed point.
173 \def\pgfutilsolvetwotwoleqfloat#1#2{%
174 \begingroup
175 \pgfmathfloatcreate{1}{1.0}{-4}% FIXME : use a smaller threshold for FPU?
176 \let\thresh=\pgfmathresult
177 %
178 \edef\pgf@temp{#1}%
179 \expandafter\pgfutilsolvetwotwoleqfloat@A\pgf@temp
180 \edef\pgf@temp{#2}%
181 \expandafter\pgfutilsolvetwotwoleqfloat@r\pgf@temp
182 %
183 \pgfutilsolvetwotwoleqfloat@ifislarger\maa\mba{%
184 % identity "permutation":
185 \def\Pa{a}%
186 \def\Pb{b}%
187 }{%
188 % permutation matrix: switch rows!
189 \def\Pa{b}%
190 \def\Pb{a}%
191 }%
192 % \pivot := 1/aa
193 \expandafter\pgfmathfloatabs@\expandafter{\csname m\Pa a\endcsname}%
194 \let\tmpa=\pgfmathresult
195 \pgfmathfloatlessthan@{\tmpa}{\thresh}%
196 \ifpgfmathfloatcomparison
197 % singular matrix!
198 \let\pgfmathresult=\pgfutil@empty
199 \else
200 \expandafter\pgfmathfloatreciprocal@\expandafter{\csname m\Pa a\endcsname}%
201 \let\pivot=\pgfmathresult
202 %
203 % \factor := 1/aa * ba
204 \expandafter\pgfmathfloatmultiply@\expandafter{\csname m\Pb a\endcsname}{\pivot}%
205 \let\factor=\pgfmathresult
206 \expandafter\let\csname m\Pb a\endcsname=\factor
207 %
208 % bb -= ba/aa * ab
209 \expandafter\pgfmathfloatmultiply@\expandafter{\csname m\Pa b\endcsname}{\factor}%
210 \let\tmpa=\pgfmathresult
211 \expandafter\pgfmathfloatsubtract@\expandafter{\csname m\Pb b\endcsname}{\tmpa}%
212 \expandafter\let\csname m\Pb b\endcsname=\pgfmathresult
213 %
214 % rb -= ba/aa * ra
215 \expandafter\pgfmathfloatmultiply@\expandafter{\csname r\Pa\endcsname}{\factor}%
216 \let\tmpa=\pgfmathresult
217 \expandafter\pgfmathfloatsubtract@\expandafter{\csname r\Pb\endcsname}{\tmpa}%
218 \expandafter\let\csname r\Pb\endcsname=\pgfmathresult
219 %
220 \expandafter\pgfmathfloatabs@\expandafter{\csname m\Pb b\endcsname}%
221 \let\tmpa=\pgfmathresult
222 \pgfmathfloatlessthan@{\tmpa}{\thresh}%
223 \ifpgfmathfloatcomparison
224 % singular matrix!
225 \let\pgfmathresult=\pgfutil@empty
226 \else
227 % xb := rb / bb (the modified rb and modified bb!)
228 \edef\pgf@marshal{
229 \noexpand\pgfmathfloatdivide@
230 {\csname r\Pb\endcsname}
231 {\csname m\Pb b\endcsname}%
232 }%
233 \pgf@marshal
234 \expandafter\let\csname pgfmathresult\Pb\endcsname=\pgfmathresult
235 \let\tmpa=\pgfmathresult
236 %
237 % ra := ra - xb * ab
238 \expandafter\pgfmathfloatmultiply@\expandafter{\csname m\Pa b\endcsname}{\tmpa}%
239 \let\tmpa=\pgfmathresult
240 \expandafter\pgfmathfloatsubtract@\expandafter{\csname r\Pa\endcsname}{\tmpa}%
241 \expandafter\let\csname r\Pa\endcsname=\pgfmathresult
242 %
243 % xa := 1/aa * ra (the modified ra!)
244 \expandafter\pgfmathfloatmultiply@\expandafter{\csname r\Pa\endcsname}{\pivot}%
245 \expandafter\let\csname pgfmathresult\Pa\endcsname=\pgfmathresult
246 %
247 \edef\pgfmathresult{%
248 {\csname pgfmathresult\Pa\endcsname}%
249 {\csname pgfmathresult\Pb\endcsname}%
250 }%
251 \expandafter\pgfutilsolvetwotwoleqfloat@to@pgf@range\pgfmathresult
252 \fi
253 \fi
254 \pgfmath@smuggleone\pgfmathresult
255 \endgroup
256 }%
257
258
259 \def\pgfutilsolvetwotwoleqfloat@to@pgf@range#1#2{%
260 \pgfmathfloatcreate{1}{1.6}{4}\let\pgfutilsolvetwotwoleqfloat@to@pgf@range@max=\pgfmathresult
261 \pgfmathfloatabs@{#1}%
262 \expandafter\pgfmathfloatlessthan@\expandafter{\pgfmathresult}{\pgfutilsolvetwotwoleqfloat@to@pgf@range@max}%
263 \ifpgfmathfloatcomparison
264 \pgfmathfloatabs@{#2}%
265 \expandafter\pgfmathfloatlessthan@\expandafter{\pgfmathresult}{\pgfutilsolvetwotwoleqfloat@to@pgf@range@max}%
266 \ifpgfmathfloatcomparison
267 % ok.
268 \pgfmathfloattofixed{#1}\let\tmpa=\pgfmathresult
269 \pgfmathfloattofixed{#2}%
270 \edef\pgfmathresult{{\tmpa}{\pgfmathresult}}%
271 \else
272 % singular (because PGF cannot represent its result
273 \let\pgfmathresult=\pgfutil@empty
274 \fi
275 \else
276 % singular (because PGF cannot represent its result
277 \let\pgfmathresult=\pgfutil@empty
278 \fi
279 }%