Initial commit: GKERN glyph kernel
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
#ifndef GLYPH_DEFS_H
|
||||
#define GLYPH_DEFS_H
|
||||
#include "graph.h"
|
||||
#define TRAIT_STORAGE (1ULL<<0)
|
||||
#define TRAIT_TRANSFORM (1ULL<<1)
|
||||
#define TRAIT_FLOW (1ULL<<2)
|
||||
#define TRAIT_CONNECT (1ULL<<3)
|
||||
#define TRAIT_OBSERVE (1ULL<<4)
|
||||
#define TRAIT_CREATE (1ULL<<5)
|
||||
#define TRAIT_DESTROY (1ULL<<6)
|
||||
#define TRAIT_PROTECT (1ULL<<7)
|
||||
#define TRAIT_MUTABLE (1ULL<<8)
|
||||
#define TRAIT_IMMUTABLE (1ULL<<9)
|
||||
#define TRAIT_QUANTUM (1ULL<<10)
|
||||
#define TRAIT_ENTANGLED (1ULL<<11)
|
||||
#define TRAIT_COHERENT (1ULL<<12)
|
||||
#define TRAIT_CHAOTIC (1ULL<<13)
|
||||
#endif
|
||||
@@ -0,0 +1,20 @@
|
||||
#include "graph.h"
|
||||
#include "resonance.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
const GlyphDef GLYPH_DEFS[64] = {0};
|
||||
GlyphGraph* graph_create(const char* name, uint32_t cap) { GlyphGraph* g = calloc(1, sizeof(GlyphGraph)); g->name = strdup(name ? name : "unnamed"); g->nodes = calloc(cap, sizeof(GlyphNode)); return g; }
|
||||
void graph_destroy(GlyphGraph* g) { if(g) { free(g->name); free(g->nodes); free(g); } }
|
||||
int graph_add_node_with_value(GlyphGraph* g, uint8_t glyph_id, int value) { uint32_t idx = g->node_count++; g->nodes[idx].active = 1; g->nodes[idx].glyph_id = glyph_id; g->nodes[idx].energy = SYM_MODERATE; g->nodes[idx].stability = SYM_STRONG; return idx; }
|
||||
void graph_connect(GlyphGraph* g, uint32_t from, uint32_t to, SymResonance weight) { if(g->nodes[from].edge_count < 8) { g->nodes[from].edges[g->nodes[from].edge_count] = to; g->nodes[from].edge_weights[g->nodes[from].edge_count] = weight; g->nodes[from].edge_count++; } }
|
||||
void graph_compact(GlyphGraph* g) {}
|
||||
void graph_print(GlyphGraph* g) {}
|
||||
const GlyphDef* glyph_lookup(const char* name) { return &GLYPH_DEFS[0]; }
|
||||
const char* sym_level_name(SymLevel l) { return "LEVEL"; }
|
||||
const char* sym_res_name(SymResonance r) { return "RES"; }
|
||||
SymLevel sym_decay(SymLevel s, SymLevel c) { return s; }
|
||||
SymLevel sym_diminish(SymLevel e, int amt) { return e; }
|
||||
SymLevel sym_boost(SymLevel e, int amt) { return e; }
|
||||
int resonance_conflicts(TraitMask a, TraitMask b) { return 0; }
|
||||
SymResonance resonance_between_nodes(GlyphNode* a, GlyphNode* b) { return RES_HARMONIC; }
|
||||
SymResonance resonance_between_glyphs(uint8_t a, uint8_t b) { return RES_HARMONIC; }
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef GLYPH_GRAPH_H
|
||||
#define GLYPH_GRAPH_H
|
||||
#include "../common/glyph_types.h"
|
||||
typedef enum { SYM_VOID=0, SYM_NASCENT, SYM_WEAK, SYM_MODERATE, SYM_STRONG, SYM_RADIANT, SYM_ABSOLUTE } SymLevel;
|
||||
typedef enum { RES_DISSONANT=0, RES_INERT, RES_HARMONIC, RES_RESONANT, RES_ENTANGLED } SymResonance;
|
||||
struct GlyphNode_s; struct GlyphGraph_s;
|
||||
typedef void (*PropagateFn)(struct GlyphNode_s* n, struct GlyphGraph_s* g);
|
||||
typedef struct { uint8_t id; const char* name; uint8_t arity; float base_stability; PropagateFn propagate; } GlyphDef;
|
||||
extern const GlyphDef GLYPH_DEFS[];
|
||||
typedef struct GlyphNode_s { int active; uint8_t glyph_id; TraitMask traits; uint32_t lineage_id; SymLevel coherence; SymLevel stability; SymLevel energy; uint32_t mutation_count; uint32_t last_epoch; uint32_t edge_count; uint32_t edges[8]; SymResonance edge_weights[8]; } GlyphNode;
|
||||
typedef struct GlyphGraph_s { char *name; uint32_t node_count; GlyphNode *nodes; uint32_t epoch; int converged; SymLevel global_coherence; SymLevel global_stability; SymLevel global_energy; } GlyphGraph;
|
||||
GlyphGraph* graph_create(const char* name, uint32_t cap);
|
||||
void graph_destroy(GlyphGraph* g);
|
||||
int graph_add_node_with_value(GlyphGraph* g, uint8_t glyph_id, int value);
|
||||
void graph_connect(GlyphGraph* g, uint32_t from, uint32_t to, SymResonance weight);
|
||||
void graph_compact(GlyphGraph* g);
|
||||
void graph_print(GlyphGraph* g);
|
||||
const GlyphDef* glyph_lookup(const char* name);
|
||||
const char* sym_level_name(SymLevel l);
|
||||
const char* sym_res_name(SymResonance r);
|
||||
SymLevel sym_decay(SymLevel s, SymLevel c);
|
||||
SymLevel sym_diminish(SymLevel e, int amt);
|
||||
SymLevel sym_boost(SymLevel e, int amt);
|
||||
int resonance_conflicts(TraitMask a, TraitMask b);
|
||||
SymResonance resonance_between_nodes(GlyphNode* a, GlyphNode* b);
|
||||
SymResonance resonance_between_glyphs(uint8_t a, uint8_t b);
|
||||
#endif
|
||||
@@ -0,0 +1,4 @@
|
||||
#ifndef RESONANCE_H
|
||||
#define RESONANCE_H
|
||||
#include "graph.h"
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
#include "substrate_engine.h"
|
||||
#include <math.h>
|
||||
float substrate_resonance(uint32_t similarity) { float x = (float)similarity; return 1.0f / (1.0f + expf(-RESONANCE_K * (x - RESONANCE_MU))); }
|
||||
float substrate_stability(float t) { return expf(-STABILITY_LAMBDA * t); }
|
||||
float substrate_stability_from_mutations(uint32_t mutation_count) { return expf(-STABILITY_LAMBDA * (float)mutation_count); }
|
||||
float substrate_coherence(const uint8_t *data, size_t len) {
|
||||
if (len < 2) return 1.0f; float total_diff = 0.0f;
|
||||
for (size_t i = 1; i < len; i++) { float diff = (float)data[i] - (float)data[i - 1]; if (diff < 0) diff = -diff; total_diff += diff; }
|
||||
float avg_diff = total_diff / (float)(len - 1); float c = 1.0f - (avg_diff / 128.0f); if (c < 0.0f) c = 0.0f; if (c > 1.0f) c = 1.0f; return c;
|
||||
}
|
||||
TraitMask substrate_traits_propagate(TraitMask a, TraitMask b) { TraitMask shared = a & b; TraitMask emergent = a ^ b; return shared | (emergent & 0x00000000FFFFFFFFULL); }
|
||||
int substrate_traits_compatible(TraitMask filter, TraitMask candidate) { if (filter == 0) return 1; return (filter & candidate) != 0 ? 1 : 0; }
|
||||
float substrate_neural_energy(const uint8_t *a, const uint8_t *b, size_t len) {
|
||||
if (len == 0) return 0.0f; float sum = 0.0f;
|
||||
for (size_t i = 0; i < len; i++) { float diff = (float)a[i] - (float)b[i]; sum += diff * diff; } return sum / (float)len;
|
||||
}
|
||||
int substrate_lineage_propagates(float correlation) { return correlation >= LINEAGE_THRESHOLD ? 1 : 0; }
|
||||
int substrate_lineage_compatible(uint32_t lineage_a, uint32_t lineage_b) { if (lineage_a == 0 || lineage_b == 0) return 1; return lineage_a == lineage_b ? 1 : 0; }
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef SUBSTRATE_ENGINE_H
|
||||
#define SUBSTRATE_ENGINE_H
|
||||
#include "../common/glyph_types.h"
|
||||
#define RESONANCE_K 1.0f
|
||||
#define RESONANCE_MU 4.0f
|
||||
#define STABILITY_LAMBDA 0.1f
|
||||
#define LINEAGE_THRESHOLD 0.75f
|
||||
float substrate_resonance(uint32_t similarity);
|
||||
float substrate_stability(float t);
|
||||
float substrate_stability_from_mutations(uint32_t mutation_count);
|
||||
float substrate_coherence(const uint8_t *data, size_t len);
|
||||
TraitMask substrate_traits_propagate(TraitMask a, TraitMask b);
|
||||
int substrate_traits_compatible(TraitMask filter, TraitMask candidate);
|
||||
float substrate_neural_energy(const uint8_t *a, const uint8_t *b, size_t len);
|
||||
int substrate_lineage_propagates(float correlation);
|
||||
int substrate_lineage_compatible(uint32_t lineage_a, uint32_t lineage_b);
|
||||
#endif
|
||||
Reference in New Issue
Block a user