o
odinpkg.dev
packages / library / soroban-measurement-odin

soroban-measurement-odin

b27c13alibrary

a Infinity Soroban Simulation on Odin using Raylib

MIT · updated 3 years ago

Soroban

try to implement a infinity Soroban Board and simulator / Assistent

Idea

use i64 as a board representation, since boards are associatives (this idea/information has not come to my mind before, this is way the main idea take so long) and values can been easily multiply by the new number/scale of necessary boards add, thereis a ways and sheap way of implement this with dynamic arrays/queues (preferable queues because infinity small numbers representation) using Odin buildin dynamic/queue and the i64

the i64 or int64_t on C, are a great way to have a board representation, because is a conveninent number, that can been expoerted/dumped and used on another language without so much conversion

the calculations show that it can perform a 12 rods board of Soroban (64 / 5 ~ 12) with can proficiently handle a 1 trilion value board support on the 1.8E19 combinations of the i64 (2^64), with this, a association of boards can been perform

the main idea is that the board is on a configuration on with the numbers are on a sequence on the binary representation of the number, using each bit to represent a uppper bead (with can bee associated on the lower beads to bee positive upper beads too (or down beads on the 5 bead value on the top of the soroban)).

bellow a board representation illustration (with the 12 rods)

-----------------------------------------------
<|> <|> <|> <|> <|> <|> <|> <|> <|> <|> <|> <|>
 |   |   |   |   |   |   |   |   |   |   |   |
-----------------------------------------------
 |   |   |   |   |   |   |   |   |   |   |   |
<|> <|> <|> <|> <|> <|> <|> <|> <|> <|> <|> <|>
<|> <|> <|> <|> <|> <|> <|> <|> <|> <|> <|> <|>
<|> <|> <|> <|> <|> <|> <|> <|> <|> <|> <|> <|>
<|> <|> <|> <|> <|> <|> <|> <|> <|> <|> <|> <|>
-----------------------------------------------

for this board, we only need to represent the beads, if they are upper or down, and with this configurations, using a assuptions of a array of bits / booleans

[ 0  0  0  0  0  0  0  0  0  0  0  0 ]
[ 0  0  0  0  0  0  0  0  0  0  0  0 ]
[ 0  0  0  0  0  0  0  0  0  0  0  0 ]
[ 0  0  0  0  0  0  0  0  0  0  0  0 ]
[ 0  0  0  0  0  0  0  0  0  0  0  0 ]

with this binary representation, we can serialize this on a binary number, on the 64 bits of a i64

bellow the 64 bits of a i64

[ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ]

on with we take 5 bits each to represent a rod ( with have 5 beads total )

[ 0 0 0 0 0 0 0 0 0 0 0 0   --- top 1, value 5 beads on
  0 0 0 0 0 0 0 0 0 0 0 0   --- bead value 1
  0 0 0 0 0 0 0 0 0 0 0 0   --- bead value 2
  0 0 0 0 0 0 0 0 0 0 0 0   --- bead value 3
  0 0 0 0 0 0 0 0 0 0 0 0   --- bead value 4
  | 0 0 0 ] --- three last bits that can bee used of represent boards states, if necessary

(DISCLAIMER .: been ware that this struct probably will not reflect the actual slicing of 5 bits at time of the actual i64)

there is 12 rods on with the top and botton, if one rod is active on a bit, of one colum, they will active value of the rod of this rod, this is exception of the rod of the top, with active, value +5 on the rod on question.

with this approuch, xor | bitwish operations will been more performantic and more eficient for more disclosure and even multiplications for zeration of ceart parts of the board. of instance, enable 4 on botton will make any rod on the botton, to been zero. for instance, we can create with bitwish operations MACRO/Magic numbers to represent board default states, and check for places where there is values, more eficiently as well as setting new state of the board more rapidly/eficiently

Simulator / Interpreter

The board will use a little instruction/Enum/Union interpreter (we know that they may have a name of emulator, but since we do not bother do emulate the world phisics we call it’s simulation, even they behave like a limited emulator.. we preferer this word as well) on with they are a array of tuple of rod number* and instruction on with

bellown a pseudo-code / haskell-like

import qu "core:container/queue"
qu.Queue (possition : i64, asm_ins : Soroban_Instruction )

perform operation on the abacus for doing the calculations and work as a interface for the infinity* soroban simulation .

the simulation, will receive a board ( a actualy number of i64 type ) that then, will perform operation acordly with MACRO numbers and the instructions, the idea is that can been performatic and easy to check.

The Instructions and ADT

MAX_NUMBER_OF_BOARDS :: 64
MAX_ROD_PER_SOROBAN_BOARD :: 12
MAX_SOROBAN_INSTRUCTIONS :: 8192 // 2^13
MAX_SOROBAN_OPERATIONS_PER_BOARD :: 64
MAX_SOROBAN_OPERANDS :: 65536              // 2^16


Soroban_Board :: struct {
	board : i64,
	idx_current_local_rod : i8,
	scale_board : i32, // value to consider for scaling state eval
	current_instruction : Soroban_Instructions,
};

Soroban_Operands :: struct {
	current_operand_idx : i64,
	operand_numbers : [MAX_SOROBAN_OPERANDS]i64,
}

Infini_Soroban :: struct {
	boards : qu.Queue(Soroban_Board),
	total_state_of_boards : i64,
	idx_current_board : i64,
	operations : Soroban_Operation_Instructions,
	operands : Soroban_Operands,
}

Soroban_Operation_Instructions :: struct {
	current_idx_opins : i64,
	remain_value : i64,
	instructions : [MAX_SOROBAN_INSTRUCTIONS]Soroban_Instructions,
	rods_idx : [MAX_SOROBAN_INSTRUCTIONS]i64,
}

Soroban_Instructions :: union {

	INS_SB_ON_GO_DAMA_5,
	INS_SB_ON_ICHI_DAMA_1,
	INS_SB_ON_ICHI_DAMA_2,
	INS_SB_ON_ICHI_DAMA_3,
	INS_SB_ON_ICHI_DAMA_4,

	INS_SB_ZERO_GO_DAMA_5,
	INS_SB_ZERO_ICHI_DAMA_1,
	INS_SB_ZERO_ICHI_DAMA_2,
	INS_SB_ZERO_ICHI_DAMA_3,
	INS_SB_ZERO_ICHI_DAMA_4,

	INS_SB_CLEAR_ROD,

	INS_SB_NOP,
};


INS_SB_ON_GO_DAMA_5 :: struct {
	MACRO_MAGIC_NUMBER_INS_SB_ON_GO_DAMA_5 : i64,
}
INS_SB_ON_ICHI_DAMA_1 :: struct {
	MACRO_MAGIC_NUMBER_INS_SB_ON_ICHI_DAMA_1 : i64,
}
INS_SB_ON_ICHI_DAMA_2 :: struct {
	MACRO_MAGIC_NUMBER_INS_SB_ON_ICHI_DAMA_2 : i64,
}
INS_SB_ON_ICHI_DAMA_3 :: struct {
	MACRO_MAGIC_NUMBER_INS_SB_ON_ICHI_DAMA_3 : i64,
}
INS_SB_ON_ICHI_DAMA_4 :: struct {
	MACRO_MAGIC_NUMBER_INS_SB_ON_ICHI_DAMA_4 : i64,
}
INS_SB_ZERO_GO_DAMA_5 :: struct {
	MACRO_MAGIC_NUMBER_INS_SB_ZERO_GO_DAMA_5 : i64,
}
INS_SB_ZERO_ICHI_DAMA_1 :: struct {
	MACRO_MAGIC_NUMBER_INS_SB_ZERO_ICHI_DAMA_1 : i64,
}
INS_SB_ZERO_ICHI_DAMA_2 :: struct {
	MACRO_MAGIC_NUMBER_INS_SB_ZERO_ICHI_DAMA_2 : i64,
}
INS_SB_ZERO_ICHI_DAMA_3 :: struct {
	MACRO_MAGIC_NUMBER_INS_SB_ZERO_ICHI_DAMA_3 : i64,
}
INS_SB_ZERO_ICHI_DAMA_4 :: struct {
	MACRO_MAGIC_NUMBER_INS_SB_ZERO_ICHI_DAMA_4 : i64,
}
INS_SB_CLEAR_ROD :: struct {
	MACRO_MAGIC_NUMBER_INS_SB_CLEAR_ROD : i64,
}
INS_SB_NOP :: struct {
	MACRO_MAGIC_NUMBER_INS_SB_NOP : i64,
}

DISCLAIMER .: pay attention that this code can been out of date with the actual code on the source, also, that this is not intent to been working code, but a touth exercise on who to model the Data Structure to represent the code. and this example code, need to been fuder analise for better design also, operations and instructions (bytecode asm) needs to been distinct on the actual code and simulation part.

for compreension, operations as multiplication and division do not exist as well as complementary numbers, because, this is all abstractions on the fundamental structure of adition and subtractions of arbitrary rods possitions, even the idea of rods for temporary state are also a completly abstration as show on how to program a infinity abacus, so yeah… thats the ‘implementation’, else where, we use the resulting simulation of the architecture to do checks with the operational system operators, on the UI, if is correct the result of the simulation and state of the board..

this instructions needs to get aways of the underline idea of sum of values, since they are not a actually adition, but a actual activation of beads as bits on a matrix*, so the best underline interpretation to figure out is on and zero bit set, because is a active seting of bits. (again go to research to see if Gray Code will better for this effort…)

now we need to implement a framework/library to deal with this idea of board configuration and exceptions*, including f*cking NaN of the IEEE_754

with this memory leout, we can deal easily with infinity* soroban boards, with pretty much no cost at all on memory… (hopefully)

research

there is also a possible and easy to use conversion using Gray Code for dealing with the amount of bitwish operations, but we can work arround that using matrix* bitwish operations directly on the i64.

demos

motivation

try to implement a infinity Soroban Board. ( also a assistend for self learn and testing with statistics and measurements )

the magic of the abacus make me think if there is any way to perform more eficient operation on the board (and test,mesure this), and always think on how this can been perform (on a Rubik’s Cube twoo)

the ultimante goal of this project is perform a generic algoritm with markov chains to generate random moviments on with they are selected on a Monte Carlo Simulation, to perform operations that are closer to the actual or even correct response ( and isolete then with statistics, exporting data for fother examination ) for operations with the determined number and operation on the soroban.

the main idead is also, to perform a nealy infinity Soroban on with they can perform infinity* calculations, as simulations .

old naming

the old project idea name has been

  • a Soroban Mesurement System on Odin and using Raylib

the new intent is been a simulation of a infinity soroban and assistant for test using raylib and odin

version of Odin

dev-2023-11:ef5eb4b6