1 /* PolyTree.h --
2 
3    Copyright 2004 Jesus A. De Loera, David Haws, Raymond Hemmecke,
4       Peter Huggins, Jeremy Tauzer, Ruriko Yoshida
5 
6    This file is part of LattE.
7 
8    LattE is free software; you can redistribute it and/or modify it
9    under the terms of the version 2 of the GNU General Public License
10    as published by the Free Software Foundation.
11 
12    LattE is distributed in the hope that it will be useful, but
13    WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    General Public License for more details.
16 
17    You should have received a copy of the GNU General Public License
18    along with LattE; if not, write to the Free Software Foundation,
19    Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20 */
21 
22 #ifndef POLYTREE_H
23 #define POLYTREE_H 1
24 
25 #include <fstream>
26 #include "latte_ntl.h"
27 using namespace std;
28 
29 // Definitions of the types of PolyTree structures
30 #define POLYTREE_ADD 0
31 #define POLYTREE_MUL 1
32 #define POLYTREE_DIV 5
33 #define POLYTREE_T_NODE 3
34 #define POLYTREE_S_NODE 2
35 #define POLYTREE_EXP 4
36 
37 // Define the types of generators of cones,  either (1-rt) or (r-t)
38 #define ONE_SUB_RT 0
39 #define R_SUB_T  1
40 
41 // This is used to hold all the information of Taylor_Expansion function
42 struct Taylor_Parameters
43 {
44 	ZZ 	*Result;
45 	int	Degree_of_Expansion;
46 	ZZ	*Ten_Power;
47 
48 };
49 
50 class PolyTree_Node
51 {
52 	public:
PolyTree_Node()53 		PolyTree_Node () { Taylor_Expansion_Result_Dirty = 1; };
~PolyTree_Node()54 		virtual ~PolyTree_Node () {};
55 
56 		PolyTree_Node **Children;
57 
58 		// 0 mean +, 1 mean *, 2 means S_Node, 3 means T_Node, 4 mean ^ , 5 means /
59 		char	Node_Type;
60 		unsigned int	Number_of_Children;
61 		virtual int 	Print(); //Returns 1 if it did print anything, otherwise returns 0
62 		virtual int	Check_For_Zero ();  //Returns 1 if this node is equal to zero
63 
64 		//This function will return the first Parameters->Degree_of_Expansion number of terms.
65 		//It accepts  Taylor_Parameter as input with the Result part of it already
66 		//allocated for enough space for Degree_of_Expansion + 1 terms.
67 		virtual void	Taylor_Expansion (Taylor_Parameters *Parameters);
68 		virtual int	Print_Rational_Functions_to_File (ofstream &Output_File);
69 
70 		//		1 indicates Taylor_Expansion_Result is invalid
71 		int		Taylor_Expansion_Result_Dirty;
72 
73 		ZZ		*Taylor_Expansion_Result;
74 };
75 
76 
77 //Currently this class is never used
78 /*class S_Node : public PolyTree_Node
79 {
80 	public:
81 		ZZ	Coefficient;
82 		ZZ	Exponent;
83 		int	Print ();
84 };*/
85 
86 class T_Node : public PolyTree_Node //Also used for ^ type.  Exponent holds the exponent.
87 {
88 	public:
~T_Node()89 		virtual ~T_Node () {};
90 		ZZ	Coefficient;
91 		ZZ	Exponent;
92 		int	Print(); //Returns 1 if it did print anything, otherwise returns 0
93 		int	Check_For_Zero (); // Returns 1 if zero, else returns 0
94 
95 		//Same as description in PolyTree_Node
96 		void	Taylor_Expansion (Taylor_Parameters *Parameters);
97 		int	Print_Rational_Functions_to_File (ofstream &Output_File);
98 };
99 
100 
101 // Used to hold information for each generator of a cone.
102 struct Generator
103 {
104 	int	Form_Type;  // 0 means (1-rt)     1 means  (r-t)
105 	ZZ	R_Exponent;
106 	ZZ	T_Exponent;
107 
108 };
109 
110 
111 struct Cone_Data
112 {
113 	int	sign;	//Holds the sign of this Cone
114 	int	order;	//Holds the order of this Cone
115 	Generator	*Generators_of_Cone;  //The denominators
116 	Generator	Numerator_Generator;
117 
118 
119 
120 };
121 
122 struct PolyTree_Node_List
123 {
124 	PolyTree_Node	*Data;
125 
126 	PolyTree_Node_List *Next;
127 
128 };
129 
130 struct T_Node_List
131 {
132 	T_Node		*Data;
133 
134 	T_Node_List 	*Next;
135 
136 };
137 
138 class Node_Controller
139 {
140 	public:
141 		Node_Controller (int Dimension, int Degree);
142 		~Node_Controller ();
143 
144 		//  Returns a pointer to a PolyNode for someone to use
145 		PolyTree_Node 	*Get_PolyTree_Node ();
146 		//  Returns a pointer to a T_Node for someone to use
147 		T_Node		*Get_T_Node ();
148 
149 		// Clears all the nodes this Controller controls
150 		void	Reset ();
151 
152 	private:
153 		int	Dimension_Plus_One;
154 		int	Degree_of_Expansion;
155 
156 
157 		PolyTree_Node_List	*PolyTree_Node_Head;
158 		PolyTree_Node_List	*PolyTree_Node_Unused;
159 
160 		T_Node_List		*T_Node_Head;
161 		T_Node_List		*T_Node_Unused;
162 
163 };
164 
165 
166 
167 #endif
168