-1

Can anyone explain me in below algorithm how the "ISZERO" function checking whether the polynomial is zero or not. Here "REM(P,e)" function removes all the values with exponent "e". what i don't able to understand is the significance of "if COEF(P,e) = - c". And also what is this "SMULT" function.

 structure POLYNOMIAL
    declare ZERO( ) poly; ISZERO(poly) Boolean
    COEF(poly,exp) coef;
    ATTACH(poly,coef,exp) poly
    REM(poly,exp) poly
    SMULT(poly,coef,exp) poly
    ADD(poly,poly) poly; MULT(poly,poly) poly;
    for all P,Q, poly c,d, coef e,f exp let
    REM(ZERO,f) :: = ZERO
    REM(ATTACH(P,c,e),f) :: =
    if e = f then REM(P,f) else ATTACH(REM(P,f),c,e)
    ***ISZERO(ZERO) :: = true
    ISZERO(ATTACH(P,c,e)):: =
    if COEF(P,e) = - c then ISZERO(REM(P,e)) else false***
    COEF(ZERO,e) :: = 0
    COEF(ATTACH(P,c,e),f) :: =
    if e = f then c + COEF(P,f) else COEF(P,f)
    SMULT(ZERO,d,f) :: = ZERO
    SMULT(ATTACH(P,c,e),d,f) :: =
    ATTACH(SMULT(P,d,f),c d,e + f)
    ADD(P,ZERO):: = P
    ADD(P,ATTACH(Q,d,f)) :: = ATTACH(ADD(P,Q),d,f)
    MULT(P,ZERO) :: = ZERO
    MULT(P,ATTACH(Q,d,f)) :: =
    ADD(MULT(P,Q),SMULT(P,d,f))
    end
    end POLYNOMIAL
borrible
  • 17,120
  • 7
  • 53
  • 75
Abhishek
  • 1,585
  • 2
  • 12
  • 15
  • 1
    *"..the significance of "if COEF(P,e) = - c.". Thats not the only thing not understood here. Why this is tagged with C? – WhozCraig Aug 17 '13 at 03:51
  • @WhozCraig cz i gonna do this algo in c – Abhishek Aug 17 '13 at 03:53
  • 1
    Source of this specification [here](http://www.icodeguru.com/vc/10book/books/book1/chap02.htm). There is apparently no complete description of this "language", but is partially described [here](http://www.icodeguru.com/vc/10book/books/book1/appa.htm). – jxh Aug 17 '13 at 05:55

1 Answers1

1

Without knowing what language this is, it looks like this line

ISZERO(ATTACH(P,c,e)):: =
if COEF(P,e) = - c then ISZERO(REM(P,e)) else false

is specifying ISZERO recursively. We are trying to determine whether ATTACH(P, c, e), otherwise known as P(x) + cx^e, is zero. It first checks whether the x^e coefficient of P is -c. If not, then P(x) + cx^e is definitely not zero, and you can return false immediately. Otherwise, P(x) + cx^e = REM(P, e), so you have to check ISZERO(REM(P, e)).

I believe SMULT is multiplication, so SMULT(P, a, b) is equivalent to a * x^b * P(x).

arghbleargh
  • 3,090
  • 21
  • 13
  • the language used in this algo is sparks. The problem is i am not able to understand the significance of checking the "negative co-efficient" . Negative or positive polynomial is not zero if it has any co-efficient. Please explain. – Abhishek Aug 17 '13 at 06:57
  • For example, suppose P is x^2 - 3x + 2, c is 3, and e is 1. Then the algorithm is checking whether P + 3x is zero. It first checks if COEF(P, 1) is -3. This is true, so it checks whether REM(P, 1) = x^2 + 2 is zero. It's not zero, so it returns false (well, it has to do further reductions, like x^2 + 2 = ATTACH(x^2, 2, 0), but it eventually finds that it's false). – arghbleargh Aug 17 '13 at 07:31
  • If we changed P to x^2 - 2x + 2 in the above example, then we would first check that COEF(P, 1) is not -3. Then we know that P + 3x cannot possibly be zero because the x coefficient is not zero. So then we can return false immediately. – arghbleargh Aug 17 '13 at 07:32
  • sorry for asking again but plz explain. why do we need to remove negative coefficient using REM(P, 1) for checking a polynomial is zero or not. An addition of polynomial algorithm is using ISZERO function before addition, is it invalid to add two negative co-efficient polynomial. – Abhishek Aug 17 '13 at 07:45
  • Also if u think that SMULT function is for multiplication then what is the purpose of MUL function. – Abhishek Aug 17 '13 at 07:56
  • The SMULT function is for multiplying with a polynomial with a single term (known as a "monomial"). It's being used as a building block for the MULT function, which multiplies any two polynomials. As for the ISZERO thing, I'm afraid I can't explain it much more simply than I already have. I'd suggest you try to work through a few examples to see what's going on, or re-read my comment. – arghbleargh Aug 17 '13 at 08:08