loda-cpp icon indicating copy to clipboard operation
loda-cpp copied to clipboard

Metaprogramming module

Open ckrause opened this issue 2 months ago • 3 comments

Add a new module meta for LODA metaprogramming. It should provide util function that combine two programs to produce a new program. The following combinations could be interesting for a start.

Composition

Let A and B be the in integer sequences generated be the two input program. The output program should generated the composition of A and B, i.e. C(n) = B(A(n)).

Elementwise combination

In addition to the two input porgrams, this also gets an arithmetic operation types as third argument. The output program should generate the sequence given by the elementwise combination of the inputs, i.e. C(n) = A(n) X B(n) where _ X _ is the given binary arithemetic operation.

Union

Let A and B be strictly increasing integer sequences representing sets of integers. The output program should generate again a strictly increasing sequences that represents the union of the two integer sets: C = A u B.

ckrause avatar Oct 26 '25 10:10 ckrause

Composition:

seq $0,A
seq $0,B

Elementwise combination:

mov $1,$0
seq $0,A
seq $1,B
[operation] $0,$1

Union:

lpb $0
mov $3,$1
mov $4,$2
seq $3,A
seq $4,B
mov $5,$3
min $5,$4
equ $3,$5
equ $4,$5
add $1,$3
add $2,$4
sub $0,1
lpe
mov $0,$5

loader3229 avatar Oct 26 '25 10:10 loader3229

Yes but the idea is to support this also if A and B are not OEIS seqs (just programs).

There are also more ways to combine programs, e.g. convolution.

ckrause avatar Oct 26 '25 19:10 ckrause

Just unfold seq $3,A and seq $4,B to these 2 programs (without indirect)

loader3229 avatar Oct 27 '25 04:10 loader3229