実行結果
Depth=0 Norm=1.0093 e0=1.0093 e1=0.0000 N=3.0 Q=1.000
imagStrength=0.0000
[通常の子]
Depth=1 Norm=1.0312 e0=1.0306 e1=0.0000 N=3.0 Q=1.000
imagStrength=0.0350
[通常の子]
Depth=2 Norm=1.0266 e0=1.0191 e1=0.1022 N=3.0 Q=1.000
imagStrength=0.1784
[通常の子]
Depth=3 Norm=0.9575 e0=0.8999 e1=0.3037 N=3.0 Q=1.000
imagStrength=0.4483
[通常の子]
Depth=4 Norm=0.8173 e0=0.5656 e1=0.5579 N=3.0 Q=1.000
imagStrength=0.8132
[通常の子]
Depth=5 Norm=1.1280 e0=0.1850 e1=1.0425 N=1.0 Q=0.333
imagStrength=1.5927
[共役の子]
Depth=5 Norm=1.1280 e0=0.1850 e1=-1.0425 N=1.0 Q=0.333
imagStrength=1.5927
[共役の子]
Depth=4 Norm=1.0211 e0=0.8335 e1=-0.5579 N=3.0 Q=1.000
imagStrength=0.8132
[通常の子]
Depth=5 Norm=1.1515 e0=1.0779 e1=-0.2196 N=0.0 Q=0.000
imagStrength=0.6969
[共役の子]
Depth=5 Norm=1.1515 e0=1.0779 e1=0.2196 N=0.0 Q=0.000
imagStrength=0.6969
[共役の子]
Depth=3 Norm=1.0590 e0=1.0073 e1=-0.3037 N=3.0 Q=1.000
imagStrength=0.4483
[通常の子]
Depth=4 Norm=1.0546 e0=1.0454 e1=0.0423 N=2.0 Q=0.667
imagStrength=0.2286
[通常の子]
Depth=5 Norm=1.1494 e0=0.9026 e1=0.6885 N=0.0 Q=0.000
imagStrength=0.8748
[共役の子]
Depth=5 Norm=1.1494 e0=0.9026 e1=-0.6885 N=0.0 Q=0.000
imagStrength=0.8748
[共役の子]
Depth=4 Norm=1.0788 e0=1.0697 e1=-0.0423 N=2.0 Q=0.667
imagStrength=0.2286
[通常の子]
Depth=5 Norm=1.1515 e0=0.9839 e1=0.5611 N=0.0 Q=0.000
imagStrength=0.8445
[共役の子]
Depth=5 Norm=1.1515 e0=0.9839 e1=-0.5611 N=0.0 Q=0.000
imagStrength=0.8445
[共役の子]
Depth=2 Norm=1.0520 e0=1.0446 e1=-0.1022 N=3.0 Q=1.000
imagStrength=0.1784
[通常の子]
Depth=3 Norm=1.0248 e0=1.0152 e1=0.1295 N=3.0 Q=1.000
imagStrength=0.2008
[通常の子]
Depth=4 Norm=0.8894 e0=0.7661 e1=0.4490 N=3.0 Q=1.000
imagStrength=0.5176
[通常の子]
Depth=5 Norm=1.1363 e0=0.4192 e1=1.0378 N=1.0 Q=0.333
imagStrength=1.2340
[共役の子]
Depth=5 Norm=1.1363 e0=0.4192 e1=-1.0378 N=1.0 Q=0.333
imagStrength=1.2340
[共役の子]
Depth=4 Norm=1.0841 e0=0.9855 e1=-0.4490 N=3.0 Q=1.000
imagStrength=0.5176
[通常の子]
Depth=5 Norm=1.1555 e0=1.1507 e1=-0.0048 N=0.0 Q=0.000
imagStrength=0.1095
[共役の子]
Depth=5 Norm=1.1555 e0=1.1507 e1=0.0048 N=0.0 Q=0.000
imagStrength=0.1095
[共役の子]
Depth=3 Norm=1.0716 e0=1.0625 e1=-0.1295 N=3.0 Q=1.000
imagStrength=0.2008
[通常の子]
Depth=4 Norm=1.0071 e0=0.9839 e1=0.2056 N=2.0 Q=0.667
imagStrength=0.2945
[通常の子]
Depth=5 Norm=1.1460 e0=0.7569 e1=0.8467 N=0.0 Q=0.000
imagStrength=1.0623
[共役の子]
Depth=5 Norm=1.1460 e0=0.7569 e1=-0.8467 N=0.0 Q=0.000
imagStrength=1.0623
[共役の子]
Depth=4 Norm=1.1042 e0=1.0831 e1=-0.2056 N=2.0 Q=0.667
imagStrength=0.2945
[通常の子]
Depth=5 Norm=1.1546 e0=1.0877 e1=0.3742 N=0.0 Q=0.000
imagStrength=0.4816
[共役の子]
Depth=5 Norm=1.1546 e0=1.0877 e1=-0.3742 N=0.0 Q=0.000
imagStrength=0.4816
[共役の子]
Depth=1 Norm=1.0319 e0=1.0313 e1=0.0000 N=3.0 Q=1.000
imagStrength=0.0350
[通常の子]
Depth=2 Norm=1.0266 e0=1.0203 e1=0.1133 N=3.0 Q=1.000
imagStrength=0.1202
[通常の子]
Depth=3 Norm=0.9526 e0=0.8937 e1=0.3249 N=3.0 Q=1.000
imagStrength=0.3871
[通常の子]
Depth=4 Norm=0.8087 e0=0.5426 e1=0.5836 N=3.0 Q=1.000
imagStrength=0.7455
[通常の子]
Depth=5 Norm=1.1270 e0=0.1478 e1=1.0665 N=1.0 Q=0.333
imagStrength=1.5252
[共役の子]
Depth=5 Norm=1.1270 e0=0.1478 e1=-1.0665 N=1.0 Q=0.333
imagStrength=1.5252
[共役の子]
Depth=4 Norm=1.0194 e0=0.8244 e1=-0.5836 N=3.0 Q=1.000
imagStrength=0.7455
[通常の子]
Depth=5 Norm=1.1517 e0=1.0871 e1=-0.2626 N=0.0 Q=0.000
imagStrength=0.6502
[共役の子]
Depth=5 Norm=1.1517 e0=1.0871 e1=0.2626 N=0.0 Q=0.000
imagStrength=0.6502
[共役の子]
Depth=3 Norm=1.0622 e0=1.0096 e1=-0.3249 N=3.0 Q=1.000
imagStrength=0.3871
[通常の子]
Depth=4 Norm=1.0677 e0=1.0652 e1=0.0155 N=2.0 Q=0.667
imagStrength=0.1085
[通常の子]
Depth=5 Norm=1.1505 e0=0.9377 e1=0.6610 N=0.0 Q=0.000
imagStrength=0.7489
[共役の子]
Depth=5 Norm=1.1505 e0=0.9377 e1=-0.6610 N=0.0 Q=0.000
imagStrength=0.7489
[共役の子]
Depth=4 Norm=1.0775 e0=1.0750 e1=-0.0155 N=2.0 Q=0.667
imagStrength=0.1085
[通常の子]
Depth=5 Norm=1.1513 e0=0.9707 e1=0.6035 N=0.0 Q=0.000
imagStrength=0.7976
[共役の子]
Depth=5 Norm=1.1513 e0=0.9707 e1=-0.6035 N=0.0 Q=0.000
imagStrength=0.7976
[共役の子]
Depth=2 Norm=1.0546 e0=1.0485 e1=-0.1133 N=3.0 Q=1.000
imagStrength=0.1202
[通常の子]
Depth=3 Norm=1.0320 e0=1.0260 e1=0.1094 N=3.0 Q=1.000
imagStrength=0.1310
[通常の子]
Depth=4 Norm=0.9019 e0=0.7921 e1=0.4259 N=3.0 Q=1.000
imagStrength=0.5061
[通常の子]
Depth=5 Norm=1.1375 e0=0.4575 e1=1.0188 N=1.0 Q=0.333
imagStrength=1.3079
[共役の子]
Depth=5 Norm=1.1375 e0=0.4575 e1=-1.0188 N=1.0 Q=0.333
imagStrength=1.3079
[共役の子]
Depth=4 Norm=1.0879 e0=0.9988 e1=-0.4259 N=3.0 Q=1.000
imagStrength=0.5061
[通常の子]
Depth=5 Norm=1.1556 e0=1.1466 e1=0.0376 N=0.0 Q=0.000
imagStrength=0.2331
[共役の子]
Depth=5 Norm=1.1556 e0=1.1466 e1=-0.0376 N=0.0 Q=0.000
imagStrength=0.2331
[共役の子]
Depth=3 Norm=1.0709 e0=1.0651 e1=-0.1094 N=2.0 Q=0.667
imagStrength=0.1310
[通常の子]
Depth=4 Norm=0.9966 e0=0.9688 e1=0.2330 N=2.0 Q=0.667
imagStrength=0.2566
[通常の子]
Depth=5 Norm=1.1452 e0=0.7256 e1=0.8778 N=0.0 Q=0.000
imagStrength=1.0027
[共役の子]
Depth=5 Norm=1.1452 e0=0.7256 e1=-0.8778 N=0.0 Q=0.000
imagStrength=1.0027
[共役の子]
Depth=4 Norm=1.1078 e0=1.0828 e1=-0.2330 N=2.0 Q=0.667
imagStrength=0.2566
[通常の子]
Depth=5 Norm=1.1551 e0=1.1057 e1=0.3340 N=0.0 Q=0.000
imagStrength=0.3515
[共役の子]
Depth=5 Norm=1.1551 e0=1.1057 e1=-0.3340 N=0.0 Q=0.000
imagStrength=0.3515
C++Builder2007ソースコード
//*** Unit1.h ***
//—————————————————————————
#ifndef Unit1H
#define Unit1H
//—————————————————————————
#include
#include
#include
#include
//—————————————————————————
struct Octonion {
double e[8];
Octonion(double a0=0.0, double a1=0.0, double a2=0.0, double a3=0.0,
double a4=0.0, double a5=0.0, double a6=0.0, double a7=0.0);
Octonion operator+(const Octonion& o) const;
Octonion operator-(const Octonion& o) const; // 減算
Octonion operator-() const; // 単項マイナス(念のため)
Octonion operator*(const Octonion& o) const; // ← 変更:完全乗算
Octonion operator*(double scalar) const; // スカラー乗算は残す
double Norm() const;
Octonion Conjugate() const; // 標準的な共役
Octonion PhaseConjugate() const; // 位相共役用(必要に応じて拡張可能)
Octonion ApplyDerivation(const Octonion& a, const Octonion& b) const; // D_a,b (this)
};
class RecursiveOcto {
public:
int depth;
Octonion value;
RecursiveOcto* child; // 通常の子
RecursiveOcto* childConj; // 共役の子(追加)
Octonion interference; // 干渉結果を保持するメンバーを追加
// ★ 追加
double N; // 数演算子(励起度)
double Q; // 電荷的な量 = N / 3
RecursiveOcto(int d, Octonion init);
~RecursiveOcto();
void Generate(int maxDepth);
void Dump(TMemo* memo);
void ComputeNumberOperator(); // ★ 追加
};
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *ButtonExit;
TButton *Button1;
TMemo *Memo1;
TButton *Button2;
void __fastcall ButtonExitClick(TObject *Sender);
void __fastcall Button1Click(TObject *Sender);
void __fastcall Button2Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//—————————————————————————
extern PACKAGE TForm1 *Form1;
//—————————————————————————
#endif
//*** Unit1.cpp ***
//—————————————————————————
#include
#pragma hdrstop
#include
#include “Unit1.h”
//—————————————————————————
#pragma package(smart_init)
#pragma resource “*.dfm”
TForm1 *Form1;
//リンカ|出力オプション|最大スタックサイズ 0x64000000(約1.56GB)大きすぎであったので、0x10000000に設定
//—————————————————————————
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//—————————————————————————
void __fastcall TForm1::ButtonExitClick(TObject *Sender)
{
Close();
}
//—————————————————————————
//—————————————————————————
Octonion::Octonion(double a0, double a1, double a2, double a3,
double a4, double a5, double a6, double a7) {
e[0]=a0; e[1]=a1; e[2]=a2; e[3]=a3;
e[4]=a4; e[5]=a5; e[6]=a6; e[7]=a7;
}
Octonion Octonion::Conjugate() const {
return Octonion(
e[0],
-e[1], -e[2], -e[3], -e[4], -e[5], -e[6], -e[7]
);
}
Octonion Octonion::PhaseConjugate() const {
return Conjugate();
}
Octonion Octonion::operator+(const Octonion& o) const {
Octonion res;
for(int i=0; i<8; i++) res.e[i] = e[i] + o.e[i];
return res;
}
// 二項減算
Octonion Octonion::operator-(const Octonion& o) const {
Octonion res;
for(int i = 0; i < 8; i++) {
res.e[i] = e[i] - o.e[i];
}
return res;
}
// 単項マイナス
Octonion Octonion::operator-() const {
Octonion res;
for(int i = 0; i < 8; i++) {
res.e[i] = -e[i];
}
return res;
}
// スカラー乗算は残す
Octonion Octonion::operator*(double scalar) const {
Octonion res;
for(int i=0; i<8; i++) res.e[i] = e[i] * scalar;
return res;
}
// 完全な八元数乗算
Octonion Octonion::operator*(const Octonion& o) const {
Octonion res;
// e0(実部)
res.e[0] = e[0]*o.e[0] - e[1]*o.e[1] - e[2]*o.e[2] - e[3]*o.e[3]
- e[4]*o.e[4] - e[5]*o.e[5] - e[6]*o.e[6] - e[7]*o.e[7];
// e1
res.e[1] = e[0]*o.e[1] + e[1]*o.e[0] + e[2]*o.e[3] - e[3]*o.e[2]
+ e[4]*o.e[5] - e[5]*o.e[4] - e[6]*o.e[7] + e[7]*o.e[6];
// e2
res.e[2] = e[0]*o.e[2] - e[1]*o.e[3] + e[2]*o.e[0] + e[3]*o.e[1]
+ e[4]*o.e[6] + e[5]*o.e[7] - e[6]*o.e[4] - e[7]*o.e[5];
// e3
res.e[3] = e[0]*o.e[3] + e[1]*o.e[2] - e[2]*o.e[1] + e[3]*o.e[0]
+ e[4]*o.e[7] - e[5]*o.e[6] + e[6]*o.e[5] - e[7]*o.e[4];
// e4
res.e[4] = e[0]*o.e[4] - e[1]*o.e[5] - e[2]*o.e[6] - e[3]*o.e[7]
+ e[4]*o.e[0] + e[5]*o.e[1] + e[6]*o.e[2] + e[7]*o.e[3];
// e5
res.e[5] = e[0]*o.e[5] + e[1]*o.e[4] - e[2]*o.e[7] + e[3]*o.e[6]
- e[4]*o.e[1] + e[5]*o.e[0] - e[6]*o.e[3] + e[7]*o.e[2];
// e6
res.e[6] = e[0]*o.e[6] + e[1]*o.e[7] + e[2]*o.e[4] - e[3]*o.e[5]
- e[4]*o.e[2] + e[5]*o.e[3] + e[6]*o.e[0] - e[7]*o.e[1];
// e7
res.e[7] = e[0]*o.e[7] - e[1]*o.e[6] + e[2]*o.e[5] + e[3]*o.e[4]
- e[4]*o.e[3] - e[5]*o.e[2] + e[6]*o.e[1] + e[7]*o.e[0];
return res;
}
double Octonion::Norm() const {
double sum = 0.0;
for(int i=0; i<8; i++) sum += e[i]*e[i];
return sqrt(sum);
}
Octonion Octonion::ApplyDerivation(const Octonion& a, const Octonion& b) const
{
// 1. 交換子 [a,b]
Octonion ab = a * b - b * a; // [a,b]
// 2. 交換子の作用 [[a,b], this]
Octonion commutator_term = ab * (*this) - (*this) * ab;
// 3. 結合子 [a,b,this] = (a*b)*this - a*(b*this)
Octonion assoc = (a * b) * (*this) - a * (b * (*this));
// 4. 標準的な導分公式(係数は調整可能)
// D = [[a,b],x] - 3[a,b,x]
Octonion result = commutator_term - assoc * 3.0;
// スケール調整(摂動が大きすぎないように)
return result * 0.5;
}
//---------------------------------------------------------------------------
RecursiveOcto::RecursiveOcto(int d, Octonion v)
: depth(d), value(v), child(NULL), childConj(NULL), N(0.0), Q(0.0)
{
}
RecursiveOcto::~RecursiveOcto() {
delete child;
delete childConj;
}
void RecursiveOcto::Generate(int maxDepth) {
if (depth >= maxDepth) return;
/* // 通常の次ステップ
Octonion rotator(cos(depth * 0.15), sin(depth * 0.15), 0.05, 0, 0, 0, 0, 0);
Octonion next = value * rotator;
next = next + Octonion(0.03, 0, 0, 0, 0, 0, 0, 0);
// 共役版
Octonion nextConj = next.PhaseConjugate();
// 子を生成
child = new RecursiveOcto(depth + 1, next);
child->Generate(maxDepth);
childConj = new RecursiveOcto(depth + 1, nextConj);
childConj->Generate(maxDepth);
// ===== 干渉計算 =====
interference = (child->value + childConj->value) * 0.5;
// ===== 親へのフィードバック(ここが追加) =====
// 干渉結果を親のvalueに少し混ぜる(フィードバック強度は調整可能)
double feedbackStrength = 0.3; // 0.1?0.5くらいで試すと良い
value = value * (1.0 – feedbackStrength) + interference * feedbackStrength;
*/
// === 既存の回転子 ===
Octonion rotator(cos(depth*0.15), sin(depth*0.15), 0.05, 0,0,0,0,0);
// === 新しい G2 的な微小導分を加える ===
// 例:e1 と e2 方向の導分を小さく作用させる
Octonion a(0, 1, 0, 0, 0, 0, 0, 0); // e1
Octonion b(0, 0, 1, 0, 0, 0, 0, 0); // e2
Octonion g2_perturb = value.ApplyDerivation(a, b) * 0.08; // 小さな摂動
Octonion next = (value + g2_perturb) * rotator;
next = next + Octonion(0.03, 0,0,0,0,0,0,0);
// 共役版
Octonion nextConj = next.PhaseConjugate();
// 子生成(既存と同じ)
child = new RecursiveOcto(depth+1, next);
child->Generate(maxDepth);
childConj = new RecursiveOcto(depth+1, nextConj);
childConj->Generate(maxDepth);
// 干渉 + フィードバック(既存)
interference = (child->value + childConj->value) * 0.5;
double feedbackStrength = 0.3;
value = value * (1.0 – feedbackStrength) + interference * feedbackStrength;
}
// 数演算子を計算するメソッド(新規追加)
void RecursiveOcto::ComputeNumberOperator()
{
// 基本励起:自分自身の虚数成分の「強さ」
// (e1?e7 の絶対値の合計を適度にスケール)
double imagStrength = 0.0;
/*imagStrength += fabs(value.e1);
imagStrength += fabs(value.e2);
imagStrength += fabs(value.e3);
imagStrength += fabs(value.e4);
imagStrength += fabs(value.e5);
imagStrength += fabs(value.e6);
imagStrength += fabs(value.e7); */
// ★ ここを e[1] ~ e[7] に修正
imagStrength += fabs(value.e[1]);
imagStrength += fabs(value.e[2]);
imagStrength += fabs(value.e[3]);
imagStrength += fabs(value.e[4]);
imagStrength += fabs(value.e[5]);
imagStrength += fabs(value.e[6]);
imagStrength += fabs(value.e[7]);
// 子供の有無による励起
int childCount = 0;
if (child) childCount++;
if (childConj) childCount++;
// 再帰的に子供の N を加算(階層全体の励起を蓄積) // 子供の N を再帰的に集める
double childrenN = 0.0;
if (child) {
child->ComputeNumberOperator();
childrenN += child->N;
}
if (childConj) {
childConj->ComputeNumberOperator();
childrenN += childConj->N;
}
// 最終的な N の定義(調整しやすい形)
// 子供の数 × 1.0 + 虚数強度 × 係数 + 子供たちの N の一部
//N = childCount * 1.0 + imagStrength * 0.8 + childrenN * 0.3;
// ★ 係数を調整したバージョン
// 子供の寄与を強め、虚数強度の影響を抑えめにする
/*N = childCount * 1.5
+ imagStrength * 0.4
+ childrenN * 0.25;*/
// ★ ここを大きく変更
N = childCount * 1.0 // 子供の数の影響を弱める
+ imagStrength * 0.6
+ childrenN * 0.05; // 子孫からの蓄積をかなり弱くする
// さらに、ある程度整数に近づけるための丸め(任意)
// N = floor(N + 0.5); // 整数にしたい場合はこの行を有効にする
// ★ ここから量子化(離散化)
/*if (N < 0.7) N = 0.0;
else if (N < 1.7) N = 1.0;
else if (N < 2.7) N = 2.0;
else if (N < 3.7) N = 3.0;
else N = 3.0; // 上限を3に制限
*/
// ★ 閾値を緩めた量子化
/*if (N < 0.8) N = 0.0;
else if (N < 1.8) N = 1.0;
else if (N < 2.8) N = 2.0;
else N = 3.0;*/
// 量子化
if (N < 0.7) N = 0.0;
else if (N < 1.5) N = 1.0;
else if (N < 2.3) N = 2.0;
else N = 3.0;
// 電荷的な量
Q = N / 3.0;
}
void RecursiveOcto::Dump(TMemo* memo)
{
/* if (!memo) return;
AnsiString s;
s.sprintf("Depth=%d Norm=%.4f e0=%.4f e1=%.4f N=%.3f Q=%.3f",
depth,
value.Norm(),
value.e[0],
value.e[1],
N,
Q);
memo->Lines->Add(s);
if (child) {
memo->Lines->Add(” [通常の子]”);
child->Dump(memo);
}
if (childConj) {
memo->Lines->Add(” [共役の子]”);
childConj->Dump(memo);
}
*/
if (!memo) return;
AnsiString s;
s.sprintf(“Depth=%d Norm=%.4f e0=%.4f e1=%.4f N=%.1f Q=%.3f”,
depth, value.Norm(), value.e[0], value.e[1], N, Q);
memo->Lines->Add(s);
// オプション:虚部の大きさを少し詳しく
double imag = 0;
for(int i=1;i<8;i++) imag += fabs(value.e[i]);
s.sprintf(" imagStrength=%.4f", imag);
memo->Lines->Add(s);
if (child) { memo->Lines->Add(” [通常の子]”); child->Dump(memo); }
if (childConj) { memo->Lines->Add(” [共役の子]”); childConj->Dump(memo); }
}
//—————————————————————————
//—————————————————————————
void __fastcall TForm1::Button1Click(TObject *Sender)
{
RecursiveOcto* root = new RecursiveOcto(0, Octonion(1.0));
root->Generate(5); // ← 2分岐なので深さは浅めに(5?6推奨)
Memo1->Clear();
root->Dump(Memo1);
delete root;
}
//—————————————————————————
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Memo1->Clear();
Octonion rootVal(1.0, 0, 0, 0, 0, 0, 0, 0); // 初期真空的な状態
RecursiveOcto* root = new RecursiveOcto(0, rootVal);
root->Generate(5); // 深さ5まで生成
root->ComputeNumberOperator(); // ★ ルートから再帰的に計算
// ★ 必ず Memo1 を渡す
root->Dump(Memo1);
delete root;
}
//—————————————————————————