Consider the following example, where we specify the precision of the numbers to perform a significant figures calculation:

(341.7`4 - 22.0`3) + (0.002240`4 * 814005`6)

(* 2143. *)

It may be the case that we receive this input as a string, and evaluate it to yield the proper result:

str = "(341.7`4 - 22.0`3) + (0.002240`4 * 814005`6)"
(* 2143. *)

Evaluating arbitrary strings is unsafe, so using an Interpreter to limit ourselves to numerical calculations is better. However, the numeric Interpreter types do not appear to obey the significant figure calculation:

(* 2143.1 *) 

(* 2143.07 *)

(Of course, we could use the Expression Interpreter, but that gets us back to the unsafe behaviour):

(* 2143. *)

Thoughts? (I'm hesitating to say the b-u-g word, but...) (running this on 14.0)

  • 2
    $\begingroup$ It looks like it does obey the precision when you give it only a number (which is done locally without connecting to their server), eg. Interpreter["ComputedNumber"]["5`2"] // FullForm. However, when it actually needs to perform some calculation (by connecting to the Wolfram Knowledgebase), the final result will be given with the machine precision. This could be mentioned in the documentation, although it's probably not a very common use case ... $\endgroup$
    – Domen
    Feb 20 at 18:23
  • 1
    $\begingroup$ If you know what restrictions you need, one could use: Interpreter[Restricted["Expression", {Plus, Minus, Times}]][str] $\endgroup$
    – chuy
    Feb 20 at 22:27
  • $\begingroup$ @Chuy That's really slick and not so well documented $\endgroup$ Feb 20 at 22:40
  • 1
    $\begingroup$ I agree it could be better documented. You can see better examples in reference.wolfram.com/language/ref/interpreter/Expression.html. $\endgroup$
    – chuy
    Feb 20 at 22:43


Your Answer

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