From: jhmeyers@miu.edu (John H Meyers)
Subject: 'algebraic poly' ==> [ coefficients ]
Date: 14 May 1998 00:00:00 GMT
Message-ID: <6jefpe$8kh$1@news.iastate.edu>
References: <3559DA54.4E60F21D@com.se>
Reply-To: jhmeyers@miu.edu
Organization: MIU Computer Services,  Fairfield, IA 52557.  Not Approved.
Newsgroups: comp.sys.hp48


In article <3559DA54.4E60F21D@com.se>,
the infamous Erik Adler <erik.adler@com.se> writes:

> Does anybody know how to convert an algebraic polynomal into coefficient
> form so that the roots of an algebraic expression can be extracted?

> Ex: X^3 + 4X^2 - 7X +9 ==> [ 1 4 -7 9 ]

> There is a softmenu on the HP48GX that will convert from coefficient
> form to algebraic but not vice versa.

  I'm still looking for that "softmenu" -- where is it?  :)

  However, there seem to be posted programs for [ coeff ] ==> 'poly'

  "Quick polynomial maker (libeval question)" 1998/03/01
  <http://www.dejanews.com/getdoc.xp?AN=329637216>

  And below we have programs to do the reverse.

-----------------------------------------------------------
With best wishes from:   John H Meyers   <jhmeyers@mum.edu>
-----------------------------------------------------------


%%HP: T(3); @ 'expression' 'var' n ==> [ poly coefficients ]

@ Note that you also get to supply the expected degree of the polynomial,
@ the arguments (and results) being the same as for the TAYLR command;
@ this helps prevent an infinite loop in case of non-polynomial symbolics
@ (or roundoff errors, etc.)

@ Example: '5*Q^3+3*Q^2-4' 'Q' 3 ==> [ 5 3 0 -4 ]

{ @ Two versions, in a list:

@ Like the battle of Netscape vs. Explorer,
@ we offer you Bill Wickes vs. Wayne H Scott;
@ challenge them head-to-head, and pick your own winner!
@ (If Scott's entry disappears, assume that HP has taken over Usenet,
@ the same as Microsoft is taking over Internet  :)

\<< @ by Bill Wickes, from Goodies Disk #1 (from early S/SX days)
  @ (originally called PCOEF, but that's another command in G/GX)
  -3 CF @ ( -3 CF and comments added by JHM)
  3 DUPN TYPE SWAP TYPE ROT
  TYPE 3 \->LIST { 0 6 9 } @ Argument type checking
  IF ==
  THEN DUP 1 + \-> n
    \<< #18CEAh SYSEVAL @ COERCE
      SWAP
      #549CCh SYSEVAL @ Unsupported! (but same in rev R)
      # 74D0h SYSEVAL @ BIND
      @ Above pair is also supported as: dvarlsBIND: 63A29
      #59373h SYSEVAL @ Unsupported! (but same in rev R)
      @ Decompile xTAYLR to find similar code
      DROP #7497h SYSEVAL @ ABND
      1 n
      FOR m m ROLL COLCT @ (for possible symbolic result)
      NEXT n
      @ Adapted by JHM for array result, if not symbolic:
      -55 CF IFERR \->ARRY THEN \->LIST END @ Was: \->LIST
    \>>
  END
\>> @ Checksum #78CCh, 223 bytes (on stack)
@ SYSEVAL Warning! - Verify checksum and make backup before use!
@ (Also note the unsupported entry points)

\<< -3 CF @ Adapted from POLY (GD#7/Math) by Wayne H Scott
  \-> E v n \<< 0 n @ (using additional argument for variable name)
    FOR I 0 v STO E EVAL v PURGE E v \.d 'E' STO I FACT / @ Derivative
    NEXT 1 n 1 + @ Changed  2 n  to  1 n
    FOR I I ROLL COLCT @ Added COLCT (for possible symbolic result)
    NEXT n 1 +
    @ Array result, if not symbolic:
    -55 CF IFERR \->ARRY THEN \->LIST END @ Was: \->LIST
  \>>
\>> @ Checksum #52CCh, 175 bytes (on stack)
@ Scott version: BUG Alert!
@ Incorrect results if same variable name exists in higher directory!
@ Also purges named variable from current directory.

@ Timings (on my GX) for '5*Q^3+3*Q^2-4' 'Q' 3 ==> [ 5 3 0 -4 ]
@ Wickes: 5.184 sec,  Scott: 4.582 sec.  ( Scott takes the lead! )

@ However, Wickes' version does not disturb (nor is it disturbed by)
@ any existing variable of the same name, whether in the current or
@ higher directory, whereas Scott's version purges the named variable,
@ if present in current directory, and also exhibits the bug noted above.

@ In reality, the methods are nearly the same, but Wickes uses subtler
@ and more thorough code from the user TAYLR command to avoid pitfalls
@ (except for forgetting about flag -3 :)

@ Try '5*Q^3.5+3*Q^2-4' 'Q' 3 ==> [ 0 3 0 -4 ]  -- Not a polynomial
@        -2 SF 'SIN(Q)' 'Q' 3 ==> Etc.

} @ End of list of two programs; call 1-900-48G-HPHQ to tally your vote :)

