Search code examples
juliajulia-jumpijulia-notebookjulia-studio

How can I use universal and existential quantification in julia?


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


Solution

  • 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