Skip to content

Simplify doesn't recognize a zero #1392

@andreasnoack

Description

@andreasnoack

The following system has no constant right-hand-side term but when I try to detect that programmatically I'm getting

julia> @parameters t CL Vc Qfast Vpfast Qslow Vpslow
(t, CL, Vc, Qfast, Vpfast, Qslow, Vpslow)

julia> @variables Central(t) Periph1(t) Periph2(t)
(Central(t), Periph1(t), Periph2(t))

julia> D = Differential(t);

julia> eqs = [
           D(Central) ~ -(CL/Vc)*Central + (Qfast/Vpfast)*Periph1 - (Qfast/Vc)*Central + (Qslow/Vpslow)*Periph2 - (Qslow/Vc)*Central,
           D(Periph1) ~ (Qfast/Vc)*Central - (Qfast/Vpfast)*Periph1,
           D(Periph2) ~ (Qslow/Vc)*Central - (Qslow/Vpslow)*Periph2
       ];

julia> @named sys = ODESystem(eqs);

julia> jac = calculate_jacobian(sys);

julia> linpart = jac*states(sys);

julia> rhs = [eq.rhs for eq  equations(sys)];

julia> cnst = rhs - linpart
3-element Vector{Num}:
 -(-CL*(Vc^-1) - (Qfast*(Vc^-1)) - (Qslow*(Vc^-1)))*Central(t) - (CL*Central(t)*(Vc^-1)) - (Qfast*Central(t)*(Vc^-1)) - (Qslow*Central(t)*(Vc^-1))
                  0
                  0

julia> simplify(cnst[1])
-(-CL*(Vc^-1) - (Qfast*(Vc^-1)) - (Qslow*(Vc^-1)))*Central(t) - (CL*Central(t)*(Vc^-1)) - (Qfast*Central(t)*(Vc^-1)) - (Qslow*Central(t)*(Vc^-1))

This happens both with version 5.20.0 and master. With version 5.20.0, I can simply the expressions with expand

julia> expand(cnst[1])
0

but on master, I'm getting

julia> simplify(expand(cnst[1]))
(CL*Central(t)) / Vc + (Qfast*Central(t)) / Vc + (Qslow*Central(t)) / Vc + (-CL*Central(t)) / Vc + (-Qfast*Central(t)) / Vc + (-Qslow*Central(t)) / Vc

Update: The versions of Symbolics are v0.1.22 and v4.1.0 respectively.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions