[seqfan] A general programming question involving recursion

Felix Fröhlich felix.froe at gmail.com
Wed Apr 25 23:43:47 CEST 2018


Dear SeqFans,

I am trying to write a somewhat complex PARI program for a sequence I am
preparing. While preparing that program, I have run into a general
algorithmic problem. Without going into detail about why I need to perform
those operations, let me describe what I am trying to do:

I take a number n and compute the list of prime factors with repetition.
Now, from that list of prime factors I want to compute recursively all
possible permutations of all sets of numbers that can be obtained by
multiplying two prime factors in the list. In this way I want to obtain ALL
possible products from multplying any two prime factors from the original
set and from all permutations of that set and, recursively, all products
from all permutations resulting from multiplying two factors until the
products result in single numbers.

Normally, I would do this using two nested loops, one for going through the
permutations and one for going through the multiply over each vector. But
then, I also need to go through the permutations of the resulting vector
with multiplied elements and through the vectors resulting from multiplying
two neighboring elements of those vectors permutations, ..., and so on.

How is this best done in order to obtain all different permutations from
all vectors from multiplying two neighboring vector elements, starting with
a vector of any length down to a single element?

Ideas anyone?

Best regards

Felix


More information about the SeqFan mailing list