As I mentioned in the comments, Dyalog APL has guards that can be used for conditional execution, and so you can just check the empty vector and give a different answer.
This can be implemented in a more traditional / pure APL method.
This version only works in 1-dimensional
In APL font:
ZβDIFFERENCE V β Calculate difference between vectors, with empty set protection β Difference is calculated by a reduced ceiling subtracted from the reduced floor β eg. (ββΏ(βV)) - (ββΏ(βV)) β Protection is implemented by comparison against the empty set β¬β‘V β Which yields 0 or 1, and using that result to select an answer from a tuple β If empty, then it drops the first element, yielding just a zero, otherwise both are retained β eg. <condition>β(ab) => 0 = (ab), 1 = (b) β The final operation is first β, to remove the first element from the tuple. Zββ(β¬β‘V)β(((ββΏ(βV)) - (ββΏ(βV))) 0)
Or in a brace for people without a font.
Z{leftarrow}DIFFERENCE V {lamp} Calculate difference between vectors, with empty set protection {lamp} Difference is calculated by a reduced ceiling subtracted from the reduced floor {lamp} eg. ({upstile}{slashbar}({upstile}V)) - ({downstile}{slashbar}({downstile}V)) {lamp} Protection is implemented by comparison against the empty set {zilde}{equalunderbar}V {lamp} Which yields 0 or 1, and using that result to select an answer from a tuple {lamp} If empty, then it drops the first element, yielding just a zero, otherwise both are retained {lamp} eg. <condition>{downarrow}(ab) => 0 = (ab), 1 = (b) {lamp} The final operation is first {uparrow}, to remove the first element from the tuple. Z{leftarrow}{uparrow}({zilde}{equalunderbar}V){downarrow}((({upstile}{slashbar}({upstile}V)) - ({downstile}{slashbar}({downstile}V))) 0)
and image to save ...

Update. multidimensional
ZβDIFFERENCE V β Calculate difference between vectors, with empty set protection β Initially enlist the vector to get reduce to single dimension β eg. βV β Difference is calculated by a reduced ceiling subtracted from the reduced floor β eg. (β/V) - (β/V) β Protection is implemented by comparison against the empty set β¬β‘V β Which yields 0 or 1, and using that result to select an answer from a tuple β If empty, then it drops the first element, yielding just a zero, otherwise both are retained β eg. <condition>β(ab) => 0 = (ab), 1 = (b) β The final operation is first β, to remove the first element from the tuple. VββV Zββ(β¬β‘V)β(((β/V) - (β/V)) 0)

source share