(*函数定义*)
GIRCF`Core[f_] :=
Block[{RegularContinuedFraction`Mod =
If[FractionalPart@# === 0, 0, 1/FractionalPart@#] &, i, ii, j, k},
Catch@For[k = {IntegerPart[f]};
i = RegularContinuedFraction`Mod@f; j = -1, j < 233, j--,
If[i === 0,
Throw@k,
If[IntegerPart@i === 0,
AppendTo[k, Indeterminate]; Throw@k,
AppendTo[k, IntegerPart@i];
ii = RegularContinuedFraction`Mod@i; i =.; i = ii; ii =.;]]]]
GaussianIntegerMinkowskiQuestionMark[x___] := GIMQM@x;
GIMQM[x_] := GIMQM`Core@GIRCF@x;
GIMQM`Core[x_] :=
Block[{AlternatingTotal = Total[# (-1)^Range[0, Length[#] - 1]] &},
If[x[[-1]] === Indeterminate, Indeterminate,
First@x + 2 AlternatingTotal@(1/2^Accumulate@Rest@x)]];
(*绘图用函数*)
Debug`PlotC`Core[fn_, xmin_, xmax_, ymin_, ymax_, step_] :=
ParallelTable[
Ember`PlotHue[fn, (Arg[fn] + \[Pi])/(2 \[Pi]), 1/(
1 + 0.3 Log[Abs[fn] + 1]), 1 - 1/(1.1 + 5 Log[Abs[fn] + 1]),
1], {y, ymin + 0.0012, ymax, step}, {x, xmin + 0.0012, xmax, step},
Method -> "FinestGrained"]
(*可行性测试*)
In[116]:= GIMQM[53/117]-MinkowskiQuestionMark[53/117]
GIMQM[2333.055+666.1005I]
GIMQM[2333.12345+666.54321I]
Out[116]= 0
Out[117]= (2333+666 I)+2 (-2^(-13+6 I)-2^(-11+5 I)+2^(-11+6 I)+2^(-11+7 I)-2^(-7+5 I)+2^(-5+7 I)-2^(-4+6 I)+2^(-4+7 I))
Out[118]= Indeterminate
(*本函数只有两种可能结果,一是正常出值,二是Indeterminate,本函数是闵可夫斯基问号函数在高斯复数上的推广。*)
(*绘图测试*)
Debug`PlotC`Core[GIMQM[x + I y], -5, 5, -5, 5, 0.1]
Plot[{GIMQM[x], MinkowskiQuestionMark[x]}, {x, -5, 5}]
Plot3D[Abs[GIMQM[x]], {x, -5, 5}, {y, -5, 5}]
(*不出图+鬼畜函数图像*)
==================================================================
依赖函数:
ComplexRationalQ[x___] :=
(Head@Re@x === Rational \[Or] Head@Re@x === Integer) \[And]
(Head@Im@x === Rational \[Or] Head@Im@x === Integer)
GaussianIntegerRegularContinuedFraction[fn___] := GIRCF@fn;
GIRCF[x_, dx_] := GIRCF`Core@Rationalize[x, dx];
GIRCF[x_] :=
If[ComplexRationalQ@x,
GIRCF`Core@x,
If[ComplexRationalQ@Rationalize@x,
GIRCF`Core@Rationalize@x,
If[ComplexRationalQ@Rationalize[x, 0],
GIRCF`Core@Rationalize[x, 0],
GIRCF`Core@Rationalize[N@x, 0]]]];
Ember`PlotHue[fn_, h_, s_, b_, a_] :=
Which[
fn === True, Hue[1/2, 0.8, 0.8, 0.5],
fn === False, Hue[1/2, 1, 0.1, 0.5],
fn === ComplexInfinity, Hue[1/8, 1, 0.8, 0.5],
Abs[fn] === Infinity, Hue[Arg[fn], 1, 1, 0.3],
fn === Indeterminate, Hue[2/3, 1, 1, 0.5],
fn === Overflow[] \[Or]
NumberQ[h] === False \[Or]
NumberQ[s] === False \[Or]
NumberQ[b] === False \[Or]
NumberQ[a] === False,
Block[{Nfn = N[fn], Nh = N[h], Ns = N[s], Nb = N[b], Na = N[a]},
Which[
Nfn === Overflow[] \[Or]
NumberQ[Nh] === False \[Or]
NumberQ[Ns] === False \[Or]
NumberQ[Nb] === False \[Or]
NumberQ[Na] === False, Hue[1, 1, 1, 0.5],
Nfn === Underflow[], Hue[0.75, 1, 1, 0.5],
NumberQ[Nfn] === False, Hue[1/4, 1, 1, 0.5],
True, Hue[Nh, Ns, Nb, Na]]],
True, Hue[h, s, b, a]]
(*用于捕获异常值*)