physics-primer.sleela
lib/advantage/examples/advanced/trust-fields/physics-primer.sleela · 170 line(s) · sleela
<< lib/advantage/physics/physics-demo.sleela
SLeeLa Standard Library Definition.
Definition: Runnable demonstration + validation of the advantage/physics
trust-field subject (metric, geodesic, contact, SDE). >>
#sleela 3.0
material;
artifact;
pure;
gasoline;
< `run` auto-links the sibling subject classes in advantage/physics >
< (SLPhysicsMath, SLTrustMetric, SLTransactionalGeodesic, >
< SLAnnouncementContact, SLTrustDecaySDE), so no imports are needed. >
class PhysicsPrimer {
< ---- Descriptive metadata (version 1.11 nested-friendly accessors) ---- >
<< Eleven catalogued attributes with getter/setter pairs. A worker-class demo
carries the baseline identity record. >>
String metaVersion = "1.0.0";
int metaId = 10539;
String metaAuthor = "Kiro Agent";
String metaDate = "2026-11-08";
String metaCopyright = "SLeeLa project";
String metaTrademark = "none";
String metaCorporation = "none";
< metaOrigin: National | <nation> | International | Galactic >
String metaOrigin = "International";
String metaBirthDate = "2026-11-08";
< metaScienceRating: maturity/robustness on a 1..10 scale >
int metaScienceRating = 7;
< metaNationalSchedule: a real, citable instrument or "none" >
String metaNationalSchedule = "none";
String getMetaVersion() { return metaVersion; }
void setMetaVersion(String v) { metaVersion = v; }
int getMetaId() { return metaId; }
void setMetaId(int v) { metaId = v; }
String getAuthor() { return metaAuthor; }
void setAuthor(String v) { metaAuthor = v; }
String getDate() { return metaDate; }
void setDate(String v) { metaDate = v; }
String getCopyright() { return metaCopyright; }
void setCopyright(String v) { metaCopyright = v; }
String getTrademark() { return metaTrademark; }
void setTrademark(String v) { metaTrademark = v; }
String getCorporation() { return metaCorporation; }
void setCorporation(String v) { metaCorporation = v; }
String getOrigin() { return metaOrigin; }
void setOrigin(String v) { metaOrigin = v; }
String getBirthDate() { return metaBirthDate; }
void setBirthDate(String v) { metaBirthDate = v; }
int getScienceRating() { return metaScienceRating; }
void setScienceRating(int v) { metaScienceRating = v; }
String getNationalSchedule() { return metaNationalSchedule; }
void setNationalSchedule(String v) { metaNationalSchedule = v; }
boolean near(double a, double b, double tol) {
double d = a - b;
if (d < 0.0) { d = 0.0 - d; }
return d < tol;
}
void main() {
SLPhysicsMath m = new SLPhysicsMath();
print("== 1. Trust metric tensor (trust field geometry) ==");
SLTrustMetric metric = new SLTrustMetric();
< Full trust: flat / Euclidean. (3,4) -> length 5, warping 0. >
double distHigh = metric.effectiveDistance(1.0, 3.0, 4.0, m);
double warpHigh = metric.warping(1.0);
< Low trust tau=0.25: f=4, (3,4) -> sqrt(4*25)=10 (distance inflates). >
double distLow = metric.effectiveDistance(0.25, 3.0, 4.0, m);
double warpLow = metric.warping(0.25);
print(" high-trust distance (3,4) = " + distHigh + " warping=" + warpHigh);
print(" low-trust distance (3,4) = " + distLow + " warping=" + warpLow);
print("");
print("== 2. Transactional geodesic ==");
SLTransactionalGeodesic geo = new SLTransactionalGeodesic();
< Flat field: geodesic == straight line, length == Euclidean 5. >
geo.configureField(1.0, 0.0, 0.0);
double flatLen = geo.geodesicLength(0.0, 0.0, 3.0, 4.0, 200, m);
double eucLen = geo.euclidean(0.0, 0.0, 3.0, 4.0, m);
boolean flatStraight = geo.isStraightLine(0.000001);
< Warped field: trust falls along the path => geodesic length exceeds >
< the Euclidean reference (more energy to cross). >
geo.configureField(0.9, 0.0 - 0.1, 0.0 - 0.1);
double warpLen = geo.geodesicLength(0.0, 0.0, 3.0, 4.0, 200, m);
print(" flat geodesic length = " + flatLen + " (euclid " + eucLen + ")");
print(" warped geodesic length = " + warpLen);
print("");
print("== 3. Announcement as a contact structure ==");
SLAnnouncementContact ann = new SLAnnouncementContact();
ann.standardForm(0.5);
double cvol = ann.contactVolume();
boolean isContact = ann.isContact(0.000001);
< A move in ker(alpha): alpha = dz - y dx with y=0.5, so dz - 0.5 dx = 0. >
< Take (vx,vy,vz) = (2, 0, 1) -> 1*1 + (-0.5)*2 = 1 - 1 = 0 (allowed). >
boolean allowed = ann.moveAllowed(2.0, 0.0, 1.0, 0.000001);
< A disallowed move off the hyperplane. >
boolean blocked = ann.moveAllowed(1.0, 0.0, 1.0, 0.000001);
< Credible announcement keeps residual value; incredible one is null. >
double resCredible = ann.homotopyResidual(0.9, 0.0);
double resNull = ann.homotopyResidual(0.0, 0.0);
boolean nullAnn = ann.isNull(0.0, 0.000001);
print(" alpha ^ dalpha = " + cvol + " isContact=" + isContact);
print(" move (2,0,1) allowed = " + allowed);
print(" move (1,0,1) allowed = " + blocked);
print(" residual (cred .9) = " + resCredible);
print(" residual (cred 0) = " + resNull + " null=" + nullAnn);
print("");
print("== 4. Stochastic trust decay (CIR + jump) ==");
SLTrustDecaySDE sde = new SLTrustDecaySDE();
sde.configure(0.5, 0.8, 0.1, 0.4);
< Expected path from low trust reverts up toward tauBar=0.8. >
double start = 0.3;
double ePath = sde.expectedPath(start, 0.1, 50);
< One expected step from 0.3: 0.3 + 0.5*(0.8-0.3)*0.1 = 0.3 + 0.025 = 0.325. >
double eStep = sde.expectedStep(0.3, 0.1);
< A breach drops trust by delta=0.4: 0.8 -> 0.4. >
double afterBreach = sde.breach(0.8);
print(" expected one step (0.3) = " + eStep);
print(" expected path (50 steps) = " + ePath + " (tauBar=0.8)");
print(" trust after breach (0.8) = " + afterBreach);
print("");
print("== validation ==");
boolean okHigh = near(distHigh, 5.0, 0.0001);
boolean okWarp0 = near(warpHigh, 0.0, 0.0001);
boolean okLow = near(distLow, 10.0, 0.0001);
boolean okWarp3 = near(warpLow, 3.0, 0.0001);
boolean okFlat = near(flatLen, 5.0, 0.01);
boolean okStraight = flatStraight;
boolean okWarpGeo = (warpLen > eucLen);
boolean okContact = isContact;
boolean okCvol = near(cvol, 1.0, 0.0001);
boolean okAllow = allowed;
boolean okBlock = (blocked == false);
boolean okResC = near(resCredible, 0.9, 0.0001);
boolean okNull = nullAnn;
boolean okStep = near(eStep, 0.325, 0.0001);
boolean okRevert = (ePath > start) && (ePath < 0.8001);
boolean okBreach = near(afterBreach, 0.4, 0.0001);
print(" high-trust dist == 5 ? " + okHigh);
print(" high-trust warp == 0 ? " + okWarp0);
print(" low-trust dist == 10 ? " + okLow);
print(" low-trust warp == 3 ? " + okWarp3);
print(" flat geodesic ~ 5 ? " + okFlat);
print(" flat is straight line ? " + okStraight);
print(" warped geodesic > euclid? " + okWarpGeo);
print(" alpha^dalpha != 0 ? " + okContact);
print(" contact volume == 1 ? " + okCvol);
print(" ker move allowed ? " + okAllow);
print(" off-plane move blocked ? " + okBlock);
print(" credible residual == .9 ? " + okResC);
print(" incredible ann is null ? " + okNull);
print(" SDE step == 0.325 ? " + okStep);
print(" SDE reverts toward bar ? " + okRevert);
print(" breach drops by delta ? " + okBreach);
if (okHigh) { if (okWarp0) { if (okLow) { if (okWarp3) {
if (okFlat) { if (okStraight) { if (okWarpGeo) { if (okContact) {
if (okCvol) { if (okAllow) { if (okBlock) { if (okResC) {
if (okNull) { if (okStep) { if (okRevert) { if (okBreach) {
print("ALL CHECKS PASSED");
} } } } } } } } } } } } } } } }
}
}