# Is there a way for accuracy backtick notation to accept variable inputs?

Backtick notation uses

1.020


to give 1 with 20 places of accuracy after the decimal point. But what I want is

acc=20
1.0acc


so that I can easily change the accuracy of all my calculations. Is this possible?

• How about using a simple factor, as in acc=120;12*acc?
– Jens
Aug 3, 2015 at 18:16
• Aug 3, 2015 at 18:23
• @Jens I've wanted the same thing at times, but I don't know of any easy way to do it, since the back ticks are not operators. It would be like setting fraction = 23456 and wanting 1.fraction to translate to 1.23456. Aug 3, 2015 at 18:53
• You could write an awful function like ack[acc_][x_]:=ToExpression[ToString@x<>""<>ToString@acc] and do 1.00//ack[20] Aug 3, 2015 at 21:26
• @N.J.Evans Compare 0.200000000000001 // ack[20] and 0.20000000000000120. -- As I said, I have yet to figure out how to do this without the actual input string to the FE (i.e., via $PreRead). Aug 4, 2015 at 0:51 ## 2 Answers [Personally, I would be satisfied with SetAccuracy, at least in the use-cases in which I imagine I would need it. It just seems easier to me to learn how to work with the system instead of around it. Nonetheless, it seems to be possible....] Here's an idea of what I was talking about with $PreRead in a comment. On a syntax error, it might fail spectacularly, but it seems to work on correct input.

\$PreRead = # //.
RowBox[{x___, s_String /; StringMatchQ[s, __ ~~ ""], a_, y___}] :>
RowBox[{x, s <> ToString@ToExpression@a, y}] &


It evaluates the box form representing the accuracy and appends its value after the  in the input.

Then

acc = 10;
1.23(2 acc)
(*  1.2300000000000000000  *)

Accuracy[%]
(*  20.  *)


And

10.23acc + 4.56(2 acc)
(*  14.790000000  *)

Accuracy[%]
(*  10.  *)


The standard accuracy input syntax works:

1.2320
(*  1.2300000000000000000  *)


Perhaps you can use the Notation package to help.

<< Notation


Notation[a_ \[ScriptA] b_\[DoubleLongLeftRightArrow] N[Rationalize[a_,0],{Infinity,b_}]]


I used a picture of a cell here to make it clear that this has been entered via the Notation palette

Now you can use

list=Table[10.75\[ScriptA] k,{k,1,10}]
(* {11.,10.8,10.75,10.750,10.7500,10.75000,10.750000,10.7500000,10.75000000,10.750000000} *)


or

k=10;

Accuracy /@
NestList[(1.25 \[ScriptA] k) (# - 0.2 \[ScriptA] k) &,
1 \[ScriptA] k, 50]
(* {10., 9.48149, 9.20936, 9.01016, 8.84585, 8.70167, 8.57032, \
8.44771, 8.33128, 8.21936, 8.1108, 8.00479, 7.90074, 7.7982, 7.69684, \
7.5964, 7.49669, 7.39755, 7.29886, 7.20054, 7.1025, 7.00469, 6.90706, \
6.80957, 6.7122, 6.61493, 6.51772, 6.42058, 6.32348, 6.22642, \
6.12939, 6.03239, 5.9354, 5.83843, 5.74147, 5.64452, 5.54758, \
5.45064, 5.35371, 5.25679, 5.15986, 5.06294, 4.96602, 4.86911, \
4.77219, 4.67528, 4.57837, 4.48145, 4.38454, 4.28763, 4.19072} *)


vs

Accuracy /@ NestList[(1.2510) (# - 0.210) &, 1.010, 50]
(* {10., 9.48149, 9.20936, 9.01016, 8.84585, 8.70167, 8.57032, \
8.44771, 8.33128, 8.21936, 8.1108, 8.00479, 7.90074, 7.7982, 7.69684, \
7.5964, 7.49669, 7.39755, 7.29886, 7.20054, 7.1025, 7.00469, 6.90706, \
6.80957, 6.7122, 6.61493, 6.51772, 6.42058, 6.32348, 6.22642, \
6.12939, 6.03239, 5.9354, 5.83843, 5.74147, 5.64452, 5.54758, \
5.45064, 5.35371, 5.25679, 5.15986, 5.06294, 4.96602, 4.86911, \
4.77219, 4.67528, 4.57837, 4.48145, 4.38454, 4.28763, 4.19072} *)
`