@@ -59,7 +59,7 @@ function steady_state_polynomial(rs::ReactionSystem, ps, u0)
59
59
eqs_pars_funcs = vcat (equations (ns), conservedequations (rs))
60
60
eqs = map (eq -> substitute (eq. rhs - eq. lhs, p_dict), eqs_pars_funcs)
61
61
eqs_intexp = make_int_exps .(eqs)
62
- ss_poly = Catalyst. to_multivariate_poly (remove_denominators .(eqs_intexp))
62
+ ss_poly = Catalyst. to_multivariate_poly (remove_denominators .(common_denominator .( eqs_intexp) ))
63
63
return poly_type_convert (ss_poly)
64
64
end
65
65
@@ -78,6 +78,45 @@ function ___make_int_exps(expr)
78
78
end
79
79
end
80
80
81
+ function common_denominator (expr)
82
+ iscall (expr) || return expr
83
+ if operation (expr) == /
84
+ num, den = arguments (expr)
85
+ num = common_denominator (num)
86
+ den = common_denominator (den)
87
+ return num / den
88
+ end
89
+ if operation (expr) == +
90
+ num = 0
91
+ den = 1
92
+ for arg in arguments (expr)
93
+ arg = common_denominator (arg)
94
+ if iscall (arg) && operation (arg) == /
95
+ n, d = arguments (arg)
96
+ else
97
+ n = arg
98
+ d = 1
99
+ end
100
+ num = num * d + den * n
101
+ den *= d
102
+ end
103
+ return num / den
104
+ end
105
+ if operation (expr) == ^
106
+ base, pow = arguments (expr)
107
+ base = common_denominator (base)
108
+ if iscall (base) && operation (base) == /
109
+ num, den = arguments (base)
110
+ else
111
+ num, den = base, 1
112
+ end
113
+ num ^= pow
114
+ den ^= pow
115
+ return num / den
116
+ end
117
+ return maketerm (BasicSymbolic, operation (expr), map (common_denominator, arguments (expr)), metadata (expr))
118
+ end
119
+
81
120
# If the input is a fraction, removes the denominator.
82
121
function remove_denominators (expr)
83
122
s_expr = simplify_fractions (expr)
0 commit comments