Re: Creating a recursive function which returns a sequence

• To: mathgroup at smc.vnet.net
• Subject: [mg128492] Re: Creating a recursive function which returns a sequence
• From: Bill Rowe <readnews at sbcglobal.net>
• Date: Thu, 25 Oct 2012 01:40:53 -0400 (EDT)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• Delivered-to: l-mathgroup@wolfram.com
• Delivered-to: mathgroup-newout@smc.vnet.net
• Delivered-to: mathgroup-newsend@smc.vnet.net

```On 10/24/12 at 3:32 AM, wei.xun.lin at gmail.com (Wei-Hsun Lin) wrote:

>I would like to create a recursive function of which the returning
>value is a sequence. For example,

>f[n_]:=Module[{}, If[n<0,Return[Sequence[]]]; Sequence[g[n],f[n-1]]
>]

>The above code doesn't work because the Sequence function was
>evaluated before it's returned.

Have you read the documentation for Sequence? My guess is this
function simply isn't designed to do what you want or perhaps
think it does. The purpose of Sequence in Mathematica is to
convert some expression into a sequence of arguments to be used
by something else. For example, suppose I had

Clear[f];
f[a_, b_, c_] := a b^c
y = c + b;

and I wanted the result

a b^c

then I could use Sequence as follows:

In:= f[a, Sequence @@ y]

Out= a b^c

Assuming the sequence you want returned is a mathematical
sequence, i.e., a list of values, then Nest is the function to
use. For example, here is something that returns the Fibonnaci sequence

In:= g[n_] := Nest[Flatten@{#, Plus @@ #[[-2 ;;]]} &, {1, 1}, n]

In:= g

Out= {1,1,2,3,5,8}

```

• Prev by Date: Re: Eigenvalues works very slow
• Next by Date: Re: Eigenvalues works very slow
• Previous by thread: Re: Creating a recursive function which returns a sequence
• Next by thread: How accurate is the solution for high degree algebraic equation?
{"ft_lang_label":"__label__en","ft_lang_prob":0.8369263,"math_prob":0.823564,"size":1537,"snap":"2019-13-2019-22","text_gpt3_token_len":456,"char_repetition_ratio":0.13372472,"word_repetition_ratio":0.043290045,"special_character_ratio":0.30839297,"punctuation_ratio":0.1994302,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99168587,"pos_list":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14],"im_url_duplicate_count":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-05-20T21:59:55Z\",\"WARC-Record-ID\":\"<urn:uuid:7ea890a9-485f-47f2-9fe5-077cd07ed98c>\",\"Content-Length\":\"42458\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:bf032ead-f497-489c-98ff-dd3e99680dfd>\",\"WARC-Concurrent-To\":\"<urn:uuid:ac8c0dee-3f6f-4db9-9c8c-fe02c422517d>\",\"WARC-IP-Address\":\"140.177.205.73\",\"WARC-Target-URI\":\"http://forums.wolfram.com/mathgroup/archive/2012/Oct/msg00255.html\",\"WARC-Payload-Digest\":\"sha1:YE3T4TUMWZIUQ5GUOJ47Q2BCFAS54OG6\",\"WARC-Block-Digest\":\"sha1:W7FQW33G7COSAP2CDBRQ3U3CP4A6KIDU\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-22/CC-MAIN-2019-22_segments_1558232256147.15_warc_CC-MAIN-20190520202108-20190520224108-00105.warc.gz\"}"}