 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}{a}\mathrm{ln}\left(ax+b\right)b-x-\frac{1}{a}b,\mathrm{exp}\left(a::\mathrm{radnum}\mathrm{_X}\right)=\frac{1}{a}\mathrm{exp}\left(ax\right),\mathrm{exp}\left(a::\mathrm{radnum}{\mathrm{_X}}^{2}+b::\mathrm{radnum}\right)=\frac{\frac{1}{2}{\mathrm{\pi }}^{\frac{1}{2}}}{{\left(-a\right)}^{\frac{1}{2}}}\mathrm{erf}\left({\left(-a\right)}^{\frac{1}{2}}x\right)\mathrm{exp}\left(b\right),\mathrm{cos}\left(a::\mathrm{radnum}\mathrm{_X}\right)=\frac{1}{a}\mathrm{sin}\left(ax\right),\mathrm{sin}\left(a::\mathrm{radnum}{\mathrm{_X}}^{2}\right)=\frac{\frac{1}{2}{2}^{\frac{1}{2}}{\mathrm{\pi }}^{\frac{1}{2}}}{{a}^{\frac{1}{2}}}\mathrm{FresnelS}\left(\frac{{2}^{\frac{1}{2}}}{{\mathrm{\pi }}^{\frac{1}{2}}}{a}^{\frac{1}{2}}x\right),\mathrm{sin}\left(a::\mathrm{radnum}\mathrm{_X}\right)=-\frac{1}{a}\mathrm{cos}\left(ax\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),\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}{2}{x}^{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}{n+1}{x}^{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{{\mathrm{sin}}{}\left({2}{}{x}\right)}{{2}}$ (1)
 > $\mathrm{tablelook}\left(\mathrm{ln}\left(2z\right),p\right)$
 ${\mathrm{ln}}{}\left({2}{}{z}\right){}{z}{-}{z}$ (2)
 > $\mathrm{tablelook}\left(\mathrm{exp}\left(2{x}^{2}-3\right),p\right)$
 ${-}\frac{\sqrt{{\mathrm{\pi }}}{}\sqrt{{-2}}{}{\mathrm{erf}}{}\left(\sqrt{{-2}}{}{x}\right){}{{ⅇ}}^{{-3}}}{{4}}$ (3)
 > $\mathrm{map}\left(\mathrm{tablelook},\frac{1}{2}{x}^{5}+3{x}^{2}-x+\frac{1}{x+2},p\right)$
 $\frac{{{x}}^{{6}}}{{12}}{+}{{x}}^{{3}}{-}\frac{{{x}}^{{2}}}{{2}}{+}{\mathrm{ln}}{}\left({x}{+}{2}\right)$ (4)