How can I use universal and existential quantification in julia?

51 Views Asked by At

I want to code domination definition in Julia. x dom y. x , y are 2 vectors.

b=all(x<=y) && any(x<y)

would you please help me. How can I code this concept in Julia?

Thank you

1

There are 1 best solutions below

0
Bogumił Kamiński On BEST ANSWER

The simplest approach can be almost like you have specified it:

dom(x, y) = all(x .<= y) && any(x .< y)

You could also use a loop e.g. like this:

function dom(x::AbstractVector, y::AbstractVector)
    @assert length(x) == length(y)
    wasless = false
    for (xi, yi) in zip(x, y)
        if xi < yi
            wasless = true
        elseif xi > yi
            return false
        end
    end
    return wasless
end