gfsmSemiring.h
Go to the documentation of this file.
1 /*=============================================================================*\
2  * File: gfsmSemiring.h
3  * Author: Bryan Jurish <moocow.bovine@gmail.com>
4  * Description: finite state machine library
5  *
6  * Copyright (c) 2004-2011 Bryan Jurish.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 3 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  *=============================================================================*/
22 
27 #ifndef _GFSM_SEMIRING_H
28 #define _GFSM_SEMIRING_H
29 
30 #include <gfsmCommon.h>
31 #include <float.h>
32 
33 /*======================================================================
34  * Semiring: types
35  */
39 typedef enum {
42  gfsmSRTLog = 2,
50  //gfsmSRTViterbi = 10, ///< Viterbi semiring: <set:[0,1], plus:max, times:*, less:>, zero:0, one:1>
51  // -log(gfsmSRTViterbi) === gfsmSRTTropical === -gfsmSRTArctic
52  //gfsmSRTLogViterbi, ///< log-Viterbi semiring: <set:[-inf,0], plus:max, times:+, less:??, zero:-inf, one:0>
53  // SRTLogViterbi === gfsmSRTArctic over set [-inf,0]
54  // TODO: concatenation sr: <set:2^(\Sigma^*), plus:\union, times:\concat, less:??, zero:\emptyset, one:{\epsilon}>
55  // TODO: string sr: <set:\sigma^* \union {s_\infty}, plus:LCP, times:\concat, less:??, zero:s_\infty, one:\epsilon>
56  // TODO: set sr: <set:2^M, plus:\union, times:\intersect, less:??, zero:\emptyset, one:M>, M an arbitrary set
57  // TODO: unification sr: <set:2^F, plus:\union, times:\unify, less:??, zero:\emptyset, one:{\bottom}>, F set of FSs
58 
59  gfsmSRTUser = 256
60 } gfsmSRType;
61 
62 /*======================================================================
63  * Semiring: types: structs
64  */
66 typedef struct {
70 } gfsmSemiring;
71 
72 /*======================================================================
73  * Semiring: types: functions
74  */
76 typedef gboolean (*gfsmSRUnaryPredicate) (gfsmSemiring *sr, gfsmWeight x);
77 
79 typedef gboolean (*gfsmSRBinaryPredicate) (gfsmSemiring *sr, gfsmWeight x, gfsmWeight y);
80 
83 
86 
87 
88 /*======================================================================
89  * Semiring: types: user structs
90  */
92 typedef struct {
95  //-- user-defined semirings *must* set these functions
104 
105 /*======================================================================
106  * Semiring: methods: constructors etc.
107  */
109 
110 
114 
117 
121  gfsmSRBinaryPredicate less_func,
122  gfsmSRBinaryOp plus_func,
123  gfsmSRBinaryOp times_func);
124 
128 
133 
134 /*======================================================================
135  * Semiring: general accessors & operations
136  */
138 
139 
143 
147 
151 
154 gboolean gfsm_sr_equal(gfsmSemiring *sr, gfsmWeight x, gfsmWeight y);
155 
158 gboolean gfsm_sr_less(gfsmSemiring *sr, gfsmWeight x, gfsmWeight y);
159 
162 
166 
170 
174 
178 
181 
185 
187 #define GFSM_SR_STAR_N_DEFAULT 8
189 
191 
192 /*======================================================================
193  * Semiring: methods: string utilities
194  */
196 
197 
198 gfsmSRType gfsm_sr_name_to_type(const char *name);
199 
201 gchar *gfsm_sr_type_to_name(gfsmSRType type);
203 
204 /*======================================================================
205  * Semiring: methods: general utilities
206  */
208 
209 
215 
216 //-- inline definitions
217 #ifdef GFSM_INLINE_ENABLED
218 # include <gfsmSemiring.hi>
219 #endif
220 
221 #endif /* _GFSM_SEMIRING_H */