Factor

From Esolang
Jump to navigation Jump to search

Factor (also known as Factors) is a zero-dimensional, cell-based, imperative programming language invented by User:Bangyen in 2020.

Factor
Paradigm(s) Imperative
Designed by Bangyen Pham
Appeared in 2020
Memory system Cell-based
Dimensions Zero-dimensional
Computational class Turing complete
Major implementations Java interpreter
Influenced by Brainfuck
File extension(s) .fact

Language overview

Factor is based on the prime factorization of numbers. Every program is a number, and the instructions of each program are determined by the number's prime factors and their multiplicity. Each factor is a different instruction (based on it's residue modulo 11), and each factor's multiplicity is the number of times the instruction is carried out. The order of the instructions is determined by sorting the factors in ascending order. The different instructions are as follows:

Move right Move left Increment Decrement Output Input Start loop End loop
Z₁₁ Residue 1 2 3 4 5 6 7 8
Brainfuck equivalent > < + - . , [ ]

Left and right refer to moving the pointer, whereas increment and decrement refer to changing the cell designated by the pointer. Loops are started if the current cell value is nonzero, and loops are ended if the current cell is zero. The cells are right unbounded and wrap at 0 and 256. All residue values other than 12345678 should be ignored. All characters other than 0123456789 should be considered comments and ignored.

Examples

Hello, World!

This program prints out the words Hello World!:

1655681263349701521084659680611551719864071403625859675993155360184979650875317924075071663014170796398214200089605837256575759246478855815981943506169969378179918285035832792782321874423879673381143676538661836790083866016752674868707301142092304365222517116382208838942082995905598124019955549

Cat

The Cat program, on the other hand, is represented as the number 310861643. The brainfuck equivalent would be ,[.,], since its prime factorization is 17 * 29 * 71 * 83 * 107. The equivalence is a result of the following congruencies:

Modular Equation Instruction
17 ≡ 6 (mod 11) Input
29 ≡ 7 (mod 11) Start loop
71 ≡ 5 (mod 11) Output
83 ≡ 6 (mod 11) Input
107 ≡ 8 (mod 11) End Loop

Truth-machine

A polyglot truth-machine by User:Salpynx.

233915737501853959241591127266540514014498928384925170744745371936977107366667491950094954248611898080571424768

Brainfuck interpreter

A brainfuck interpreter—original brainfuck code by Daniel B. Cristofani.

368855440011508260862450845373028072890813281876469684683466922977077776177247800552750717741812069432976120309340221938416776845493867296973951452840435491034328601495512730076926615215212383785853736543472783033594456315859326953695889493408883009750425138050844651886706519801267566755335040672769169314246314850096718381986217936538440978135796693186989285043518057083340698273100650740589170195944853545483117790840997254250431629873080400750638774072825327191509138222612338977142620589863600348218537048658597258852509353537173568671203552120996239185547386547855325347653142800549655880422575434246296592537566701190628313696689733814465190330854677385721890537798834133035312331218717681231768585411090749681388413701637848511821034275778015368885914416481728428368261819825748829491804055008670081513669181308499057177529659148439008707075389446903465545471675098029277846800886915820990250871509807705153209006144218167193691653670501061553110766552961219388025392574648961277078708851624794680376756007874280235420045187300289752000897984938289529466030800489239331379367208591621761722051490960163414413721023935201373298623861708704137798701766456816518388727419990119162281303945678618374744879985967667263711716239289270655822617297458187893109709477794801499438033800499001330034630332428972334774369394775556305217422378433767553969477390814636968707308732239542389301520687302337766872505644966051907429523694391319691589154855599276779048735777479669316766704156814084591354216434428512065158173722669676843275655431631295470654442175485742940558078916419832634153303347

Translations

Brainfuck to Factor

# Ruby program
require 'prime'

def translate(code)
    res = 1; i = 2; str = '0><+-.,[]'
    for char in code.chars
        while i % 11 != str.index(char) || !i.prime?
            i += 1
        end
       res *= i
    end
    res
end

Factor to brainfuck

# Ruby program
require 'prime'

def translate(num)
    res = ""; i = 2; str = '0><+-.,[]'
    while num != 1
        while num % i != 0
            i += 1
        end
        num /= i
        res += str[i % 11]
    end
    res
end

Computational class

The number 11 was chosen because it is the smallest number such that there exists at least 8 (the number of instructions) natural numbers less than and coprime to it. The reason why coprimality is important is because Dirichlet's theorem ensures that there are an infinite number of primes that are congruent to each coprime integer modulo 11. As a result, because Factor is equivalent to Brainfuck, a Turing-complete language, Factor is also Turing complete.

External Resources