Main Page
Related Pages
Data Structures
Files
File List
Globals
src
libgfsm
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
{
40
gfsmSRTUnknown
= 0,
41
gfsmSRTBoolean
= 1,
42
gfsmSRTLog
= 2,
43
gfsmSRTReal
= 3,
44
gfsmSRTTrivial
= 4,
45
gfsmSRTTropical
= 5,
46
gfsmSRTPLog
= 6,
47
gfsmSRTArctic
= 7,
48
gfsmSRTFuzzy
= 8,
49
gfsmSRTProb
= 9,
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
{
67
gfsmSRType
type
;
68
gfsmWeight
zero
;
69
gfsmWeight
one
;
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
82
typedef
gfsmWeight
(*
gfsmSRUnaryOp
) (
gfsmSemiring
*sr,
gfsmWeight
x);
83
85
typedef
gfsmWeight
(*
gfsmSRBinaryOp
) (
gfsmSemiring
*sr,
gfsmWeight
x,
gfsmWeight
y);
86
87
88
/*======================================================================
89
* Semiring: types: user structs
90
*/
92
typedef
struct
{
93
gfsmSemiring
sr
;
95
//-- user-defined semirings *must* set these functions
96
gfsmSRBinaryPredicate
equal_func
;
97
gfsmSRBinaryPredicate
less_func
;
98
gfsmSRBinaryOp
plus_func
;
99
gfsmSRBinaryOp
times_func
;
100
gfsmSRUnaryOp
inv_l_func
;
101
gfsmSRBinaryOp
pow_func
;
102
gfsmSRUnaryOp
star_func
;
103
}
gfsmUserSemiring
;
104
105
/*======================================================================
106
* Semiring: methods: constructors etc.
107
*/
109
110
112
GFSM_INLINE
113
gfsmSemiring
*
gfsm_semiring_new
(
gfsmSRType
type);
114
116
void
gfsm_semiring_init
(
gfsmSemiring
*sr,
gfsmSRType
type);
117
119
GFSM_INLINE
120
gfsmUserSemiring
*
gfsm_user_semiring_new
(
gfsmSRBinaryPredicate
equal_func,
121
gfsmSRBinaryPredicate
less_func,
122
gfsmSRBinaryOp
plus_func,
123
gfsmSRBinaryOp
times_func);
124
126
GFSM_INLINE
127
gfsmSemiring
*
gfsm_semiring_copy
(
gfsmSemiring
*sr);
128
130
GFSM_INLINE
131
void
gfsm_semiring_free
(
gfsmSemiring
*sr);
133
134
/*======================================================================
135
* Semiring: general accessors & operations
136
*/
138
139
141
GFSM_INLINE
142
gfsmSRType
gfsm_sr_type
(
const
gfsmSemiring
*sr);
143
145
GFSM_INLINE
146
gfsmWeight
gfsm_sr_zero
(
gfsmSemiring
*sr);
147
149
GFSM_INLINE
150
gfsmWeight
gfsm_sr_one
(
gfsmSemiring
*sr);
151
153
GFSM_INLINE
154
gboolean
gfsm_sr_equal
(
gfsmSemiring
*sr,
gfsmWeight
x,
gfsmWeight
y);
155
157
GFSM_INLINE
158
gboolean
gfsm_sr_less
(
gfsmSemiring
*sr,
gfsmWeight
x,
gfsmWeight
y);
159
161
gint
gfsm_sr_compare
(
gfsmSemiring
*sr,
gfsmWeight
x,
gfsmWeight
y);
162
164
GFSM_INLINE
165
gfsmWeight
gfsm_sr_plus
(
gfsmSemiring
*sr,
gfsmWeight
x,
gfsmWeight
y);
166
168
GFSM_INLINE
169
gfsmWeight
gfsm_sr_times
(
gfsmSemiring
*sr,
gfsmWeight
x,
gfsmWeight
y);
170
172
GFSM_INLINE
173
gfsmWeight
gfsm_sr_inv_l
(
gfsmSemiring
*sr,
gfsmWeight
x);
174
176
GFSM_INLINE
177
gfsmWeight
gfsm_sr_pow
(
gfsmSemiring
*sr,
gfsmWeight
x,
gfsmWeight
n);
178
180
gfsmWeight
gfsm_sr_pow_n
(
gfsmSemiring
*sr,
gfsmWeight
x, gint n);
181
183
GFSM_INLINE
184
gfsmWeight
gfsm_sr_star
(
gfsmSemiring
*sr,
gfsmWeight
x);
185
187
#define GFSM_SR_STAR_N_DEFAULT 8
188
gfsmWeight
gfsm_sr_star_n
(
gfsmSemiring
*sr,
gfsmWeight
x, guint n);
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
212
GFSM_INLINE
213
gfsmWeight
gfsm_log_add
(
gfsmWeight
x,
gfsmWeight
y);
215
216
//-- inline definitions
217
#ifdef GFSM_INLINE_ENABLED
218
# include <gfsmSemiring.hi>
219
#endif
220
221
#endif
/* _GFSM_SEMIRING_H */
Generated on Tue Oct 21 2014 09:44:47 for libgfsm by
1.8.1.2