Post Reply 
(48G, 50g) Define a new symbolic constant
09-14-2014, 09:24 PM (This post was last modified: 09-14-2014 09:25 PM by ettlz.)
Post: #1
(48G, 50g) Define a new symbolic constant
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.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)