#439 ntrig is broken

closed
nobody
5
2006-07-10
2003-11-05
No

(C4) load("ntrig.mac");
(D4) ?C\:\/maxima\/Maxima\/share\/maxima\/5\.9\.0
\/share\/trigonometry\/ntrig\.mac
(C5) sin(6*%pi/5);
(D5) (SQRT(5)-1)*SQRT(SQRT(5)+5)/(4*SQRT(2))
(C6) float(%);
(D6) 0.58778525229247
(C7) sin(float(6*%pi/5));
(D7) -0.58778525229247

Barton

Discussion

  • Wolfgang Jenkner

    Logged In: YES
    user_id=581700

    Perhaps simply rewrite

    USIN(N):= BLOCK([YUK:mod(N,20)],
    signum(YUK)*(YUK:abs(mod(YUK,10)),
    IF YUK=1 THEN (SQRT(5)-1)/4 ELSE
    IF YUK=2 THEN (SQRT(5)-1)*SQRT(SQRT(5)+5)/(4*SQRT(2)) ELSE
    IF YUK=3 THEN (SQRT(5)+1)/4 ELSE
    IF YUK=4 THEN SQRT(SQRT(5)+5)/(2*SQRT(2))))$

    UCOS(N):= USIN(5-N)$

     
  • Stavros Macrakis

    Logged In: YES
    user_id=588346

    Please test the following replacement for ntrig.

    /* Some of these simplifications give results with radicals in
    the denominator. These could be pre-simplified here, but
    ratsimp(...),algebraic:true will also take care of it. */

    eval_when([translate,batch,demo,load,loadfile],
    matchdeclare(n,integerp))$

    tellsimpafter(sin(n*%pi/10),usin(n))$
    tellsimpafter(cos(n*%pi/10),ucos(n))$
    tellsimpafter(tan(n*%pi/10),usin(n)/ucos(n))$
    tellsimpafter(cot(n*%pi/10),ucos(n)/usin(n))$
    tellsimpafter(sec(n*%pi/10),1/ucos(n))$
    tellsimpafter(csc(n*%pi/10),1/usin(n))$

    usin_list:
    makelist(
    [ 0,
    (sqrt(5)-1)/4,
    sqrt(2)*(sqrt(5)-1)*sqrt(sqrt(5)+5)/8,
    (sqrt(5)+1)/4,
    sqrt(sqrt(5)+5)/(2*sqrt(2)),
    1] [i],
    i,[1,2,3,4,5,6,5,4,3,2,1,2,3,4,5,6,5,4,3,2] )

    /* In the pre-11/2003 version, usin_list[3] was
    (sqrt(5)-1)*sqrt(sqrt(5)+5)/(4*sqrt(2)).
    But the new version is better simplified, and
    simplifies just as well.
    */ $

    usin(n):=
    (declare(n,integer),
    n : remainder(n,20),
    if n<0 then n:n+20, /* Workaround for bug in
    remainder */
    (if n <= 10 then usin_list[n+1] /* 1-origin indexing */
    else -usin_list[n+1]) )$

    ucos(n):=usin(n+5)$

     
  • Barton Willis

    Barton Willis - 2003-11-15

    ntrig test

     
  • Barton Willis

    Barton Willis - 2003-11-15

    Logged In: YES
    user_id=895922

    I wrote testing code for ntrig; both proposed fixes
    pass all the tests.

    Barton

     
  • Wolfgang Jenkner

    Logged In: YES
    user_id=581700

    What about combining the two approaches like this.

    define_variable
    (usin_list,
    block([e1 : (sqrt(5)-1)/4,
    e2 : (sqrt(5)-1)*sqrt(sqrt(5)+5)/(4*sqrt(2)),
    e3 : (sqrt(5)+1)/4,
    e4 : sqrt(sqrt(5)+5)/(2*sqrt(2))],
    [e1, e2, e3, e4, 1, e4, e3, e2, e1, 0]), any)$

    usin(n):=
    /* MODE_DECLARE treats INTEGER like FIXNUM... */
    (mode_declare(n,number),
    /* Note that this works because MOD is supposed to return an integer
    in [-9, 10] here. Sadly, GCL misbehaves (see bug #706562).
    Normally, this doesn't matter, however: If the argument of SIN is
    an integer multiple of %pi/2 the usual simplification routines
    take care of it, so at this point N won't be a multiple of 5. */
    if (n : mod(n, 20)) > 0
    then usin_list[n]
    else -usin_list[10+n])$

    ucos(n):= usin(5-n)$

     
  • Robert Dodier

    Robert Dodier - 2006-07-10

    Logged In: YES
    user_id=501686

    Bug shown in original report is fixed by r1.2
    share/trigonometry/ntrig.mac, which was made to fix bug
    report # 1082010 (sign error). Patches proposed here were
    never applied so far as I can tell. Bug not observed in
    5.9.3cvs. Closing this report as fixed.

     
  • Robert Dodier

    Robert Dodier - 2006-07-10
    • status: open --> closed
    • labels: --> 460522
     
  • Robert Dodier

    Robert Dodier - 2006-07-10

    Logged In: YES
    user_id=501686

    Assign category = share libraries.

     
  • Robert Dodier

    Robert Dodier - 2006-07-10
    • labels: 460522 --> Share Libraries
     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks