JuliaSymbolics / SymbolicUtils.jl

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

Updating dict #467

Open lamorton opened 2 years ago

lamorton commented 2 years ago

OK, maybe this is pathological, but I was thinking maybe this would be an easy way to add unit conversion within equations in ModelingToolkit:

@syms x y z
summed = x + y + z
# Black magic
summed.dict[z] = 2 *summed.dict[z] # Multiply by new coefficient
print(summed)

The printout is still:

x + y + z

But I see the dict is successfully modified:

julia> summed.dict
Dict{Any, Number} with 3 entries:
  y => 1
  x => 1
  z => 2

So that means I changed the equation, right? So, there's a bug in the show function because it's not showing the correct value of the sum now. (Or is the dict just a leftover from the construction of the sum, and I shouldn't try to change the sum by modifying the dict? Maybe it should be immutable?)