Fundamental Mathematics from an Advanced Standpoint

Math 4303

Helmut Knaust, Department of Mathematical Sciences, UTEP, El Paso TX 79968
hknaust@utep.edu

Last edits: 2/13/2011

Digit Representation

This command generates generalized “decimal” representations. DigitRepresentation[r,b] takes as input a rational number  r (in decimal representation) and an optional base b (default is 10). The base b must be an integer between 2 and 36.

DigitRepresentation[fraction_,base_:10]:=Module[{nr=fraction,b,d1,d2,d3,fp,d,pos},b=base;d1=IntegerString[IntegerPart[nr],b];nr=nr-IntegerPart[nr];fp={};d={};
While[Not[MemberQ[fp,nr]],fp=Append[fp,nr];nr=b nr;d=Append[d,IntegerPart[nr]];nr=nr-IntegerPart[nr];];
pos=Position[fp,nr][[1,1]];d2=If[pos>1,d[[1;;pos-1]],{}];d3=d[[pos;;Length[d]]];
Print[If[b==10,"","("],d1,".",If[d2=={},"",IntegerString[FromDigits[d2,b],b,Length[d2]]],If[d3=={}||d3=={0},"",OverBar[IntegerString[FromDigits[d3,b],b,Length[d3]]]],If[b==10,"",")"],If[b==10,"",Subscript["",b]]]]

DigitRepresentation[380/959]

DigitRepresentation[1/4,3]

DigitRepresentation[38370/9,23]

DigitRepresentation[38370/(9 23^5),23]