HP Forums
(48G, 50g) Define a new symbolic constant - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: General Software Library (/forum-13.html)
+--- Thread: (48G, 50g) Define a new symbolic constant (/thread-2137.html)



(48G, 50g) Define a new symbolic constant - ettlz - 09-14-2014 09:24 PM

This is a trick I've found to define a new symbolic constant (typically transcendental, or with no proof to the contrary) for use in algebraics; that is, the symbol is unchanged on EVAL but changes to its approximate value with →NUM. In this example, we define the Euler--Mascheroni constant gammaE = 0.577...

First, define the program SYMBCONST:

Code:
« → n x
  «
    IF x '\pi' SAME
    THEN n
    ELSE
      CASE n 'gammaE' SAME
        THEN 0.577215664902
        END
      END
    END
  »
»

Now define gammaE:

Code:
« 'SYMBCONST(QUOTE(gammaE),\pi)' EVAL »

To see this at work:

Code:
'SIN(gammaE)' EVAL  →  'SIN(gammaE)'
'SIN(gammaE)' →NUM  →  0.5456928233204

This trick relies on →NUM changing the \pi to 3.14159265359 in the second argument to SYMBCONST; it holds no other special meaning. (A more elegant solution would be to find some way to hook →NUM.) More constants can be added with additional clauses in SYMBCONST's CASE.