Bogus

From Esolang
Jump to navigation Jump to search
Bogus
Paradigm(s) imperative
Designed by User:Matthilde
Appeared in 2021
Memory system stack-based
Computational class
Reference implementation Bogus
Influenced by FALSE
File extension(s) .bog

Bogus is a stack-based esoteric programming language based on FALSE made by User:Matthilde. It has no way to explicitly set any constant or consistent value. The only values the programmer can push are random integers. The lang has been called Bogus in reference to the Bogosort which is a very inefficient sorting algorithm where the list will be shuffled until it is in the right order.

Syntax

Bogus is stack-based and is "Forth-like", inspired by FALSE as said previously. Its instruction set is designed to prevent the user from getting a constant value in obvious ways.

Instruction set
Instruction Action
d dup
s swap
r rot
o over
y yeet (also known as drop)
R generate a random non-negative integer
+ Add 2 numbers from the stack
- Subtract 2 numbers from the stack
% Bitwise AND with 255
() Codeblock, used for control flow and function definition
; comment
[A-Za-z0-9] function
? if >0 then (codeblock)
! while >0 (codeblock)
~ Logical NOT
& Logical AND
| Logical OR
. Print character from stack
, Input character then push it to the stack with the spice added.
> Push from main stack to stack B
< Push from stack B to main stack
: Dup from stack B to main stack

Control-flow and functions

Control-flow and function definitions are followed by a codeblock, some code between parentheses. Control-flow pops from the stack to get a boolean value. If the number is positive, it is true, if it is zero or negative, it is false. Logical statements will output a random non-positive number when false and a random positive number when true.

For example, an if statement will look like this: ?(...)

If a function is not followed by a codeblock, it will run it instead.

I/O

Print function will just pop from the stack and print straight away.

The input function will get one character from stdin and add it to the spice. A random 8-bit constant value that cannot be obtained. It is only kept internally. The programmer's job would be to figure out how to extract it to get the actual input.

Programming standards

The programming standards are a few programming and implementation rules to make Bogus programs and interpreters spicier. One does not have to follow these. If they aren't respected, the program will be considered "non-standard". The reference implementation complies with all these standards.

  • The interpreter must lack any means of getting a consistent value using explicit/obvious instructions (example: literals or division).
  • Since Bogus is not intended to be used with specific random seeds, any random number generator can be used to implement a Bogus interpreter.
  • Programs written in Bogus must work with (almost) any random seed, no matter what is the random number generator. It is almost impossible to guarantee that every seed will work, but the program should work with as much as possible.
  • It is preferable the programs have an "accuracy score". This is a score scaled in percentage.
  • Programs do not rely on debugging features if the interpreter provides debug features.

Accuracy score

To make an accuracy score, the programmer must test their Bogus program on different random seeds. If the program returns the expected result, the seed is compatible with the program. If not, the program isn't.

The score is the percentage of compatible seeds out of all tested seeds. The more seeds are tested, the more accurate this score will be. The goal of the programmer is to maximize the accuracy score.

Implementation

There is a reference implementation of an updated version at https://codeberg.org/matthilde/bogus

High accuracy constants

The main challenge in programming Bogus is reliably producing known constants. The usual approach in similar languages is to divide a random number by itself or to raise it to a zeroth power, but neither of these operations is available, and they can't be implemented without already having access to a constant 1. One probabilistic approach is to get some random number and make it better with some iterative process. The process presented here is to generate a new number and keep subtracting the smaller from the bigger until they're equal, therefore finding the greatest common divisor between them. A probability of many random numbers having a GCD greater than 1 is low, therefore this process should achieve high accuracy.

; ( n -- gcd(n,R) )
f(Rd~!(yRd~)oos-?(s)oo-!(oo-!(d>-<oo-)soo-)y)

; Repeating 30 times was sufficient in my 150000000 tests on 32-bit random numbers.
; 50 times should be an overkill, but adding even more will increase accuracy.

1(ffffffffffffffffffffffffffffffffffffffffffffffffff)

For maximum accuracy the one should be computed once and copied for all other purposes.