compiletable - Maple Programming Help

Home : Support : Online Help : Programming : Data Types : Tables, lists, and sets : compiletable

compiletable

create lookup table

tablelook

perform table lookup

insertpattern

append to lookup table

 Calling Sequence compiletable([pattern1=entry1, pattern2=entry2, ...]) tablelook(expr, pattree) insertpattern(pattern=entry, pattree)

Parameters

 pattern, pattern1, pattern2, ... - pattern to match entry, entry1, entry2, ... - table entry corresponding to a pattern expr - expression to be matched pattree - pattern match tree returned by compiletable or insertpattern

Description

 • The compiletable([pattern1=entry1, pattern2=entry2, ...]) calling sequence creates an efficient lookup table by merging patterns (with parameters) into a tree that the pattern matcher (tablelook command) can search in logarithmic time. For example, you can create an integration table in which each pattern is an integrand and the corresponding entry its integral.
 Each table entry is of the form pattern=entry. For information on the format, see patmatch.
 • The tablelook(expr, pattree) calling sequence compares expr to patterns in pattree. If tablelook finds a match, it returns the corresponding entry with parameter values substituted. Otherwise, it returns FAIL.
 • The insertpattern(pattern=entry, pattree) calling sequence appends pattern=entry to the end of pattree.

Examples

 > $\mathrm{tab}≔\left[\mathrm{ln}\left(a::\mathrm{radnum}\mathrm{_X}+b::\mathrm{radnum}\right)=\mathrm{ln}\left(ax+b\right)x+\frac{1\mathrm{ln}\left(ax+b\right)b}{a}-x-\frac{1b}{a},{ⅇ}^{a::\mathrm{radnum}\mathrm{_X}}=\frac{1{ⅇ}^{ax}}{a},{ⅇ}^{a::\mathrm{radnum}{\mathrm{_X}}^{2}+b::\mathrm{radnum}}=\frac{1{\mathrm{π}}^{\frac{1}{2}}\mathrm{erf}\left({\left(-a\right)}^{\frac{1}{2}}x\right){ⅇ}^{b}}{2{\left(-a\right)}^{\frac{1}{2}}},\mathrm{cos}\left(a::\mathrm{radnum}\mathrm{_X}\right)=\frac{1\mathrm{sin}\left(ax\right)}{a},\mathrm{sin}\left(a::\mathrm{radnum}{\mathrm{_X}}^{2}\right)=\frac{1{2}^{\frac{1}{2}}{\mathrm{π}}^{\frac{1}{2}}\mathrm{FresnelS}\left(\frac{{2}^{\frac{1}{2}}{a}^{\frac{1}{2}}x}{{\mathrm{π}}^{\frac{1}{2}}}\right)}{2{a}^{\frac{1}{2}}},\mathrm{sin}\left(a::\mathrm{radnum}\mathrm{_X}\right)=-\frac{1\mathrm{cos}\left(ax\right)}{a},\frac{\mathrm{_X}}{1+\mathrm{sin}\left(\mathrm{_X}\right)}=-\frac{x}{\mathrm{cos}\left(x\right)}+x\mathrm{tan}\left(x\right)+\mathrm{ln}\left(\mathrm{cos}\left(x\right)\right)+\mathrm{ln}\left(\mathrm{sec}\left(x\right)+\mathrm{tan}\left(x\right)\right),\frac{\mathrm{_X}}{1-\mathrm{sin}\left(\mathrm{_X}\right)}=\frac{x}{\mathrm{cos}\left(x\right)}+x\mathrm{tan}\left(x\right)+\mathrm{ln}\left(\mathrm{cos}\left(x\right)\right)-\mathrm{ln}\left(\mathrm{sec}\left(x\right)+\mathrm{tan}\left(x\right)\right),a::\mathrm{radnum}\mathrm{_X}+b::\mathrm{radnum}=\frac{a{x}^{2}}{2}+bx,{\left(\mathrm{_X}+a::\mathrm{radnum}\right)}^{-1}=\mathrm{ln}\left(x+a\right),a::\mathrm{radnum}{\mathrm{_X}}^{n::\mathrm{integer}}=\frac{a{x}^{n+1}}{n+1}\right]:$
 > $\mathrm{tab}≔\mathrm{subs}\left(\mathrm{_X}=x::\mathrm{name},\mathrm{tab}\right):$
 > $p≔\mathrm{compiletable}\left(\mathrm{tab}\right):$

Now we can use the table:

 > $\mathrm{tablelook}\left(\mathrm{cos}\left(2x\right),p\right)$
 $\frac{{1}}{{2}}{}{\mathrm{sin}}{}\left({2}{}{x}\right)$ (1)
 > $\mathrm{tablelook}\left(\mathrm{ln}\left(2z\right),p\right)$
 ${\mathrm{ln}}{}\left({2}{}{z}\right){}{z}{-}{z}$ (2)
 > $\mathrm{tablelook}\left({ⅇ}^{2{x}^{2}-3},p\right)$
 ${-}\frac{{1}}{{4}}{}\sqrt{{\mathrm{π}}}{}\sqrt{{-}{2}}{}{\mathrm{erf}}{}\left(\sqrt{{-}{2}}{}{x}\right){}{{ⅇ}}^{{-}{3}}$ (3)
 > $\mathrm{map}\left(\mathrm{tablelook},\frac{1{x}^{5}}{2}+3{x}^{2}-x+\frac{1}{x+2},p\right)$
 $\frac{{1}}{{12}}{}{{x}}^{{6}}{+}{{x}}^{{3}}{-}\frac{{1}}{{2}}{}{{x}}^{{2}}{+}{\mathrm{ln}}{}\left({x}{+}{2}\right)$ (4)