Filtering syntactically positive non constant symbolic terms from a matrix in Symbolics.jl fails in 2×2 test case

Here is a minimal test in Julia using Symbolics.jl:

using Symbolics
using LinearAlgebra

function NGM(M, var)
    M = simplify.(M)  # normalize all expressions
    F = map(e -> begin
        expr = string(e)
        depends = any(v -> occursin(string(v), expr), var)
        positive = !occursin("-", expr)
        depends && positive ? e : 0
    end, M)
    A = simplify.(M .- F)
    return F, A
end

@variables β γ μ N s r
var = [s, r]

M = [
    β*s/N - γ - μ - 1    β*r/N - 2
    -γ - 3               β*s/N - γ - μ - 4
]

F, A = NGM(M, var)

display(F)
display(A)

I don’t understand what you mean. “Syntactically positive non-constant symbolic terms” isn’t really well defined? Since x - y == x + (-y), is the second term positive?

I should have added “after a use of simplify” (so, use the “simplest” form a human would use).

In Mathematica, F=Replace[F1, _. _?Negative → 0, {2}] works reasonably well, after having used Simplify, which seems to have standardized answers. For info, it seems also that Together produces syntactically positive denominators whenever possible . Do also Julia simplifications standardize answers?

The desired answer for the test is:

F = [
    β*s/N     β*r/N
    0         β*s/N
]