Fix possible lisp error when translating entier
[maxima.git] / share / hompack / lisp / stepqs.lisp
blobfb8b59dbe318e74ed66e6ceceb2b35fc9ddb7b5d
1 ;;; Compiled by f2cl version:
2 ;;; ("f2cl1.l,v 95098eb54f13 2013/04/01 00:45:16 toy $"
3 ;;; "f2cl2.l,v 95098eb54f13 2013/04/01 00:45:16 toy $"
4 ;;; "f2cl3.l,v 96616d88fb7e 2008/02/22 22:19:34 rtoy $"
5 ;;; "f2cl4.l,v 96616d88fb7e 2008/02/22 22:19:34 rtoy $"
6 ;;; "f2cl5.l,v 95098eb54f13 2013/04/01 00:45:16 toy $"
7 ;;; "f2cl6.l,v 1d5cbacbb977 2008/08/24 00:56:27 rtoy $"
8 ;;; "macros.l,v 1409c1352feb 2013/03/24 20:44:50 toy $")
10 ;;; Using Lisp CMU Common Lisp snapshot-2020-04 (21D Unicode)
11 ;;;
12 ;;; Options: ((:prune-labels nil) (:auto-save t) (:relaxed-array-decls t)
13 ;;; (:coerce-assigns :as-needed) (:array-type ':array)
14 ;;; (:array-slicing t) (:declare-common nil)
15 ;;; (:float-format double-float))
17 (in-package "HOMPACK")
20 (let ((wrge
21 (make-array 8
22 :element-type 'single-float
23 :initial-contents '(0.8735115f0 0.1531947f0 0.03191815f0
24 3.339946f-11 0.4677788f0 6.970123f-4
25 1.980863f-6 1.122789f-9)))
26 (acof
27 (make-array 12
28 :element-type 'single-float
29 :initial-contents '(0.9043128f0 -0.7075675f0 -4.667383f0
30 -3.677482f0 0.8516099f0 -0.1953119f0
31 -4.830636f0 -0.9770528f0 1.040061f0
32 0.03793395f0 1.042177f0 0.04450706f0)))
33 (failed nil)
34 (i 0)
35 (itcnt 0)
36 (litfh 0)
37 (j 0)
38 (lk 0)
39 (lst 0)
40 (np1 0)
41 (pcgwk 0)
42 (zu 0)
43 (alpha 0.0)
44 (cordis 0.0)
45 (dels 0.0)
46 (fouru 0.0)
47 (gamma 0.0)
48 (hfail 0.0)
49 (htemp 0.0)
50 (idlerr 0.0)
51 (omega 0.0)
52 (one 0.0)
53 (p0 0.0)
54 (p1 0.0)
55 (pp0 0.0)
56 (pp1 0.0)
57 (sigma 0.0)
58 (temp 0.0)
59 (theta 0.0)
60 (twou 0.0)
61 (wkold 0.0)
62 (xstep 0.0)
63 (lambda$ 0.0))
64 (declare (type (array single-float (8)) wrge)
65 (type (array single-float (12)) acof)
66 (type f2cl-lib:logical failed)
67 (type (f2cl-lib:integer4) i itcnt litfh j lk lst np1 pcgwk zu)
68 (type (double-float) alpha cordis dels fouru gamma hfail htemp
69 idlerr omega one p0 p1 pp0 pp1 sigma temp theta
70 twou wkold xstep lambda$))
71 (defun stepqs
72 (n nfe iflag lenqr start crash hold h wk relerr abserr s y yp yold
73 ypold a qr pivot pp rhovec z0 dz t$ work sspar par ipar)
74 (declare (type (array f2cl-lib:integer4 (*)) ipar)
75 (type (array double-float (*)) par)
76 (type (array double-float (*)) sspar)
77 (type (array f2cl-lib:integer4 (*)) pivot)
78 (type (array double-float (*)) work t$ dz z0 rhovec pp qr a ypold
79 yold yp y)
80 (type (double-float) s abserr relerr wk h hold)
81 (type f2cl-lib:logical crash start)
82 (type (f2cl-lib:integer4) lenqr iflag nfe n))
83 (f2cl-lib:with-multi-array-data
84 ((y double-float y-%data% y-%offset%)
85 (yp double-float yp-%data% yp-%offset%)
86 (yold double-float yold-%data% yold-%offset%)
87 (ypold double-float ypold-%data% ypold-%offset%)
88 (a double-float a-%data% a-%offset%)
89 (qr double-float qr-%data% qr-%offset%)
90 (pp double-float pp-%data% pp-%offset%)
91 (rhovec double-float rhovec-%data% rhovec-%offset%)
92 (z0 double-float z0-%data% z0-%offset%)
93 (dz double-float dz-%data% dz-%offset%)
94 (t$ double-float t$-%data% t$-%offset%)
95 (work double-float work-%data% work-%offset%)
96 (pivot f2cl-lib:integer4 pivot-%data% pivot-%offset%)
97 (sspar double-float sspar-%data% sspar-%offset%)
98 (par double-float par-%data% par-%offset%)
99 (ipar f2cl-lib:integer4 ipar-%data% ipar-%offset%))
100 (labels ((dd01 (p0 p1 dels)
101 (f2cl-lib:f2cl/ (+ p1 (- p0)) dels))
102 (dd001 (p0 pp0 p1 dels)
103 (/ (- (dd01 p0 p1 dels) pp0) dels))
104 (dd011 (p0 p1 pp1 dels)
105 (/ (- pp1 (dd01 p0 p1 dels)) dels))
106 (dd0011 (p0 pp0 p1 pp1 dels)
107 (/ (- (dd011 p0 p1 pp1 dels) (dd001 p0 pp0 p1 dels)) dels))
108 (qofs (p0 pp0 p1 pp1 dels s)
113 (+ (* (dd0011 p0 pp0 p1 pp1 dels) (- s dels))
114 (dd001 p0 pp0 p1 dels))
116 pp0)
118 p0)))
119 (declare (ftype (function (double-float double-float double-float)
120 (values double-float &rest t))
121 dd01))
122 (declare (ftype (function
123 (double-float double-float double-float double-float)
124 (values double-float &rest t))
125 dd001))
126 (declare (ftype (function
127 (double-float double-float double-float double-float)
128 (values double-float &rest t))
129 dd011))
130 (declare (ftype (function
131 (double-float double-float double-float double-float
132 double-float)
133 (values double-float &rest t))
134 dd0011))
135 (declare (ftype (function
136 (double-float double-float double-float double-float
137 double-float double-float)
138 (values double-float &rest t))
139 qofs))
140 (prog ()
141 (declare)
142 (setf one (coerce 1.0f0 'double-float))
143 (setf twou (* 2.0f0 (f2cl-lib:d1mach 4)))
144 (setf fouru (+ twou twou))
145 (setf np1 (f2cl-lib:int-add n 1))
146 (setf failed f2cl-lib:%false%)
147 (setf crash f2cl-lib:%true%)
148 (setf litfh 10)
149 (setf pcgwk (f2cl-lib:int-add (f2cl-lib:int-mul 2 n) 3))
150 (setf zu (f2cl-lib:int-add (f2cl-lib:int-mul 3 n) 4))
151 (if (< s 0.0f0) (go end_label))
152 (cond
153 ((< h (* fouru (+ 1.0f0 s)))
154 (setf h (* fouru (+ 1.0f0 s)))
155 (go end_label)))
156 (setf temp (+ (dnrm2 np1 y 1) 1.0f0))
157 (cond
158 ((< (* 0.5f0 (+ (* relerr temp) abserr)) (* twou temp))
159 (cond
160 ((/= relerr 0.0f0)
161 (setf relerr (* fouru (+ 1.0f0 fouru)))
162 (setf temp (coerce 0.0f0 'double-float))
163 (setf abserr (max abserr temp)))
165 (setf abserr (* fouru temp))))
166 (go end_label)))
167 (setf crash f2cl-lib:%false%)
168 (cond
169 (start
170 (setf idlerr (f2cl-lib:fsqrt (f2cl-lib:fsqrt abserr)))
171 (f2cl-lib:fdo (j 1 (f2cl-lib:int-add j 1))
172 ((> j (f2cl-lib:int-add (f2cl-lib:int-mul 2 n) 2))
173 nil)
174 (tagbody
175 (setf (f2cl-lib:fref work-%data%
178 (f2cl-lib:int-add
179 (f2cl-lib:int-mul 8
180 (f2cl-lib:int-add n
182 lenqr)))
183 work-%offset%)
184 (coerce 0.0f0 'double-float))
185 label10))
186 (multiple-value-bind
187 (var-0 var-1 var-2 var-3 var-4 var-5 var-6 var-7 var-8 var-9
188 var-10 var-11 var-12 var-13 var-14)
189 (tangqs y yp ypold a qr pivot pp rhovec work n lenqr iflag nfe
190 par ipar)
191 (declare (ignore var-0 var-1 var-2 var-3 var-4 var-5 var-6 var-7
192 var-8 var-9 var-10 var-13 var-14))
193 (setf iflag var-11)
194 (setf nfe var-12))
195 (if (> iflag 0) (go end_label))))
196 label20
197 (cond
198 (start
199 (dcopy np1 y 1 z0 1)
200 (daxpy np1 h yp 1 z0 1))
202 (f2cl-lib:fdo (i 1 (f2cl-lib:int-add i 1))
203 ((> i np1) nil)
204 (tagbody
205 (setf (f2cl-lib:fref z0-%data%
207 ((1 (f2cl-lib:int-add n 1)))
208 z0-%offset%)
209 (qofs
210 (f2cl-lib:fref yold-%data%
212 ((1 (f2cl-lib:int-add n 1)))
213 yold-%offset%)
214 (f2cl-lib:fref ypold-%data%
216 ((1 (f2cl-lib:int-add n 1)))
217 ypold-%offset%)
218 (f2cl-lib:fref y-%data%
220 ((1 (f2cl-lib:int-add n 1)))
221 y-%offset%)
222 (f2cl-lib:fref yp-%data%
224 ((1 (f2cl-lib:int-add n 1)))
225 yp-%offset%)
226 hold (+ hold h)))
227 label30))))
228 (f2cl-lib:fdo (itcnt 1 (f2cl-lib:int-add itcnt 1))
229 ((> itcnt litfh) nil)
230 (tagbody
231 (f2cl-lib:fdo (j zu (f2cl-lib:int-add j 1))
232 ((> j
233 (f2cl-lib:int-add zu (f2cl-lib:int-mul 2 n) 1))
234 nil)
235 (tagbody
236 (setf (f2cl-lib:fref work-%data%
239 (f2cl-lib:int-add
240 (f2cl-lib:int-mul 8
241 (f2cl-lib:int-add n
243 lenqr)))
244 work-%offset%)
245 (coerce 0.0f0 'double-float))
246 label40))
247 (setf lambda$
248 (f2cl-lib:fref z0-%data%
249 (np1)
250 ((1 (f2cl-lib:int-add n 1)))
251 z0-%offset%))
252 (cond
253 ((= iflag (f2cl-lib:int-sub 2))
254 (rhojs a lambda$ z0 qr lenqr pivot pp par ipar)
255 (multiple-value-bind (var-0 var-1 var-2 var-3 var-4 var-5)
256 (rho a lambda$ z0 rhovec par ipar)
257 (declare (ignore var-0 var-2 var-3 var-4 var-5))
258 (setf lambda$ var-1)))
259 ((= iflag (f2cl-lib:int-sub 1))
260 (fjacs z0 qr lenqr pivot)
261 (dscal lenqr lambda$ qr 1)
262 (setf sigma (- 1.0f0 lambda$))
263 (f2cl-lib:fdo (j 1 (f2cl-lib:int-add j 1))
264 ((> j n) nil)
265 (tagbody
266 (setf (f2cl-lib:fref qr-%data%
267 ((f2cl-lib:fref pivot
270 (f2cl-lib:int-add n
271 2)))))
272 ((1 lenqr))
273 qr-%offset%)
275 (f2cl-lib:fref qr-%data%
276 ((f2cl-lib:fref pivot
279 (f2cl-lib:int-add
281 2)))))
282 ((1 lenqr))
283 qr-%offset%)
284 sigma))
285 label50))
286 (dcopy n z0 1 rhovec 1)
287 (daxpy n (- one) a 1 rhovec 1)
288 (f z0 pp)
289 (dscal n (- one) pp 1)
290 (daxpy n one rhovec 1 pp 1)
291 (daxpy n (- lambda$) pp 1 rhovec 1))
293 (fjacs z0 qr lenqr pivot)
294 (dscal lenqr (- lambda$) qr 1)
295 (f2cl-lib:fdo (j 1 (f2cl-lib:int-add j 1))
296 ((> j n) nil)
297 (tagbody
298 (setf (f2cl-lib:fref qr-%data%
299 ((f2cl-lib:fref pivot
302 (f2cl-lib:int-add n
303 2)))))
304 ((1 lenqr))
305 qr-%offset%)
307 (f2cl-lib:fref qr-%data%
308 ((f2cl-lib:fref pivot
311 (f2cl-lib:int-add
313 2)))))
314 ((1 lenqr))
315 qr-%offset%)
316 1.0f0))
317 label60))
318 (dcopy n z0 1 rhovec 1)
319 (daxpy n (- one) a 1 rhovec 1)
320 (f z0 pp)
321 (daxpy n (- one) a 1 pp 1)
322 (daxpy n (- lambda$) pp 1 rhovec 1)))
323 (setf (f2cl-lib:fref rhovec-%data%
324 (np1)
325 ((1 (f2cl-lib:int-add n 1)))
326 rhovec-%offset%)
327 (coerce 0.0f0 'double-float))
328 (setf nfe (f2cl-lib:int-add nfe 1))
329 (multiple-value-bind
330 (var-0 var-1 var-2 var-3 var-4 var-5 var-6 var-7 var-8
331 var-9)
332 (pcgqs n qr lenqr pivot pp yp rhovec dz
333 (f2cl-lib:array-slice work-%data%
334 double-float
335 (pcgwk)
337 (f2cl-lib:int-add
338 (f2cl-lib:int-mul 8
339 (f2cl-lib:int-add
342 lenqr)))
343 work-%offset%)
344 iflag)
345 (declare (ignore var-0 var-1 var-2 var-3 var-4 var-5 var-6
346 var-7 var-8))
347 (setf iflag var-9))
348 (if (> iflag 0) (go end_label))
349 (daxpy np1 one dz 1 z0 1)
350 (setf xstep (dnrm2 np1 dz 1))
351 (cond
352 ((<= xstep (+ (* relerr (dnrm2 np1 z0 1)) abserr))
353 (go label160)))
354 label140))
355 label150
356 (setf failed f2cl-lib:%true%)
357 (setf hfail h)
358 (cond
359 ((<= h (* fouru (+ 1.0f0 s)))
360 (setf iflag 6)
361 (go end_label))
363 (setf h (* 0.5f0 h))))
364 (go label20)
365 label160
366 (multiple-value-bind
367 (var-0 var-1 var-2 var-3 var-4 var-5 var-6 var-7 var-8 var-9
368 var-10 var-11 var-12 var-13 var-14)
369 (tangqs z0 t$ yp a qr pivot pp rhovec work n lenqr iflag nfe par
370 ipar)
371 (declare (ignore var-0 var-1 var-2 var-3 var-4 var-5 var-6 var-7
372 var-8 var-9 var-10 var-13 var-14))
373 (setf iflag var-11)
374 (setf nfe var-12))
375 (if (> iflag 0) (go end_label))
376 (setf alpha (ddot np1 t$ 1 yp 1))
377 (if (< alpha 0.5f0) (go label150))
378 (setf alpha (acos alpha))
379 (cond
380 (start
381 (dcopy np1 y 1
382 (f2cl-lib:array-slice work-%data%
383 double-float
384 (pcgwk)
386 (f2cl-lib:int-add
387 (f2cl-lib:int-mul 8
388 (f2cl-lib:int-add n
390 lenqr)))
391 work-%offset%)
393 (daxpy np1 h yp 1
394 (f2cl-lib:array-slice work-%data%
395 double-float
396 (pcgwk)
398 (f2cl-lib:int-add
399 (f2cl-lib:int-mul 8
400 (f2cl-lib:int-add n
402 lenqr)))
403 work-%offset%)
406 (f2cl-lib:fdo (i 1 (f2cl-lib:int-add i 1))
407 ((> i np1) nil)
408 (tagbody
409 (setf (f2cl-lib:fref work-%data%
410 ((f2cl-lib:int-sub
411 (f2cl-lib:int-add pcgwk i)
414 (f2cl-lib:int-add
415 (f2cl-lib:int-mul 8
416 (f2cl-lib:int-add n
418 lenqr)))
419 work-%offset%)
420 (qofs
421 (f2cl-lib:fref yold-%data%
423 ((1 (f2cl-lib:int-add n 1)))
424 yold-%offset%)
425 (f2cl-lib:fref ypold-%data%
427 ((1 (f2cl-lib:int-add n 1)))
428 ypold-%offset%)
429 (f2cl-lib:fref y-%data%
431 ((1 (f2cl-lib:int-add n 1)))
432 y-%offset%)
433 (f2cl-lib:fref yp-%data%
435 ((1 (f2cl-lib:int-add n 1)))
436 yp-%offset%)
437 hold (+ hold h)))
438 label170))))
439 (daxpy np1 (- one) z0 1
440 (f2cl-lib:array-slice work-%data%
441 double-float
442 (pcgwk)
444 (f2cl-lib:int-add
445 (f2cl-lib:int-mul 8 (f2cl-lib:int-add n 1))
446 lenqr)))
447 work-%offset%)
449 (setf cordis
450 (dnrm2 np1
451 (f2cl-lib:array-slice work-%data%
452 double-float
453 (pcgwk)
455 (f2cl-lib:int-add
456 (f2cl-lib:int-mul 8
457 (f2cl-lib:int-add
460 lenqr)))
461 work-%offset%)
463 (dcopy np1 y 1 yold 1)
464 (dcopy np1 z0 1 y 1)
465 (dcopy np1 yp 1 ypold 1)
466 (dcopy np1 t$ 1 yp 1)
467 (setf htemp hold)
468 (daxpy np1 (- one) yold 1 z0 1)
469 (setf hold (dnrm2 np1 z0 1))
470 (setf s (+ s hold))
471 (cond
472 ((<= itcnt 1)
473 (setf theta (coerce 8.0f0 'double-float)))
474 ((= itcnt 4)
475 (setf theta (coerce 1.0f0 'double-float)))
477 (setf omega (/ xstep cordis))
478 (cond
479 ((< itcnt 4)
480 (setf lk (f2cl-lib:int-sub (f2cl-lib:int-mul 4 itcnt) 7))
481 (cond
482 ((>= omega (f2cl-lib:fref wrge (lk) ((1 8))))
483 (setf theta (coerce 1.0f0 'double-float)))
484 ((>= omega
485 (f2cl-lib:fref wrge ((f2cl-lib:int-add lk 1)) ((1 8))))
486 (setf theta
487 (+ (f2cl-lib:fref acof (lk) ((1 12)))
489 (f2cl-lib:fref acof
490 ((f2cl-lib:int-add lk 1))
491 ((1 12)))
492 (f2cl-lib:flog omega)))))
493 ((>= omega
494 (f2cl-lib:fref wrge ((f2cl-lib:int-add lk 2)) ((1 8))))
495 (setf theta
497 (f2cl-lib:fref acof
498 ((f2cl-lib:int-add lk 2))
499 ((1 12)))
501 (f2cl-lib:fref acof
502 ((f2cl-lib:int-add lk 3))
503 ((1 12)))
504 (f2cl-lib:flog omega)))))
506 (setf theta (coerce 8.0f0 'double-float)))))
507 ((>= itcnt 7)
508 (setf theta (coerce 0.125f0 'double-float)))
510 (setf lk (f2cl-lib:int-sub (f2cl-lib:int-mul 4 itcnt) 16))
511 (cond
512 ((> omega (f2cl-lib:fref wrge (lk) ((1 8))))
513 (setf lst (f2cl-lib:int-sub (f2cl-lib:int-mul 2 itcnt) 1))
514 (setf theta
515 (+ (f2cl-lib:fref acof (lst) ((1 12)))
517 (f2cl-lib:fref acof
518 ((f2cl-lib:int-add lst 1))
519 ((1 12)))
520 (f2cl-lib:flog omega)))))
522 (setf theta (coerce 0.125f0 'double-float))))))))
523 (setf idlerr (* theta idlerr))
524 (setf idlerr (min (* 0.5f0 hold) idlerr))
525 (setf wkold wk)
526 (setf wk (/ (* 2.0f0 (abs (sin (* 0.5f0 alpha)))) hold))
527 (cond
528 (start
529 (setf gamma wk))
531 (setf gamma (+ wk (* (/ hold (+ hold htemp)) (- wk wkold))))))
532 (setf gamma (max gamma (* 0.01f0 one)))
533 (setf h (f2cl-lib:fsqrt (/ (* 2.0f0 idlerr) gamma)))
534 (setf h
535 (min
536 (max (f2cl-lib:fref sspar-%data% (1) ((1 4)) sspar-%offset%)
538 (f2cl-lib:fref sspar-%data%
540 ((1 4))
541 sspar-%offset%)
542 hold)
544 (* (f2cl-lib:fref sspar-%data% (4) ((1 4)) sspar-%offset%)
545 hold)
546 (f2cl-lib:fref sspar-%data% (2) ((1 4)) sspar-%offset%)))
547 (if failed (setf h (min hfail h)))
548 (setf start f2cl-lib:%false%)
549 (go end_label)
550 end_label
551 (return
552 (values nil
554 iflag
556 start
557 crash
558 hold
561 relerr
562 abserr
579 nil)))))))
581 (in-package #:cl-user)
582 #+#.(cl:if (cl:find-package '#:f2cl) '(and) '(or))
583 (eval-when (:load-toplevel :compile-toplevel :execute)
584 (setf (gethash 'fortran-to-lisp::stepqs
585 fortran-to-lisp::*f2cl-function-info*)
586 (fortran-to-lisp::make-f2cl-finfo
587 :arg-types '((fortran-to-lisp::integer4) (fortran-to-lisp::integer4)
588 (fortran-to-lisp::integer4) (fortran-to-lisp::integer4)
589 fortran-to-lisp::logical fortran-to-lisp::logical
590 (double-float) (double-float) (double-float)
591 (double-float) (double-float) (double-float)
592 (array double-float (*)) (array double-float (*))
593 (array double-float (*)) (array double-float (*))
594 (array double-float (*)) (array double-float (*))
595 (array fortran-to-lisp::integer4 (*))
596 (array double-float (*)) (array double-float (*))
597 (array double-float (*)) (array double-float (*))
598 (array double-float (*)) (array double-float (*))
599 (array double-float (*)) (array double-float (*))
600 (array fortran-to-lisp::integer4 (*)))
601 :return-values '(nil fortran-to-lisp::nfe fortran-to-lisp::iflag nil
602 fortran-to-lisp::start fortran-to-lisp::crash
603 fortran-to-lisp::hold fortran-to-lisp::h
604 fortran-to-lisp::wk fortran-to-lisp::relerr
605 fortran-to-lisp::abserr fortran-to-lisp::s nil nil
606 nil nil nil nil nil nil nil nil nil nil nil nil nil
607 nil)
608 :calls '(fortran-to-lisp::f fortran-to-lisp::fjacs
609 fortran-to-lisp::rhojs fortran-to-lisp::ddot
610 fortran-to-lisp::dscal fortran-to-lisp::daxpy
611 fortran-to-lisp::dcopy fortran-to-lisp::dnrm2
612 fortran-to-lisp::pcgqs fortran-to-lisp::rho
613 fortran-to-lisp::tangqs fortran-to-lisp::d1mach))))