I want to use a replacement rule to transform a list of equations. The following works as expected:

eqns = {x'[t] == 2 y[t], y'[t] == -3 x[t]};
eqns /. (var_'[t] == rhs_) -> {var, rhs}
(* {{x, 2 y[t]}, {y, -3 x[t]}} *)

Now I want to use the same idea to get the Min and Max of an Interval associated with each variable.

range[x] = Interval[{-1, 1}]; range[y] = Interval[{-2, 2}];
eqns /. (var_'[t] == rhs_) -> {Min[range[var]], Max[range[var]]}

Since {Min[range[x]], Max[range[x]]} = {-1 ,1}, I expected to get

(* {{-1, 1}, {-2, 2}} *)

but instead I get

(* {{Interval[{-1, 1}], Interval[{-1, 1}]}, {Interval[{-2, 2}], Interval[{-2, 2}]}} *)

What am I doing wrong and how to fix it?


closed as off-topic by Bob Hanlon, m_goldberg, Henrik Schumacher, MarcoB, xzczd Feb 11 at 4:39

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Bob Hanlon, m_goldberg, Henrik Schumacher, MarcoB, xzczd
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    $\begingroup$ Use :> instead of ->. Notice Min@aaaa evaluates to aaaa. :) $\endgroup$ – xzczd Feb 10 at 15:26
  • $\begingroup$ @xzczd Yep, it was that easy. Thanks! $\endgroup$ – Chris K Feb 10 at 15:27
  • $\begingroup$ @xzczd Any rule of thumb when to use :> vs. -> in this context? $\endgroup$ – Chris K Feb 10 at 15:31
  • 2
    $\begingroup$ Well, personally I don't recommend deciding it based on rule of thumb. Just think about if the right hand side can be/should be evaluate before pattern matching. -> evaluates the right hand side instantly, while in this case, Min[range[var]] will evaluate to range[var], so the right hand side should not be evaluated before the pattern matches. You may use Trace to check the evaluation order. $\endgroup$ – xzczd Feb 10 at 15:36