1 /*
2 
3     This file is part of the Maude 2 interpreter.
4 
5     Copyright 2004 SRI International, Menlo Park, CA 94025, USA.
6 
7     This program is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11 
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16 
17     You should have received a copy of the GNU General Public License
18     along with this program; if not, write to the Free Software
19     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
20 
21 */
22 
23 //
24 //      Class for symbols for built in operations on matrices of numbers.
25 //
26 #ifndef _matrixOpSymbol_hh_
27 #define _matrixOpSymbol_hh_
28 #include <map>
29 #include "numberOpSymbol.hh"
30 
31 class MatrixOpSymbol : public NumberOpSymbol
32 {
33 public:
34   MatrixOpSymbol(int id, int arity);
35 
36   bool attachData(const Vector<Sort*>& opDeclaration,
37 		  const char* purpose,
38 		  const Vector<const char*>& data);
39   bool attachSymbol(const char* purpose, Symbol* symbol);
40 
41   void copyAttachments(Symbol* original, SymbolMap* map);
42 
43   void getDataAttachments(const Vector<Sort*>& opDeclaration,
44 			  Vector<const char*>& purposes,
45 			  Vector<Vector<const char*> >& data);
46   void getSymbolAttachments(Vector<const char*>& purposes,
47 			    Vector<Symbol*>& symbols);
48 
49   bool eqRewrite(DagNode* subject, RewritingContext& context);
50 
51 private:
52   enum Algorithm
53     {
54       SYSTEMS_CHOICE,
55       CD,
56       GCD
57     };
58 
59   typedef map<int, mpz_class> SparseVector;
60   typedef map<int, SparseVector> SparseMatrix;
61   typedef Vector<mpz_class> IntVec;
62 
63   bool downMatrixEntry(DagNode* dagNode, SparseMatrix& matrix, int& maxRowNr, int& maxColNr);
64   bool downMatrix(DagNode* dagNode, SparseMatrix& matrix, int& maxRowNr, int& maxColNr);
65   bool downVectorEntry(DagNode* dagNode, IntVec& vec, int& maxRowNr);
66   bool downVector(DagNode* dagNode, IntVec& vec, int& maxRowNr);
67   bool downAlgorithm(DagNode* dagNode, Algorithm& algorithm);
68   DagNode* upSet(const Vector<DagNode*>& elts);
69   DagNode* upVector(const IntVec& row);
70 
71 #define MACRO(SymbolName, SymbolClass, RequiredFlags, NrArgs) \
72   SymbolClass* SymbolName;
73 #include "matrixOpSignature.cc"
74 #undef MACRO
75 };
76 
77 #endif
78