Révision 138

pobysoC-4.0/src/test-pobyso-constant-expression.c (revision 138)
1
/** @file test-pobyso-constant-expression.c
2
 * Name & purpose
3
 *
4
 * @author
5
 * @date
6
 *
7
 * @details Verbosity manipulation are performed  to make sur  that verbosity
8
 *  suppression is correctly managed in pobyso_is_constant_expression()
9
 *  function.
10
 */
11
/******************************************************************************/
12
/* Headers, applying the "particular to general" convention.*/
13

  
14
#include "pobyso.h"
15

  
16
/* includes of local headers */
17

  
18
/* includes of project headers */
19

  
20
/* includes of system headers */
21

  
22
/* Other declarations */
23

  
24
/* Internal prototypes */
25

  
26
/* Types, constants and macros definitions */
27

  
28
/* Global variables */
29

  
30
/* Functions */
31

  
32
int
33
main(int argc, char** argv)
34
{
35
  pobyso_func_exp_t func_exp  = NULL;
36
  int verbosity               = 0;
37
  sollya_obj_t on             = NULL;
38
  sollya_obj_t off            = NULL;
39

  
40
  sollya_lib_init();
41

  
42
  pobyso_set_canonical_on();
43
  off = sollya_lib_off();
44
  on  = sollya_lib_on();
45

  
46
  fprintf(stdout, "NULL argument:\n");
47
  if (! pobyso_is_constant_expression(func_exp))
48
  {
49
    fprintf(stdout, "OK.\n");
50
  }
51
  else
52
  {
53
    fprintf(stdout, "Error for NULL argument.\n");
54
    return 1;
55
  }
56

  
57
  fprintf(stdout, "Argument : 1\n");
58
  func_exp = pobyso_parse_string("1");
59
  if (pobyso_is_constant_expression(func_exp))
60
  {
61
    pobyso_autoprint(func_exp);
62
    fprintf(stdout, "OK.\n");
63
    sollya_lib_clear_obj(func_exp);
64
  }
65
  else
66
  {
67
    fprintf(stdout, "Error for \"1\".\n");
68
    return 1;
69
  }
70
  verbosity = pobyso_set_verbosity_off();
71
  func_exp = pobyso_parse_string("1.1");
72
  pobyso_set_verbosity_to(verbosity);
73
  if (pobyso_is_constant_expression(func_exp))
74
  {
75
    pobyso_autoprint(func_exp);
76
    fprintf(stdout, "OK.\n");
77
    sollya_lib_clear_obj(func_exp);
78
  }
79
  else
80
  {
81
    fprintf(stdout, "Error for \"1.1\".\n");
82
    return 1;
83
  }
84

  
85
  func_exp = pobyso_parse_string("1/2");
86
  if (pobyso_is_constant_expression(func_exp))
87
  {
88
    pobyso_set_verbosity_off();
89
    pobyso_autoprint(func_exp);
90
    fprintf(stdout, "OK for \"1/2\".\n");
91
    sollya_lib_clear_obj(func_exp);
92
  }
93
  else
94
  {
95
    fprintf(stdout, "Error for \"1/2\".\n");
96
    return 1;
97
  }
98

  
99
  verbosity = pobyso_set_verbosity_off();
100
  sollya_lib_set_roundingwarnings(off);
101
  func_exp = sollya_lib_pi();
102
  pobyso_set_verbosity_to(verbosity);
103
  sollya_lib_set_roundingwarnings(on);
104
  if (pobyso_is_constant_expression(func_exp))
105
  {
106
    pobyso_autoprint(func_exp);
107
    fprintf(stdout,"OK for pi.\n");
108
    sollya_lib_clear_obj(func_exp);
109
  }
110
  else
111
  {
112
    fprintf(stdout, "Error for \"pi\".\n");
113
    return 1;
114
  }
115

  
116
  func_exp = pobyso_parse_string("x^2");
117
  if (! pobyso_is_constant_expression(func_exp))
118
  {
119
    fprintf(stdout, "Non constant expression \"x^2\": OK\n");
120
  }
121
  else
122
  {
123
    fprintf(stdout, "Error for \"x^2\".\n");
124
    return 1;
125
  }
126

  
127
  func_exp = pobyso_parse_string("cos(x)");
128
  if (! pobyso_is_constant_expression(func_exp))
129
  {
130
    pobyso_autoprint(func_exp);
131
    fprintf(stdout, "OK for non constant expression \"cos(x)\".\n");
132
    sollya_lib_clear_obj(func_exp);
133
  }
134
  else
135
  {
136
    fprintf(stdout, "Error for \"cos(x)\".\n");
137
    return 1;
138
  }
139

  
140
  verbosity = pobyso_set_verbosity_off();
141
  func_exp = pobyso_parse_string("cos(pi)");
142
  pobyso_set_verbosity_to(verbosity);
143
  if (pobyso_is_constant_expression(func_exp))
144
  {
145
    pobyso_set_verbosity_off();
146
    pobyso_autoprint(func_exp);
147
    fprintf(stdout, "OK for \"cos(pi)\".\n");
148
    sollya_lib_clear_obj(func_exp);
149
  }
150
  else
151
  {
152
    fprintf(stdout, "Error for \"cos(pi)\".\n");
153
    return 1;
154
  }
155
  /*  */
156

  
157
  sollya_lib_close();
158
  return 0;
159
} /* End main */
pobysoC-4.0/src/test-pobyso-is-constant-expression.c (revision 138)
1
/** @file test-pobyso-is-constant-expression.c
2
 * Name & purpose
3
 *
4
 * @author S. T.
5
 * @date 2014-11-14
6
 *
7
 * @details Verbosity manipulation are performed  to make sur  that verbosity
8
 *  suppression is correctly managed in pobyso_is_constant_expression()
9
 *  function.
10
 */
11
/******************************************************************************/
12
/* Headers, applying the "particular to general" convention.*/
13

  
14
#include "pobyso.h"
15

  
16
/* includes of local headers */
17

  
18
/* includes of project headers */
19

  
20
/* includes of system headers */
21

  
22
/* Other declarations */
23

  
24
/* Internal prototypes */
25

  
26
/* Types, constants and macros definitions */
27

  
28
/* Global variables */
29

  
30
/* Functions */
31

  
32
int
33
main(int argc, char** argv)
34
{
35
  pobyso_func_exp_t funcExpSo  = NULL;
36
  int outcome = 1;
37

  
38
  sollya_lib_init();
39

  
40
  /* No command line argument test the function with the NULL argument. */
41
  if (argc == 1)
42
  {
43
    outcome = pobyso_is_constant_expression(funcExpSo);
44
    sollya_lib_close();
45
    return ! outcome;
46
  }
47

  
48
  pobyso_set_canonical_on();
49
  funcExpSo = pobyso_parse_string(argv[1]);
50
  if (funcExpSo != NULL)
51
  {
52
    fprintf(stdout, "Sollya expression: ");
53
    pobyso_autoprint(funcExpSo);
54
  }
55
  else
56
  {
57
    fprintf(stdout, "NULL expression");
58
  }
59
  if (pobyso_is_constant_expression(funcExpSo))
60
  {
61
    sollya_lib_close();
62
    return 0;
63
  }
64
  else
65
  {
66
    sollya_lib_close();
67
    return 1;
68
  }
69
} /* End main */
pobysoC-4.0/src/test-pobyso-is-polynomial-term.c (revision 138)
1
/** @file test-pobyso-is-polynomial-term.c
2
 * Name & purpose
3
 *
4
 * @author S.T.
5
 * @date 2014-11-14
6
 *
7
 */
8
/******************************************************************************/
9
/* Headers, applying the "particular to general" convention.*/
10

  
11
#include "pobyso.h"
12

  
13
/* includes of local headers */
14

  
15
/* includes of project headers */
16

  
17
/* includes of system headers */
18
#include <stdlib.h>
19
/* Other declarations */
20

  
21
/* Internal prototypes */
22
int
23
read_long_decimal(long int* value, char* string);
24
int
25
read_unsigned_long_decimal(long unsigned int* value, char* string);
26

  
27
/* Types, constants and macros definitions */
28

  
29
/* Global variables */
30

  
31
/* Functions */
32
int
33
read_long_decimal(long int* returnValue, char* string)
34
{
35
  char* endptr[1];
36
  long int convertedValue = 0;
37

  
38
  convertedValue = strtol(string, endptr, 10);
39
  /* For a completely safe conversion *endptr must point to 0 value char. */
40
  if (**endptr != '\0')
41
  {
42
    return 1;
43
  }
44
  else
45
  {
46
    *returnValue = convertedValue;
47
    return 0;
48
  }
49
} /* End read_long_decimal. */
50

  
51
int
52
read_unsigned_long_decimal(long unsigned int* returnValue, char* string)
53
{
54
  char* endptr[1];
55
  long int convertedValue = 0;
56

  
57
  /* Negative sign -> failure. */
58
  if (*string == '-')
59
  {
60
    return 1;
61
  }
62
  convertedValue = strtoul(string, endptr, 10);
63
  /* For a completely safe conversion *endptr must point to 0 value char. */
64
  if (**endptr != '\0')
65
  {
66
    return 1;
67
  }
68
  else
69
  {
70
    *returnValue = convertedValue;
71
    return 0;
72
  }
73
} /* End read_unsigned_long_decimal. */
74

  
75
int
76
main(int argc, char** argv)
77
{
78
  pobyso_func_exp_t expressionSo = NULL;
79
  int outcome = 1;
80

  
81
  sollya_lib_init();
82
  /* No command line argument test the function with the NULL argument. */
83
  if (argc == 1)
84
  {
85
    outcome = pobyso_is_polynomial_term(expressionSo);
86
    sollya_lib_close();
87
    return ! outcome;
88
  }
89

  
90
  pobyso_set_canonical_on();
91
  expressionSo = pobyso_parse_string(argv[1]);
92
  if (expressionSo != NULL)
93
  {
94
    fprintf(stdout, "Sollya expression: ");
95
    pobyso_autoprint(expressionSo);
96
  }
97
  else
98
  {
99
    fprintf(stdout, "NULL expression");
100
  }
101
  if (pobyso_is_polynomial_term(expressionSo))
102
  {
103
    sollya_lib_close();
104
    return 0;
105
  }
106
  else
107
  {
108
    sollya_lib_close();
109
    return 1;
110
  }
111
} /* End main */
0 112

  
pobysoC-4.0/src/test-pobyso-is-int.c (revision 138)
79 79
main(int argc, char** argv)
80 80
{
81 81
  pobyso_func_exp_t expressionSo = NULL;
82
  int outcome = 1;
82 83

  
83
  if (argc < 2)
84
  sollya_lib_init();
85

  
86
  /* No command line argument test the function with the NULL argument. */
87
  if (argc == 1)
84 88
  {
85
    fprintf(stderr,
86
            "Usage: %s quotedExpression \n",
87
            argv[0]);
88
    return 1;
89
    outcome = pobyso_is_int(expressionSo);
90
    sollya_lib_close();
91
    return outcome;
89 92
  }
90 93

  
91 94
  pobyso_set_canonical_on();
......
101 104
  }
102 105
  if (pobyso_is_int(expressionSo))
103 106
  {
107
    sollya_lib_close();
104 108
    return 0;
105 109
  }
106 110
  else
107 111
  {
112
    sollya_lib_close();
108 113
    return 1;
109 114
  }
110 115
} /* End main */
pobysoC-4.0/src/Makefile (revision 138)
13 13
               # Add the suites definition sources
14 14

  
15 15
ALL_TARGETS = test-pobyso-01 test-pobyso-02 \
16
              test-pobyso-constant-expression \
16
              test-pobyso-is-constant-expression \
17 17
              test-pobyso-is-int \
18
              test-pobyso-is-monomial \
19
              test-pobyso-is-polynomial-term \
18 20
              test-pobyso-new-monomial \
19 21
              test-pobyso-subpoly
20 22

  
pobysoC-4.0/src/test-pobyso-is-monomial.sh (revision 138)
1
#! /bin/sh
2
#
3
#
4
TEST_BIN=./test-pobyso-is-monomial
5

  
6
echo
7
## Functions
8
ok_if_fail() {
9
  echo "$@"
10
  eval "$TEST_BIN $ARGUMENTS"
11
if [ $? -eq 0 ] ; then 
12
  echo "Succeeded (but should not have) for $ARGUMENTS"
13
  exit 1
14
fi
15
echo "Correctly failing$WHY."
16
echo
17
}
18
##
19
ok_if_ok() {
20
  echo "$@"
21
  eval "$TEST_BIN $ARGUMENTS"
22
if [ $? -ne 0 ] ; then
23
  echo "Failed for $ARGUMENTS" 
24
  exit 1 
25
fi
26
echo
27
}
28
##
29
ARGUMENTS="\"x\""
30
ok_if_ok "Testing: $ARGUMENTS"
31

  
32
ARGUMENTS="\"1\""
33
ok_if_ok "Testing: $ARGUMENTS"
34

  
35
ARGUMENTS="\"-1\""
36
WHY=" ($ARGUMENTS is not a monomial)"
37
ok_if_fail "Testing: $ARGUMENTS"
38

  
39
ARGUMENTS="\"2\""
40
WHY=" ($ARGUMENTS is not a monomial)"
41
ok_if_fail "Testing: $ARGUMENTS"
42

  
43
ARGUMENTS="\"(x^0)\""
44
ok_if_ok "Testing: $ARGUMENTS"
45

  
46
ARGUMENTS="\"(x^63)\""
47
ok_if_ok "Testing: $ARGUMENTS"
48

  
49
ARGUMENTS="\"x^-2\""
50
WHY=" ($ARGUMENTS is has negative integer exponent)"
51
ok_if_fail "Testing: $ARGUMENTS"
52

  
53
ARGUMENTS="\"x^((2^63)-2)\""
54
ok_if_ok "Testing: $ARGUMENTS"
55

  
56
ARGUMENTS="\"x^((2^63)-1)\""
57
WHY=" (\"2^63-1\" is a too large integer)"
58
ok_if_fail "Testing: $ARGUMENTS"
59

  
60
ARGUMENTS="\"cos(pi)\""
61
WHY=" ($ARGUMENTS is a negative integer)"
62
ok_if_fail "Testing: $ARGUMENTS"
63

  
64
ARGUMENTS="\"x^sin(pi)\""
65
#WHY=" ($ARGUMENTS is not an integer)"
66
ok_if_ok "Testing: $ARGUMENTS"
67

  
68
##
69
ARGUMENTS="\"x^1.1\""
70
WHY=" ($ARGUMENTS is not an integer)"
71
ok_if_fail "Testing: $ARGUMENTS"
72

  
73
ARGUMENTS="\"x^ceil(1.1)\""
74
WHY=" ($ARGUMENTS is not an integer)"
75
ok_if_ok "Testing: $ARGUMENTS"
76

  
77
ARGUMENTS="\"x^(2/3)\""
78
WHY=" ($ARGUMENTS is not an integer)"
79
ok_if_fail "Testing: $ARGUMENTS"
80

  
81
ARGUMENTS="\"-1.1\""
82
WHY=" ($ARGUMENTS is not a positive integer)"
83
ok_if_fail "Testing: $ARGUMENTS"
84

  
85
ARGUMENTS="\"x^floor(-1.1)\""
86
WHY=" (\"floor(-1.1)\" is not a positive integer)"
87
ok_if_fail "Testing: $ARGUMENTS"
88

  
89
ARGUMENTS="\"x+2\""
90
WHY=" ($ARGUMENTS is not a monomial)"
91
ok_if_fail "Testing: $ARGUMENTS"
92

  
93
##
94
ARGUMENTS="\"4-2*x+4*x^2\""
95
WHY=" (expression not a monomial)"
96
ok_if_fail "Testing: $ARGUMENTS"
97

  
98
##
99
ARGUMENTS="\"yx+\""
100
WHY=" ($ARGUMENTS not expression)"
101
ok_if_fail "Testing: $ARGUMENTS"
102

  
103
##
104
ARGUMENTS="\"1/0\""
105
WHY=" ($ARGUMENTS not a number)"
106
ok_if_fail "Testing: $ARGUMENTS"
107

  
108
##
109
ARGUMENTS="\"exp(1000000)\""
110
WHY=" ($ARGUMENTS is too large)"
111
ok_if_fail "Testing: $ARGUMENTS"
112

  
113
ARGUMENTS="\"-exp(1000000)\""
114
WHY=" ($ARGUMENTS is too small)"
115
ok_if_fail "Testing: $ARGUMENTS"
116

  
117
ARGUMENTS="\"+infty\""
118
WHY=" ($ARGUMENTS is infinity)"
119
ok_if_fail "Testing: $ARGUMENTS"
120

  
121
ARGUMENTS="\"infty\""
122
WHY=" ($ARGUMENTS is infinity)"
123
ok_if_fail "Testing: $ARGUMENTS"
124

  
125
ARGUMENTS="\"-infty\""
126
WHY=" ($ARGUMENTS is infinity)"
127
ok_if_fail "Testing: $ARGUMENTS"
128

  
129
##
130
echo "Tests terminated without error."
131
echo
0 132

  
pobysoC-4.0/src/test-pobyso-is-monomial.c (revision 138)
1
/** @file test-pobyso-monomial-int.c
2
 * Name & purpose
3
 *
4
 * @author S.T.
5
 * @date 2014-11-14
6
 *
7
 */
8
/******************************************************************************/
9
/* Headers, applying the "particular to general" convention.*/
10

  
11
#include "pobyso.h"
12

  
13
/* includes of local headers */
14

  
15
/* includes of project headers */
16

  
17
/* includes of system headers */
18
#include <stdlib.h>
19
/* Other declarations */
20

  
21
/* Internal prototypes */
22
int
23
read_long_decimal(long int* value, char* string);
24
int
25
read_unsigned_long_decimal(long unsigned int* value, char* string);
26

  
27
/* Types, constants and macros definitions */
28

  
29
/* Global variables */
30

  
31
/* Functions */
32
int
33
read_long_decimal(long int* returnValue, char* string)
34
{
35
  char* endptr[1];
36
  long int convertedValue = 0;
37

  
38
  convertedValue = strtol(string, endptr, 10);
39
  /* For a completely safe conversion *endptr must point to 0 value char. */
40
  if (**endptr != '\0')
41
  {
42
    return 1;
43
  }
44
  else
45
  {
46
    *returnValue = convertedValue;
47
    return 0;
48
  }
49
} /* End read_long_decimal. */
50

  
51
int
52
read_unsigned_long_decimal(long unsigned int* returnValue, char* string)
53
{
54
  char* endptr[1];
55
  long int convertedValue = 0;
56

  
57
  /* Negative sign -> failure. */
58
  if (*string == '-')
59
  {
60
    return 1;
61
  }
62
  convertedValue = strtoul(string, endptr, 10);
63
  /* For a completely safe conversion *endptr must point to 0 value char. */
64
  if (**endptr != '\0')
65
  {
66
    return 1;
67
  }
68
  else
69
  {
70
    *returnValue = convertedValue;
71
    return 0;
72
  }
73
} /* End read_unsigned_long_decimal. */
74

  
75
int
76
main(int argc, char** argv)
77
{
78
  pobyso_func_exp_t expressionSo = NULL;
79
  int outcome = 1;
80

  
81
  sollya_lib_init();
82
  /* No command line argument test the function with the NULL argument. */
83
  if (argc == 1)
84
  {
85
    outcome = pobyso_is_monomial(expressionSo);
86
    sollya_lib_close();
87
    return ! outcome;
88
  }
89

  
90
  pobyso_set_canonical_on();
91
  expressionSo = pobyso_parse_string(argv[1]);
92
  if (expressionSo != NULL)
93
  {
94
    fprintf(stdout, "Sollya expression: ");
95
    pobyso_autoprint(expressionSo);
96
  }
97
  else
98
  {
99
    fprintf(stdout, "NULL expression");
100
  }
101
  if (pobyso_is_monomial(expressionSo))
102
  {
103
    sollya_lib_close();
104
    return 0;
105
  }
106
  else
107
  {
108
    sollya_lib_close();
109
    return 1;
110
  }
111
} /* End main */
0 112

  
pobysoC-4.0/src/pobyso.c (revision 138)
83 83
  /* Todo: change verbosity suppression strategy with a message call back. */
84 84
  pobyso_set_verbosity_off();
85 85
  test = sollya_lib_get_constant(dummy, obj_to_test);
86
  mpfr_clear(dummy);
87 86
  pobyso_set_verbosity_to(initial_verbosity_level);
88
  return test;
89
} /* End pobyso_is_constant_expression. */
90

  
91
/** @see pobyso.h#pobyso_is_free_var_int_poson_power. */
92
int
93
pobyso_is_free_var_posze_int_power(sollya_obj_t objToTestSo)
94
{
95
  int arity;
96
  sollya_base_function_t headTypeSo;
97
  sollya_obj_t sub1So           = NULL;
98
  sollya_obj_t sub2So           = NULL;
99

  
100
  /* Argument check. */
101
  if (objToTestSo == NULL)
87
  if (test)
102 88
  {
103
    pobyso_error_message("pobyso_is_free_var_int_poson_power",
104
                        "NULL_POINTER_ARGUMENT",
105
                        "The expression is a NULL pointer");
106
    return 0;
89
    if(mpfr_number_p(dummy))
90
    {
91
      mpfr_clear(dummy);
92
      return test;
93
    }
94
    else
95
    {
96
      mpfr_clear(dummy);
97
      return 0;
98
    }
107 99
  }
108
  if (! sollya_lib_obj_is_function(objToTestSo))
100
  else
109 101
  {
110 102
    return 0;
111 103
  }
112
  if (!sollya_lib_get_head_function(&headTypeSo, objToTestSo)) return 0;
113
  if (! sollya_lib_get_subfunctions(objToTestSo,
114
                                    &arity,
115
                                    &sub1So,
116
                                    &sub2So,
117
                                    NULL)) return 0;
118
  /* Power function: arity == 2. */
119
  if (arity != 2) return 0;
120
  if (! pobyso_is_constant_expression(sub1So)) return 0;
121
  return 1;
122
} /* End pobyso_is_free_var_posze_int_power. */
104
} /* End pobyso_is_constant_expression. */
123 105

  
124

  
125 106
/** @see pobyso.h#pobyso_is_monomial. */
126 107
int
127 108
pobyso_is_int(pobyso_func_exp_t exprSo)
......
196 177
  }
197 178
  else
198 179
  {
199
    pobyso_autoprint(exprSo);
200
    pobyso_autoprint(newConstantSo);
201 180
    mpfr_clear(float1M);
202 181
    mpfr_clear(float2M);
203 182
    sollya_lib_clear_obj(newConstantSo);
......
213 192
int
214 193
pobyso_is_monomial(sollya_obj_t objSo)
215 194
{
195
  int arity;
196
  sollya_obj_t subFun1So = NULL;
197
  sollya_obj_t subFun2So = NULL;
198
  sollya_obj_t subFun3So = NULL;
199
  sollya_base_function_t head = 0;
200
  long int exponent = 0;
201
  long int exprIntValue = 0;
202

  
203
  /* Arguments check. */
204
  if (objSo == NULL)
205
  {
206
    pobyso_error_message("pobyso_is_monomial",
207
                        "NULL_POINTER_ARGUMENT",
208
                        "The expression is a NULL pointer");
209
    return 0;
210
  }
211
  /* The object must be a function. */
212
  if (! sollya_lib_obj_is_function(objSo)) return 0;
213
  /* Check if it is the 1 constant. */
214
  if (pobyso_is_int(objSo))
215
  {
216
    if (! sollya_lib_get_constant_as_int64(&exprIntValue, objSo))
217
    {
218
      return 0;
219
    }
220
    else
221
    {
222
      if (exprIntValue == 1) return 1;
223
      else return 0;
224
    }
225
  }
226
  if (! sollya_lib_decompose_function(objSo,
227
                                      &head,
228
                                      &arity,
229
                                      &subFun1So,
230
                                      &subFun2So,
231
                                      NULL)) return 0;
232
  if (arity > 2)
233
  {
234
    if (subFun1So != NULL) sollya_lib_clear_obj(subFun1So);
235
    if (subFun2So != NULL) sollya_lib_clear_obj(subFun2So);
236
    return 0;
237
  }
238
  /* Arity == 1 must be free variable by itself. */
239
  if (arity == 1 && head == SOLLYA_BASE_FUNC_FREE_VARIABLE)
240
  {
241
    if (subFun1So != NULL) sollya_lib_clear_obj(subFun1So);
242
    if (subFun2So != NULL) sollya_lib_clear_obj(subFun2So);
243
    return 1;
244
  }
245
  else
246
  {
247
    /* Another expression. Must be: free variable  ^ poze integer. */
248
    if (arity == 2)
249
    {
250
      if (head != SOLLYA_BASE_FUNC_POW)
251
      {
252
        if (subFun1So != NULL) sollya_lib_clear_obj(subFun1So);
253
        if (subFun2So != NULL) sollya_lib_clear_obj(subFun2So);
254
        return 0;
255
      }
256
      if (! pobyso_is_int(subFun2So))
257
      {
258
        if (subFun1So != NULL) sollya_lib_clear_obj(subFun1So);
259
        if (subFun2So != NULL) sollya_lib_clear_obj(subFun2So);
260
        return 0;
261
      }
262
      if (! sollya_lib_get_constant_as_int64(&exponent, subFun2So))
263
      {
264
        if (subFun1So != NULL) sollya_lib_clear_obj(subFun1So);
265
        if (subFun2So != NULL) sollya_lib_clear_obj(subFun2So);
266
        return 0;
267
      }
268
      if (exponent < 0)
269
      {
270
        if (subFun1So != NULL) sollya_lib_clear_obj(subFun1So);
271
        if (subFun2So != NULL) sollya_lib_clear_obj(subFun2So);
272
        return 0;
273
      }
274
      if (subFun2So != NULL) sollya_lib_clear_obj(subFun2So);
275
      /* Check that the first subfunction is the free variable. */
276
      if (! sollya_lib_decompose_function(subFun1So,
277
                                          &head,
278
                                          &arity,
279
                                          &subFun2So,
280
                                          &subFun3So,
281
                                          NULL))
282
      {
283
        if (subFun1So != NULL) sollya_lib_clear_obj(subFun1So);
284
        return 0;
285
      }
286
      if (arity == 1 && head == SOLLYA_BASE_FUNC_FREE_VARIABLE)
287
      {
288
        if (subFun1So != NULL) sollya_lib_clear_obj(subFun1So);
289
        if (subFun2So != NULL) sollya_lib_clear_obj(subFun2So);
290
        if (subFun3So != NULL) sollya_lib_clear_obj(subFun3So);
291
        return 1;
292
      }
293
      else
294
      {
295
        if (subFun1So != NULL) sollya_lib_clear_obj(subFun1So);
296
        if (subFun2So != NULL) sollya_lib_clear_obj(subFun2So);
297
        return 0;
298
      }
299
    } /* End if arity == 2. */
300
  } /* End else if arity == 1. */
216 301
  return 0;
217 302
} /* End pobyso_is_monomial. */
218 303

  
304
/** @see pobyso.h#pobyso_is_polynomial_term.
305
 * Strategy: check that the object is a functional expression and
306
 * if so check that it is made of cte * monomial.
307
 */
308
int
309
pobyso_is_polynomial_term(sollya_obj_t objSo)
310
{
311
  int arity;
312
  sollya_obj_t subFun1So = NULL;
313
  sollya_obj_t subFun2So = NULL;
314
  sollya_base_function_t head = 0;
315

  
316
  /* Arguments check. */
317
  if (objSo == NULL)
318
  {
319
    pobyso_error_message("pobyso_is_polynomial_term",
320
                        "NULL_POINTER_ARGUMENT",
321
                        "The expression is a NULL pointer");
322
    return 0;
323
  }
324
  /* The object must be a function. */
325
  if (! sollya_lib_obj_is_function(objSo)) return 0;
326
  /* A constant expression is degree 0 polynomial term. */
327
  if (pobyso_is_constant_expression(objSo)) return 1;
328
  /* A monomial is a polynomial term. */
329
  if (pobyso_is_monomial(objSo)) return 1;
330
  /* Decompose the functional expression and study the elements. */
331
  if (! sollya_lib_decompose_function(objSo,
332
                                      &head,
333
                                      &arity,
334
                                      &subFun1So,
335
                                      &subFun2So,
336
                                      NULL)) return 0;
337
  /* Monomial case has been dealt with abobe. */
338
  if (arity != 2)
339
  {
340
    if (subFun1So != NULL) sollya_lib_clear_obj(subFun1So);
341
    if (subFun2So != NULL) sollya_lib_clear_obj(subFun2So);
342
    return 0;
343
  }
344
  /* The expression must be: cte  * monomial or monomial * cte. */
345
  if (head != SOLLYA_BASE_FUNC_MUL)
346
  {
347
    if (subFun1So != NULL) sollya_lib_clear_obj(subFun1So);
348
    if (subFun2So != NULL) sollya_lib_clear_obj(subFun2So);
349
    return 0;
350
  }
351
  if (! pobyso_is_monomial(subFun2So))
352
  {
353
    if (! pobyso_is_constant_expression(subFun2So) ||
354
        ! pobyso_is_monomial(subFun1So))
355
    {
356
      if (subFun1So != NULL) sollya_lib_clear_obj(subFun1So);
357
      if (subFun2So != NULL) sollya_lib_clear_obj(subFun2So);
358
      return 0;
359
    }
360
  }
361
  else
362
  {
363
    if (! pobyso_is_constant_expression(subFun1So))
364
    {
365
      if (subFun1So != NULL) sollya_lib_clear_obj(subFun1So);
366
      if (subFun2So != NULL) sollya_lib_clear_obj(subFun2So);
367
      return 0;
368
    }
369
  }
370
  return 1;
371
} /* End pobyso_is_polynomial_term. */
219 372
/** @see pobyso.h#pobyso_new_monomial. */
220 373
pobyso_func_exp_t
221 374
pobyso_new_monomial(pobyso_func_exp_t coefficientSo, long degree)
pobysoC-4.0/src/test-pobyso-is-constant-expression.sh (revision 138)
1
#! /bin/sh
2
#
3
#
4
TEST_BIN=./test-pobyso-is-constant-expression
5

  
6
echo
7
## Functions
8
ok_if_fail() {
9
  echo "$@"
10
  eval "$TEST_BIN $ARGUMENTS"
11
if [ $? -eq 0 ] ; then 
12
  echo "Succeeded (but should not have) for $ARGUMENTS"
13
  exit 1
14
fi
15
echo "Correctly failing$WHY."
16
echo
17
}
18
##
19
ok_if_ok() {
20
  echo "$@"
21
  eval "$TEST_BIN $ARGUMENTS"
22
if [ $? -ne 0 ] ; then
23
  echo "Failed for $ARGUMENTS" 
24
  exit 1 
25
fi
26
echo
27
}
28
##
29
ARGUMENTS=
30
WHY=" (NULL argument)"
31
ok_if_fail "Testing: $ARGUMENTS"
32

  
33
##
34
ARGUMENTS="\"1\""
35
ok_if_ok "Testing: $ARGUMENTS"
36

  
37
##
38
ARGUMENTS="\"-1\""
39
ok_if_ok "Testing: $ARGUMENTS"
40

  
41
##
42
ARGUMENTS="\"cos(pi)\""
43
ok_if_ok "Testing: $ARGUMENTS"
44

  
45
##
46
ARGUMENTS="\"1.1\""
47
#WHY=" (because -1 in exponents list)"
48
ok_if_ok "Testing: $ARGUMENTS"
49

  
50
##
51
ARGUMENTS="\"cos(pi/4)^(exp(cos(0)))\""
52
#WHY=" (because -1 in exponents list)"
53
ok_if_ok "Testing: $ARGUMENTS"
54

  
55
##
56
ARGUMENTS="\"1.1*cos(pi)^(exp(cos(0)))\""
57
WHY=" (because \"cos(pi)\" (i.e -1) is raised to a fractionnal power)"
58
ok_if_fail "Testing: $ARGUMENTS"
59

  
60
##
61
echo "Tests terminated without error."
62
echo
0 63

  
pobysoC-4.0/src/test-pobyso-is-polynomial-term.sh (revision 138)
1
#! /bin/sh
2
#
3
#
4
TEST_BIN=./test-pobyso-is-polynomial-term
5

  
6
echo
7
## Functions
8
ok_if_fail() {
9
  echo "$@"
10
  eval "$TEST_BIN $ARGUMENTS"
11
if [ $? -eq 0 ] ; then 
12
  echo "Succeeded (but should not have) for $ARGUMENTS"
13
  exit 1
14
fi
15
echo "Correctly failing$WHY."
16
echo
17
}
18
##
19
ok_if_ok() {
20
  echo "$@"
21
  eval "$TEST_BIN $ARGUMENTS"
22
if [ $? -ne 0 ] ; then
23
  echo "Failed for $ARGUMENTS" 
24
  exit 1 
25
fi
26
echo
27
}
28
##
29
ARGUMENTS="\"x\""
30
ok_if_ok "Testing: $ARGUMENTS"
31

  
32
ARGUMENTS="\"1\""
33
ok_if_ok "Testing: $ARGUMENTS"
34

  
35
ARGUMENTS="\"-1\""
36
WHY=" ($ARGUMENTS is not a monomial)"
37
ok_if_ok "Testing: $ARGUMENTS"
38

  
39
ARGUMENTS="\"2\""
40
WHY=" ($ARGUMENTS is not a monomial)"
41
ok_if_ok "Testing: $ARGUMENTS"
42

  
43
ARGUMENTS="\"(x^0)\""
44
ok_if_ok "Testing: $ARGUMENTS"
45

  
46
ARGUMENTS="\"(x^63)\""
47
ok_if_ok "Testing: $ARGUMENTS"
48

  
49
ARGUMENTS="\"x^-2\""
50
WHY=" ($ARGUMENTS is has negative integer exponent)"
51
ok_if_fail "Testing: $ARGUMENTS"
52

  
53
ARGUMENTS="\"x^((2^63)-2)\""
54
ok_if_ok "Testing: $ARGUMENTS"
55

  
56
ARGUMENTS="\"x^((2^63)-1)\""
57
WHY=" (\"2^63-1\" is a too large integer)"
58
ok_if_fail "Testing: $ARGUMENTS"
59

  
60
ARGUMENTS="\"(x^(2))*3\""
61
ok_if_ok "Testing: $ARGUMENTS"
62

  
63
ARGUMENTS="\"cos(pi)\""
64
WHY=" ($ARGUMENTS is a negative integer)"
65
ok_if_ok "Testing: $ARGUMENTS"
66

  
67
ARGUMENTS="\"cos(pi)*x^exp(0)\""
68
WHY=" ($ARGUMENTS is a negative integer)"
69
ok_if_ok "Testing: $ARGUMENTS"
70

  
71
ARGUMENTS="\"x^(2*exp(0))*cos(pi)*4\""
72
WHY=" ($ARGUMENTS is a negative integer)"
73
ok_if_ok "Testing: $ARGUMENTS"
74

  
75
ARGUMENTS="\"x^exp(0)*cos(pi)\""
76
WHY=" ($ARGUMENTS is a negative integer)"
77
ok_if_ok "Testing: $ARGUMENTS"
78

  
79
ARGUMENTS="\"x^sin(pi)\""
80
#WHY=" ($ARGUMENTS is not an integer)"
81
ok_if_ok "Testing: $ARGUMENTS"
82

  
83
##
84
ARGUMENTS="\"x^1.1\""
85
WHY=" ($ARGUMENTS is not an integer)"
86
ok_if_fail "Testing: $ARGUMENTS"
87

  
88
ARGUMENTS="\"x^ceil(1.1)\""
89
WHY=" ($ARGUMENTS is not an integer)"
90
ok_if_ok "Testing: $ARGUMENTS"
91

  
92
ARGUMENTS="\"-1.1\""
93
WHY=" ($ARGUMENTS is not a positive integer)"
94
ok_if_ok "Testing: $ARGUMENTS"
95

  
96
ARGUMENTS="\"x^floor(-1.1)\""
97
WHY=" (\"floor(-1.1)\" is not a positive integer)"
98
ok_if_fail "Testing: $ARGUMENTS"
99

  
100
ARGUMENTS="\"x+2\""
101
WHY=" ($ARGUMENTS is not a monomial)"
102
ok_if_fail "Testing: $ARGUMENTS"
103

  
104
ARGUMENTS="\"x^(2/3)\""
105
WHY=" (\"2/3\" is not an integer)"
106
ok_if_fail "Testing: $ARGUMENTS"
107

  
108
ARGUMENTS="\"x^(2)*(2/3)\""
109
WHY=" ($ARGUMENTS is not an integer)"
110
ok_if_ok "Testing: $ARGUMENTS"
111

  
112
##
113
ARGUMENTS="\"4-2*x+4*x^2\""
114
WHY=" (expression not a polynomial term)"
115
ok_if_fail "Testing: $ARGUMENTS"
116

  
117
##
118
ARGUMENTS="\"yx+\""
119
WHY=" ($ARGUMENTS not expression)"
120
ok_if_fail "Testing: $ARGUMENTS"
121

  
122
##
123
ARGUMENTS="\"1/0\""
124
WHY=" ($ARGUMENTS not a number)"
125
ok_if_fail "Testing: $ARGUMENTS"
126

  
127
##
128
ARGUMENTS="\"exp(1000000)\""
129
WHY=" ($ARGUMENTS is too large)"
130
ok_if_ok "Testing: $ARGUMENTS"
131

  
132
ARGUMENTS="\"-exp(1000000)\""
133
WHY=" ($ARGUMENTS is too small)"
134
ok_if_ok "Testing: $ARGUMENTS"
135

  
136
ARGUMENTS="\"+infty\""
137
WHY=" ($ARGUMENTS is infinity)"
138
ok_if_fail "Testing: $ARGUMENTS"
139

  
140
ARGUMENTS="\"infty\""
141
WHY=" ($ARGUMENTS is infinity)"
142
ok_if_fail "Testing: $ARGUMENTS"
143

  
144
ARGUMENTS="\"-infty\""
145
WHY=" ($ARGUMENTS is infinity)"
146
ok_if_fail "Testing: $ARGUMENTS"
147

  
148
ARGUMENTS="\"-infty*x^2\""
149
WHY=" ($ARGUMENTS has infinity)"
150
ok_if_fail "Testing: $ARGUMENTS"
151

  
152
ARGUMENTS="\"2*x^infty\""
153
WHY=" ($ARGUMENTS has infinity)"
154
ok_if_fail "Testing: $ARGUMENTS"
155

  
156

  
157
##
158
echo "Tests terminated without error."
159
echo
0 160

  
pobysoC-4.0/src/pobyso.h (revision 138)
80 80
int
81 81
pobyso_is_constant_expression(sollya_obj_t obj_to_text);
82 82

  
83
int
84
pobyso_is_free_var_posze_int_power(sollya_obj_t objToTestSo);
85

  
86 83
/**
87
 * Check if an expression is a monomial (made of a constant expression
88
 * and the free variable to an integer positive or null power.
84
 * Check if an expression is a monomial (the free variable to an integer
85
 * positive or null power.
89 86
 * @param exprSo: a Sollya functional expression object;
90 87
 * @return 1 if exprSo is a monomial (as defined above), 0 otherwise.
91 88
 */
92 89
int pobyso_is_monomial(pobyso_func_exp_t exprSo);
93 90

  
94 91
/**
92
 * Check if an expression is a polynomial term (monome)
93
 * (a constant * the free variable to an integer positive or null power or
94
 *  the free variable to an integer positive or null power * a constant).
95
 * @param exprSo: a Sollya functional expression object;
96
 * @return 1 if exprSo is a polynomial term (as defined above), 0 otherwise.
97
 */
98
int pobyso_is_polynomial_term(pobyso_func_exp_t exprSo);
99

  
100
/**
95 101
 * Check if an expression is an integer.
96 102
 */
97 103
int
98 104

  

Formats disponibles : Unified diff