Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate expression trees from given sets of numbers and operations and find those that evaluate to a target number in Mathematica 8 or above
    primarykey
    data
    text
    <p>Given a set of numbers and a set of binary operations, what is the fastest way to create random expression trees or exhaustively check every possible combination in Mathematica?</p> <p>What I am trying to solve is given:</p> <pre><code>numbers={25,50,75,100,3,6} (* each can ONLY be used ONCE *) operators={Plus,Subtract,Times,Divide} (* each can be used repeatedly *) target=99 </code></pre> <p>find expression trees that would evaluate to target.</p> <p>I have two solutions whose performances I give for the case where expression trees contain exactly 4 of the numbers and 3 operators:</p> <ol> <li>random sample &amp; choice: ~25K trees / second</li> <li>exhaustive scan: 806400 trees in ~2.15 seconds</li> </ol> <p>(timed on a laptop with: Intel(R) Core(TM)2 Duo CPU T9300 @ 2.50GHz, 3GB ram, no parallelization used yet but would be most welcome in answers)</p> <p>My notebooks are a bit messy at the moment. So I would first love to pose the question and hope for original ideas and answers while I clean up my code for sharing.</p> <p>Largest possible case is where every expression tree uses up all the (6) numbers and 'Length[numbers]-1' (5) operators.</p> <p>Performance of methods in the largest case is:</p> <ol> <li>random sample &amp; choice: ~21K trees / second</li> <li>exhaustive scan: 23224320 trees in ~100 seconds</li> </ol> <p>Also I am using Mathematica 8.0.1 so I am more than all ears if there are any ways to do it in OpenCL or using compiled functions wiht CompilationTarget->"C", etc.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload