How to resolve the algorithm Kronecker product based fractals step by step in the Factor programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Kronecker product based fractals step by step in the Factor programming language

Table of Contents

Problem Statement

This task is based on   Kronecker product   of two matrices. If your language has no a built-in function for such product then you need to implement it first. The essence of fractals is self-replication (at least, self-similar replications). So, using   n   times self-product of the matrix   (filled with 0/1)   we will have a fractal of the   nth   order. Actually, "self-product" is a Kronecker power of the matrix. In other words: for a matrix   M   and a power   n   create a function like   matkronpow(M, n), which returns   MxMxMx...   (n   times product). A formal recurrent algorithm of creating Kronecker power of a matrix is the following:

Even just looking at the resultant matrix you can see what will be plotted. There are virtually infinitely many fractals of this type. You are limited only by your creativity and the power of your computer.

Using Kronecker product implement and show two popular and well-known fractals, i.e.:

The last one ( Sierpinski carpet) is already here on RC, but built using different approaches.

These 2 fractals (each order/power 4 at least) should be built using the following 2 simple matrices:

See implementations and results below in JavaScript, PARI/GP and R languages. They have additional samples of "H", "+" and checkerboard fractals.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Kronecker product based fractals step by step in the Factor programming language

Source code in the factor programming language

USING: io kernel math math.matrices.extras sequences ;

: mat-kron-pow ( m n -- m' )
    1 - [ dup kronecker-product ] times ;

: print-fractal ( m -- )
    [ [ 1 = "*" " " ? write ] each nl ] each ;
    
{ { 0 1 0 } { 1 1 1 } { 0 1 0 } }
{ { 1 1 1 } { 1 0 1 } { 1 1 1 } }
{ { 0 1 1 } { 0 1 0 } { 1 1 0 } }
[ 3 mat-kron-pow print-fractal ] tri@


  

You may also check:How to resolve the algorithm Flow-control structures step by step in the 6502 Assembly programming language
You may also check:How to resolve the algorithm Amicable pairs step by step in the R programming language
You may also check:How to resolve the algorithm Honaker primes step by step in the Rust programming language
You may also check:How to resolve the algorithm Permutations by swapping step by step in the Racket programming language
You may also check:How to resolve the algorithm Make directory path step by step in the JavaScript programming language