Hashtron inference: Difference between revisions

m
m (→‎{{header|Phix}}: mior tidy)
Line 328:
function hashtron(integer n, s, mx)
// Mixing stage, mix input with salt using subtraction
atom m = and_bitsu(n-s,U32) && U32
// Hashing stage, use xor shift with prime coefficients
for p in {-2,-3,+5,+7,-11,-13,+17,-19} do
m = xor_bitsu(m,and_bitsu(shift_bits(m,p), && U32))
end for
 
// Mixing stage 2, mix input with salt using addition
m = and_bitsu(m+s, && U32)
 
// Modular stage using Lemire's fast alternative to modulo reduction
Line 342:
end function
 
function inference(integer commandcmd, bits, sequence program)
atom out = 0
if length(program) then
for j=0 to bits-1 do
integer {ss, maxx} = program[1],
input = hashtron(or_bitsucmd||(command,j<<16), ss, maxx)
for p in program from 2 do
integer {s, mx}maxx -= p[2]
maxxinput -= mxhashtron(input, p[1], maxx)
input = hashtron(input, s, maxx)
end for
if odd(input) then
7,820

edits