1
$\begingroup$

With Equal (==), if a and b are undefined symbols, a==b does not evaluate. This way we can say something like a==b/.{a->1,b->1} I want this behavior for Chop.

In other words, right now, Chop[a] gives a, but I want it to give Chop[a].

Ultimately I want the following behavior: Chop[a]/.a->10^-17 to evaluate to 0 (right now it evaluates to 10^-17).

$\endgroup$
1
  • $\begingroup$ Hold[Chop[a]] /. a -> 10.^-17 //ReleaseHold. Note that the number should not be exact. $\endgroup$
    – Domen
    Mar 8, 2022 at 10:13

1 Answer 1

2
$\begingroup$

Define your own chop function that only operates on numeric quantities:

ClearAll[chop]
chop[a_?NumericQ] := Chop[a]

chop[b]
(* chop[b] *)

chop[b] /. b -> 1.*^-17
(* 0 *)

Note that, as mentioned by Domen in comments, an arbitrary-precision number like 10^-17 won't be chopped to zero: you need machine-precision input. You could add a call to N in the definition of chop (Chop[N@a]) if you really want that behavior.

$\endgroup$
1
  • $\begingroup$ is this how Equal is defined? $\endgroup$ Mar 8, 2022 at 23:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.