1 | /* emacs edit mode for this file is -*- C++ -*- */ |
---|
2 | /* $Id: bextgcd.m4,v 1.1 1998-01-22 09:47:46 schmidt Exp $ */ |
---|
3 | |
---|
4 | ftestSetNameOfGame( bextgcd, `" |
---|
5 | Usage: bextgcd [<options>] [<envSpec>] <f> <g> [<realResult>] |
---|
6 | calculates the positive greatest common divider c of canonical |
---|
7 | forms f and g and CanonicalForms a and b such that f*a + b*c = c. |
---|
8 | f and g should be from a base domain. |
---|
9 | The results ar printed in the order a - b - c. |
---|
10 | |
---|
11 | If the gcd of f and g is already known, the optional canonical |
---|
12 | form realResult may be used to check the result of the gcd |
---|
13 | computation. |
---|
14 | "'`' ) |
---|
15 | |
---|
16 | //{{{ docu |
---|
17 | // |
---|
18 | // ftestAlgorithm.m4 - ftestAlgorithm test program. |
---|
19 | // |
---|
20 | // To create ftestAlgorithm.cc, run m4 using the ftest_util.m4 library in |
---|
21 | // the following way: |
---|
22 | // |
---|
23 | // m4 ftest_util.m4 ftestAlgorithm.m4 > ftestAlgorithm.cc |
---|
24 | // |
---|
25 | //}}} |
---|
26 | |
---|
27 | ftestPreprocInit(); |
---|
28 | |
---|
29 | ftestGlobalInit(); |
---|
30 | |
---|
31 | // |
---|
32 | // - functions. |
---|
33 | // |
---|
34 | |
---|
35 | //{{{ ftestStatusT bextgcdCheck ( const CanonicalForm & f, const CanonicalForm & g, const CanonicalForm & a, const CanonicalForm & b, const CanonicalForm & result, const CanonicalForm & realResult ) |
---|
36 | //{{{ docu |
---|
37 | // |
---|
38 | // bextgcdCheck() - check result of bextgcd(). |
---|
39 | // |
---|
40 | //}}} |
---|
41 | ftestStatusT |
---|
42 | bextgcdCheck ( const CanonicalForm & f, const CanonicalForm & g, const CanonicalForm & a, const CanonicalForm & b, const CanonicalForm & result, const CanonicalForm & realResult ) |
---|
43 | { |
---|
44 | // use old gcd to compare results |
---|
45 | if ( result != gcd( f, g ) ) { |
---|
46 | ftestError( CheckError, "new and old gcd differ\n" ); |
---|
47 | return Failed; |
---|
48 | } |
---|
49 | |
---|
50 | // if realResult is given, use it to compare with result |
---|
51 | if ( ! realResult.isZero() ) |
---|
52 | if ( realResult == result ) |
---|
53 | return Passed; |
---|
54 | else if ( -realResult == result ) |
---|
55 | return Passed; |
---|
56 | else { |
---|
57 | ftestError( CheckError, "result and real result differ\n" ); |
---|
58 | return Failed; |
---|
59 | } |
---|
60 | |
---|
61 | if ( result.isZero() ) |
---|
62 | if ( f.isZero() && g.isZero() ) |
---|
63 | return Passed; |
---|
64 | else { |
---|
65 | ftestError( CheckError, "result is zero but f and g are not\n" ); |
---|
66 | return Failed; |
---|
67 | } |
---|
68 | |
---|
69 | if ( f*a + g*b != result ) { |
---|
70 | ftestError( CheckError, "f*a + g*b != c\n" ); |
---|
71 | return Failed; |
---|
72 | } |
---|
73 | |
---|
74 | if ( divides( result, f ) && divides( result, g ) ) |
---|
75 | if ( bgcd( f/result, g/result ).isOne() ) |
---|
76 | return Passed; |
---|
77 | else { |
---|
78 | ftestError( CheckError, "result is not greatest common divisor\n" ); |
---|
79 | return Failed; |
---|
80 | } |
---|
81 | else { |
---|
82 | ftestError( CheckError, "result is not a common divisor\n" ); |
---|
83 | return Failed; |
---|
84 | } |
---|
85 | } |
---|
86 | //}}} |
---|
87 | |
---|
88 | // |
---|
89 | // - main program. |
---|
90 | // |
---|
91 | int |
---|
92 | main ( int argc, char ** argv ) |
---|
93 | { |
---|
94 | // initialization |
---|
95 | ftestMainInit(); |
---|
96 | |
---|
97 | // declare input and output variables |
---|
98 | ftestOutVar( CanonicalForm, a ); |
---|
99 | ftestOutVar( CanonicalForm, b ); |
---|
100 | ftestOutVar( CanonicalForm, result ); |
---|
101 | ftestInVar( CanonicalForm, f ); |
---|
102 | ftestInVar( CanonicalForm, g ); |
---|
103 | ftestInVar( CanonicalForm, realResult ); |
---|
104 | |
---|
105 | // process argument list and set environment |
---|
106 | ftestGetOpts(); |
---|
107 | ftestGetEnv(); |
---|
108 | ftestGetInVar( f ); |
---|
109 | ftestGetInVar( g ); |
---|
110 | ftestGetInVar( realResult, 0 ); |
---|
111 | |
---|
112 | // do the test! |
---|
113 | ftestRun( |
---|
114 | result = bextgcd( f, g, a, b ); ); |
---|
115 | |
---|
116 | // do the check |
---|
117 | ftestCheck( |
---|
118 | bextgcdCheck( f, g, a, b, result, realResult ) ); |
---|
119 | |
---|
120 | // print results |
---|
121 | ftestOutput( "a", a, "b", b, "bextgcd(f, g, a, b)", result ); |
---|
122 | |
---|
123 | // clean up |
---|
124 | ftestMainExit(); |
---|
125 | } |
---|