1999-09-27 18:44:28 +00:00
|
|
|
/*
|
|
|
|
* File: math_utils.C
|
|
|
|
* Purpose: X independent general mathed routines
|
|
|
|
* Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
|
|
|
|
* Created: August 1996
|
|
|
|
*
|
2000-03-09 03:36:48 +00:00
|
|
|
* Copyright: 1996, 1997 Alejandro Aguilar Sierra
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
|
|
|
* License: GNU GPL version 2 or later
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2000-01-20 01:41:55 +00:00
|
|
|
#include <algorithm>
|
2000-01-06 02:44:26 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "math_defs.h"
|
|
|
|
#include "symbol_def.h"
|
|
|
|
|
2000-01-20 01:41:55 +00:00
|
|
|
using std::sort;
|
|
|
|
using std::lower_bound;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// This table includes all binary operators and relations
|
2000-01-20 01:41:55 +00:00
|
|
|
struct binary_op_pair {
|
|
|
|
short id;
|
|
|
|
short isrel;
|
|
|
|
};
|
|
|
|
|
|
|
|
binary_op_pair binary_op_table[] = {
|
1999-09-27 18:44:28 +00:00
|
|
|
{ LM_leq, LMB_RELATION }, { LM_geq, LMB_RELATION },
|
|
|
|
{ LM_equiv, LMB_RELATION }, { LM_models, LMB_RELATION },
|
|
|
|
{ LM_prec, LMB_RELATION }, { LM_succ, LMB_RELATION },
|
|
|
|
{ LM_sim, LMB_RELATION }, { LM_perp, LMB_RELATION },
|
|
|
|
{ LM_preceq, LMB_RELATION }, { LM_succeq, LMB_RELATION },
|
|
|
|
{ LM_simeq, LMB_RELATION }, { LM_mid, LMB_RELATION },
|
|
|
|
{ LM_ll, LMB_RELATION }, { LM_gg, LMB_RELATION },
|
|
|
|
{ LM_asymp, LMB_RELATION }, { LM_parallel, LMB_RELATION },
|
|
|
|
{ LM_subset, LMB_RELATION }, { LM_supset, LMB_RELATION },
|
|
|
|
{ LM_approx, LMB_RELATION }, { LM_smile, LMB_RELATION },
|
|
|
|
{ LM_subseteq, LMB_RELATION }, { LM_supseteq, LMB_RELATION },
|
|
|
|
{ LM_cong, LMB_RELATION }, { LM_frown, LMB_RELATION },
|
|
|
|
{ LM_sqsubseteq, LMB_RELATION }, { LM_sqsupseteq, LMB_RELATION },
|
|
|
|
{ LM_doteq, LMB_RELATION }, { LM_neq, LMB_RELATION },
|
|
|
|
{ LM_in, LMB_RELATION }, { LM_ni, LMB_RELATION },
|
|
|
|
{ LM_propto, LMB_RELATION }, { LM_notin, LMB_RELATION },
|
|
|
|
{ LM_vdash, LMB_RELATION }, { LM_dashv, LMB_RELATION },
|
|
|
|
{ LM_bowtie, LMB_RELATION },
|
|
|
|
{ LM_pm, LMB_OPERATOR }, { LM_cap, LMB_OPERATOR },
|
|
|
|
{ LM_diamond, LMB_OPERATOR }, { LM_oplus, LMB_OPERATOR },
|
|
|
|
{ LM_mp, LMB_OPERATOR }, { LM_cup, LMB_OPERATOR },
|
|
|
|
{ LM_bigtriangleup, LMB_OPERATOR }, { LM_ominus, LMB_OPERATOR },
|
|
|
|
{ LM_times, LMB_OPERATOR }, { LM_uplus, LMB_OPERATOR },
|
|
|
|
{ LM_bigtriangledown, LMB_OPERATOR }, { LM_otimes, LMB_OPERATOR },
|
|
|
|
{ LM_div, LMB_OPERATOR }, { LM_sqcap, LMB_OPERATOR },
|
|
|
|
{ LM_triangleright, LMB_OPERATOR }, { LM_oslash, LMB_OPERATOR },
|
|
|
|
{ LM_cdot, LMB_OPERATOR }, { LM_sqcup, LMB_OPERATOR },
|
|
|
|
{ LM_triangleleft, LMB_OPERATOR }, { LM_odot, LMB_OPERATOR },
|
|
|
|
{ LM_star, LMB_OPERATOR }, { LM_vee, LMB_OPERATOR },
|
|
|
|
{ LM_amalg, LMB_OPERATOR }, { LM_bigcirc, LMB_OPERATOR },
|
|
|
|
{ LM_setminus, LMB_OPERATOR }, { LM_wedge, LMB_OPERATOR },
|
|
|
|
{ LM_dagger, LMB_OPERATOR }, { LM_circ, LMB_OPERATOR },
|
|
|
|
{ LM_bullet, LMB_OPERATOR }, { LM_wr, LMB_OPERATOR },
|
|
|
|
{ LM_ddagger, LMB_OPERATOR }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-01-20 01:41:55 +00:00
|
|
|
struct compara {
|
|
|
|
// used by sort
|
2000-03-02 02:19:43 +00:00
|
|
|
inline
|
2000-01-20 01:41:55 +00:00
|
|
|
int operator()(binary_op_pair const & a,
|
|
|
|
binary_op_pair const & b) const {
|
|
|
|
return a.id < b.id;
|
|
|
|
}
|
|
|
|
// used by lower_bound
|
2000-03-02 02:19:43 +00:00
|
|
|
inline
|
2000-01-20 01:41:55 +00:00
|
|
|
int operator()(binary_op_pair const & a, short int id) const {
|
|
|
|
return a.id < id;
|
|
|
|
}
|
|
|
|
};
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2000-01-20 01:41:55 +00:00
|
|
|
int MathedLookupBOP(short id)
|
|
|
|
{
|
2000-03-02 02:19:43 +00:00
|
|
|
static int const bopCount =
|
|
|
|
sizeof(binary_op_table) / sizeof(binary_op_pair);
|
2000-01-20 01:41:55 +00:00
|
|
|
static bool issorted = false;
|
|
|
|
|
|
|
|
if (!issorted) {
|
|
|
|
sort(binary_op_table, binary_op_table + bopCount, compara());
|
|
|
|
issorted = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
binary_op_pair * res = lower_bound(binary_op_table,
|
|
|
|
binary_op_table + bopCount,
|
|
|
|
id, compara());
|
2000-03-02 02:19:43 +00:00
|
|
|
if (res != binary_op_table + bopCount && res->id == id)
|
2000-03-01 18:15:39 +00:00
|
|
|
return res->isrel;
|
|
|
|
else
|
|
|
|
return LMB_NONE;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|