/
hermite.c
94 lines (75 loc) · 1.14 KB
/
hermite.c
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
//-----------------------------------------------------------------------------
//
// Hermite polynomial
//
// Input: tos-2 x (can be a symbol or expr)
//
// tos-1 n
//
// Output: Result on stack
//
//-----------------------------------------------------------------------------
#include "stdafx.h"
#include "defs.h"
void
hermite(void)
{
save();
yyhermite();
restore();
}
// uses the recurrence relation H(x,n+1)=2*x*H(x,n)-2*n*H(x,n-1)
#define X p1
#define N p2
#define Y p3
#define Y1 p4
#define Y0 p5
void
yyhermite(void)
{
int n;
N = pop();
X = pop();
push(N);
n = pop_integer();
if (n < 0) {
push_symbol(HERMITE);
push(X);
push(N);
list(3);
return;
}
if (issymbol(X))
yyhermite2(n);
else {
Y = X; // do this when X is an expr
X = symbol(SECRETX);
yyhermite2(n);
X = Y;
push(symbol(SECRETX));
push(X);
subst();
eval();
}
}
void
yyhermite2(int n)
{
int i;
push_integer(1);
push_integer(0);
Y1 = pop();
for (i = 0; i < n; i++) {
Y0 = Y1;
Y1 = pop();
push(X);
push(Y1);
multiply();
push_integer(i);
push(Y0);
multiply();
subtract();
push_integer(2);
multiply();
}
}