Re: Using a Mathematica Program to write a Mathematica Program
- To: mathgroup at smc.vnet.net
- Subject: [mg119287] Re: Using a Mathematica Program to write a Mathematica Program
- From: Heike Gramberg <heike.gramberg at gmail.com>
- Date: Sun, 29 May 2011 07:36:15 -0400 (EDT)
Not sure if this is the most elegant way but this should work: f[list_, n_] := With[{rec = FindLinearRecurrence[list]}, Defer[LinearRecurrence[#1, #2, n]] & @@ {rec, Take[list, Length[rec]]}] Then f[{2, 5, 8, 11, 14, 17}, 10] will give LinearRecurrence[{2, -1}, {2, 5}, 10] After copying and pasting this output to a new input line and evaluating you get {2, 5, 8, 11, 14, 17, 20, 23, 26, 29} Heike On 28 May 2011, at 12:18, Harvey P. Dale wrote: > How can one write a Mathematica program the output of which is > itself a Mathematica program? > Here is a specific example. Suppose one runs > FindLinearRecurrence on a sequence of numbers and Mathematica provides a > list of the recurrence factors. What I would like is to run a program > that would (1) enter the command "Linear Recurrence" plus the opening > square bracket, (2) copy the output of the FindLinearRecurrence program, > i.e., the recurrence factors (as a list), (3) determine the length of > the list of those recurrence factors, (4) take from the sequence of > numbers that had been provided to FindLinearRecurrence the same (first) > number of numbers that corresponds to the length of the recurrence > factors, (5) insert those numbers, as a list, into the program being > created for Linear Recurrence, separated from the recurrence-factor list > by a comma, (6) insert a comma following that, (7) insert a number and > closing square bracket following that, in turn, and (8) provide that > output as a program that could be copied from the output line into a new > input line and run. > For example, suppose FindLinearRecurrence is run on this list > {2,5,8,11,14,17} producing {2,-1}. The output I want from the program > to be written would be LinearRecurrence[{2,-1},{2,5},30]. > Any ideas would be welcome. > Thanks. > Harvey P. Dale > > ______________________________________________________________________ > This email has been scanned by the MessageLabs Email Security System. > For more information please visit http://www.messagelabs.com/email > ______________________________________________________________________ >