;; BACKTEST v3: 3-pass deduction + Pass4 abduction
(= (ded-tv $f1 $c1 $f2 $c2) (let $f (* $f1 $f2) (let $c (* $f (* $c1 $c2)) (stv $f $c))))
(= (rev-tv $f1 $c1 $f2 $c2) (let $w1 (/ $c1 (- 1.0 $c1)) (let $w2 (/ $c2 (- 1.0 $c2)) (let $ws (+ $w1 $w2) (let $fr (/ (+ (* $f1 $w1) (* $f2 $w2)) $ws) (let $cr (/ $ws (+ $ws 1.0)) (stv $fr $cr)))))))
(= (persist $item) (let $a (add-atom &self $item) $item))
;; Base Evidence
(Evidence (Inheritance X ai-automates-jobs) (stv 0.7 0.6))
(Evidence (Inheritance X working-class-near-poverty) (stv 0.8 0.7))
(Evidence (Inheritance X ubi-proposed-solution) (stv 0.5 0.4))
(Evidence (Inheritance X tax-funding-contested) (stv 0.7 0.8))
(Evidence (Inheritance X social-decay) (stv 0.75 0.45))
;; Implications + TVs
(Implication (Inheritance X ai-automates-jobs) (Inheritance X unemployment-rises))
(TV (Implication ai-automates-jobs unemployment-rises) (stv 0.65 0.5))
(Implication (Inheritance X unemployment-rises) (Inheritance X poverty-deepens))
(TV (Implication unemployment-rises poverty-deepens) (stv 0.7 0.6))
(Implication (Inheritance X poverty-deepens) (Inheritance X crime-increases))
(TV (Implication poverty-deepens crime-increases) (stv 0.6 0.5))
(Implication (Inheritance X ubi-proposed-solution) (Inheritance X poverty-reduced))
(TV (Implication ubi-proposed-solution poverty-reduced) (stv 0.6 0.5))
(Implication (Inheritance X poverty-reduced) (Inheritance X crime-decreases))
(TV (Implication poverty-reduced crime-decreases) (stv 0.7 0.6))
(Implication (Inheritance X tax-funding-contested) (Inheritance X ubi-politically-fragile))
(TV (Implication tax-funding-contested ubi-politically-fragile) (stv 0.8 0.7))
(Implication (Inheritance X working-class-near-poverty) (Inheritance X social-instability))
(TV (Implication working-class-near-poverty social-instability) (stv 0.75 0.7))
(Implication (Inheritance X social-instability) (Inheritance X political-extremism))
(TV (Implication social-instability political-extremism) (stv 0.6 0.5))
(Implication (Inheritance X social-decay) (Inheritance X crime-increases))
(TV (Implication social-decay crime-increases) (stv 0.8 0.5))
;; Pass1-3 deduction (same as v2)
!(map-atom (collapse (match &self (Evidence (Inheritance X $src) (stv $f1 $c1)) (match &self (Implication (Inheritance X $src) (Inheritance X $tgt)) (match &self (TV (Implication $src $tgt) (stv $f2 $c2)) (let (stv $fo $co) (ded-tv $f1 $c1 $f2 $c2) (Evidence (Inheritance X $tgt) (stv $fo $co))))))) $x (persist $x))
!(map-atom (collapse (match &self (Evidence (Inheritance X $src) (stv $f1 $c1)) (match &self (Implication (Inheritance X $src) (Inheritance X $tgt)) (match &self (TV (Implication $src $tgt) (stv $f2 $c2)) (let (stv $fo $co) (ded-tv $f1 $c1 $f2 $c2) (Evidence (Inheritance X $tgt) (stv $fo $co))))))) $x (persist $x))
!(map-atom (collapse (match &self (Evidence (Inheritance X $src) (stv $f1 $c1)) (match &self (Implication (Inheritance X $src) (Inheritance X $tgt)) (match &self (TV (Implication $src $tgt) (stv $f2 $c2)) (let (stv $fo $co) (ded-tv $f1 $c1 $f2 $c2) (Evidence (Inheritance X $tgt) (stv $fo $co))))))) $x (persist $x))
;; Pass4: Abduction — from observed conclusions, hypothesize causes
;; For each derived Evidence $tgt, and each Implication $cause->$tgt, abduce $cause
;; abd-tv: f_abd = f_obs * f_imp, c_abd = f_obs * c_obs * c_imp * 0.4 (abductive discount)
(= (abd-tv $f_obs $c_obs $f_imp $c_imp) (let $f (* $f_obs $f_imp) (let $c (* 0.4 (* $f_obs (* $c_obs $c_imp))) (stv $f $c))))
!(map-atom (collapse (match &self (Evidence (Inheritance X $tgt) (stv $f1 $c1)) (match &self (Implication (Inheritance X $cause) (Inheritance X $tgt)) (match &self (TV (Implication $cause $tgt) (stv $f2 $c2)) (let (stv $fo $co) (abd-tv $f1 $c1 $f2 $c2) (Abduced (Inheritance X $cause) from $tgt (stv $fo $co))))))) $x (persist $x))
;; Query results
!(match &self (Abduced (Inheritance X $cause) from $effect (stv $f $c)) (abduced $cause from $effect $f $c))