Search code examples
maxima

Maxima function that check if each elements satisfies a condition


I have a lot of code like this:

ans: [[1,2,3,4],[1,2,3]];
condition: length(sublist(ans, lambda([u], length(u) = 4)) # length(ans));

In other languages the standard library provides a function like any or every to check for conditions like this. Does maxima provide a function like this? I'm searching for a function that could express the above in the following way:

ans: [[1,2,3,4],[1,2,3]];
condition: every(ans, lambda([u], length(u) = 4));

Solution

  • There is, indeed, an every in maxima:

    every(lambda([u], length(u) = 4), [[1,2,3,4],[3,4,5,6],[1,1,1,1]]);
        true
    every(lambda([u], length(u) = 4), ans);
        false