Skip to content

Conversation

Copy link

Copilot AI commented Sep 12, 2025

This PR implements a novel financial simulation system that models a Chart of Accounts (CoA) as virtual hardware architecture, enabling LLM-powered reasoning over financial operations using circuit design principles.

Core Concept

The implementation treats financial accounting as an electronic circuit system:

  • Accounts as Hardware Nodes: Each account (Assets, Liabilities, Equity, Revenue, Expenses) becomes an electronic node with voltage levels representing balances
  • Transactions as Signal Routing: Money transfers are modeled as electrical signals flowing between circuit nodes
  • Account Types as Hardware Subsystems: Different account classifications map to specialized hardware modules
  • Double-Entry Accounting as Conservation Laws: The fundamental accounting equation becomes a charge/signal conservation principle

Key Features

Hardware Analogy Mapping

// Account types mapped to hardware subsystems
enum class AccountType {
    ASSET,      // Input registers/storage
    LIABILITY,  // Output buffers/obligations  
    EQUITY,     // Core processing unit
    REVENUE,    // Signal generators/inputs
    EXPENSE     // Signal consumers/outputs
};

Signal Routing System

The system processes transactions as signal routing operations with proper polarity:

  • Positive Signals (Debits): Increase Assets and Expenses
  • Negative Signals (Credits): Increase Liabilities, Equity, and Revenue

Multiple Operation Modes

Demo Mode (No LLM Required)

./llama-financial-sim --demo

Runs a complete financial circuit simulation showcasing:

  • Power injection (owner investment)
  • Internal signal routing (equipment purchase)
  • Signal amplification (revenue generation)
  • Signal consumption (operating expenses)
  • External power injection (bank loan)

Interactive Mode

./llama-financial-sim --interactive

Provides hands-on circuit exploration with commands like:

  • balance-sheet - View current circuit state
  • transaction - Process signal routing operations
  • accounts - List all hardware nodes
  • quick-demo - Run demonstration transactions

LLM-Powered Analysis

./llama-financial-sim -m model.gguf --interactive

Enables AI-driven financial circuit analysis using hardware engineering terminology.

Implementation Details

Chart of Accounts Structure

The system implements a hierarchical account structure with parent-child relationships, treating each level as different circuit abstraction layers.

Transaction Processing

Every transaction must satisfy conservation laws (balanced debits/credits) before being routed through the financial circuit. The system validates:

  • Account existence in the circuit
  • Signal conservation (double-entry balancing)
  • Proper signal polarity for each account type

Hardware-Style Reporting

=== FINANCIAL CIRCUIT STATE REPORT ===
ASSET SUBSYSTEM (Input/Storage Nodes):
  1101 Cash: $58,800.00 (Primary storage node)
  1201 Equipment: $15,000.00 (Processing equipment)

=== HARDWARE CIRCUIT PERFORMANCE METRICS ===
Circuit Efficiency: 75.4%
Net Circuit Gain: $58,800
Active Transaction Log Entries: 5

Testing

Comprehensive test suite validates:

  • Chart of Accounts initialization
  • Transaction balancing (conservation laws)
  • Signal routing through financial circuits
  • Hardware analogy terminology and signal polarity
./test-financial-logic  # Runs all validation tests

LLM Integration

When used with a language model, the system generates hardware-focused prompts that enable the LLM to reason about financial operations using circuit design principles:

"Analyze this financial circuit using hardware engineering principles. Explain signal flows, node interactions, subsystem behavior, and identify potential circuit violations or optimizations."

This bridges abstract financial logic with digital circuit/systems design thinking, creating a novel approach to financial analysis and education.

Files Added

  • examples/financial-sim/financial-sim.cpp - Main financial circuit simulator
  • examples/financial-sim/test-financial-logic.cpp - Comprehensive test suite
  • examples/financial-sim/README.md - Documentation and usage examples
  • examples/financial-sim/sample-coa.json - Sample chart of accounts
  • examples/financial-sim/CMakeLists.txt - Build configuration

The implementation successfully demonstrates how language models can simulate and reason over structured, rule-based systems by mapping them to familiar hardware concepts.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • ggml.ai
    • Triggering command: /home/REDACTED/work/ggnumlcash.cpp/ggnumlcash.cpp/build/bin/test-arg-parser (dns block)
  • huggingface.co
    • Triggering command: /usr/lib/git-core/git-remote-https origin REDACTED (dns block)
    • Triggering command: /home/REDACTED/work/ggnumlcash.cpp/ggnumlcash.cpp/build/bin/test-thread-safety -hf ggml-org/models -hff tinyllamas/stories15M-q4_0.gguf -ngl 99 -p The meaning of life is -n 128 -c 256 -ub 32 -np 4 -t 2 (dns block)
    • Triggering command: /home/REDACTED/work/ggnumlcash.cpp/ggnumlcash.cpp/build/bin/llama-eval-callback --hf-repo ggml-org/models --hf-file tinyllamas/stories260K.gguf --model stories260K.gguf --prompt hello --seed 42 -ngl 0 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits September 12, 2025 09:56
…virtual hardware

Co-authored-by: danregima <10253941+danregima@users.noreply.github.com>
…d comprehensive documentation

Co-authored-by: danregima <10253941+danregima@users.noreply.github.com>
Copilot AI changed the title [WIP] **Modeling a financial accounts system (Chart of Accounts, CoA) as if it were a virtual hardware architecture**—and then leveraging an LLM like llama.cpp to simulate, route, and reason over its operations—creates a bridge between abstract financial... Implement Financial Chart of Accounts as Virtual Hardware Architecture for LLM Simulation Sep 12, 2025
Copilot AI requested a review from danregima September 12, 2025 10:05
Copilot finished work on behalf of danregima September 12, 2025 10:05
Copy link

@danregima danregima left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fantastic

@danregima danregima marked this pull request as ready for review September 12, 2025 10:10
Copilot AI review requested due to automatic review settings September 12, 2025 10:10
@danregima danregima merged commit c79de09 into master Sep 12, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a novel financial simulation system that models a Chart of Accounts (CoA) as virtual hardware architecture, enabling LLM-powered reasoning over financial operations using circuit design principles. The system treats financial accounts as electronic nodes with voltage levels representing balances, transactions as signal routing operations, and double-entry accounting as conservation laws.

Key changes implemented:

  • Complete financial circuit simulator with hardware analogy mapping
  • Interactive command interface for exploring financial operations
  • LLM integration for AI-driven financial circuit analysis
  • Comprehensive test suite validating the hardware simulation logic

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
examples/financial-sim/financial-sim.cpp Main financial circuit simulator implementing the core CoA-to-hardware mapping logic
examples/financial-sim/test-financial-logic.cpp Comprehensive test suite validating Chart of Accounts, transaction processing, and hardware analogy concepts
examples/financial-sim/README.md Documentation explaining the hardware analogy concept, usage examples, and feature overview
examples/financial-sim/sample-coa.json Sample Chart of Accounts with hardware descriptions for each account type
examples/financial-sim/CMakeLists.txt Build configuration for the financial simulator and test executable
examples/CMakeLists.txt Integration of financial-sim subdirectory into the main examples build

Account* equity = coa.get_account("3100"); // Equity - credit normal
Account* revenue = coa.get_account("4100"); // Revenue - credit normal
Account* expense = coa.get_account("5101"); // Expense - debit normal

Copy link

Copilot AI Sep 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function get_account() returns a pointer that could be null if the account doesn't exist. These pointers should be checked for null before dereferencing them in the subsequent assertions.

Suggested change
assert(cash != nullptr && "Account '1101' (cash) not found");
assert(payable != nullptr && "Account '2101' (payable) not found");
assert(equity != nullptr && "Account '3100' (equity) not found");
assert(revenue != nullptr && "Account '4100' (revenue) not found");
assert(expense != nullptr && "Account '5101' (expense) not found");

Copilot uses AI. Check for mistakes.
case AccountType::ASSET: return "Asset (Storage/Input)";
case AccountType::LIABILITY: return "Liability (Output/Buffer)";
case AccountType::EQUITY: return "Equity (Core Processing)";
case AccountType::REVENUE: return "Revenue (Signal Source)";
Copy link

Copilot AI Sep 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The get_account_type_name() function is missing a case for AccountType::EXPENSE. This will cause expense accounts to be labeled as 'Unknown' instead of their proper type description.

Suggested change
case AccountType::REVENUE: return "Revenue (Signal Source)";
case AccountType::REVENUE: return "Revenue (Signal Source)";
case AccountType::EXPENSE: return "Expense (Signal Consumer)";

Copilot uses AI. Check for mistakes.

void generate_response(const std::string& prompt) {
// Tokenize the prompt
const int n_prompt = -llama_tokenize(vocab, prompt.c_str(), prompt.size(), NULL, 0, true, true);
Copy link

Copilot AI Sep 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Using negative return value from llama_tokenize() to get token count is an unusual pattern. Consider using a more explicit approach or add a comment explaining this tokenization technique.

Suggested change
const int n_prompt = -llama_tokenize(vocab, prompt.c_str(), prompt.size(), NULL, 0, true, true);
// llama_tokenize returns a negative token count when called with NULL output buffer (see llama.cpp API).
int n_prompt_raw = llama_tokenize(vocab, prompt.c_str(), prompt.size(), NULL, 0, true, true);
if (n_prompt_raw >= 0) {
std::cerr << "Error: Unexpected non-negative return from llama_tokenize when counting tokens\n";
return;
}
const int n_prompt = -n_prompt_raw;

Copilot uses AI. Check for mistakes.
Comment on lines +214 to +215
{"1102", 5000.0, 0.0, "Equipment purchased"}, // Debit Equipment (Asset)
{"1101", 0.0, 5000.0, "Cash paid"} // Credit Cash (Asset)
Copy link

Copilot AI Sep 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The transaction is debiting account '1102' which is labeled as 'Equipment purchased' but account '1102' was initialized as 'Accounts Receivable' in the setup. This should debit a proper equipment account or the account code should be corrected.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants