Hashtron inference: Difference between revisions

Content added Content deleted
m (→‎{{header|Phix}}: mior tidy)
Line 328: Line 328:
function hashtron(integer n, s, mx)
function hashtron(integer n, s, mx)
// Mixing stage, mix input with salt using subtraction
// Mixing stage, mix input with salt using subtraction
atom m = and_bitsu(n-s,U32)
atom m = (n-s) && U32
// Hashing stage, use xor shift with prime coefficients
// Hashing stage, use xor shift with prime coefficients
for p in {-2,-3,+5,+7,-11,-13,+17,-19} do
for p in {-2,-3,+5,+7,-11,-13,+17,-19} do
m = xor_bitsu(m,and_bitsu(shift_bits(m,p),U32))
m = xor_bitsu(m,shift_bits(m,p) && U32)
end for
end for


// Mixing stage 2, mix input with salt using addition
// Mixing stage 2, mix input with salt using addition
m = and_bitsu(m+s,U32)
m = m+s && U32


// Modular stage using Lemire's fast alternative to modulo reduction
// Modular stage using Lemire's fast alternative to modulo reduction
Line 342: Line 342:
end function
end function


function inference(integer command, bits, sequence program)
function inference(integer cmd, bits, sequence program)
atom out = 0
atom out = 0
if length(program) then
if length(program) then
for j=0 to bits-1 do
for j=0 to bits-1 do
integer {ss, maxx} = program[1],
integer {ss, maxx} = program[1],
input = hashtron(or_bitsu(command,j<<16), ss, maxx)
input = hashtron(cmd||(j<<16), ss, maxx)
for p in program from 2 do
for p in program from 2 do
integer {s, mx} = p
maxx -= p[2]
maxx -= mx
input = hashtron(input, p[1], maxx)
input = hashtron(input, s, maxx)
end for
end for
if odd(input) then
if odd(input) then