summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pgfplots/oldpgfcompatib/pgfplotsoldpgfsupp_leq.code.tex
blob: 8be16c806a44242b67e4c3703ab6ea3bc0bf5e68 (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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
% ======================================================
% compatibility with PGF 3.0.1a
% ======================================================
%
%%% This file is a copy of some part of PGF/Tikz.
%%% It has been copied here to provide :
%%%  - compatibility with older PGF versions
%%%  - availability of PGF contributions by Christian Feuersaenger
%%%    which are necessary or helpful for pgfplots.
%%%
%%% It contains a couple of patches such that selected changes which
%%% are also part of PGF/TikZ (and can be found in the development
%%% version of PGF/TikZ) are available within pgfplots.
%%%
%%% this file contains solvers which have been written by Christian Feuersaenger (primarily, but not only, for pgfplots)

% Solves a linear equation system of size 2x2 using gauss elimination.
%
% It employs TeX register arithmetics to do so.
% #1: should contain 4 sets of braces with matrix entries, 
% 	{<a11>}{<a12>}
% 	{<a21>}{<a22>}
% 	where each entry should be a number without unit.
% 	It is acceptable if '#1' is a macro which expands to the expected
% 	format.
% #2: should contain 2 sets of braces with the right-hand-side,
% 	{<r1>}{<r2>}
% 	where each entry should be a number without unit.
% 	It is acceptable if '#2' is a macro which expands to the expected
% 	format.
%
% It will assign \pgfmathresult to contain two sets of braces with the
% result.
%
% Example:
% \pgfutilsolvetwotwoleq{
% 	{0.24}{1}
% 	{-0.97}{0}
% }{
% 	{-7}
% 	{18}
% }
% -> yields \pgfmathresult={−18.55618}{−2.54642}
%
% The algorithm employs column pivotisation.
%
% If the matrix is singular, the routine will return {}.
\def\pgfutilsolvetwotwoleq#1#2{%
	\begingroup
		\dimendef\aa=0
		\dimendef\ab=1
		\dimendef\ba=2
		\dimendef\bb=3
		\dimendef\ra=4
		\dimendef\rb=5
		\dimendef\tmpa=6
		\dimendef\tmpb=7
		\edef\pgf@temp{#1}%
		\expandafter\pgfutilsolvetwotwoleq@A\pgf@temp
		\edef\pgf@temp{#2}%
		\expandafter\pgfutilsolvetwotwoleq@r\pgf@temp
		%
		\pgfutilsolvetwotwoleq@ifislarger\aa\ba{%
			% identity "permutation":
			\def\Pa{a}%
			\def\Pb{b}%
		}{%
			% permutation matrix: switch rows!
			\def\Pa{b}%
			\def\Pb{a}%
		}%
		% \pivot := 1/aa
		\tmpa=\csname m\Pa a\endcsname pt %
		\ifdim\tmpa<0pt \tmpa=-\tmpa\fi
		\ifdim\tmpa<0.0001pt
			% singular matrix!
			\let\pgfmathresult=\pgfutil@empty
		\else
			\pgfmathreciprocal@
				{\csname m\Pa a\endcsname}%
			\let\pivot=\pgfmathresult
			%
			% \factor := 1/aa * ba 
			\csname \Pb a\endcsname=\pivot\csname \Pb a\endcsname
			\edef\factor{\expandafter\pgf@sys@tonumber\csname \Pb a\endcsname}%
			%
			% bb -= ba/aa * ab
			\tmpa=-\factor\csname \Pa b\endcsname
			\advance\csname \Pb b\endcsname by\tmpa
			%
			% rb -= ba/aa * ra
			\tmpa=-\factor\csname r\Pa\endcsname
			\advance\csname r\Pb\endcsname by\tmpa
			%
			\tmpa=\csname \Pb b\endcsname%
			\ifdim\tmpa<0pt \tmpa=-\tmpa\fi
			\ifdim\tmpa<0.0001pt
				% singular matrix!
				\let\pgfmathresult=\pgfutil@empty
			\else
				% xb := rb / bb (the modified rb and modified bb!)
				\pgfmathdivide@
					{\expandafter\pgf@sys@tonumber\csname r\Pb\endcsname}
					{\expandafter\pgf@sys@tonumber\csname \Pb b\endcsname}%
				\expandafter\let\csname pgfmathresult\Pb\endcsname=\pgfmathresult
				%
				% ra := ra - xb * ab
				\tmpa=\csname pgfmathresult\Pb\endcsname\csname \Pa b\endcsname
				\advance\csname r\Pa\endcsname by-\tmpa
				%
				% xa := 1/aa * ra  (the modified ra!)
				\tmpa=\pivot\csname r\Pa\endcsname
				\expandafter\edef\csname pgfmathresult\Pa\endcsname{\pgf@sys@tonumber\tmpa}%
				%
				\edef\pgfmathresult{%
					{\csname pgfmathresult\Pa\endcsname}%
					{\csname pgfmathresult\Pb\endcsname}%
				}%
			\fi
		\fi
		\pgfmath@smuggleone\pgfmathresult
	\endgroup
}%

\def\pgfutilsolvetwotwoleq@ifislarger#1#2#3#4{%
	\tmpa=#1
	\ifdim\tmpa<0pt
		\multiply\tmpa by-1
	\fi
	\tmpb=#2
	\ifdim\tmpb<0pt
		\multiply\tmpb by-1
	\fi
	\ifdim\tmpa>\tmpb
		#3%
	\else
		#4%
	\fi
}%

\def\pgfutilsolvetwotwoleqfloat@ifislarger#1#2#3#4{%
	\pgfmathfloatabs@{#1}\let\tmpa=\pgfmathresult
	\pgfmathfloatabs@{#2}\let\tmpb=\pgfmathresult
	\pgfmathfloatlessthan@{\tmpb}{\tmpa}%
	\ifpgfmathfloatcomparison
		#3%
	\else
		#4%
	\fi
}%
\def\pgfutilsolvetwotwoleq@A#1#2#3#4{%
	\def\maa{#1}\def\mab{#2}%
	\def\mba{#3}\def\mbb{#3}%
	\aa=#1pt \ab=#2pt
	\ba=#3pt \bb=#4pt
}
\def\pgfutilsolvetwotwoleq@r#1#2{%
	\ra=#1pt \rb=#2pt
}%
\def\pgfutilsolvetwotwoleqfloat@A#1#2#3#4{%
	\pgfmathfloatparsenumber{#1}\let\maa=\pgfmathresult
	\pgfmathfloatparsenumber{#2}\let\mab=\pgfmathresult
	\pgfmathfloatparsenumber{#3}\let\mba=\pgfmathresult
	\pgfmathfloatparsenumber{#4}\let\mbb=\pgfmathresult
}
\def\pgfutilsolvetwotwoleqfloat@r#1#2{%
	\pgfmathfloatparsenumber{#1}\let\ra=\pgfmathresult
	\pgfmathfloatparsenumber{#2}\let\rb=\pgfmathresult
}%

% Same as \pgfutilsolvetwotwoleq, but using floating point
% arithmetics. The return value is still in fixed point.
\def\pgfutilsolvetwotwoleqfloat#1#2{%
	\begingroup
		\pgfmathfloatcreate{1}{1.0}{-4}% FIXME : use a smaller threshold for FPU?
		\let\thresh=\pgfmathresult
		%
		\edef\pgf@temp{#1}%
		\expandafter\pgfutilsolvetwotwoleqfloat@A\pgf@temp
		\edef\pgf@temp{#2}%
		\expandafter\pgfutilsolvetwotwoleqfloat@r\pgf@temp
		%
		\pgfutilsolvetwotwoleqfloat@ifislarger\maa\mba{%
			% identity "permutation":
			\def\Pa{a}%
			\def\Pb{b}%
		}{%
			% permutation matrix: switch rows!
			\def\Pa{b}%
			\def\Pb{a}%
		}%
		% \pivot := 1/aa
		\expandafter\pgfmathfloatabs@\expandafter{\csname m\Pa a\endcsname}%
		\let\tmpa=\pgfmathresult
		\pgfmathfloatlessthan@{\tmpa}{\thresh}%
		\ifpgfmathfloatcomparison
			% singular matrix!
			\let\pgfmathresult=\pgfutil@empty
		\else
			\expandafter\pgfmathfloatreciprocal@\expandafter{\csname m\Pa a\endcsname}%
			\let\pivot=\pgfmathresult
			%
			% \factor := 1/aa * ba 
			\expandafter\pgfmathfloatmultiply@\expandafter{\csname m\Pb a\endcsname}{\pivot}%
			\let\factor=\pgfmathresult
			\expandafter\let\csname m\Pb a\endcsname=\factor
			%
			% bb -= ba/aa * ab
			\expandafter\pgfmathfloatmultiply@\expandafter{\csname m\Pa b\endcsname}{\factor}%
			\let\tmpa=\pgfmathresult
			\expandafter\pgfmathfloatsubtract@\expandafter{\csname m\Pb b\endcsname}{\tmpa}%
			\expandafter\let\csname m\Pb b\endcsname=\pgfmathresult
			%
			% rb -= ba/aa * ra
			\expandafter\pgfmathfloatmultiply@\expandafter{\csname r\Pa\endcsname}{\factor}%
			\let\tmpa=\pgfmathresult
			\expandafter\pgfmathfloatsubtract@\expandafter{\csname r\Pb\endcsname}{\tmpa}%
			\expandafter\let\csname r\Pb\endcsname=\pgfmathresult
			%
			\expandafter\pgfmathfloatabs@\expandafter{\csname m\Pb b\endcsname}%
			\let\tmpa=\pgfmathresult
			\pgfmathfloatlessthan@{\tmpa}{\thresh}%
			\ifpgfmathfloatcomparison
				% singular matrix!
				\let\pgfmathresult=\pgfutil@empty
			\else
				% xb := rb / bb (the modified rb and modified bb!)
				\edef\pgf@marshal{
					\noexpand\pgfmathfloatdivide@
						{\csname r\Pb\endcsname}
						{\csname m\Pb b\endcsname}%
				}%
				\pgf@marshal
				\expandafter\let\csname pgfmathresult\Pb\endcsname=\pgfmathresult
				\let\tmpa=\pgfmathresult
				%
				% ra := ra - xb * ab
				\expandafter\pgfmathfloatmultiply@\expandafter{\csname m\Pa b\endcsname}{\tmpa}%
				\let\tmpa=\pgfmathresult
				\expandafter\pgfmathfloatsubtract@\expandafter{\csname r\Pa\endcsname}{\tmpa}%
				\expandafter\let\csname r\Pa\endcsname=\pgfmathresult
				%
				% xa := 1/aa * ra  (the modified ra!)
				\expandafter\pgfmathfloatmultiply@\expandafter{\csname r\Pa\endcsname}{\pivot}%
				\expandafter\let\csname pgfmathresult\Pa\endcsname=\pgfmathresult
				%
				\edef\pgfmathresult{%
					{\csname pgfmathresult\Pa\endcsname}%
					{\csname pgfmathresult\Pb\endcsname}%
				}%
				\expandafter\pgfutilsolvetwotwoleqfloat@to@pgf@range\pgfmathresult
			\fi
		\fi
		\pgfmath@smuggleone\pgfmathresult
	\endgroup
}%


\def\pgfutilsolvetwotwoleqfloat@to@pgf@range#1#2{%
	\pgfmathfloatcreate{1}{1.6}{4}\let\pgfutilsolvetwotwoleqfloat@to@pgf@range@max=\pgfmathresult
	\pgfmathfloatabs@{#1}%
	\expandafter\pgfmathfloatlessthan@\expandafter{\pgfmathresult}{\pgfutilsolvetwotwoleqfloat@to@pgf@range@max}%
	\ifpgfmathfloatcomparison
		\pgfmathfloatabs@{#2}%
		\expandafter\pgfmathfloatlessthan@\expandafter{\pgfmathresult}{\pgfutilsolvetwotwoleqfloat@to@pgf@range@max}%
		\ifpgfmathfloatcomparison
			% ok.
			\pgfmathfloattofixed{#1}\let\tmpa=\pgfmathresult
			\pgfmathfloattofixed{#2}%
			\edef\pgfmathresult{{\tmpa}{\pgfmathresult}}%
		\else
			% singular (because PGF cannot represent its result
			\let\pgfmathresult=\pgfutil@empty
		\fi
	\else
		% singular (because PGF cannot represent its result
		\let\pgfmathresult=\pgfutil@empty
	\fi
}%