-
Notifications
You must be signed in to change notification settings - Fork 0
/
prs.py
53 lines (42 loc) · 887 Bytes
/
prs.py
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
from sympy import *
x = Symbol('x')
###########
# Get PRS #
###########
# PRS by pseudo division
def prs_prem(f, g):
prs = []
while degree(f) > 1:
p = prem(f, g)
prs.append(p)
f = g
g = p
return prs
# Get leading coefficient
def lcoeff(f):
return f.coeff(x ** degree(f))
# Pseudo division for Reduced PRS
def prem2(f, g):
if degree(f) < degree(g):
prem2(g, f)
else:
a = lcoeff(g) ** (degree(f) - degree(g) + 1)
p = div(a * f, g, domain='Z')[1]
return (p, a)
# Reduced PRS
def prs_red_prem(f, g):
prs = []
a0 = 1
while degree(f) > 1:
(p, a) = prem2(f, g)
p = p / a0
prs.append(p)
a0 = a
f = g
g = p
return prs
# Subresultant PRS
def prs_subresultant(f, g):
prs = subresultants(f, g)
del prs[0:2]
return prs