1 | #-----------------------------------------------------------------------------
|
2 | #
|
3 | # Hermite polynomial
|
4 | #
|
5 | # Input: tos-2 x (can be a symbol or expr)
|
6 | #
|
7 | # tos-1 n
|
8 | #
|
9 | # Output: Result on stack
|
10 | #
|
11 | #-----------------------------------------------------------------------------
|
12 |
|
13 |
|
14 |
|
15 | hermite = ->
|
16 | save()
|
17 | yyhermite()
|
18 | restore()
|
19 |
|
20 | # uses the recurrence relation H(x,n+1)=2*x*H(x,n)-2*n*H(x,n-1)
|
21 |
|
22 | #define X p1
|
23 | #define N p2
|
24 | #define Y p3
|
25 | #define Y1 p4
|
26 | #define Y0 p5
|
27 |
|
28 | yyhermite = ->
|
29 |
|
30 | n = 0
|
31 |
|
32 | p2 = pop()
|
33 | p1 = pop()
|
34 |
|
35 | push(p2)
|
36 | n = pop_integer()
|
37 |
|
38 | if (n < 0 || isNaN(n))
|
39 | push_symbol(HERMITE)
|
40 | push(p1)
|
41 | push(p2)
|
42 | list(3)
|
43 | return
|
44 |
|
45 | if (issymbol(p1))
|
46 | yyhermite2(n)
|
47 | else
|
48 | p3 = p1; # do this when X is an expr
|
49 | p1 = symbol(SECRETX)
|
50 | yyhermite2(n)
|
51 | p1 = p3
|
52 | push(symbol(SECRETX))
|
53 | push(p1)
|
54 | subst()
|
55 | Eval()
|
56 |
|
57 | yyhermite2 = (n) ->
|
58 | i = 0
|
59 |
|
60 | push_integer(1)
|
61 | push_integer(0)
|
62 |
|
63 | p4 = pop()
|
64 |
|
65 | for i in [0...n]
|
66 |
|
67 | p5 = p4
|
68 |
|
69 | p4 = pop()
|
70 |
|
71 | push(p1)
|
72 | push(p4)
|
73 | multiply()
|
74 |
|
75 | push_integer(i)
|
76 | push(p5)
|
77 | multiply()
|
78 |
|
79 | subtract()
|
80 |
|
81 | push_integer(2)
|
82 | multiply()
|
83 |
|