poly.py

Created by christian-mercat

Created on December 06, 2023

625 Bytes

Des procédures pour manipuler les polynômes. Un polynôme est codé comme une liste de coefficients, de 0 à deg(P).


def somme(p,q):
  if len(p)>len(q):
    s=p
    for i in range(len(q)):
      s[i]=p[i]+q[i]
  else:
    s=q
    for i in range(len(p)):
      s[i]=p[i]+q[i]
  return s
  
def scal(u,p):
  return list(map(lambda x:u*x,p))
  
def prod(p,q):
  l=[0 for i in range(len(p)+len(q)-1)]
  for i in range(len(p)):
    l=somme(l,[0 for j in range(i)]+scal(p[i],q))
  return l

def quo(a,b): #Return (q,r) s.th. a=b*q+r, deg(r)<deg(b)
  q=[]
  if len(b)>len(a):
    return [0], a
  while len(a)>=len(b):
    q.insert(0,a[-1]/b[-1])
    a=somme(a,[0 for j in range(len(a)-len(b))]+scal(-q[0],b))
    a.pop()
  return q, a

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our <a href="https://www.numworks.com/legal/cookies-policy/">cookies policy</a>.