指定コードを入れて実行してみました
結果は次の通りです
実行結果
Depth=0 Norm=1.0093 e0=1.0093 e1=0.0000 N=3.000 Q=1.000
[通常の子]
Depth=1 Norm=1.0308 e0=1.0302 e1=0.0000 N=3.000 Q=1.000
[通常の子]
Depth=2 Norm=1.0244 e0=1.0162 e1=0.1077 N=3.000 Q=1.000
[通常の子]
Depth=3 Norm=0.9498 e0=0.8883 e1=0.3196 N=3.000 Q=1.000
[通常の子]
Depth=4 Norm=0.8027 e0=0.5329 e1=0.5868 N=3.000 Q=1.000
[通常の子]
Depth=5 Norm=1.1149 e0=0.1305 e1=1.0935 N=1.000 Q=0.333
[共役の子]
Depth=5 Norm=1.1149 e0=0.1305 e1=-1.0935 N=1.000 Q=0.333
[共役の子]
Depth=4 Norm=1.0178 e0=0.8219 e1=-0.5868 N=3.000 Q=1.000
[通常の子]
Depth=5 Norm=1.1405 e0=1.0939 e1=-0.2969 N=0.000 Q=0.000
[共役の子]
Depth=5 Norm=1.1405 e0=1.0939 e1=0.2969 N=0.000 Q=0.000
[共役の子]
Depth=3 Norm=1.0601 e0=1.0054 e1=-0.3196 N=3.000 Q=1.000
[通常の子]
Depth=4 Norm=1.0686 e0=1.0664 e1=0.0092 N=2.000 Q=0.667
[通常の子]
Depth=5 Norm=1.1475 e0=0.9481 e1=0.6383 N=0.000 Q=0.000
[共役の子]
Depth=5 Norm=1.1475 e0=0.9481 e1=-0.6383 N=0.000 Q=0.000
[共役の子]
Depth=4 Norm=1.0710 e0=1.0688 e1=-0.0092 N=2.000 Q=0.667
[通常の子]
Depth=5 Norm=1.1477 e0=0.9559 e1=0.6233 N=0.000 Q=0.000
[共役の子]
Depth=5 Norm=1.1477 e0=0.9559 e1=-0.6233 N=0.000 Q=0.000
[共役の子]
Depth=2 Norm=1.0531 e0=1.0452 e1=-0.1077 N=3.000 Q=1.000
[通常の子]
Depth=3 Norm=1.0309 e0=1.0241 e1=0.1132 N=3.000 Q=1.000
[通常の子]
Depth=4 Norm=0.9000 e0=0.7897 e1=0.4296 N=3.000 Q=1.000
[通常の子]
Depth=5 Norm=1.1323 e0=0.4529 e1=1.0313 N=1.000 Q=0.333
[共役の子]
Depth=5 Norm=1.1323 e0=0.4529 e1=-1.0313 N=1.000 Q=0.333
[共役の子]
Depth=4 Norm=1.0878 e0=0.9985 e1=-0.4296 N=2.000 Q=0.667
[通常の子]
Depth=5 Norm=1.1506 e0=1.1489 e1=0.0235 N=0.000 Q=0.000
[共役の子]
Depth=5 Norm=1.1506 e0=1.1489 e1=-0.0235 N=0.000 Q=0.000
[共役の子]
Depth=3 Norm=1.0695 e0=1.0628 e1=-0.1132 N=2.000 Q=0.667
[通常の子]
Depth=4 Norm=0.9958 e0=0.9671 e1=0.2279 N=2.000 Q=0.667
[通常の子]
Depth=5 Norm=1.1431 e0=0.7257 e1=0.8758 N=0.000 Q=0.000
[共役の子]
Depth=5 Norm=1.1431 e0=0.7257 e1=-0.8758 N=0.000 Q=0.000
[共役の子]
Depth=4 Norm=1.1055 e0=1.0797 e1=-0.2279 N=2.000 Q=0.667
[通常の子]
Depth=5 Norm=1.1529 e0=1.1013 e1=0.3331 N=0.000 Q=0.000
[共役の子]
Depth=5 Norm=1.1529 e0=1.1013 e1=-0.3331 N=0.000 Q=0.000
[共役の子]
Depth=1 Norm=1.0323 e0=1.0317 e1=0.0000 N=3.000 Q=1.000
[通常の子]
Depth=2 Norm=1.0282 e0=1.0225 e1=0.1077 N=3.000 Q=1.000
[通常の子]
Depth=3 Norm=0.9549 e0=0.8988 e1=0.3201 N=3.000 Q=1.000
[通常の子]
Depth=4 Norm=0.8061 e0=0.5456 e1=0.5887 N=3.000 Q=1.000
[通常の子]
Depth=5 Norm=1.1160 e0=0.1427 e1=1.0991 N=1.000 Q=0.333
[共役の子]
Depth=5 Norm=1.1160 e0=0.1427 e1=-1.0991 N=1.000 Q=0.333
[共役の子]
Depth=4 Norm=1.0233 e0=0.8337 e1=-0.5887 N=3.000 Q=1.000
[通常の子]
Depth=5 Norm=1.1415 e0=1.1030 e1=-0.2879 N=0.000 Q=0.000
[共役の子]
Depth=5 Norm=1.1415 e0=1.1030 e1=0.2879 N=0.000 Q=0.000
[共役の子]
Depth=3 Norm=1.0636 e0=1.0135 e1=-0.3201 N=3.000 Q=1.000
[通常の子]
Depth=4 Norm=1.0690 e0=1.0689 e1=0.0132 N=2.000 Q=0.667
[通常の子]
Depth=5 Norm=1.1480 e0=0.9455 e1=0.6495 N=0.000 Q=0.000
[共役の子]
Depth=5 Norm=1.1480 e0=0.9455 e1=-0.6495 N=0.000 Q=0.000
[共役の子]
Depth=4 Norm=1.0752 e0=1.0750 e1=-0.0132 N=2.000 Q=0.667
[通常の子]
Depth=5 Norm=1.1485 e0=0.9661 e1=0.6172 N=0.000 Q=0.000
[共役の子]
Depth=5 Norm=1.1485 e0=0.9661 e1=-0.6172 N=0.000 Q=0.000
[共役の子]
Depth=2 Norm=1.0542 e0=1.0486 e1=-0.1077 N=3.000 Q=1.000
[通常の子]
Depth=3 Norm=1.0294 e0=1.0223 e1=0.1147 N=3.000 Q=1.000
[通常の子]
Depth=4 Norm=0.8967 e0=0.7827 e1=0.4325 N=3.000 Q=1.000
[通常の子]
Depth=5 Norm=1.1320 e0=0.4428 e1=1.0355 N=1.000 Q=0.333
[共役の子]
Depth=5 Norm=1.1320 e0=0.4428 e1=-1.0355 N=1.000 Q=0.333
[共役の子]
Depth=4 Norm=1.0868 e0=0.9948 e1=-0.4325 N=3.000 Q=1.000
[通常の子]
Depth=5 Norm=1.1506 e0=1.1497 e1=0.0130 N=0.000 Q=0.000
[共役の子]
Depth=5 Norm=1.1506 e0=1.1497 e1=-0.0130 N=0.000 Q=0.000
[共役の子]
Depth=3 Norm=1.0710 e0=1.0642 e1=-0.1147 N=2.000 Q=0.667
[通常の子]
Depth=4 Norm=0.9996 e0=0.9738 e1=0.2249 N=2.000 Q=0.667
[通常の子]
Depth=5 Norm=1.1437 e0=0.7357 e1=0.8713 N=0.000 Q=0.000
[共役の子]
Depth=5 Norm=1.1437 e0=0.7357 e1=-0.8713 N=0.000 Q=0.000
[共役の子]
Depth=4 Norm=1.1064 e0=1.0831 e1=-0.2249 N=2.000 Q=0.667
[通常の子]
Depth=5 Norm=1.1532 e0=1.1002 e1=0.3436 N=0.000 Q=0.000
[共役の子]
Depth=5 Norm=1.1532 e0=1.1002 e1=-0.3436 N=0.000 Q=0.000
ソースコードは次の通りです
Unit1.h
//—————————————————————————
#ifndef Unit1H
#define Unit1H
//—————————————————————————
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//—————————————————————————
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*(double scalar) const; // スカラー乗算は残す
double Norm() const;
Octonion Conjugate() const; // 標準的な共役
Octonion PhaseConjugate() const; // 位相共役用(必要に応じて拡張可能)
};
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 <vcl.h>
#pragma hdrstop
#include <math.h>
#include “Unit1.h”
//—————————————————————————
#pragma package(smart_init)
#pragma resource “*.dfm”
TForm1 *Form1;
//—————————————————————————
__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;
}
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;
}
// スカラー乗算は残す
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);
}
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;
}
// 数演算子を計算するメソッド(新規追加)
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);
}
}
//—————————————————————————
//—————————————————————————
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;
}
//—————————————————————————