#1036 trigreduce([atan(sin(a)/cos(a))]) => [ atan(tan(a)) ] (FIX)

closed
nobody
5
2006-12-22
2006-12-02
No

trigexpand( [ atan(sin(a)/cos(a)) ] ) => atan(tan(a))
(UNSIMPLIFIED!)

whereas

trigexpand( atan(sin(a)/cos(a)) ) => a

and

atan(tan(a)) => a

Though the simplification atan(tan(a))=> is questionable (it needs to do reduction), it is weird that putting the argument to trigexpand in a list changes the behavior.

Discussion

  • Stavros Macrakis

    Logged In: YES
    user_id=588346
    Originator: YES

    Oops, it's actually

    trigexpand( [ atan(sin(a)/cos(a)) ] ) => [ atan(tan(a)) ]
    (UNSIMPLIFIED!)

    It doesn't simplify atan of tan, but it does preserve the list...

     
  • Stavros Macrakis

    • summary: trigexpand([atan(sin(a)/cos(a))]) => atan(tan(a)) --> trigexpand([atan(sin(a)/cos(a))]) => [ atan(tan(a)) ]
     
  • Raymond Toy

    Raymond Toy - 2006-12-04

    Logged In: YES
    user_id=28849
    Originator: NO

    What version?

    With 5.10.0 and cmucl, trigexpand([atan(sin(a)/cos(a))]) => [atan(sin(a)/cos(a))]

    Corresponding result if the arg is not a list.

     
  • Stavros Macrakis

    • summary: trigexpand([atan(sin(a)/cos(a))]) => [ atan(tan(a)) ] --> trigreduce([atan(sin(a)/cos(a))]) => [ atan(tan(a)) ]
     
  • Stavros Macrakis

    Logged In: YES
    user_id=588346
    Originator: YES

    Sorry, it's trigreduce in Maxima 5.10.0 GCL 2.6.8 Windows2k Athlon

    trigreduce(atan(sin(a)/cos(a))) => a
    trigreduce([atan(sin(a)/cos(a))]) => [atan(tan(a))]

    PS I should always cut and paste rather than retyping....

     
  • Stavros Macrakis

    Logged In: YES
    user_id=588346
    Originator: YES

    Other simplifications also don't happen:

    trigreduce( sin(x)^2 ) => (1- cos(2*x))/2 (OK)
    trigreduce([sin(x)^2]) => [ (2-2*cos(2*x))/4 ] (?)

     
  • Raymond Toy

    Raymond Toy - 2006-12-08

    Logged In: YES
    user_id=28849
    Originator: NO

    With current CVS, the example with sin(x)^2 gives the same results whether it's a list or not.

    Also, if you :lisp (trace $trigreduce), you can see that trigreduce([atan(sin(a)/cos(a))]) returns [atan(tan(a))] and trigreduce(atan(sin(a)/cos(a)) returns atan(tan(a)). Something after trigreduce returns causes the simplification to happen. Perhaps in meval or something?

     
  • Stavros Macrakis

    Logged In: YES
    user_id=588346
    Originator: YES

    The problem is that sp1 isn't handling simplification quite right. The result is
    ((MLIST SIMP) ((%ATAN) ((%TAN SIMP) $A)))
    The %ATAN doesn't have a SIMP flag, though it is within a SIMP expression.

    The fix is simple. In trgred.lisp, function sp1:

    BEFORE:
    ((mbagp e) (cons (car e) (mapcar #'sp1 (cdr e))))
    AFTER:
    ((mbagp e) (cons (car e) (mapcar #'(lambda (q) (simplifya (sp1 q))) (cdr e))))

    Interestingly, trigreduce doesn't go inside unknown functions at all, e.g.

    trigreduce( f(sin(x)/cos(x)) )

    doesn't do anything at all. I wonder if there is a good reason for this?

     
  • Stavros Macrakis

    • summary: trigreduce([atan(sin(a)/cos(a))]) => [ atan(tan(a)) ] --> trigreduce([atan(sin(a)/cos(a))]) => [ atan(tan(a)) ] (FIX)
     
  • Raymond Toy

    Raymond Toy - 2006-12-09

    Logged In: YES
    user_id=28849
    Originator: NO

    This change works for me. I get a and [a] for results. I'll apply the fix soon.

     
  • Stavros Macrakis

    Logged In: YES
    user_id=588346
    Originator: YES

    Actually, my suggested fix only works in some cases. Better would be the following:

    BEFORE:
    ((mbagp e) (cons (car e) (mapcar #'sp1 (cdr e))))
    AFTER:
    ((mbagp e) (cons (list (caar e)) (mapcar #'(lambda (u) (gcdred (sp1 u))) (cdr e))))))

    Note two things here: any "simp" flags on the bag are dropped (so this will work if bags come to include sets some day) and gcdred is applied as in the top level of $trigreduce.

    Sorry I didn't get it right the first time.

     
  • Raymond Toy

    Raymond Toy - 2006-12-11

    Logged In: YES
    user_id=28849
    Originator: NO

    I'm applying your fix. Could you send some examples where your original fix didn't work. I'd like them for regression tests.

     
  • Stavros Macrakis

    Logged In: YES
    user_id=588346
    Originator: YES

    Here is an example of one handled by the new and not the old code:

    trigreduce([sin(x)^2]) => [ (2-2*cos(2*x))/4 ] WRONG
    => [ (1-cos(2*x))/2 ] Fixed

    Also, leaving the bag unsimplified is more correct in general, though it doesn't currently matter. It will matter if (for example) sets get added to mbagp.

     
  • Raymond Toy

    Raymond Toy - 2006-12-22
    • status: open --> closed
     
  • Raymond Toy

    Raymond Toy - 2006-12-22

    Logged In: YES
    user_id=28849
    Originator: NO

    Additional test added, so closing bug.

     

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

Sign up for the SourceForge newsletter:





No, thanks