00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef MEATAXE_H_INCLUDED
00011 #define MEATAXE_H_INCLUDED
00012
00013 #include <stdio.h>
00014 #include <stdarg.h>
00015
00016 #define MTX_VERSION "2.4"
00017
00018
00019 extern char *MtxVersion;
00025 #define FM_READ 0x01
00026 #define FM_CREATE 0x02
00027 #define FM_APPEND 0x03
00028 #define FM_TEXT 0x10
00029 #define FM_LIB 0x20
00030 #define FM_NOERROR 0x40
00031
00035 int SysCreateDirectory(const char *name);
00036 int SysGetPid();
00037 void SysInit(void);
00038 void *SysMalloc(size_t nbytes);
00039 FILE *SysFopen(const char *name, int mode);
00040 void SysFree(void *x);
00041 int SysFseek(FILE *f,long pos);
00042 int SysFseekRelative(FILE *file, long distance);
00043 void *SysRealloc(void *buf, size_t nbytes);
00044 int SysReadLong32(FILE *f, long *buf, int n);
00045 #define SysReadLong SysReadLong32
00046 int SysReadLongX(FILE *f, long *buf, int n);
00047 int SysRemoveDirectory(const char *name);
00048 int SysRemoveFile(const char *name);
00049 void SysSetTimeLimit(long nsecs);
00050 long SysTimeUsed(void);
00051 int SysWriteLong32(FILE *f, const long *buf, int n);
00052 #define SysWriteLong SysWriteLong32
00053 int SysWriteLongX(FILE *f, const long *buf, int n);
00054
00055 #define ALLOC(type) ((type *) SysMalloc(sizeof(type)))
00056 #define NALLOC(type,n) ((type *) SysMalloc((size_t)(n) * sizeof(type)))
00057 #define NREALLOC(x,type,n)\
00058 ((type *) SysRealloc(x,(size_t)(n) * sizeof(type)))
00059 #define FREE(x) SysFree(x)
00060
00065
00066
00072
00073
00074
00075 #if ZZZ==0
00076
00077 typedef unsigned char FEL;
00078 typedef FEL *PTR;
00079 #define FF_ZERO ((FEL)0)
00080 #define FF_ONE ((FEL)1)
00081 #define ZZZVERSION 6
00082
00083 #elif ZZZ==1
00084
00085 typedef unsigned short FEL;
00086 typedef unsigned short *PTR;
00087 #define FF_ZERO ((FEL)0xFFFF)
00088 #define FF_ONE ((FEL)0)
00089 #define ZZZVERSION 0x101
00090
00091 #else
00092
00093 #error "ZZZ undefined"
00094
00095 #endif
00096
00097
00098
00099
00100 extern int FfOrder;
00101 extern int FfChar;
00102 extern FEL FfGen;
00103 extern int FfNoc;
00104 extern size_t FfCurrentRowSize;
00105
00106
00107
00108 FEL FfAdd(FEL a, FEL b);
00109 FEL FfSub(FEL a, FEL b);
00110 FEL FfMul(FEL a, FEL b);
00111 FEL FfDiv(FEL a, FEL b);
00112 FEL FfNeg(FEL a);
00113 FEL FfInv(FEL a);
00114
00115 int FfMakeTables(int field);
00116 int FfSetField(int field);
00117 int FfSetNoc(int noc);
00118
00119
00120 void FfAddMulRow(PTR dest, PTR src, FEL f);
00121 PTR FfAddRow(PTR dest, PTR src);
00122 PTR FfAddRowPartial(PTR dest, PTR src, int first, int len);
00123 PTR FfAlloc(int nor);
00124 int FfCmpRows(PTR p1, PTR p2);
00125 void FfCleanRow(PTR row, PTR matrix, int nor, const int *piv);
00126 void FfCleanRow2(PTR row, PTR matrix, int nor, const int *piv, PTR row2);
00127 void FfCleanRowAndRepeat(PTR row, PTR mat, int nor, const int *piv,
00128 PTR row2, PTR mat2);
00129 void FfCopyRow(PTR dest, PTR src);
00130 FEL FfEmbed(FEL a, int subfield);
00131 FEL FfExtract(PTR row, int col);
00132 void FfExtractColumn(PTR mat,int nor,int col,PTR result);
00133 int FfFindPivot(PTR row, FEL *mark);
00134 void FfFree(PTR x);
00135 FEL FfFromInt(int l);
00136 PTR FfGetPtr(PTR base, int row);
00137 void FfInsert(PTR row, int col, FEL mark);
00138 void FfMulRow(PTR row, FEL mark);
00139 FILE *FfReadHeader(const char *name, int *fld, int *nor, int *noc);
00140 int FfReadRows(FILE *f, PTR buf, int n);
00141 FEL FfRestrict(FEL a, int subfield);
00142 size_t FfRowSize(int noc);
00143 FEL FfScalarProduct(PTR a, PTR b);
00144 int FfSeekRow(FILE *f, int pos);
00145 int FfStepPtr(PTR *x);
00146 void FfSwapRows(PTR dest, PTR src);
00147 const char *FfToGap(FEL f);
00148 int FfToInt(FEL f);
00149 size_t FfTrueRowSize(int noc);
00150 FILE *FfWriteHeader(const char *name, int fld, int nor, int noc);
00151 int FfWriteRows(FILE *f, PTR buf, int n);
00152
00153
00154
00155
00156
00157
00158
00159 #if ZZZ==0
00160
00161 extern FEL mtx_tmult[256][256];
00162 extern FEL mtx_tadd[256][256];
00163 extern FEL mtx_taddinv[256], mtx_tmultinv[256];
00164 extern FEL mtx_tffirst[256][2];
00165 extern FEL mtx_textract[8][256];
00166 extern FEL mtx_tnull[8][256];
00167 extern FEL mtx_tinsert[8][256];
00168 extern long mtx_embedord[4];
00169 extern FEL mtx_embed[4][16];
00170 extern FEL mtx_restrict[4][256];
00171
00172 #define FfAdd(a,b) ((FEL)mtx_tadd[(int)(unsigned char)a][(int)(unsigned char)b])
00173 #define FfDiv(a,b) FfMul((a),FfInv(b))
00174 #define FfInv(a) (mtx_tmultinv[(int)(unsigned char)a])
00175 #define FfMul(a,b) ((FEL)mtx_tmult[(int)(unsigned char)a][(int)(unsigned char)b])
00176 #define FfNeg(a) (mtx_taddinv[(int)(unsigned char)a])
00177 #define FfSub(a,b) FfAdd((a),FfNeg(b))
00178
00179 #elif ZZZ==1
00180
00181 #define FfExtract(row,col) ((FEL)((row)[(col)-1]))
00182 #define FfInsert(row,col,mark) ((void)((row)[(col)-1] = mark))
00183
00184
00185 #endif
00186
00189
00190
00191
00192
00193 void FfMapRow(PTR row, PTR matrix, int nor, PTR result);
00194 void FfPermRow(PTR row, const long *perm, PTR result);
00195 int FfSumAndIntersection(PTR wrk1, int *nor1, int *nor2, PTR wrk2, int *piv);
00196
00197
00198
00199
00200
00201
00202 extern int Mtx_IsInitialized;
00203 extern int Mtx_IsX86;
00204 extern int MtxOpt_UseOldWordGenerator;
00205
00206 int MtxInitLibrary();
00207 void MtxCleanupLibrary();
00208
00209
00210
00211
00212
00213
00214 extern char MtxBinDir[];
00215 extern char MtxLibDir[];
00216
00217 #define APP_MAX_ARGS 50
00218
00240 typedef struct
00241 {
00242 const char *Name;
00243 const char *Description;
00244 const char *Help;
00245 } MtxApplicationInfo_t;
00246
00247
00248
00249
00256 typedef struct
00257 {
00258 MtxApplicationInfo_t const *AppInfo;
00259 int OrigArgC;
00260 const char **OrigArgV;
00261 int ArgC;
00262 const char **ArgV;
00263 int OptEnd;
00264 unsigned long IsDone[APP_MAX_ARGS];
00265 const char *OptArg;
00266 int OptInd;
00267 char TempDirName[200];
00268 } MtxApplication_t;
00269
00270
00271 MtxApplication_t *AppAlloc(MtxApplicationInfo_t const *ai, int argc, const char **argv);
00272 int AppFree(MtxApplication_t *a);
00273 int AppGetOption(MtxApplication_t *app, const char *spec);
00274 int AppGetCountedOption(MtxApplication_t *app, const char *spec);
00275 const char *AppGetTextOption(MtxApplication_t *app, const char *spec,
00276 const char *dflt);
00277 int AppGetIntOption(MtxApplication_t *app, const char *spec, int dflt,
00278 int min, int max);
00279 int AppGetArguments(MtxApplication_t *app, int min_argc, int max_argc);
00280 const char *AppCreateTempDir(MtxApplication_t *app);
00281
00282 #define MTX_COMMON_OPTIONS_SYNTAX \
00283 "[<Options>]"
00284
00285 #define MTX_COMMON_OPTIONS_DESCRIPTION \
00286 " -Q ...................... Quiet, no messages\n" \
00287 " -V ...................... Verbose, more messages\n" \
00288 " -T <MaxTime> ............ Set CPU time limit [s]\n"
00289
00290
00291
00292
00293
00294
00295 #define MTX_ERR_NOMEM 1
00296 #define MTX_ERR_GAME_OVER 2
00297 #define MTX_ERR_DIV0 8
00298 #define MTX_ERR_FILEFMT 24
00299 #define MTX_ERR_BADARG 31
00300 #define MTX_ERR_RANGE 33
00301 #define MTX_ERR_NOTECH 34
00302 #define MTX_ERR_NOTSQUARE 35
00303 #define MTX_ERR_INCOMPAT 36
00304 #define MTX_ERR_BADUSAGE 41
00305 #define MTX_ERR_OPTION 42
00306 #define MTX_ERR_NARGS 43
00307 #define MTX_ERR_NOTMATRIX 51
00308 #define MTX_ERR_NOTPERM 53
00309
00310
00311
00312 typedef struct { const char *Name; const char *BaseName; } MtxFileInfo_t;
00313 typedef struct { const MtxFileInfo_t *FileInfo; int LineNo; const char *Text; }
00314 MtxErrorRecord_t;
00315 typedef void MtxErrorHandler_t(const MtxErrorRecord_t *);
00316
00317 #define MTX_DEFINE_FILE_INFO \
00318 static MtxFileInfo_t Mtx_ThisFile = { __FILE__, NULL };
00319
00320 int MtxError(MtxFileInfo_t *fi, int line, const char *text, ...);
00321 MtxErrorHandler_t *MtxSetErrorHandler(MtxErrorHandler_t *h);
00322
00323
00324 #define MTX_ERROR(msg) MtxError(&Mtx_ThisFile,__LINE__,msg)
00325 #define MTX_ERROR1(msg,a1) MtxError(&Mtx_ThisFile,__LINE__,msg,a1)
00326 #define MTX_ERROR2(msg,a1,a2) MtxError(&Mtx_ThisFile,__LINE__,msg,a1,a2)
00327 #define MTX_ERROR3(msg,a1,a2,a3) MtxError(&Mtx_ThisFile,__LINE__,msg,a1,a2,a3)
00328 #define MTX_ERROR4(msg,a1,a2,a3,a4) MtxError(&Mtx_ThisFile,__LINE__,\
00329 msg,a1,a2,a3,a4)
00330 #define MTX_ERROR5(msg,a1,a2,a3,a4,a5) MtxError(&Mtx_ThisFile,__LINE__,\
00331 msg,a1,a2,a3,a4,a5)
00332 #define MTX_ERROR7(msg,a1,a2,a3,a4,a5,a6,a7) MtxError(&Mtx_ThisFile,__LINE__,\
00333 msg,a1,a2,a3,a4,a5,a6,a7)
00334
00335
00336 #define MTX_VERIFY(e) ((void)((e) ||\
00337 MtxError(&Mtx_ThisFile,__LINE__,"Assertion failed: %s",#e)))
00338
00339 #ifdef _DEBUG
00340 #define DEBUG 1
00341 #endif
00342
00343 #ifdef DEBUG
00344 #define MTX_ASSERT(e) MTX_VERIFY(e)
00345 #else
00346 #define MTX_ASSERT(e)
00347 #undef PARANOID
00348 #endif
00349
00350
00351
00352
00353
00354
00355
00356 int MtxFormatMessage(char *buf, int bufsize, const char *msg, va_list al);
00357 int MtxPrintMessage(FILE *f, const char *fmt, ...);
00358
00359 extern int MtxMessageLevel;
00360 #define MSG0 (MtxMessageLevel >= 0)
00361 #define MSG1 (MtxMessageLevel >= 1)
00362 #define MSG2 (MtxMessageLevel >= 2)
00363 #define MSG3 (MtxMessageLevel >= 3)
00364 #define MSG4 (MtxMessageLevel >= 4)
00365 #define MESSAGE(level,args)\
00366 (MtxMessageLevel>=(level) ? ( printf args , fflush(stdout), 1) : 0 )
00367
00368
00369
00370
00371
00372
00373 void MtxRandomInit(unsigned seed);
00374 long int MtxRandom(void);
00375 int MtxRandomInt(int max);
00376 long gcd(long a, long b);
00377 long lcm(long a, long b);
00378
00379
00380
00381
00382
00383
00388 typedef struct
00389 {
00390 FILE *File;
00391 char *LineBuf;
00392 char *GetPtr;
00393 int LineBufSize;
00394 int OutPos;
00395 int LineNo;
00396 } StfData;
00397
00398 int StfClose(StfData *f);
00399 StfData *StfOpen(const char *name, int mode);
00400
00401 int StfPut(StfData *f, const char *text);
00402 int StfPutInt(StfData *f, int value);
00403 int StfPutString(StfData *f, const char *text);
00404 int StfPutVector(StfData *f, int size, const int *value);
00405 int StfBeginEntry(StfData *f, const char *name);
00406 int StfEndEntry(StfData *f);
00407 int StfWriteValue(StfData *f, const char *name, const char *value);
00408 int StfWriteInt(StfData *f, const char *name, int value);
00409 int StfWriteString(StfData *f, const char *name, const char *value);
00410 int StfWriteVector(StfData *f, const char *name, int size, const int *value);
00411
00412 int StfReadLine(StfData *f);
00413 const char *StfGetName(StfData *f);
00414 int StfGetInt(StfData *f, int *buf);
00415 int StfGetString(StfData *f, char *buf, int bufsize);
00416 int StfMatch(StfData *f, const char *pattern);
00417 int StfGetVector(StfData *f, int *bufsize, int *buf);
00418
00419
00420
00421
00422
00423
00424
00425
00429 typedef struct
00430 {
00431 unsigned long Magic;
00432 int Field;
00433 int Nor;
00434 int Noc;
00435 FILE *File;
00436 char *Name;
00437 } MtxFile_t;
00438
00439 int MfIsValid(const MtxFile_t *file);
00440 MtxFile_t *MfOpen(const char *name);
00441 MtxFile_t *MfCreate(const char *name, int field, int nor, int noc);
00442 int MfClose(MtxFile_t *file);
00443 int MfReadLong(MtxFile_t *f, long *buf, int nrows);
00444 int MfReadRows(MtxFile_t *f, PTR buf, int nrows);
00445 int MfWriteLong(MtxFile_t *f, const long *buf, int count);
00446 int MfWriteRows(MtxFile_t *f, PTR buf, int nrows);
00447
00448
00449
00450
00451 typedef struct
00452 {
00453 unsigned long Magic;
00454 int Field;
00455 int Nor;
00456 int Noc;
00457 PTR Data;
00458 size_t RowSize;
00459 int *PivotTable;
00460 } Matrix_t;
00461
00462 Matrix_t *MatAdd(Matrix_t *dest, const Matrix_t *src);
00463 Matrix_t *MatAddMul(Matrix_t *dest, const Matrix_t *src, FEL coeff);
00464 Matrix_t *MatAlloc(int field, int nor, int noc);
00465 int MatClean(Matrix_t *mat, const Matrix_t *sub);
00466 int MatCompare(const Matrix_t *a, const Matrix_t *b);
00467 int MatCopyRegion(Matrix_t *dest, int destrow, int destcol,
00468 const Matrix_t *src, int row1, int col1, int nrows, int ncols);
00469 Matrix_t *MatCut(const Matrix_t *src, int row1, int col1, int nrows, int ncols);
00470 Matrix_t *MatCutRows(const Matrix_t *src, int row1, int nrows);
00471 Matrix_t *MatDup(const Matrix_t *src);
00472 int MatEchelonize(Matrix_t *mat);
00473 int MatFree(Matrix_t *mat);
00474 PTR MatGetPtr(const Matrix_t *mat, int row);
00475 Matrix_t *MatId(int fl, int nor);
00476 Matrix_t *MatInverse(const Matrix_t *src);
00477 int MatIsValid(const Matrix_t *m);
00478 Matrix_t *MatLoad(const char *fn);
00479 Matrix_t *MatMul(Matrix_t *dest, const Matrix_t *src);
00480 Matrix_t *MatMulScalar(Matrix_t *dest, FEL coeff);
00481 long MatNullity(const Matrix_t *mat);
00482 long MatNullity__(Matrix_t *mat);
00483 Matrix_t *MatNullSpace(const Matrix_t *mat);
00484 Matrix_t *MatNullSpace_(Matrix_t *mat, int flags);
00485 Matrix_t *MatNullSpace__(Matrix_t *mat);
00486 int MatOrder(const Matrix_t *mat);
00487 int MatPivotize(Matrix_t *mat);
00488 Matrix_t *MatPower(const Matrix_t *mat, long n);
00489 void MatPrint(const char *name, const Matrix_t *m);
00490 Matrix_t *MatRead(FILE *f);
00491 int MatSave(const Matrix_t *mat, const char *fn);
00492 FEL MatTrace(const Matrix_t *mat);
00493 Matrix_t *MatTransposed(const Matrix_t *src);
00494 int MatWrite(const Matrix_t *mat, FILE *f);
00495
00496
00497 void Mat_DeletePivotTable(Matrix_t *mat);
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514 typedef struct {
00515 long ***tabs;
00516
00517 int *nrvals;
00518 int nrtabs;
00519 } GrExtractionTable_t;
00520
00521 const GrExtractionTable_t *GrGetExtractionTable(int fl,int grrows);
00522
00523
00524 typedef struct
00525 {
00526 unsigned long Magic;
00527 int Field, Nor, Noc;
00528 int GrRows;
00529 int GrBlockSize;
00530 int NumVecs;
00531 PTR PrecalcData;
00532 const GrExtractionTable_t
00533 *ExtrTab;
00534 int MPB;
00535 } GreasedMatrix_t;
00536
00537 void GrMapRow(PTR v,GreasedMatrix_t *M, PTR w);
00538 GreasedMatrix_t *GrMatAlloc(const Matrix_t *m, int gr_rows);
00539 int GrMatFree(GreasedMatrix_t *mat);
00540 int GrMatIsValid(const GreasedMatrix_t *mat);
00541
00542
00543
00544
00545
00546
00547
00549 typedef struct
00550 {
00551 unsigned long Magic;
00552 int Degree;
00553 long *Data;
00554 } Perm_t;
00555
00556
00557 Perm_t *PermAlloc(int deg);
00558 int PermCompare(const Perm_t *a, const Perm_t *b);
00559 Perm_t *PermDup(const Perm_t *src);
00560 int PermFree(Perm_t *p);
00561 Perm_t *PermInverse(const Perm_t *src);
00562 int PermIsValid(const Perm_t *p);
00563 Perm_t *PermLoad(const char *fn);
00564 Perm_t *PermMul(Perm_t *dest, const Perm_t *src);
00565 int PermOrder(const Perm_t *perm);
00566 void PermPrint(const char *name, const Perm_t *perm);
00567 Perm_t *PermPower(const Perm_t *p, int n);
00568 Perm_t *PermRead(FILE *f);
00569 int PermSave(const Perm_t *perm, const char *fn);
00570 int PermWrite(const Perm_t *perm, FILE *f);
00571
00572 void Perm_ConvertOld(long *data, int len);
00573
00574
00575
00576
00577
00578 typedef struct
00579 {
00580 unsigned long Magic;
00581 int Field;
00582 int Degree;
00583 FEL *Data;
00585 int BufSize;
00586 }
00587 Poly_t;
00588
00589
00590 Poly_t *PolAdd(Poly_t *dest, const Poly_t *src);
00591 Poly_t *PolAlloc(int fl, int n);
00592 int PolCompare(const Poly_t *a, const Poly_t *b);
00593 Poly_t *PolDerive(Poly_t *pol);
00594 Poly_t *PolDivMod(Poly_t *a, const Poly_t *b);
00595 Poly_t *PolDup(const Poly_t *p);
00596 int PolFree(Poly_t *p);
00597 Poly_t *PolGcd(const Poly_t *a, const Poly_t *b);
00598 int PolGcdEx(const Poly_t *a, const Poly_t *b, Poly_t **result);
00599 int PolIsValid(const Poly_t *p);
00600 Poly_t *PolMod(Poly_t *a, const Poly_t *b);
00601 void Pol_Normalize(Poly_t *p);
00602 Poly_t *PolLoad(const char *fn);
00603 Poly_t *PolMul(Poly_t *dest, const Poly_t *src);
00604 void PolPrint(char *name, const Poly_t *p);
00605 Poly_t *PolRead(FILE *f);
00606 int PolSave(const Poly_t *pol, const char *fn);
00607 int PolWrite(const Poly_t *p, FILE *f);
00608
00609
00610
00611
00612
00613
00614
00615 typedef struct
00616 {
00617 unsigned long Magic;
00618 int NFactors;
00619 int BufSize;
00620 Poly_t **Factor;
00621 int *Mult;
00622 } FPoly_t;
00623
00624 FPoly_t *FpAlloc();
00625 int FpFree(FPoly_t *x);
00626 int FpIsValid(const FPoly_t *p);
00627 FPoly_t *FpMul(FPoly_t *dest, const FPoly_t *src);
00628 FPoly_t *FpMulP(FPoly_t *dest, const Poly_t *src, int pwr);
00629 int FpPrint(const char *name, const FPoly_t *p);
00630
00631
00632
00633 typedef struct
00634 {
00635 unsigned long Magic;
00636 int Size;
00637 int BufSize;
00638 long Data[1];
00640 } BitString_t;
00642 BitString_t *BsAlloc(int size);
00643 int BsAnd(BitString_t *dest, const BitString_t *src);
00644 int BsClear(BitString_t *bs, int i);
00645 int BsClearAll(BitString_t *bs);
00646 int BsCompare(const BitString_t *a, const BitString_t *b);
00647 BitString_t *BsCopy(BitString_t *dest, const BitString_t *src);
00648 BitString_t *BsDup(const BitString_t *src);
00649 int BsFree(BitString_t *bs);
00650 int BsIntersectionCount(const BitString_t *a, const BitString_t *b);
00651 int BsIsSub(const BitString_t *a, const BitString_t *b);
00652 int BsIsValid(const BitString_t *bs);
00653 int BsMinus(BitString_t *dest, const BitString_t *src);
00654 int BsOr(BitString_t *dest, const BitString_t *src);
00655 void BsPrint(const char *name, const BitString_t *bs);
00656 BitString_t *BsRead(FILE *f);
00657 int BsSet(BitString_t *bs, int i);
00658 int BsTest(const BitString_t *bs, int i);
00659 int BsWrite(BitString_t *bs, FILE *f);
00660
00661 #ifndef DEBUG
00662
00663 #define BS_BPL (sizeof(long) * 8)
00664 #define BsSet(bs,i) ((bs)->Data[(i) / BS_BPL] |= 1L << ((i) % BS_BPL))
00665 #define BsClear(bs,i) ((bs)->Data[(i) / BS_BPL] &= ~(1L << ((i) % BS_BPL)))
00666 #define BsTest(bs,i) (((bs)->Data[(i) / BS_BPL] & (1L << ((i) % BS_BPL))) != 0 ? 1 : 0)
00667
00668 #endif
00669
00670
00671
00672
00673
00674
00675 typedef struct
00676 {
00677 unsigned long Magic;
00678 int Size;
00679 int BufSize;
00680 long *Data;
00681 } Set_t;
00682
00683
00684 Set_t *SetAlloc();
00685 int SetContains(const Set_t *set, long elem);
00686 Set_t *SetDup(const Set_t *s);
00687 int SetFree(Set_t *x);
00688 int SetInsert(Set_t *set, long elem);
00689 int SetIsValid(const Set_t *s);
00690 int SetPrint(char *name, const Set_t *s);
00691
00692
00693
00694
00695
00696
00697 typedef struct
00698 {
00699 unsigned long Magic;
00700 int Nor;
00701 int Noc;
00702 long *Data;
00703 } IntMatrix_t;
00704
00705 IntMatrix_t *ImatAlloc(int nor, int noc);
00706 int ImatFree(IntMatrix_t *mat);
00707 int ImatIsValid(const IntMatrix_t *m);
00708 IntMatrix_t *ImatLoad(const char *fn);
00709 IntMatrix_t *ImatRead(FILE *f);
00710 int ImatSave(const IntMatrix_t *mat, const char *file_name);
00711 int ImatWrite(const IntMatrix_t *mat, FILE *f);
00712
00713
00714
00715
00716
00717
00718 void *XDup(void *a);
00719 int XIsCompatible(void *a, void *b);
00720 void XFree(void *a);
00721 void *XInverse(void *a);
00722 void *XLoad(const char *fn);
00723 void XMul(void *a, void *b);
00724 long XOrder(void *a);
00725 void *XPower(void *a, int n);
00726 int XSave(void *a, const char *fn);
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738 typedef struct
00739 {
00740 Matrix_t *Matrix;
00741 int PivRow;
00742 int PivCol;
00743 FEL PivMark;
00744 } MatrixSetElement_t;
00745
00746
00747 typedef struct {
00748 unsigned long Magic;
00749 int Len;
00750 MatrixSetElement_t *List;
00751 } MatrixSet_t;
00752
00753 MatrixSet_t *MsAlloc();
00754 int MsClean(const MatrixSet_t *set, Matrix_t *mat);
00755 int MsCleanAndAppend(MatrixSet_t *set, Matrix_t *mat);
00756 int MsFree(MatrixSet_t *set);
00757 int MsIsValid(const MatrixSet_t *set);
00758
00759
00760
00761
00762
00763
00764
00765 typedef struct
00766 {
00767 unsigned long Magic;
00768 int NGen;
00769 Matrix_t **Gen;
00770 } MatRep_t;
00771
00772 #define MR_COPY_GENERATORS 0x0001
00773
00774 int MrAddGenerator(MatRep_t *rep, Matrix_t *gen, int flags);
00775 MatRep_t *MrAlloc(int ngen, Matrix_t **gen, int flags);
00776 int MrChangeBasis(MatRep_t *rep, const Matrix_t *trans);
00777 int MrIsValid(const MatRep_t *rep);
00778 int MrFree(MatRep_t *rep);
00779 MatRep_t *MrLoad(const char *basename, int ngen);
00780 int MrSave(const MatRep_t *rep, const char *basename);
00781 MatRep_t *MrTransposed(const MatRep_t *rep);
00782
00783
00784
00785
00786
00787
00788
00789 typedef struct
00790 {
00791 const MatRep_t *Rep;
00792 Matrix_t *Basis[8];
00793 int N2[8];
00794 } WgData_t;
00795
00796
00797 WgData_t *WgAlloc(const MatRep_t *rep);
00798 int WgFree(WgData_t *b);
00799 Matrix_t *WgMakeWord(WgData_t *b, long n);
00800 void WgMakeFingerPrint(WgData_t *b, int fp[6]);
00801 const char *WgSymbolicName(const WgData_t *b, long n);
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811 #define SF_FIRST 0x0001
00812 #define SF_EACH 0x0002
00813 #define SF_MAKE 0x0004
00814 #define SF_SUB 0x0010
00815 #define SF_CYCLIC 0x0020
00816 #define SF_COMBINE 0x0040
00817 #define SF_SEED_MASK 0x000F
00818 #define SF_MODE_MASK 0x00F0
00819 #define SF_STD 0x0100
00820
00821 Matrix_t *QProjection(const Matrix_t *subspace, const Matrix_t *vectors);
00822 Matrix_t *QAction(const Matrix_t *sub, const Matrix_t *gen);
00823 Matrix_t *SAction(const Matrix_t *sub, const Matrix_t *gen);
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836 typedef struct
00837 {
00838 int MaxSubspaceDimension;
00839 int MaxTries;
00840 int Result;
00841 } SpinUpInfo_t;
00842
00843 int SpinUpInfoInit(SpinUpInfo_t *info);
00844 Matrix_t *SpinUp(const Matrix_t *seed, const MatRep_t *rep, int flags,
00845 IntMatrix_t **script, SpinUpInfo_t *info);
00846 Matrix_t *SpinUpWithScript(const Matrix_t *seed, const MatRep_t *rep,
00847 const IntMatrix_t *script);
00848 int Split(Matrix_t *subspace, const MatRep_t *rep,
00849 MatRep_t **sub, MatRep_t **quot);
00850
00851 int ConvertSpinUpScript(IntMatrix_t *script);
00852
00853 Matrix_t *SpinUpWithPermutations(const Matrix_t *seed, int ngen,
00854 const Perm_t **gen, int flags, IntMatrix_t **script, SpinUpInfo_t *info);
00855
00856
00857
00858
00859
00860
00861 long MakeSeedVector(const Matrix_t *basis, long lastno, PTR vec);
00862
00863
00864
00865
00866
00867
00868
00869 Matrix_t *MatInsert_(Matrix_t *mat, const Poly_t *pol);
00870 Matrix_t *MatInsert(const Matrix_t *mat, const Poly_t *pol);
00871 int IsSubspace(const Matrix_t *sub, const Matrix_t *space, int ngen);
00872
00873 Matrix_t *MatTensor(const Matrix_t *m1, const Matrix_t *m2);
00874 int MatrixToVector(const Matrix_t *mat, Matrix_t *vecs, int n);
00875 Matrix_t *VectorToMatrix(Matrix_t *vecs, int n, int noc);
00876 Matrix_t *TensorMap(Matrix_t *vec, const Matrix_t *a, const Matrix_t *b);
00877
00878 int StablePower(const Matrix_t *mat, int *pwr, Matrix_t **ker);
00879 int StablePower_(Matrix_t *mat, int *pwr, Matrix_t **ker);
00880
00881
00882
00883
00884
00885
00886
00887 FPoly_t *Factorization(const Poly_t *pol);
00888
00889
00890
00891
00892
00893
00894
00895 extern long CharPolSeed;
00896 Poly_t *CharPolFactor(const Matrix_t *mat);
00897 FPoly_t *CharPol(const Matrix_t *mat);
00898 Poly_t *MinPolFactor(Matrix_t *mat);
00899 FPoly_t *MinPol(Matrix_t *mat);
00900
00901
00902
00903
00904
00905
00906
00907 #define MAXGEN 20
00908 #define LAT_MAXCF 200
00909 #define MAXCYCL 30000
00910 #define MAXDOTL 90000
00911 #define MAXNSUB 20000
00912
00913 #define LAT_MAXBASENAME 100
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943 typedef struct
00944 {
00945 long dim, num, mult;
00946 long idword;
00947 Poly_t *idpol;
00948 long peakword;
00949 Poly_t *peakpol;
00950 long nmount;
00951 long ndotl;
00952 long spl;
00953 }
00954 CfInfo;
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974 typedef struct
00975
00976 {
00977 char BaseName[LAT_MAXBASENAME];
00978 int Field;
00979 int NGen;
00980 int NCf;
00981 CfInfo Cf[LAT_MAXCF];
00982 int NSocles;
00983 int *Socle;
00984 int NHeads;
00985 int *Head;
00986 } Lat_Info;
00987
00988 int Lat_ReadInfo(Lat_Info *li, const char *basename);
00989 int Lat_WriteInfo(const Lat_Info *li);
00990 const char *Lat_CfName(const Lat_Info *li, int cf);
00991 int Lat_AddHead(Lat_Info *li, int *mult);
00992 int Lat_AddSocle(Lat_Info *li, int *mult);
00993
00994
00995 #define LAT_RG_INVERT 0x0001
00996 #define LAT_RG_TRANSPOSE 0x0002
00997 #define LAT_RG_STD 0x0004
00998
00999 MatRep_t *Lat_ReadCfGens(Lat_Info *info, int cf, int flags);
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017 typedef struct
01018 {
01019 char NameM[LAT_MAXBASENAME];
01020 char NameN[LAT_MAXBASENAME];
01021 int Dim;
01022 int NCf;
01023 int CfIndex[2][LAT_MAXCF];
01024 } TkData_t;
01025
01026 int TK_ReadInfo(TkData_t *tki, const char *name);
01027 int TK_WriteInfo(TkData_t *tki, const char *name);
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042 #define EXIT_OK 0
01043 #define EXIT_ERR 1
01044
01045
01046
01047
01048
01049
01050
01051 int IsIsomorphic(const MatRep_t *rep1, const CfInfo *info1,
01052 const MatRep_t *rep2, Matrix_t **trans, int use_pw);
01053 int MakeEndomorphisms(const MatRep_t *rep, const Matrix_t *nsp,
01054 Matrix_t *endo[]);
01055 Matrix_t *HomogeneousPart(MatRep_t *m, MatRep_t *s, Matrix_t *npw,
01056 const IntMatrix_t *op, int dimends);
01057
01058
01059
01060
01061
01062
01063
01064 typedef struct
01065 {
01066 double PosX, PosY;
01067 unsigned long UserData;
01068 int Layer;
01069 double Score;
01070 int ScoreCount;
01071 } LdNode_t;
01072
01073 typedef struct
01074 {
01075 int NNodes;
01076 LdNode_t *Nodes;
01077 int *IsSub;
01078 int *LayerNo;
01079 int NLayers;
01080 } LdLattice_t;
01081
01082 #define LD_ISSUB(l,i,k) ((l)->IsSub[(i) * (l)->NNodes + (k)])
01083
01084 LdLattice_t *LdAlloc(int num_nodes);
01085 int LdFree(LdLattice_t *l);
01086 int LdAddIncidence(LdLattice_t *lat, int sub, int sup);
01087 int LdSetPositions(LdLattice_t *l);
01088
01089
01090
01091
01092
01093 int ChangeBasisOLD(const Matrix_t *M, int ngen, const Matrix_t *gen[],
01094 Matrix_t *newgen[]);
01095
01096
01097 #endif
01098
01099