Ian Jauslin
summaryrefslogtreecommitdiff
blob: e74319179f3cfdafe057c1a8c41de0660b4c2572 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
/*
Copyright 2016 Ian Jauslin

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

/*
  Base functions for integration

  see integral_*.h for the values taken by INTEGRAL_FUNC, etc...
*/


// compute the integral of a real function of 1 variable using the Gauss-Legendre scheme
int INTEGRAL_FUNC(integrate_gauss) (INTEGRAL_FLOAT_TYPE* out, int (*func)(INTEGRAL_FLOAT_TYPE*, INTEGRAL_FLOAT_TYPE, void*), INTEGRAL_FLOAT_TYPE lower, INTEGRAL_FLOAT_TYPE upper, INTEGRAL_FLOATARRAY_TYPE abcissa, INTEGRAL_FLOATARRAY_TYPE weights, void* extra_args){
  unsigned int i;
  INTEGRAL_FLOAT_TYPE valf, delta, avg, x;
  int ret;

  // check arguments
  if(abcissa.length != weights.length){
    return(LIBINUM_ERROR_SIZE_MISMATCH);
  }

  #ifdef INTEGRAL_FLOAT_INIT
    INTEGRAL_FLOAT_INIT(valf);
    INTEGRAL_FLOAT_INIT(delta);
    INTEGRAL_FLOAT_INIT(avg);
    INTEGRAL_FLOAT_INIT(x);
  #endif

  // init to 0
  INTEGRAL_FLOAT_SET_UI(*out, 0);

  // half length of interval
  INTEGRAL_FLOAT_SUB(delta, upper, lower);
  INTEGRAL_FLOAT_DIV_UI(delta, delta, 2);
  // average of interval
  INTEGRAL_FLOAT_ADD(avg, upper, lower);
  INTEGRAL_FLOAT_DIV_UI(avg, avg, 2);

  for(i=0;i<abcissa.length;i++){
    // evaluate at x
    INTEGRAL_FLOAT_MUL(x, delta, abcissa.values[i]);
    INTEGRAL_FLOAT_ADD(x, x, avg);

    ret=(*func)(&valf, x, extra_args);
    if(ret<0){
      #ifdef INTEGRAL_FLOAT_FREE
	INTEGRAL_FLOAT_FREE(valf);
	INTEGRAL_FLOAT_FREE(delta);
	INTEGRAL_FLOAT_FREE(avg);
	INTEGRAL_FLOAT_FREE(x);
      #endif
      return(ret);
    }
    // check whether valf is a number
    if(! INTEGRAL_FLOAT_ISNUMBER(valf)){
      #ifdef INTEGRAL_FLOAT_FREE
	INTEGRAL_FLOAT_FREE(valf);
	INTEGRAL_FLOAT_FREE(delta);
	INTEGRAL_FLOAT_FREE(avg);
	INTEGRAL_FLOAT_FREE(x);
      #endif
      return(LIBINUM_ERROR_NAN);
    }
      
    INTEGRAL_FLOAT_MUL(valf, valf, weights.values[i]);
    INTEGRAL_FLOAT_ADD(*out, *out, valf);
  }

  INTEGRAL_FLOAT_MUL(*out, *out, delta);

  #ifdef INTEGRAL_FLOAT_FREE
    INTEGRAL_FLOAT_FREE(valf);
    INTEGRAL_FLOAT_FREE(delta);
    INTEGRAL_FLOAT_FREE(avg);
    INTEGRAL_FLOAT_FREE(x);
  #endif

  return(0);
}

// multithreaded version
// arguments to pass to each thread
struct INTEGRAL_FUNC(pthread_integrate_gauss_args) {
  // partial sum of the values assigned to the thread
  INTEGRAL_FLOAT_TYPE out;
  // abcissa
  INTEGRAL_FLOATARRAY_TYPE x;
  // weights
  INTEGRAL_FLOATARRAY_TYPE weights;
  // pointer to the function to evaluate
  int (*func)(INTEGRAL_FLOAT_TYPE*, INTEGRAL_FLOAT_TYPE, void*);
  // extra arguments passed to func
  void* extra_args;
  // return value
  int ret;
};
int INTEGRAL_FUNC(integrate_gauss_multithread) (INTEGRAL_FLOAT_TYPE* out, int (*func)(INTEGRAL_FLOAT_TYPE*, INTEGRAL_FLOAT_TYPE, void*), INTEGRAL_FLOAT_TYPE lower, INTEGRAL_FLOAT_TYPE upper, INTEGRAL_FLOATARRAY_TYPE abcissa, INTEGRAL_FLOATARRAY_TYPE weights, void* extra_args, unsigned int threads, array_pthread_t* thread_ids){
  unsigned int i;
  INTEGRAL_FLOAT_TYPE x, delta, avg;
  struct INTEGRAL_FUNC(pthread_integrate_gauss_args) args[threads];
  int ret=0;
  unsigned int thread_nr;

  array_pthread_t_init(thread_ids, threads);
  thread_ids->length=threads;

  // check arguments
  if(abcissa.length != weights.length){
    return(LIBINUM_ERROR_SIZE_MISMATCH);
  }

  #ifdef INTEGRAL_FLOAT_INIT
    INTEGRAL_FLOAT_INIT(delta);
    INTEGRAL_FLOAT_INIT(avg);
    INTEGRAL_FLOAT_INIT(x);
  #endif

  // init to 0
  INTEGRAL_FLOAT_SET_UI(*out, 0);

  // half length of interval
  INTEGRAL_FLOAT_SUB(delta, upper, lower);
  INTEGRAL_FLOAT_DIV_UI(delta, delta, 2);
  // average of interval
  INTEGRAL_FLOAT_ADD(avg, upper, lower);
  INTEGRAL_FLOAT_DIV_UI(avg, avg, 2);

  // inits
  for(thread_nr=0;thread_nr<threads;thread_nr++){
    INTEGRAL_FLOATARRAY_FUNC(init) (&(args[thread_nr].x),abcissa.length/threads+1);
    INTEGRAL_FLOATARRAY_FUNC(init) (&(args[thread_nr].weights),abcissa.length/threads+1);
    #ifdef INTEGRAL_FLOAT_INIT
      INTEGRAL_FLOAT_INIT(args[thread_nr].out);
    #endif
  }

  // set abcissa and weights
  for(i=0,thread_nr=0;i<abcissa.length;i++,thread_nr=(thread_nr+1)%threads){
    INTEGRAL_FLOAT_MUL(x, delta, abcissa.values[i]);
    INTEGRAL_FLOAT_ADD(x, x, avg);

    INTEGRAL_FLOATARRAY_FUNC(append) (x, &(args[thread_nr].x));
    INTEGRAL_FLOATARRAY_FUNC(append) (weights.values[i], &(args[thread_nr].weights));
  }

  for(thread_nr=0;thread_nr<threads;thread_nr++){
    // set func
    args[thread_nr].func=func;
    // set extra_args
    args[thread_nr].extra_args=extra_args;
    // init ret
    args[thread_nr].ret=0;
    // run threads
    pthread_create(thread_ids->values+thread_nr, NULL, INTEGRAL_FUNC(integrate_gauss_thread), (void*)(args+thread_nr));
  }

  // wait for completion and join
  for(thread_nr=0;thread_nr<threads;thread_nr++){
    pthread_join(thread_ids->values[thread_nr], NULL);

    if(args[thread_nr].ret<0){
      ret=args[thread_nr].ret;
    }
    else{
      INTEGRAL_FLOAT_ADD(*out, *out, args[thread_nr].out);
    }
  }

  // multiply by size of interval
  INTEGRAL_FLOAT_MUL(*out, *out, delta);

  for(thread_nr=0;thread_nr<threads;thread_nr++){
    INTEGRAL_FLOATARRAY_FUNC(free) (args[thread_nr].x);
    INTEGRAL_FLOATARRAY_FUNC(free) (args[thread_nr].weights);
    #ifdef INTEGRAL_FLOAT_FREE
      INTEGRAL_FLOAT_FREE(args[thread_nr].out);
    #endif
  }

  #ifdef INTEGRAL_FLOAT_FREE
    INTEGRAL_FLOAT_FREE(delta);
    INTEGRAL_FLOAT_FREE(avg);
    INTEGRAL_FLOAT_FREE(x);
  #endif


  return(ret);
}
// per-thread function
void* INTEGRAL_FUNC(integrate_gauss_thread) (void* args){
  unsigned int i;
  INTEGRAL_FLOAT_TYPE valf;
  int ret;
  struct INTEGRAL_FUNC(pthread_integrate_gauss_args)* argument=((struct INTEGRAL_FUNC(pthread_integrate_gauss_args)*)args);
  #ifdef INTEGRAL_FLOAT_INIT
    INTEGRAL_FLOAT_INIT(valf);
  #endif

  INTEGRAL_FLOAT_SET_UI(argument->out, 0);

  for(i=0;i<argument->x.length;i++){
    // evaluate
    ret=(*(argument->func))(&valf, argument->x.values[i], argument->extra_args);

    if(ret<0){
      #ifdef INTEGRAL_FLOAT_FREE
	INTEGRAL_FLOAT_FREE(valf);
      #endif
      argument->ret=ret;
      return(NULL);
    }
    // check whether valf is a number
    if(! INTEGRAL_FLOAT_ISNUMBER(valf)){
      #ifdef INTEGRAL_FLOAT_FREE
	INTEGRAL_FLOAT_FREE(valf);
      #endif
      argument->ret=LIBINUM_ERROR_NAN;
      return(NULL);
    }

    INTEGRAL_FLOAT_MUL(valf, valf, argument->weights.values[i]);
    INTEGRAL_FLOAT_ADD(argument->out, argument->out, valf);
  }
  #ifdef INTEGRAL_FLOAT_FREE
    INTEGRAL_FLOAT_FREE(valf);
  #endif

  return(NULL);
}



// smart management of temporary variables: initialize as many as needed but allow them to be re-used instead of freeing them
#ifdef INTEGRAL_FLOAT_INIT
int INTEGRAL_FUNC(integrate_gauss_smarttmp) (INTEGRAL_FLOAT_TYPE* out, int (*func)(INTEGRAL_FLOAT_TYPE*, INTEGRAL_FLOAT_TYPE, void*), INTEGRAL_FLOAT_TYPE lower, INTEGRAL_FLOAT_TYPE upper, INTEGRAL_FLOATARRAY_TYPE abcissa, INTEGRAL_FLOATARRAY_TYPE weights, INTEGRAL_FLOATARRAY_TYPE* tmps, void* extra_args){
  unsigned int i;
  int ret;

  // check arguments
  if(abcissa.length != weights.length){
    return(LIBINUM_ERROR_SIZE_MISMATCH);
  }

  // allocate tmp values if needed
  INTEGRAL_FLOATARRAY_FUNC(alloc_tmps)(4, tmps);

  // init to 0
  INTEGRAL_FLOAT_SET_UI(*out, 0);

  // half length of interval
  INTEGRAL_FLOAT_SUB(tmps->values[0], upper, lower);
  INTEGRAL_FLOAT_DIV_UI(tmps->values[0], tmps->values[0], 2);
  // average of interval
  INTEGRAL_FLOAT_ADD(tmps->values[1], upper, lower);
  INTEGRAL_FLOAT_DIV_UI(tmps->values[1], tmps->values[1], 2);

  for(i=0;i<abcissa.length;i++){
    // evaluation point
    INTEGRAL_FLOAT_MUL(tmps->values[2], tmps->values[0], abcissa.values[i]);
    INTEGRAL_FLOAT_ADD(tmps->values[2], tmps->values[2], tmps->values[1]);

    ret=(*func)(tmps->values+3, tmps->values[2], extra_args);
    if(ret<0){
      return(ret);
    }
    // check whether tmps->values[3] is a number
    if(! INTEGRAL_FLOAT_ISNUMBER(tmps->values[3])){
      return(LIBINUM_ERROR_NAN);
    }
      
    INTEGRAL_FLOAT_MUL(tmps->values[3], tmps->values[3], weights.values[i]);
    INTEGRAL_FLOAT_ADD(*out, *out, tmps->values[3]);
  }

  INTEGRAL_FLOAT_MUL(*out, *out, tmps->values[0]);

  return(0);
}
#endif

// multithreaded version with smart management of temporary variables (only for datatypes that need to be initialized)
#ifdef INTEGRAL_FLOAT_INIT
// arguments to pass to each thread
struct INTEGRAL_FUNC(pthread_integrate_gauss_smarttmp_args) {
  // partial sum of the values assigned to the thread
  INTEGRAL_FLOAT_TYPE* out;
  // abcissa
  INTEGRAL_FLOATARRAY_TYPE x;
  // weights
  INTEGRAL_FLOATARRAY_TYPE weights;
  // tmp
  INTEGRAL_FLOAT_TYPE* tmp;
  // pointer to the function to evaluate
  int (*func)(INTEGRAL_FLOAT_TYPE*, INTEGRAL_FLOAT_TYPE, void*);
  // extra arguments passed to func
  void* extra_args;
  // return value
  int ret;
};
int INTEGRAL_FUNC(integrate_gauss_smarttmp_multithread) (INTEGRAL_FLOAT_TYPE* out, int (*func)(INTEGRAL_FLOAT_TYPE*, INTEGRAL_FLOAT_TYPE, void*), INTEGRAL_FLOAT_TYPE lower, INTEGRAL_FLOAT_TYPE upper, INTEGRAL_FLOATARRAY_TYPE abcissa, INTEGRAL_FLOATARRAY_TYPE weights, INTEGRAL_FLOATARRAY_TYPE* tmps, void* extra_args, unsigned int threads, array_pthread_t* thread_ids){
  unsigned int i;
  struct INTEGRAL_FUNC(pthread_integrate_gauss_smarttmp_args) args[threads];
  int ret=0;
  unsigned int thread_nr;

  array_pthread_t_init(thread_ids, threads);
  thread_ids->length=threads;

  // check arguments
  if(abcissa.length != weights.length){
    return(LIBINUM_ERROR_SIZE_MISMATCH);
  }

  // allocate tmps if needed
  if(tmps->memory<2+2*threads+abcissa.length){
    // no need to resize since the values should not be kept
    INTEGRAL_FLOATARRAY_FUNC(free)(*tmps);
    INTEGRAL_FLOATARRAY_FUNC(init)(tmps, 2+2*threads+abcissa.length);
  }
  for (i=tmps->length;i<2+2*threads+abcissa.length;i++){
    INTEGRAL_FLOAT_INIT(tmps->values[i]);
    (tmps->length)++;
  }


  // init to 0
  INTEGRAL_FLOAT_SET_UI(*out, 0);

  // half length of interval
  INTEGRAL_FLOAT_SUB(tmps->values[0], upper, lower);
  INTEGRAL_FLOAT_DIV_UI(tmps->values[0], tmps->values[0], 2);
  // average of interval
  INTEGRAL_FLOAT_ADD(tmps->values[1], upper, lower);
  INTEGRAL_FLOAT_DIV_UI(tmps->values[1], tmps->values[1], 2);

  // inits
  for(thread_nr=0;thread_nr<threads;thread_nr++){
    INTEGRAL_FLOATARRAY_FUNC(init) (&(args[thread_nr].x),abcissa.length/threads+1);
    INTEGRAL_FLOATARRAY_FUNC(init) (&(args[thread_nr].weights),abcissa.length/threads+1);
    args[thread_nr].out=tmps->values+2+thread_nr;
    args[thread_nr].tmp=tmps->values+2+threads+thread_nr;
  }

  // set abcissa and weights
  for(i=0,thread_nr=0;i<abcissa.length;i++,thread_nr=(thread_nr+1)%threads){
    INTEGRAL_FLOAT_MUL(tmps->values[2+2*threads+i], tmps->values[0], abcissa.values[i]);
    INTEGRAL_FLOAT_ADD(tmps->values[2+2*threads+i], tmps->values[2+2*threads+i], tmps->values[1]);

    INTEGRAL_FLOATARRAY_FUNC(append_noinit) (tmps->values[2+2*threads+i], &(args[thread_nr].x));
    INTEGRAL_FLOATARRAY_FUNC(append_noinit) (weights.values[i], &(args[thread_nr].weights));
  }

  for(thread_nr=0;thread_nr<threads;thread_nr++){
    // set func
    args[thread_nr].func=func;
    // set extra_args
    args[thread_nr].extra_args=extra_args;
    // init ret
    args[thread_nr].ret=0;
    // run threads
    pthread_create(thread_ids->values+thread_nr, NULL, INTEGRAL_FUNC(integrate_gauss_smarttmp_thread), (void*)(args+thread_nr));
  }

  // wait for completion and join
  for(thread_nr=0;thread_nr<threads;thread_nr++){
    pthread_join(thread_ids->values[thread_nr], NULL);

    if(args[thread_nr].ret<0){
      ret=args[thread_nr].ret;
    }
    else{
      INTEGRAL_FLOAT_ADD(*out, *out, *(args[thread_nr].out));
    }
  }

  // multiply by size of interval
  INTEGRAL_FLOAT_MUL(*out, *out, tmps->values[0]);

  // free x and weights
  for(thread_nr=0;thread_nr<threads;thread_nr++){
    INTEGRAL_FLOATARRAY_FUNC(free_vects)(args[thread_nr].x);
    INTEGRAL_FLOATARRAY_FUNC(free_vects)(args[thread_nr].weights);
  }
  return(ret);
}
// per-thread function
void* INTEGRAL_FUNC(integrate_gauss_smarttmp_thread) (void* args){
  unsigned int i;
  int ret;
  struct INTEGRAL_FUNC(pthread_integrate_gauss_smarttmp_args)* argument=((struct INTEGRAL_FUNC(pthread_integrate_gauss_smarttmp_args)*)args);

  INTEGRAL_FLOAT_SET_UI(*(argument->out), 0);

  for(i=0;i<argument->x.length;i++){
    // evaluate
    ret=(*(argument->func))(argument->tmp, argument->x.values[i], argument->extra_args);

    if(ret<0){
      argument->ret=ret;
      return(NULL);
    }
    // check whether argument->tmp is a number
    if(! INTEGRAL_FLOAT_ISNUMBER(*(argument->tmp))){
      argument->ret=LIBINUM_ERROR_NAN;
      return(NULL);
    }

    INTEGRAL_FLOAT_MUL(*(argument->tmp), *(argument->tmp), argument->weights.values[i]);
    INTEGRAL_FLOAT_ADD(*(argument->out), *(argument->out), *(argument->tmp));
  }

  return(NULL);
}
#endif


// compute the abcissa and weights for the Gauss-Legendre numerical integration scheme
int INTEGRAL_FUNC(gauss_legendre_weights) (unsigned int order, INTEGRAL_FLOAT_TYPE tolerance, unsigned int maxiter, INTEGRAL_FLOATARRAY_TYPE* abcissa, INTEGRAL_FLOATARRAY_TYPE* weights){
  unsigned int i;
  INTEGRAL_FLOAT_TYPE x, tmp;
  INTEGRAL_POLYNOMIALARRAY_TYPE legendre;
  int ret;

  INTEGRAL_FLOATARRAY_FUNC(init) (abcissa, order);
  INTEGRAL_FLOATARRAY_FUNC(init) (weights, order);

  #ifdef INTEGRAL_FLOAT_INIT
    INTEGRAL_FLOAT_INIT(x);
    INTEGRAL_FLOAT_INIT(tmp);
  #endif

  INTEGRAL_POLYNOMIALARRAY_FUNC(init) (&legendre, 2);
  // compute the roots of the 'order'-th Legendre polynomial
  INTEGRAL_POLYNOMIAL_FUNC(legendre) (order, legendre.values);
  INTEGRAL_POLYNOMIAL_FUNC(derive) (legendre.values[0], legendre.values+1);
  legendre.length=2;

  for(i=0;i<order;i++){
    // initial guess
    INTEGRAL_FLOAT_SET_D(x, cos(3.1415926*(i+0.75)/(order+0.5)));
    ret=INTEGRAL_FUNC(root_newton_inplace) (&x, &INTEGRAL_FUNC(legendre_wrapper), &INTEGRAL_FUNC(deriv_legendre_wrapper), tolerance, maxiter, &legendre);

    if(ret<0){
      #ifdef INTEGRAL_FLOAT_FREE
	INTEGRAL_FLOAT_FREE(x);
	INTEGRAL_FLOAT_FREE(tmp);
      #endif
      INTEGRAL_POLYNOMIALARRAY_FUNC(free) (legendre);
      INTEGRAL_FLOATARRAY_FUNC(free) (*abcissa);
      INTEGRAL_FLOATARRAY_FUNC(free) (*weights);
      return(ret);
    }

    INTEGRAL_FLOATARRAY_FUNC(append) (x, abcissa);

    // weight: 2/((1-x^2)*(deriv_Legendre(x)))^2
    INTEGRAL_POLYNOMIAL_FUNC(evaluate) (&tmp, x, legendre.values[1]);
    INTEGRAL_FLOAT_POW_UI(tmp, tmp, 2);
    INTEGRAL_FLOAT_POW_UI(x, x, 2);
    INTEGRAL_FLOAT_UI_SUB(x, 1, x);
    INTEGRAL_FLOAT_MUL(x, x, tmp);
    INTEGRAL_FLOAT_SET_UI(tmp, 2);
    INTEGRAL_FLOAT_DIV(x, tmp, x);

    INTEGRAL_FLOATARRAY_FUNC(append) (x, weights);
  }

  #ifdef INTEGRAL_FLOAT_FREE
    INTEGRAL_FLOAT_FREE(x);
    INTEGRAL_FLOAT_FREE(tmp);
  #endif
  INTEGRAL_POLYNOMIALARRAY_FUNC(free) (legendre);

  return(0);
}

// wrapper functions to evaluate the legendre polynomial and its derivative
int INTEGRAL_FUNC(legendre_wrapper) (INTEGRAL_FLOAT_TYPE* out, INTEGRAL_FLOAT_TYPE in, void* legendre){
  INTEGRAL_POLYNOMIAL_FUNC(evaluate) (out, in, ((INTEGRAL_POLYNOMIALARRAY_TYPE*)legendre)->values[0]);
  return(0);
}
int INTEGRAL_FUNC(deriv_legendre_wrapper) (INTEGRAL_FLOAT_TYPE* out, INTEGRAL_FLOAT_TYPE in, void* legendre){
  INTEGRAL_POLYNOMIAL_FUNC(evaluate) (out, in, ((INTEGRAL_POLYNOMIALARRAY_TYPE*)legendre)->values[1]);
  return(0);
}