Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4081432
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:03:37+00:00 2026-05-20T18:03:37+00:00

Good day, Reading this thread about performance of pattern matching and functions in Mathematica

  • 0

Good day,

Reading this thread about performance of pattern matching and functions in Mathematica I was impressed by Timo’s idea on optimizing the evaluation of expressions:

I have on occasion constructed a
Dispatch table of all the functions I
need and manually applied it to my
starting expression. This provides a
significant speed increase over normal
evaluation as none of Mathematica’s
inbuilt functions need to be parsed
against my expression.

How exactly should such a Dispatch table be constructed? In which cases would such an approach be recommended? How does it really work? Are there other methods for optimizing of the Main Loop?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:03:37+00:00Added an answer on May 20, 2026 at 6:03 pm

    To do this, first you need to be able to calculate the dependencies for your symbol(s). There’s a package to do that in a back issue of the Mathematica Journal, which is now free online. Here is the URL: http://www.mathematica-journal.com/issue/v6i1/. See the article “Power Programming: Dependency Analysis.”

    Here’s a worked example:

    In[1]:= <<"/path/to/DEPEND.MA"
    
    In[2]:= $ContextPath
    
    Out[2]= {DependencyAnalysis`,PacletManager`,WebServices`,System`,Global`}
    
    In[3]:= f[x_]:=x x
    
    In[4]:= g[x_]:=x+1
    
    In[5]:= h[x_]:=f[x]+g[x]
    
    In[6]:= i[x_]:=f[g[x]]
    
    In[7]:= DependsOn[g][[2]]
    
    Out[7]= {Blank,Pattern,Plus,x}
    
    In[8]:= DownValues@@@DependsOn[g][[2]]
    
    Out[8]= {{},{},{},{}}
    
    In[9]:= getDownValues[s_Symbol]:=DownValues[s]
    
    In[10]:= getDownValues[s_HoldForm]:=getDownValues@@s
    
    In[11]:= getDownValues[s_]:={}
    
    In[12]:= hasDownValues[x_]:=getDownValues[x]=!={} 
    
    In[13]:= ruleListEntries[x_List]:=Union[Union@@ruleListEntries/@x,{x}]
    
    In[14]:= ruleListEntries[x_]:=Select[Union[DependsOn[x][[2]],{x}],hasDownValues]
    
    In[15]:= ruleListEntries[f]
    
    Out[15]= {f}
    
    In[16]:= ruleListEntries[g]
    
    Out[16]= {g}
    
    In[17]:= ruleListEntries[h]
    
    Out[17]= {h,f,g}
    
    In[18]:= ruleListEntries[i]
    
    Out[18]= {i,f,g}
    
    In[19]:= dispatch=getDownValues/@ruleListEntries[i]//Flatten//Union//Dispatch
    
    Out[19]= {HoldPattern[f[x_]]:>x x,HoldPattern[g[x_]]:>x+1,HoldPattern[i[x_]]:>f[g[x]]}
    
    In[20]:= i[x]
    
    Out[20]= (1+x)^2
    
    In[21]:= HoldForm[i[x]]//.dispatch
    
    Out[21]= (x+1) (x+1)
    

    I see no way to get the DownValues for the built-in symbols, so this is useful only to the point of reducing an expression to the point of containing only built-ins.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good day! I am reading a Java book about encapsulation and it mentioned the
Good day everyone, this is one of those areas that is a little over
Good day everyone. I have a question about making and using derived classes of
After reading the android documentation about String, which includes this: This class is implemented
Good day. I got a problem about the attribute of ref for my XSD
good day stackoverflow! im not sure if any of you has tried this but
Good day, I have this weird problem: This following statement works Query q =
A good day dear developers. My name is Danny. This is my first post
I have been reading this ebook about DDD and it says that only highly
Good day! I am reading Head First Servlets and JSP and it says that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.