NAME

Logic::Probabilistic::Syntax - Declarative hybrid syntax for probabilistic relational logic.

SYNOPSIS

use v5.38;
use Logic::Probabilistic::Syntax;

prob_logic AlarmNet {
    pfacts {
        0.70 => burglary;
        0.20 => earthquake;
    }

    # First-order and propositional probabilistic rules
    prule 0.90 => alarm { burglary; earthquake; }
    prule 0.80 => alarm { burglary; not { earthquake; } }
    prule 0.10 => alarm { not { burglary; } earthquake; }

    facts {
        person('John');
        person('Mary');
    }

    prule 0.80 => calls($x) { alarm; person($x); }
    prule 0.10 => calls($x) { not { alarm; } person($x); }
}

# Point query with evidence conditioning
my $res;
query_prob AlarmNet::burglary,
    evidence => [ AlarmNet::calls('John') => 1, AlarmNet::calls('Mary') => 1 ]->$res;
say "P(burglary | calls) = " . $res->probability;

# Query discrete probability distributions
fresh my $who;
my $dist;
query_dist AlarmNet::calls($who)->$dist;
say $dist;

DESCRIPTION

Exports declarative keywords (prob_logic, pfact, pfacts, pchoice, rule, prule, fact, facts, fresh, table, query_prob, and query_dist) via Keyword::Simple.

PROGRAM INSTANCE ACCESS

Inside each prob_logic ModelName { ... } declaration, an instance of Logic::Probabilistic::Program is automatically instantiated and stored in the package variable our $PROGRAM.

Just like in Logic::Relational, this instance can be accessed:

  • Inside the block: directly as $PROGRAM.

  • Outside the block: via the fully qualified package variable $ModelName::PROGRAM.

This allows combining high-level declarative syntax with object-oriented program methods:

# Direct query via object method
my $result = $AlarmNet::PROGRAM->query('burglary');

# Dynamic real-time parameter mutations
$AlarmNet::PROGRAM->update_pfact(0.05, 'burglary');

# Access the underlying relational logic engine
my $rel_prog = $AlarmNet::PROGRAM->relational_program;