source: CGBLisp/src/RCS/xgcd.lisp,v@ 1

Last change on this file since 1 was 1, checked in by Marek Rychlik, 15 years ago

First import of a version circa 1997.

File size: 2.0 KB
Line 
1head 1.4;
2access;
3symbols;
4locks; strict;
5comment @;;; @;
6
7
81.4
9date 2009.01.22.04.09.05; author marek; state Exp;
10branches;
11next 1.3;
12
131.3
14date 2009.01.19.09.32.12; author marek; state Exp;
15branches;
16next 1.2;
17
181.2
19date 2009.01.19.07.53.33; author marek; state Exp;
20branches;
21next 1.1;
22
231.1
24date 2009.01.19.06.41.22; author marek; state Exp;
25branches;
26next ;
27
28
29desc
30@@
31
32
331.4
34log
35@*** empty log message ***
36@
37text
38@#|
39 $Id$
40 *--------------------------------------------------------------------------*
41 | Copyright (C) 1994, Marek Rychlik (e-mail: rychlik@@math.arizona.edu) |
42 | Department of Mathematics, University of Arizona, Tucson, AZ 85721 |
43 | |
44 | Everyone is permitted to copy, distribute and modify the code in this |
45 | directory, as long as this copyright note is preserved verbatim. |
46 *--------------------------------------------------------------------------*
47|#
48
49(defpackage "XGCD"
50 (:use "COMMON-LISP")
51 (:export xgcd))
52(in-package "XGCD")
53
54#+debug(proclaim '(optimize (speed 0) (debug 3)))
55#-debug(proclaim '(optimize (speed 3) (debug 0)))
56
57(defun xgcd (X Y)
58 "Extended gcd; the call
59 (xgcd X Y)
60returns a multiple value list:
61- GCD
62- U,V such that they solve the equation
63 GCD=U*X+V*Y
64- U1,V1 such that
65 LCM=U1*X=V1*Y (up to the sign)."
66 (labels ((xgcd-aux (x0 x1 u0 v0 u1 v1)
67 (cond
68 ((= x1 0) (values x0 u0 v0 u1 v1))
69 (t (multiple-value-bind (n x2) (floor x0 x1)
70 (let ((u2 (- u0 (* n u1)))
71 (v2 (- v0 (* n v1))))
72 (xgcd-aux x1 x2 u1 v1 u2 v2)))))))
73 (xgcd-aux X Y 1 0 0 1)))
74
75
76@
77
78
791.3
80log
81@*** empty log message ***
82@
83text
84@d17 2
85a18 2
86;;(proclaim '(optimize (speed 0) (debug 3)))
87(proclaim '(optimize (speed 3) (debug 0)))
88@
89
90
911.2
92log
93@*** empty log message ***
94@
95text
96@d2 1
97a2 1
98 $Id: xgcd.lisp,v 1.1 2009/01/19 06:41:22 marek Exp marek $
99d17 2
100a18 1
101(proclaim '(optimize (speed 0) (debug 3)))
102@
103
104
1051.1
106log
107@Initial revision
108@
109text
110@d2 1
111a2 1
112 $Id: xgcd.lisp,v 1.3 1997/12/07 05:51:11 marek Exp $
113d17 2
114@
Note: See TracBrowser for help on using the repository browser.