MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Using a Mathematica Program to write a Mathematica Program

  • To: mathgroup at smc.vnet.net
  • Subject: [mg119295] Re: Using a Mathematica Program to write a Mathematica Program
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Sun, 29 May 2011 07:37:46 -0400 (EDT)

linearRecur[data_List, n_Integer?Positive] := Module[
  {flr = FindLinearRecurrence[data]},
  LinearRecurrence[flr, Take[data, Length[flr]], n]]

data = {2, 5, 8, 11, 14, 17};

linearRecur[data, 30]

{2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47, 50, 53, \
56, 59, 62, 65, 68, 71, 74, 77, 80, 83, 86, 89}

data == Take[%, Length[data]]

True


Bob Hanlon

---- "Harvey P. Dale" <hpd1 at nyu.edu> 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
______________________________________________________________________




  • Prev by Date: Re: Filtering of the higher frequency terms.
  • Next by Date: Re: how to calculate an index and vice versa
  • Previous by thread: Using a Mathematica Program to write a Mathematica Program
  • Next by thread: Re: Using a Mathematica Program to write a Mathematica Program