JuliaSymbolics / SymbolicUtils.jl

Symbolic expressions, rewriting and simplification
https://docs.sciml.ai/SymbolicUtils/stable/
Other
536 stars 107 forks source link

About simplify / simplify_fractions /quick_cancel for div expr #404

Open liushang0322 opened 2 years ago

liushang0322 commented 2 years ago

simplify / simplify_fractions /quick_cancel for div maybe too weak These functions seem to be unable to reduce the expression containing multiple div operations into an expression with only one div left at the end

@syms G1 G2 G3 G4 H1 H2 H3 Q = zeros(Num,5,5) Q[1,5] = -H3 Q[2,1] =  G1 Q[2,4] = -H2 Q[3,2] =  G2 Q[3,5] =  H1 Q[4,3] =  G3 Q[5,4] =  G4

P=[1 0 0 0 0]' G=(I(size(Q,1))-Q)\P g = G[end] g = expand(g)

op = operation(g) g1,g2 = arguments(g) g2 = PolyForm(g2) g2 = simplify_fractions(g2) g = g1//g2 @syms s a=[G1,G2,G3,G4,H1,H2,H3] b=[1/(1+s),(s+1)/(s^2+1),(2s+1)/(s^2+3s+1),1/s,(0.5s^2+s+1)/(s^3+2s^2+s-1),(1+2s)/(s^4+3s-10),1/(s^3-8*s^2-s+10)]; Dicts=a.=>b

G = substitute(g,Dict(Dicts)) G5 = substitute(g1/g2,Dict(Dicts))#G8 G6 = simplify(G5,expand=true) G5 = PolyForm(G5) G5A = simplify_fractions(simplify(expand(G5)))

G6 G5A G can not be simplified!!!!!!!

thank you so much!!!!!