Function Repository Resource:

TakagiT

Source Notebook

Evaluate the Takagi function

Contributed by: Jan Mangaldan

ResourceFunction["TakagiT"][x]

gives the Takagi function T(x).

Details

The Takagi function is also known as the blancmange function or the Takagi–Landsberg function.
Mathematical function, suitable for both symbolic and numeric manipulation.
The Takagi function is a self-affine function that is continuous and nowhere differentiable.
The Takagi function is a singly periodic function in x with period 1.
For certain arguments, ResourceFunction["TakagiT"] automatically evaluates to exact values.
ResourceFunction["TakagiT"] can be evaluated to arbitrary numerical precision.
ResourceFunction["TakagiT"] automatically threads over lists.

Examples

Basic Examples (1) 

Plot the Takagi function:

In[1]:=
Plot[ResourceFunction["TakagiT"][x], {x, -1/2, 3/2}]
Out[1]=

Scope (4) 

Evaluate at integers or rationals:

In[2]:=
ResourceFunction["TakagiT"][2]
Out[2]=
In[3]:=
ResourceFunction["TakagiT"][12/19]
Out[3]=

Evaluate at inexact real numbers:

In[4]:=
ResourceFunction["TakagiT"][1.273]
Out[4]=
In[5]:=
ResourceFunction["TakagiT"][1.27300000000000000000000]
Out[5]=

Parity transformation is automatically applied:

In[6]:=
ResourceFunction["TakagiT"][-x]
Out[6]=

TakagiT threads elementwise over lists:

In[7]:=
ResourceFunction["TakagiT"][{1/9, 1/7, 1/5}]
Out[7]=

Applications (2) 

Compare the Takagi function with a sum of the successive iterates of the tent map:

In[8]:=
tent[x_] := \!\(\*
TagBox[GridBox[{
{"\[Piecewise]", GridBox[{
{
RowBox[{"2", "x"}], 
RowBox[{"0", "<=", "x", "<=", 
RowBox[{"1", "/", "2"}]}]},
{
RowBox[{"2", "-", 
RowBox[{"2", "x"}]}], 
RowBox[{
RowBox[{"1", "/", "2"}], "<", "x", "<=", "1"}]}
},
AllowedDimensions->{2, Automatic},
Editable->True,
GridBoxAlignment->{"Columns" -> {{Left}}, "ColumnsIndexed" -> {}, "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxItemSize->{"Columns" -> {{Automatic}}, "ColumnsIndexed" -> {}, "Rows" -> {{1.}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[
            0.27999999999999997`], {
Offset[0.84]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}},
Selectable->True]}
},
GridBoxAlignment->{"Columns" -> {{Left}}, "ColumnsIndexed" -> {}, "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxItemSize->{"Columns" -> {{Automatic}}, "ColumnsIndexed" -> {}, "Rows" -> {{1.}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[
         0.27999999999999997`], {
Offset[0.35]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
"Piecewise",
DeleteWithContents->True,
Editable->False,
SelectWithContents->True,
Selectable->False,
StripWrapperBoxes->True]\)
In[9]:=
With[{n = 9}, Plot[{ResourceFunction["TakagiT"][x], Total[Rest[NestList[tent, x, n]]/2^Range[n]]}, {x, 0, 1}, {PlotLegends -> {"Takagi function", "tent map approximation"}, PlotStyle -> {
Thickness[0.015], 
Thickness[0.008]}}]]
Out[9]=

Compare the Takagi function with its Fourier series approximation:

In[10]:=
cc[0] = 1/2;
cc[n_Integer] := Module[{an = Abs[n], r},
  r = BitShiftRight[an, IntegerExponent[an, 2]];
  -1/(Pi^2 an r)]
In[11]:=
With[{n = 41}, Plot[{ResourceFunction["TakagiT"][x], Sum[cc[k] E^(2 \[Pi] I k x), {k, -n, n}]}, {x, 0, 1}, {PlotLegends -> {"Takagi function", "partial Fourier sum"}, PlotStyle -> {
Thickness[0.015], 
Thickness[0.008]}}]]
Out[11]=

Properties and Relations (2) 

The Takagi function satisfies the reflection identity T(1-x)=T(x) for 0≤x≤1:

In[12]:=
Plot[{ResourceFunction["TakagiT"][x], ResourceFunction["TakagiT"][1 - x]}, {x, 0, 1}, {PlotLegends -> {"T(x)", "T(1-x)"}, PlotStyle -> {
Thickness[0.025], 
Thickness[0.008]}}]
Out[12]=

The Takagi function satisfies the self-similarity identity T(x/2)=x/2+T(x)/2 for 0≤x≤1:

In[13]:=
Plot[{ResourceFunction["TakagiT"][x/2], x/2 + ResourceFunction["TakagiT"][x]/2}, {x, 0, 1}, {PlotLegends -> {"T(x/2)", "x/2 + T(x)/2"}, PlotStyle -> {
Thickness[0.025], 
Thickness[0.008]}}]
Out[13]=

Version History

  • 1.0.0 – 10 May 2021

Source Metadata

Related Resources

License Information