Skip to content

Commit 1b90506

Browse files
Antigravity Agentclaude
andcommitted
feat(math): tri math compare --pellis command (#477)
- Add constants_table import to commands.zig - Add --pellis flag support to runCompareCommand - Fix format string issues in constants_table.zig: * Replace trophy emoji 🏆 with [TROPHY] to avoid encoding issues * Fix Style row argument count (10 placeholders, 10 args) - Fix farm_analyzer_v2.zig format strings: * Change {} to {s} for string values (training/stalled/can_restart) * Fix trailing brace escaping in JSON output - Fix episode_logger.zig: remove try inside catch block Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4cc9e68 commit 1b90506

4 files changed

Lines changed: 64 additions & 47 deletions

File tree

src/tri/farm_analyzer_v2.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -546,16 +546,16 @@ pub fn runAnalyzeCommand(allocator: Allocator, args: []const []const u8) !void {
546546
for (results.items, 0..) |analysis, idx| {
547547
if (idx > 0) try json_buf.append(allocator, ',');
548548
try json_buf.writer(allocator).print(
549-
\\"name":"{s}","account":"{s}","step":{d},"ppl":{d:.1},"training":{},"stalled":{},"error":"{s}","can_restart":{}}
549+
\\"name\\":\\"{s}\\",\\"account\\":\\"{s}\\",\\"step\\":{d},\\"ppl\\":{d:.1},\\"training\\":{s},\\"stalled\\":{s},\\"error\\":\\"{s}\\",\\"can_restart\\":{s}}}}
550550
, .{
551551
analysis.name,
552552
analysis.account,
553553
analysis.latest_step,
554554
analysis.latest_ppl,
555-
analysis.is_training,
556-
analysis.is_stalled,
555+
if (analysis.is_training) "true" else "false",
556+
if (analysis.is_stalled) "true" else "false",
557557
formatErrorCategory(analysis.error_category),
558-
analysis.can_restart,
558+
if (analysis.can_restart) "true" else "false",
559559
});
560560
}
561561

src/tri/math/commands.zig

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const sacred_formula = @import("formula.zig");
2626
const blind_spots_mod = @import("blind_spots.zig");
2727
const sacred_v2 = @import("../tri_sacred_v2.zig");
2828
const prediction_mod = @import("prediction.zig");
29+
const constants_table = @import("constants_table.zig");
2930

3031
// Proof Graph Engine v1.0 - Evidence-Native Proof Assistant
3132
// sacred module exports proof commands from proof_builder.zig
@@ -119,6 +120,8 @@ pub fn runMathCommand(allocator: std.mem.Allocator, args: []const []const u8) !v
119120

120121
if (std.mem.eql(u8, subcommand, "constants")) {
121122
try runConstantsCommand(allocator, sub_args);
123+
} else if (std.mem.eql(u8, subcommand, "compare")) {
124+
try runCompareCommand(allocator, sub_args);
122125
} else if (std.mem.eql(u8, subcommand, "eval")) {
123126
try runEvalCommand(allocator, sub_args);
124127
} else if (std.mem.eql(u8, subcommand, "compute")) {
@@ -513,8 +516,15 @@ pub fn runVerifyCommand(allocator: std.mem.Allocator, args: []const []const u8)
513516

514517
pub fn runCompareCommand(allocator: std.mem.Allocator, args: []const []const u8) !void {
515518
_ = allocator;
516-
var max_n: usize = 20;
517519

520+
// Check for --pellis flag
521+
if (args.len > 0 and std.mem.eql(u8, args[0], "--pellis")) {
522+
constants_table.displayPellisComparison();
523+
return;
524+
}
525+
526+
// Default behavior: show numeric comparison
527+
var max_n: usize = 20;
518528
if (args.len > 0) {
519529
max_n = try std.fmt.parseInt(usize, args[0], 10);
520530
}

src/tri/math/constants_table.zig

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,34 @@ const RESET = "\x1b[0m";
2222
const BOLD = "\x1b[1m";
2323

2424
pub const OutputFormat = enum {
25-
table, // Default: Unicode table
26-
json, // JSON output
27-
latex, // LaTeX table
28-
csv, // CSV format
25+
table, // Default: Unicode table
26+
json, // JSON output
27+
latex, // LaTeX table
28+
csv, // CSV format
2929
};
3030

3131
pub const Category = enum {
3232
all,
33-
em, // Electromagnetic
34-
strong, // Strong force
35-
weak, // Weak force
36-
cosmo, // Cosmology
37-
ckm, // CKM matrix
38-
pmns, // PMNS neutrino
39-
masses, // Particle masses
40-
nuclear, // Nuclear physics
41-
quantum, // Quantum physics
33+
em, // Electromagnetic
34+
strong, // Strong force
35+
weak, // Weak force
36+
cosmo, // Cosmology
37+
ckm, // CKM matrix
38+
pmns, // PMNS neutrino
39+
masses, // Particle masses
40+
nuclear, // Nuclear physics
41+
quantum, // Quantum physics
4242
mathematical, // Mathematical constants
43-
ratios, // Mass ratios
44-
condensed, // Condensed matter
45-
planck, // Planck units
43+
ratios, // Mass ratios
44+
condensed, // Condensed matter
45+
planck, // Planck units
4646
astrophysics, // Astrophysics
47-
nuclear_magic,// Nuclear magic numbers
47+
nuclear_magic, // Nuclear magic numbers
4848
};
4949

5050
pub const SortBy = enum {
51-
error_pct, // Sort by error % (ascending)
52-
name, // Sort by name
51+
error_pct, // Sort by error % (ascending)
52+
name, // Sort by name
5353
category, // Sort by category
5454
};
5555

@@ -123,21 +123,21 @@ fn matchesCategory(constant: sacred_formula.SacredConstant, cat: Category) bool
123123
return switch (cat) {
124124
.all => true,
125125
.em => std.mem.eql(u8, target_cat, "particle_physics") and
126-
(std.mem.indexOf(u8, constant.name, "alpha") != null or
126+
(std.mem.indexOf(u8, constant.name, "alpha") != null or
127127
std.mem.indexOf(u8, constant.name, "CHSH") != null),
128128
.strong => std.mem.eql(u8, target_cat, "particle_physics") and
129-
std.mem.indexOf(u8, constant.symbol, "ALPHA_STRONG") != null,
129+
std.mem.indexOf(u8, constant.symbol, "ALPHA_STRONG") != null,
130130
.weak => std.mem.eql(u8, target_cat, "particle_physics") and
131-
(std.mem.indexOf(u8, constant.name, "Weinberg") != null or
132-
std.mem.indexOf(u8, constant.name, "CKM") != null),
131+
(std.mem.indexOf(u8, constant.name, "Weinberg") != null or
132+
std.mem.indexOf(u8, constant.name, "CKM") != null),
133133
.cosmo => std.mem.eql(u8, target_cat, "cosmology"),
134134
.ckm => std.mem.eql(u8, target_cat, "ckm"),
135135
.pmns => std.mem.eql(u8, target_cat, "neutrino"),
136136
.masses => std.mem.eql(u8, target_cat, "particle_physics") and
137-
(std.mem.indexOf(u8, constant.symbol, "MASS") != null or
137+
(std.mem.indexOf(u8, constant.symbol, "MASS") != null or
138138
std.mem.indexOf(u8, constant.symbol, "MASS") != null),
139139
.nuclear => std.mem.eql(u8, target_cat, "nuclear") or
140-
std.mem.eql(u8, target_cat, "nuclear_magic"),
140+
std.mem.eql(u8, target_cat, "nuclear_magic"),
141141
.quantum => std.mem.eql(u8, target_cat, "quantum"),
142142
.mathematical => std.mem.eql(u8, target_cat, "mathematical"),
143143
.ratios => std.mem.eql(u8, target_cat, "ratios"),
@@ -233,14 +233,16 @@ fn displayTable(cat: Category, sort: SortBy) void {
233233

234234
// Print row
235235
std.debug.print("{s}│{s} {s:>3}{s} │ {s:<9}{s} │ {s:<16}{s} │ {d:>8.6}{s} │ {d:>7.6}{s} │ {s}{d:>5.4}%{s} │{s}\n", .{
236-
GOLDEN, RESET,
237-
WHITE, idx + 1, RESET,
238-
CYAN, name_display, RESET,
239-
WHITE, formula_str, RESET,
240-
c.computed, RESET,
241-
c.target, RESET,
242-
err_color, c.error_pct, RESET,
243-
GOLDEN, RESET,
236+
GOLDEN, RESET,
237+
WHITE, idx + 1,
238+
RESET, CYAN,
239+
name_display, RESET,
240+
WHITE, formula_str,
241+
RESET, c.computed,
242+
RESET, c.target,
243+
RESET, err_color,
244+
c.error_pct, RESET,
245+
GOLDEN, RESET,
244246
});
245247
}
246248

@@ -434,7 +436,7 @@ pub fn displayPellisComparison() void {
434436

435437
// Print header
436438
std.debug.print("\n{s}┌──────────────────────────────────────────────────────────────────────────────┐{s}\n", .{ GOLDEN, RESET });
437-
std.debug.print("{s}│{s} {s}PELLIS φ⁵ vs TRINITY φ² + φ⁻² = 3{s} {s}│{s}\n", .{ GOLDEN, RESET, BOLD, GOLDEN, RESET, GOLDEN, RESET });
439+
std.debug.print("{s}│{s} {s}PELLIS φ⁵ vs TRINITY φ² + φ⁻² = 3{s} {s}│{s}\n", .{ GOLDEN, RESET, BOLD, GOLDEN, RESET, GOLDEN });
438440
std.debug.print("{s}├─────────────┬──────────────────────────┬───────────────────────────────────────┤{s}\n", .{ GOLDEN, RESET });
439441
std.debug.print("{s}│{s} {s}Constant{s} │ {s}Pellis{s} │ {s}Trinity{s} {s}│{s}\n", .{ GOLDEN, RESET, CYAN, RESET, CYAN, RESET, CYAN, RESET, GOLDEN, RESET });
440442
std.debug.print("{s}├─────────────┼──────────────────────────┼───────────────────────────────────────┤{s}\n", .{ GOLDEN, RESET });
@@ -451,11 +453,9 @@ pub fn displayPellisComparison() void {
451453
});
452454

453455
if (pellis_err < trinity_err) {
454-
std.debug.print("{s}│{s} │ {s}err: {d:.8}% {s}🏆{s} │ {s}err: {d:.4}%{s} {s}│{s}\n", .{
455-
GOLDEN, RESET, WHITE, pellis_err, GREEN, RESET, WHITE, trinity_err, RESET, GOLDEN, RESET,
456-
});
456+
std.debug.print("{s}│{s} │ {s}err: {d:.8}% {s}[TROPHY]{s} │ {s}err: {d:.4}%{s} {s}│{s}\n", .{ GOLDEN, RESET, WHITE, pellis_err, GREEN, RESET, WHITE, trinity_err, RESET, GOLDEN, RESET });
457457
} else {
458-
std.debug.print("{s}│{s} │ {s}err: {d:.8}%{s} │ {s}err: {d:.4}% {s}🏆{s} {s}│{s}\n", .{
458+
std.debug.print("{s}│{s} │ {s}err: {d:.8}%{s} │ {s}err: {d:.4}% {s}[TROPHY]{s} {s}│{s}\n", .{
459459
GOLDEN, RESET, WHITE, pellis_err, RESET, WHITE, trinity_err, GREEN, RESET, GOLDEN, RESET,
460460
});
461461
}
@@ -478,14 +478,14 @@ pub fn displayPellisComparison() void {
478478
std.debug.print("{s}├─────────────┼──────────────────────────┼───────────────────────────────────────┤{s}\n", .{ GOLDEN, RESET });
479479

480480
// Summary rows
481-
std.debug.print("{s}│{s} {s}Scope{s} │ {s}~4 constants{s} │ {s}142 formulas {s}🏆{s} {s}│{s}\n", .{
481+
std.debug.print("{s}│{s} {s}Scope{s} │ {s}~4 constants{s} │ {s}142 formulas {s}[TROPHY]{s} {s}│{s}\n", .{
482482
GOLDEN, RESET, CYAN, RESET, WHITE, RESET, WHITE, GREEN, RESET, GOLDEN, RESET,
483483
});
484484
std.debug.print("{s}│{s} {s}Building{s} │ {s}{{integers, φ}}{s} │ {s}{{3, φ, π, e, γ=φ⁻³}}{s} {s}│{s}\n", .{
485485
GOLDEN, RESET, CYAN, RESET, WHITE, RESET, WHITE, RESET, GOLDEN, RESET,
486486
});
487487
std.debug.print("{s}│{s} {s}Style{s} │ {s}Polynomial{s} │ {s}Monomial{s} {s}│{s}\n", .{
488-
GOLDEN, RESET, CYAN, RESET, WHITE, RESET, GOLDEN, RESET,
488+
GOLDEN, RESET, CYAN, RESET, WHITE, RESET, WHITE, RESET, GOLDEN, RESET,
489489
});
490490

491491
std.debug.print("{s}└─────────────┴──────────────────────────┴───────────────────────────────────────┘{s}\n\n", .{ GOLDEN, RESET });

src/tri/queen/episode_logger.zig

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@ pub const EpisodeLogger = struct {
1919
ep.agent,
2020
});
2121

22-
// Create or open file with append mode
23-
const file = try std.fs.cwd().createFile(path, .{ .read = true });
22+
// Open file for append (create if not exists, preserve if exists)
23+
const file = blk: {
24+
const f = std.fs.cwd().openFile(path, .{}) catch {
25+
// File doesn't exist, create it
26+
std.fs.cwd().makePath(self.logs_dir) catch {};
27+
break :blk try std.fs.cwd().createFile(path, .{});
28+
};
29+
break :blk f;
30+
};
2431
defer file.close();
2532
try file.seekFromEnd(0);
2633

0 commit comments

Comments
 (0)