I want to generate all the non-associative product for any ordered list. The code is following

struct X<: Number

first

second

function X(a,b)

new(a,b)

end

end

function XProduct(TL::Vector)

if length(TL)>1

h=vcat(X(TL[1],TL[2]),TL[3:end]);

for i = 2:length(TL)-1

a=TL[1:i-1]

b=X(TL[i],TL[i+1])

c=TL[i+2:end]

h=hcat(h,vcat(a,b,c))

end

return(h)

else

return(TL)

end

end

function binaryProduct(n::Int64)

TL=Vector(1:n)

XP = XProduct(TL)

while length(XP[:,1])>1

h=XProduct(XP[:,1])

for i = 2:size(XP)[2]

h=hcat(h,XProduct(XP[:,i]))

end

XP=h

end

return XP

end

Then I call the function binaryProduct(9). It takes nearly 9 seconds

.

While same program in Mathematica only need 0.8 seconds.

.

I am a newer in Julia. Are there any way to improve the efficiency of the Julia code?