Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
| Download
GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
Project: cocalc-sagemath-dev-slelievre
Views: 418346/****************************************************************************1**2*W dteval.c GAP source Wolfgang Merkwitz3**4**5*Y Copyright (C) 1996, Lehrstuhl D für Mathematik, RWTH Aachen, Germany6*Y (C) 1998 School Math and Comp. Sci., University of St Andrews, Scotland7*Y Copyright (C) 2002 The GAP Group8**9** This file contains the part of the deep thought package which uses the10** deep thought polynomials to multiply in nilpotent groups.11**12** The deep thought polynomials are stored in the list <dtpols> where13** <dtpols>[i] contains the polynomials f_{i1},...,f_{in}.14** <dtpols>[i] is a record consisting of the components <evlist> and15** <evlistvec>. <evlist> is a list of all deep thought monomials occuring16** in the polynomials f_{i1},...,f_{in}. <evlistvec>is a list of vectors17** describing the coefficients of the corresponding deep thought monomials18** in the polynomials f_{i1},..,f_{in}. For example when a pair [j,k]19** occurs in <dtpols>[i].<evlistvec>[l] then the deep thought monomial20** <dtpols>[i].<evlist>[l] occurs in f_{ij} with the coefficient k.21** If the polynomials f_{i1},..,f_{in} are trivial i.e. f_{ii} = x_i + y_i22** and f_{ij} = x_j (j<>i), then <dtpols>[i] is either 1 or 0. <dtpols>[i]23** is 0 if also the polynomials f_{m1},...,f_{mn} for (m > i) are trivial .24*/25#include "system.h"262728#include "gasman.h" /* garbage collector */29#include "objects.h" /* objects */30#include "scanner.h" /* scanner */31#include "bool.h" /* booleans */32#include "calls.h" /* generic call mechanism */33#include "gap.h" /* error handling, initialisation */34#include "gvars.h" /* global variables */35#include "precord.h" /* plain records */36#include "records.h" /* generic records */37#include "integer.h" /* integers */38#include "dt.h" /* deep thought */39#include "objcftl.h" /* from the left collect */4041#include "dteval.h" /* deep though evaluation */4243#define CELM(list, pos) ( INT_INTOBJ( ELM_PLIST(list, pos) ) )4445#include "records.h" /* generic records */46#include "precord.h" /* plain records */4748#include "lists.h" /* generic lists */49#include "listfunc.h" /* functions for generic lists */50#include "plist.h" /* plain lists */51#include "string.h" /* strings */5253#include "code.h" /* coder */54#include "thread.h" /* threads */55#include "tls.h" /* thread-local storage */565758static int evlist, evlistvec;5960extern Obj ShallowCopyPlist( Obj list );616263/****************************************************************************64**6566*F MultGen( <xk>, <gen>, <power>, <dtpols> )67**68** MultGen multiplies the word given by the exponent vector <xk> with69** g_<gen>^<power> by evaluating the deep thought polynomials. The result70** is an ordered word and stored in <xk>.71*/7273/* See below: */74Obj Evaluation( Obj vec, Obj xk, Obj power );7576void MultGen(77Obj xk,78UInt gen,79Obj power,80Obj dtpols )81{82UInt i, j, len, len2;83Obj copy, sum, sum1, sum2, prod, ord, help;8485if ( IS_INTOBJ(power) && INT_INTOBJ(power) == 0 )86return;87sum = SumInt(ELM_PLIST(xk, gen), power);88if ( IS_INTOBJ( ELM_PLIST(dtpols, gen) ) )89{90/* if f_{<gen>1},...,f_{<gen>n} are trivial we only have to add91** <power> to <xk>[ <gen> ]. */92SET_ELM_PLIST(xk, gen, sum);93CHANGED_BAG(xk);94return;95}96copy = ShallowCopyPlist(xk);97/* first add <power> to <xk>[ gen> ]. */98SET_ELM_PLIST(xk, gen, sum);99CHANGED_BAG(xk);100sum = ElmPRec( ELM_PLIST(dtpols, gen), evlist );101sum1 = ElmPRec( ELM_PLIST(dtpols, gen), evlistvec);102len = LEN_PLIST(sum);103for ( i=1;104i <= len;105i++ )106{107/* evaluate the deep thought monomial <sum>[<i>], */108ord = Evaluation( ELM_PLIST( sum, i), copy, power );109if ( !IS_INTOBJ(ord) || INT_INTOBJ(ord) != 0 )110{111help = ELM_PLIST(sum1, i);112len2 = LEN_PLIST(help);113for ( j=1;114j < len2;115j+=2 )116{117/* and add the result multiplicated with the right coefficient118** to <xk>[ <help>[j] ]. */119prod = ProdInt( ord, ELM_PLIST( help, j+1 ) );120sum2 = SumInt(ELM_PLIST( xk, CELM( help,j ) ),121prod);122SET_ELM_PLIST(xk, CELM( help, j ),123sum2 );124CHANGED_BAG(xk);125}126}127}128}129130131132/****************************************************************************133**134*F Evaluation( <vec>, <xk>, <power>)135**136** Evaluation evaluates the deep thought monomial <vec> at the entries in137** <xk> and at <power>.138*/139140Obj Evaluation(141Obj vec,142Obj xk,143Obj power )144{145UInt i, len;146Obj prod, help;147148if ( IS_INTOBJ(power) && INT_INTOBJ(power) > 0 &&149power < ELM_PLIST(vec, 6) )150return INTOBJ_INT(0);151prod = binomial(power, ELM_PLIST(vec, 6) );152len = LEN_PLIST(vec);153for (i=7; i < len; i+=2)154{155help = ELM_PLIST(xk, CELM(vec, i) );156if ( IS_INTOBJ( help ) &&157( INT_INTOBJ(help) == 0 ||158( INT_INTOBJ(help) > 0 && help < ELM_PLIST(vec, i+1) ) ) )159return INTOBJ_INT(0);160prod = ProdInt( prod, binomial( help, ELM_PLIST(vec, i+1) ) );161}162return prod;163}164165166167/****************************************************************************168**169*F Multbound( <xk>, <y>, <anf>, <end>, <dtpols> )170**171** Multbound multiplies the word given by the exponent vector <xk> with172** <y>{ [<anf>..<end>] } by evaluating the deep thought polynomials <dtpols>173** The result is an ordered word and is stored in <xk>.174*/175176void Multbound(177Obj xk,178Obj y,179Int anf,180Int end,181Obj dtpols )182{183int i;184185for (i=anf; i < end; i+=2)186MultGen(xk, CELM( y, i), ELM_PLIST( y, i+1) , dtpols);187}188189190191/****************************************************************************192**193*F Multiplybound( <x>, <y>, <anf>, <end>, <dtpols> )194**195** Multiplybound returns the product of the word <x> with the word196** <y>{ [<anf>..<end>] } by evaluating the deep thought polynomials <dtpols>.197** The result is an ordered word.198*/199200Obj Multiplybound(201Obj x,202Obj y,203Int anf,204Int end,205Obj dtpols )206{207UInt i, j, k, len, help;208Obj xk, res, sum;209210if ( LEN_PLIST( x ) == 0 )211return y;212if ( anf > end )213return x;214/* first deal with the case that <y>{ [<anf>..<end>] } lies in the center215** of the group defined by <dtpols> */216if ( IS_INTOBJ( ELM_PLIST(dtpols, CELM(y, anf) ) ) &&217CELM(dtpols, CELM(y, anf) ) == 0 )218{219res = NEW_PLIST( T_PLIST, 2*LEN_PLIST( dtpols ) );220len = LEN_PLIST(x);221j = 1;222k = anf;223i = 1;224while ( j<len && k<end )225{226if ( ELM_PLIST(x, j) == ELM_PLIST(y, k) )227{228sum = SumInt( ELM_PLIST(x, j+1), ELM_PLIST(y, k+1) );229SET_ELM_PLIST(res, i, ELM_PLIST(x, j) );230SET_ELM_PLIST(res, i+1, sum );231j+=2;232k+=2;233}234else if ( ELM_PLIST(x, j) < ELM_PLIST(y, k) )235{236SET_ELM_PLIST(res, i, ELM_PLIST(x, j) );237SET_ELM_PLIST(res, i+1, ELM_PLIST(x, j+1) );238j+=2;239}240else241{242SET_ELM_PLIST(res, i, ELM_PLIST(y, k) );243SET_ELM_PLIST(res, i+1, ELM_PLIST(y, k+1) );244k+=2;245}246CHANGED_BAG(res);247i+=2;248}249if ( j>=len )250while ( k<end )251{252SET_ELM_PLIST(res, i, ELM_PLIST(y, k) );253SET_ELM_PLIST(res, i+1, ELM_PLIST(y, k+1 ) );254CHANGED_BAG(res);255k+=2;256i+=2;257}258else259while ( j<len )260{261SET_ELM_PLIST(res, i, ELM_PLIST(x, j) );262SET_ELM_PLIST(res, i+1, ELM_PLIST(x, j+1) );263CHANGED_BAG(res);264j+=2;265i+=2;266}267SET_LEN_PLIST(res, i-1);268SHRINK_PLIST(res, i-1);269return res;270}271len = LEN_PLIST(dtpols);272help = LEN_PLIST(x);273/* convert <x> into a exponent vector */274xk = NEW_PLIST( T_PLIST, len );275SET_LEN_PLIST(xk, len );276j = 1;277for (i=1; i <= len; i++)278{279if ( j >= help || i < CELM(x, j) )280SET_ELM_PLIST(xk, i, INTOBJ_INT(0) );281else282{283SET_ELM_PLIST(xk, i, ELM_PLIST(x, j+1) );284j+=2;285}286}287/* let Multbound do the work */288Multbound(xk, y, anf, end, dtpols);289/* finally convert the result back into a word */290res = NEW_PLIST(T_PLIST, 2*len);291j = 0;292for (i=1; i <= len; i++)293{294if ( !( IS_INTOBJ( ELM_PLIST(xk, i) ) && CELM(xk, i) == 0 ) )295{296j+=2;297SET_ELM_PLIST(res, j-1, INTOBJ_INT(i) );298SET_ELM_PLIST(res, j, ELM_PLIST(xk, i) );299}300}301SET_LEN_PLIST(res, j);302SHRINK_PLIST(res, j);303return res;304}305306307308/****************************************************************************309**310*F Power( <x>, <n>, <dtpols> )311**312** Power returns the <n>-th power of the word <x> as ordered word by313** evaluating the deep thought polynomials <dtpols>.314*/315316/* See below: */317Obj Solution( Obj x, Obj y, Obj dtpols );318319Obj Power(320Obj x,321Obj n,322Obj dtpols )323{324Obj res, m, y;325UInt i,len;326327if ( LEN_PLIST(x) == 0 )328return x;329/* first deal with the case that <x> lies in the centre of the group330** defined by <dtpols> */331if ( IS_INTOBJ( ELM_PLIST( dtpols, CELM(x, 1) ) ) &&332CELM( dtpols, CELM(x, 1) ) == 0 )333{334len = LEN_PLIST(x);335res = NEW_PLIST( T_PLIST, len );336SET_LEN_PLIST(res, len );337for (i=2;i<=len;i+=2)338{339m = ProdInt( ELM_PLIST(x, i), n );340SET_ELM_PLIST(res, i, m );341SET_ELM_PLIST(res, i-1, ELM_PLIST(x, i-1) );342CHANGED_BAG( res );343}344return res;345}346/* if <n> is a negative integer compute ( <x>^-1 )^(-<n>) */347if ( TNUM_OBJ(n) == T_INTNEG || INT_INTOBJ(n) < 0 )348{349y = NEW_PLIST( T_PLIST, 0);350SET_LEN_PLIST(y, 0);351return Power( Solution(x, y, dtpols),352ProdInt(INTOBJ_INT(-1), n), dtpols );353}354res = NEW_PLIST(T_PLIST, 2);355SET_LEN_PLIST(res, 0);356if ( IS_INTOBJ(n) && INT_INTOBJ(n) == 0 )357return res;358/* now use the russian peasant rule to get the result */359while( LtInt(INTOBJ_INT(0), n) )360{361len = LEN_PLIST(x);362if ( ModInt(n, INTOBJ_INT(2) ) == INTOBJ_INT(1) )363res = Multiplybound(res, x, 1, len, dtpols);364if ( LtInt(INTOBJ_INT(1), n) )365x = Multiplybound(x, x, 1, len, dtpols);366n = QuoInt(n, INTOBJ_INT(2) );367}368return res;369}370371372373/****************************************************************************374**375*F Solution( <x>, <y>, <dtpols> )376**377** Solution returns a solution for the equation <x>*a = <y> by evaluating378** the deep thought polynomials <dtpols>. The result is an ordered word.379*/380381Obj Solution( Obj x,382Obj y,383Obj dtpols )384385{386Obj xk, res, m;387UInt i,j,k, len1, len2;388389if ( LEN_PLIST(x) == 0)390return y;391/* first deal with the case that <x> and <y> ly in the centre of the392** group defined by <dtpols>. */393if ( IS_INTOBJ( ELM_PLIST( dtpols, CELM(x, 1) ) ) &&394CELM( dtpols, CELM(x, 1) ) == 0 &&395( LEN_PLIST(y) == 0 ||396( IS_INTOBJ( ELM_PLIST( dtpols, CELM(y, 1) ) ) &&397CELM( dtpols, CELM(y, 1) ) == 0 ) ) )398{399res = NEW_PLIST( T_PLIST, 2*LEN_PLIST( dtpols ) );400i = 1;401j = 1;402k = 1;403len1 = LEN_PLIST(x);404len2 = LEN_PLIST(y);405while ( j < len1 && k < len2 )406{407if ( ELM_PLIST(x, j) == ELM_PLIST(y, k) )408{409m = DiffInt( ELM_PLIST(y, k+1), ELM_PLIST(x, j+1) );410SET_ELM_PLIST( res, i, ELM_PLIST(x, j) );411SET_ELM_PLIST( res, i+1, m );412CHANGED_BAG( res );413i+=2; j+=2; k+=2;414}415else if ( CELM(x, j) < CELM(y, k) )416{417m = ProdInt( INTOBJ_INT(-1), ELM_PLIST(x, j+1) );418SET_ELM_PLIST( res, i, ELM_PLIST(x, j) );419SET_ELM_PLIST( res, i+1, m );420CHANGED_BAG( res );421i+=2; j+=2;422}423else424{425SET_ELM_PLIST( res, i, ELM_PLIST(y, k) );426SET_ELM_PLIST( res, i+1, ELM_PLIST(y, k+1) );427CHANGED_BAG( res );428i+=2; k+=2;429}430}431if ( j < len1 )432while( j < len1 )433{434m = ProdInt( INTOBJ_INT(-1), ELM_PLIST( x, j+1 ) );435SET_ELM_PLIST( res, i, ELM_PLIST(x, j) );436SET_ELM_PLIST( res, i+1, m );437CHANGED_BAG( res );438i+=2; j+=2;439}440else441while( k < len2 )442{443SET_ELM_PLIST( res, i ,ELM_PLIST(y, k) );444SET_ELM_PLIST( res, i+1, ELM_PLIST(y, k+1) );445CHANGED_BAG( res );446i+=2; k+=2;447}448SET_LEN_PLIST( res, i-1 );449SHRINK_PLIST( res, i-1);450return res;451}452/* convert <x> into an exponent vector */453xk = NEW_PLIST( T_PLIST, LEN_PLIST(dtpols) );454SET_LEN_PLIST(xk, LEN_PLIST(dtpols) );455j = 1;456for (i=1; i <= LEN_PLIST(dtpols); i++)457{458if ( j >= LEN_PLIST(x) || i < CELM(x, j) )459SET_ELM_PLIST(xk, i, INTOBJ_INT(0) );460else461{462SET_ELM_PLIST(xk, i, ELM_PLIST(x, j+1) );463j+=2;464}465}466res = NEW_PLIST( T_PLIST, 2*LEN_PLIST( xk ) );467j = 1;468k = 1;469len1 = LEN_PLIST(xk);470len2 = LEN_PLIST(y);471for (i=1; i <= len1; i++)472{473if ( k < len2 && i == CELM(y, k) )474{475if ( !EqInt( ELM_PLIST(xk, i), ELM_PLIST(y, k+1) ) )476{477m = DiffInt( ELM_PLIST(y, k+1), ELM_PLIST(xk, i) );478SET_ELM_PLIST(res, j, INTOBJ_INT(i) );479SET_ELM_PLIST(res, j+1, m);480CHANGED_BAG(res);481MultGen(xk, i, m, dtpols);482j+=2;483}484k+=2;485}486else if ( !IS_INTOBJ( ELM_PLIST(xk, i) ) || CELM( xk, i ) != 0 )487{488m = ProdInt( INTOBJ_INT(-1), ELM_PLIST(xk, i) );489SET_ELM_PLIST( res, j, INTOBJ_INT(i) );490SET_ELM_PLIST( res, j+1, m );491CHANGED_BAG(res);492MultGen(xk, i, m, dtpols);493j+=2;494}495}496SET_LEN_PLIST(res, j-1);497SHRINK_PLIST(res, j-1);498return res;499}500501502503/****************************************************************************504**505*F Commutator( <x>, <y>, <dtpols> )506**507** Commutator returns the commutator of the word <x> and <y> by evaluating508** the deep thought polynomials <dtpols>.509*/510511Obj Commutator( Obj x,512Obj y,513Obj dtpols )514{515Obj res, help;516517res = Multiplybound(x, y, 1, LEN_PLIST(y), dtpols);518help = Multiplybound(y, x, 1, LEN_PLIST(x), dtpols);519res = Solution(help, res, dtpols);520return res;521}522523524525/****************************************************************************526**527*F Conjugate( <x>, <y>, <dtpols> )528**529** Conjugate returns <x>^<y> for the words <x> and <y> by evaluating the530** deep thought polynomials <dtpols>. The result is an ordered word.531*/532533Obj Conjugate( Obj x,534Obj y,535Obj dtpols )536{537Obj res;538539res = Multiplybound(x, y, 1, LEN_PLIST(y), dtpols);540res = Solution(y, res, dtpols);541return res;542}543544545546/****************************************************************************547**548*F Multiplyboundred( <x>, <y>, <anf>, <end>, <pcp> )549**550** Multiplyboundred returns the product of the words <x> and <y>. The result551** is an ordered word with the additional property that all word exponents552** are reduced modulo the corresponding generator orders given by the553** deep thought rewriting system <pcp>..554*/555556Obj Multiplyboundred( Obj x,557Obj y,558UInt anf,559UInt end,560Obj pcp )561{562Obj orders, res, mod, c;563UInt i, len, len2, help;564565orders = ELM_PLIST(pcp, PC_ORDERS);566res = Multiplybound(x,y,anf, end, ELM_PLIST( pcp, PC_DEEP_THOUGHT_POLS) );567len = LEN_PLIST(res);568len2 = LEN_PLIST(orders);569for (i=2; i<=len; i+=2)570if ( (help=CELM(res, i-1)) <= len2 &&571( c=ELM_PLIST( orders, help )) != 0 )572{573mod = ModInt( ELM_PLIST(res, i), c );574SET_ELM_PLIST( res, i, mod);575CHANGED_BAG(res);576}577return res;578}579580581582/****************************************************************************583**584*F Powerred( <x>, <n>, <pcp>585**586** Powerred returns the <n>-th power of the word <x>. The result is an587** ordered word with the additional property that all word exponents are588** reduced modulo the generator orders given by the deep thought rewriting589** system <pcp>.590*/591592Obj Powerred( Obj x,593Obj n,594Obj pcp )595{596Obj orders, res, mod, c;597UInt i, len, len2,help;598599orders = ELM_PLIST(pcp, PC_ORDERS);600res = Power(x, n, ELM_PLIST( pcp, PC_DEEP_THOUGHT_POLS) );601len = LEN_PLIST(res);602len2 = LEN_PLIST(orders);603for (i=2; i<=len; i+=2)604if ( (help=CELM(res, i-1)) <= len2 &&605( c=ELM_PLIST( orders, help )) != 0 )606{607mod = ModInt( ELM_PLIST(res, i), c );608SET_ELM_PLIST( res, i, mod);609CHANGED_BAG(res);610}611return res;612}613614615616/****************************************************************************617**618*F Solutionred( <x>, <y>, <pcp> )619**620** Solutionred returns the solution af the equation <x>*a = <y>. The result621** is an ordered word with the additional property that all word exponents622** are reduced modulo the generator orders given by the deep thought623** rewriting system <pcp>.624*/625626Obj Solutionred( Obj x,627Obj y,628Obj pcp )629{630Obj orders, res, mod, c;631UInt i, len, len2, help;632633orders = ELM_PLIST(pcp, PC_ORDERS);634res = Solution(x, y, ELM_PLIST( pcp, PC_DEEP_THOUGHT_POLS) );635len = LEN_PLIST(res);636len2 = LEN_PLIST(orders);637for (i=2; i<=len; i+=2)638if ( (help=CELM(res, i-1)) <= len2 &&639( c=ELM_PLIST( orders, help )) != 0 )640{641mod = ModInt( ELM_PLIST(res, i), c );642SET_ELM_PLIST( res, i, mod);643CHANGED_BAG(res);644}645return res;646}647648649650/****************************************************************************651**652** Commutatorred( <x>, <y>, <pcp> )653**654** Commutatorred returns the commutator of the words <x> and <y>. The result655** is an ordered word with the additional property that all word exponents656** are reduced modulo the corresponding generator orders given by the deep657** thought rewriting system <pcp>.658*/659660Obj Commutatorred( Obj x,661Obj y,662Obj pcp )663{664Obj orders, mod, c, res;665UInt i, len, len2, help;666667orders = ELM_PLIST(pcp, PC_ORDERS);668res = Commutator(x, y, ELM_PLIST( pcp, PC_DEEP_THOUGHT_POLS) );669len = LEN_PLIST(res);670len2 = LEN_PLIST(orders);671for (i=2; i<=len; i+=2)672if ( (help=CELM(res, i-1)) <= len2 &&673( c=ELM_PLIST( orders, help )) != 0 )674{675mod = ModInt( ELM_PLIST(res, i), c );676SET_ELM_PLIST( res, i, mod);677CHANGED_BAG(res);678}679return res;680}681682683684/****************************************************************************685**686*F Conjugate( <x>, <y>, <pcp> )687**688** Conjugate returns <x>^<y> for the words <x> and <y>. The result is an689** ordered word with the additional property that all word exponents are690** reduced modulo the corresponding generator orders given by the deep691** thought rewriting system <pcp>.692*/693694Obj Conjugatered( Obj x,695Obj y,696Obj pcp )697{698Obj orders, mod, c, res;699UInt i, len, len2, help;700701orders = ELM_PLIST(pcp, PC_ORDERS);702res = Conjugate(x, y, ELM_PLIST( pcp, PC_DEEP_THOUGHT_POLS) );703len = LEN_PLIST(res);704len2 = LEN_PLIST(orders);705for (i=2; i<=len; i+=2)706if ( (help=CELM(res, i-1)) <= len2 &&707( c=ELM_PLIST( orders, help )) != 0 )708{709mod = ModInt( ELM_PLIST(res, i), c );710SET_ELM_PLIST( res, i, mod);711CHANGED_BAG(res);712}713return res;714}715716717718/****************************************************************************719**720** compress( <list> )721**722** compress removes pairs (n,0) from the list of GAP integers <list>.723*/724725void compress( Obj list )726{727UInt i, skip, len;728729skip = 0;730i = 2;731len = LEN_PLIST( list );732while ( i <= len )733{734while ( i<=len && CELM(list, i) == 0)735{736skip+=2;737i+=2;738}739if ( i <= len )740{741SET_ELM_PLIST(list, i-skip, ELM_PLIST(list, i) );742SET_ELM_PLIST(list, i-1-skip, ELM_PLIST( list, i-1 ) );743}744i+=2;745}746SET_LEN_PLIST( list, len-skip );747CHANGED_BAG( list );748SHRINK_PLIST( list, len-skip );749}750751752753/****************************************************************************754**755*F FuncDTCompress( <self>, <list> )756**757** FuncDTCompress implements the internal function DTCompress.758*/759760Obj FuncDTCompress( Obj self,761Obj list )762{763compress(list);764return (Obj)0;765}766767768769/****************************************************************************770**771*F ReduceWord( <x>, <pcp> )772**773** ReduceWord reduces the ordered word <x> with respect to the deep thought774** rewriting system <pcp> i.e after applying ReduceWord <x> is an ordered775** word with exponents less than the corresponding relative orders given776** by <pcp>.777*/778779void ReduceWord( Obj x,780Obj pcp )781{782Obj powers, exponent;783Obj deepthoughtpols, help, potenz, quo, mod, prel;784UInt i,j,flag, len, gen, lenexp, lenpow;785786powers = ELM_PLIST(pcp, PC_POWERS);787exponent = ELM_PLIST(pcp, PC_EXPONENTS);788deepthoughtpols = ELM_PLIST(pcp, PC_DEEP_THOUGHT_POLS);789len = **deepthoughtpols;790lenexp = LEN_PLIST(exponent);791lenpow = LEN_PLIST(powers);792GROW_PLIST(x, 2*len );793flag = LEN_PLIST(x);794for (i=1; i<flag; i+=2)795{796if ( (gen = CELM(x, i) ) <= lenexp &&797(potenz = ELM_PLIST(exponent, gen) ) != 0 )798{799quo = ELM_PLIST(x, i+1);800if ( !IS_INTOBJ(quo) || INT_INTOBJ(quo) >= INT_INTOBJ(potenz) ||801INT_INTOBJ(quo)<0 )802{803/* reduce the exponent of the generator <gen> */804mod = ModInt( quo, potenz );805SET_ELM_PLIST(x, i+1, mod);806CHANGED_BAG(x);807if ( gen <= lenpow &&808(prel = ELM_PLIST( powers, gen) ) != 0 )809{810if ( ( IS_INTOBJ(quo) && INT_INTOBJ(quo) >= INT_INTOBJ(potenz) ) ||811TNUM_OBJ(quo) == T_INTPOS )812{813help = Powerred( prel,814QuoInt(quo, potenz),815pcp );816help = Multiplyboundred( help, x, i+2, flag, pcp);817}818else819{820quo = INT_INTOBJ(mod) == 0? QuoInt(quo,potenz):SumInt(QuoInt(quo, potenz),INTOBJ_INT(-1));821help = Powerred( prel,822quo,823pcp );824help = Multiplyboundred( help, x, i+2, flag, pcp);825}826len = LEN_PLIST(help);827for (j=1; j<=len; j++)828SET_ELM_PLIST(x, j+i+1, ELM_PLIST(help, j) );829CHANGED_BAG(x);830flag = i+len+1;831/*SET_LEN_PLIST(x, flag);*/832}833}834}835}836SET_LEN_PLIST(x, flag);837SHRINK_PLIST(x, flag);838/* remove all syllables with exponent 0 from <x>. */839compress(x);840}841842843844/****************************************************************************845**846*F FuncDTMultiply( <self>, <x>, <y>, <pcp> )847**848** FuncDTMultiply implements the internal function849**850*F DTMultiply( <x>, <y>, <pcp> ).851**852** DTMultiply returns the product of <x> and <y>. The result is reduced853** with respect to the deep thought rewriting system <pcp>.854*/855856Obj FuncDTMultiply( Obj self,857Obj x,858Obj y,859Obj pcp )860{861Obj res;862863if ( LEN_PLIST(x) == 0 )864return y;865if ( LEN_PLIST(y) == 0 )866return x;867res = Multiplyboundred(x, y, 1, LEN_PLIST(y), pcp);868ReduceWord(res, pcp);869return res;870}871872873874/****************************************************************************875**876*F FuncDTPower( <self>, <x>, <n>, <pcp> )877**878** FuncDTPower implements the internal function879**880*F DTPower( <x>, <n>, <pcp> ).881**882** DTPower returns the <n>-th power of the word <x>. The result is reduced883** with respect to the deep thought rewriting system <pcp>.884*/885886Obj FuncDTPower( Obj self,887Obj x,888Obj n,889Obj pcp )890{891Obj res;892893res = Powerred(x, n, pcp);894ReduceWord(res, pcp);895return res;896}897898899900/****************************************************************************901**902*F FuncDTSolution( <self>, <x>, <y>, <pcp> )903**904** FuncDTSolution implements the internal function905**906*F DTSolution( <x>, <y>, <pcp> ).907**908** DTSolution returns the solution of the equation <x>*a = <y>. The result909** is reduced with respect to the deep thought rewriting system <pcp>.910*/911912Obj FuncDTSolution( Obj self,913Obj x,914Obj y,915Obj pcp )916{917Obj res;918919if ( LEN_PLIST(x) == 0 )920return y;921res = Solutionred(x, y, pcp);922ReduceWord(res, pcp);923return res;924}925926927928/****************************************************************************929**930*F FuncDTCommutator( <self>, <x>, <y>. <pcp> )931**932** FuncDTCommutator implements the internal function933**934*F DTCommutator( <x>, <y>, <pcp> )935**936** DTCommutator returns the commutator of the words <x> and <y>. The result937** is reduced with respect to the deep thought rewriting sytem <pcp>.938*/939940Obj FuncDTCommutator( Obj self,941Obj x,942Obj y,943Obj pcp )944{945Obj res;946947res = Commutatorred(x, y, pcp);948ReduceWord(res, pcp);949return res;950}951952953954/****************************************************************************955**956*F FuncConjugate( <self>, <x>, <y>, <pcp> )957**958** FuncConjugate implements the internal function959**960*F Conjugate( <x>, <y>, <pcp> ).961**962** Conjugate returns <x>^<y> for the words <x> and <y>. The result is963** ewduced with respect to the deep thought rewriting system <pcp>.964*/965966Obj FuncDTConjugate( Obj self,967Obj x,968Obj y,969Obj pcp )970{971Obj res;972973if ( LEN_PLIST(y) == 0 )974return x;975res = Conjugatered(x, y, pcp);976ReduceWord(res, pcp);977return res;978}979980981982/****************************************************************************983**984*F FuncDTQuotient( <self>, <x>, <y>, <pcp> )985**986** FuncDTQuotient implements the internal function987**988*F DTQuotient( <x>, <y>, <pcp> ).989**990*F DTQuotient returns the <x>/<y> for the words <x> and <y>. The result is991** reduced with respect to the deep thought rewriting system <pcp>.992*/993994Obj FuncDTQuotient( Obj self,995Obj x,996Obj y,997Obj pcp )998{999Obj help, res;10001001if ( LEN_PLIST(y) == 0 )1002return x;1003help = NEW_PLIST( T_PLIST, 0 );1004SET_LEN_PLIST(help, 0);1005res = Solutionred(y, help, pcp);1006res = Multiplyboundred(x, res, 1, LEN_PLIST(res), pcp);1007ReduceWord(res, pcp);1008return(res);1009}1010101110121013/****************************************************************************1014**10151016*F * * * * * * * * * * * * * initialize package * * * * * * * * * * * * * * *1017*/101810191020/****************************************************************************1021**10221023*V GVarFuncs . . . . . . . . . . . . . . . . . . list of functions to export1024*/1025static StructGVarFunc GVarFuncs [] = {10261027{ "DTCompress", 1, "list",1028FuncDTCompress, "src/dteval.c:DTCompress" },10291030{ "DTMultiply", 3, "lword, rword, rws",1031FuncDTMultiply, "src/dteval.c:DTMultiply" },10321033{ "DTPower", 3, "word, exponent, rws",1034FuncDTPower, "src/dteval.c:DTPower" },10351036{ "DTSolution", 3, "lword, rword, rws",1037FuncDTSolution, "src/dteval.c:DTSolution" },10381039{ "DTCommutator", 3, "lword, rword, rws",1040FuncDTCommutator, "src/dteval.c:DTCommutator" },10411042{ "DTQuotient", 3, "lword, rword, rws",1043FuncDTQuotient, "src/dteval.c:DTQuotient" },10441045{ "DTConjugate", 3, "lword, rword, rws",1046FuncDTConjugate, "src/dteval.c:DTConjugate" },10471048{ 0 }10491050};105110521053/****************************************************************************1054**10551056*F InitKernel( <module> ) . . . . . . . . initialise kernel data structures1057*/1058static Int InitKernel (1059StructInitInfo * module )1060{1061/* init filters and functions */1062InitHdlrFuncsFromTable( GVarFuncs );10631064/* return success */1065return 0;1066}106710681069/****************************************************************************1070**1071*F PostRestore( <module> ) . . . . . . . . . . . . . after restore workspace1072*/1073static Int PostRestore (1074StructInitInfo * module )1075{1076evlist = RNamName("evlist");1077evlistvec = RNamName("evlistvec");10781079/* return success */1080return 0;1081}108210831084/****************************************************************************1085**1086*F InitLibrary( <module> ) . . . . . . . initialise library data structures1087*/1088static Int InitLibrary (1089StructInitInfo * module )1090{1091/* init filters and functions */1092InitGVarFuncsFromTable( GVarFuncs );10931094/* return success */1095return PostRestore( module );1096}109710981099/****************************************************************************1100**1101*F InitInfoDTEvaluation() . . . . . . . . . . . . . table of init functions1102*/1103static StructInitInfo module = {1104MODULE_BUILTIN, /* type */1105"dteval", /* name */11060, /* revision entry of c file */11070, /* revision entry of h file */11080, /* version */11090, /* crc */1110InitKernel, /* initKernel */1111InitLibrary, /* initLibrary */11120, /* checkInit */11130, /* preSave */11140, /* postSave */1115PostRestore /* postRestore */1116};11171118StructInitInfo * InitInfoDTEvaluation ( void )1119{1120return &module;1121}112211231124/****************************************************************************1125**11261127*E dteval.c . . . . . . . . . . . . . . . . . . . . . . . . . . . ends here1128**1129*/113011311132