@lucern/confidence 1.0.29 → 1.0.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/index.d.ts +7 -7
  2. package/dist/index.js +905 -770
  3. package/dist/index.js.map +1 -1
  4. package/dist/proof-attestation.json +1 -1
  5. package/dist/v1/codec.js.map +1 -1
  6. package/dist/v1/index.d.ts +7 -7
  7. package/dist/v1/index.js +905 -770
  8. package/dist/v1/index.js.map +1 -1
  9. package/dist/v1/interfaces.d.ts +5 -5
  10. package/dist/v1/operations/approximation.d.ts +1 -1
  11. package/dist/v1/operations/approximation.js +8 -7
  12. package/dist/v1/operations/approximation.js.map +1 -1
  13. package/dist/v1/operations/bridge/index.js +7 -6
  14. package/dist/v1/operations/bridge/index.js.map +1 -1
  15. package/dist/v1/operations/canonical.d.ts +1 -1
  16. package/dist/v1/operations/canonical.js +106 -57
  17. package/dist/v1/operations/canonical.js.map +1 -1
  18. package/dist/v1/operations/contracts/epistemicContract.d.ts +1 -1
  19. package/dist/v1/operations/contracts/epistemicContract.js +9 -3
  20. package/dist/v1/operations/contracts/epistemicContract.js.map +1 -1
  21. package/dist/v1/operations/contradiction/detectTupleContradiction.js.map +1 -1
  22. package/dist/v1/operations/contradiction/index.js.map +1 -1
  23. package/dist/v1/operations/dynamics/cascade.js +1 -1
  24. package/dist/v1/operations/dynamics/cascade.js.map +1 -1
  25. package/dist/v1/operations/dynamics/decay.js +105 -41
  26. package/dist/v1/operations/dynamics/decay.js.map +1 -1
  27. package/dist/v1/operations/dynamics/defeat.js.map +1 -1
  28. package/dist/v1/operations/dynamics/propagation.d.ts +3 -3
  29. package/dist/v1/operations/dynamics/propagation.js +101 -57
  30. package/dist/v1/operations/dynamics/propagation.js.map +1 -1
  31. package/dist/v1/operations/dynamics/revision.js +7 -6
  32. package/dist/v1/operations/dynamics/revision.js.map +1 -1
  33. package/dist/v1/operations/index.js +8 -3
  34. package/dist/v1/operations/index.js.map +1 -1
  35. package/dist/v1/operations/lucern.d.ts +7 -7
  36. package/dist/v1/operations/lucern.js +934 -807
  37. package/dist/v1/operations/lucern.js.map +1 -1
  38. package/dist/v1/operations/operatorTaxonomy.d.ts +10 -10
  39. package/dist/v1/operations/operatorTaxonomy.js.map +1 -1
  40. package/dist/v1/operations/scoring.d.ts +2 -1
  41. package/dist/v1/operations/scoring.js +20 -5
  42. package/dist/v1/operations/scoring.js.map +1 -1
  43. package/dist/v1/operations/subjectiveLogic/index.js +91 -54
  44. package/dist/v1/operations/subjectiveLogic/index.js.map +1 -1
  45. package/dist/v1/operations/temporalDecay.d.ts +3 -3
  46. package/dist/v1/operations/temporalDecay.js +8 -3
  47. package/dist/v1/operations/temporalDecay.js.map +1 -1
  48. package/dist/v1/types.d.ts +101 -101
  49. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/v1/operations/subjectiveLogic/index.ts","../../../src/v1/operations/scoring.ts","../../../src/v1/operations/canonical.ts"],"names":["opinion"],"mappings":";AAEO,SAAS,OAAA,CACd,MAAA,EACA,SAAA,EACA,WAAA,EACA,QAAA,EACW;AACX,EAAA,MAAM,CAAA,GAAI,OAAO,QAAA,CAAS,MAAM,IAAI,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,MAAM,CAAA,GAAI,CAAA;AAC1D,EAAA,MAAM,CAAA,GAAI,OAAO,QAAA,CAAS,SAAS,IAAI,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,SAAS,CAAA,GAAI,CAAA;AAChE,EAAA,MAAM,CAAA,GAAI,OAAO,QAAA,CAAS,WAAW,IAAI,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,WAAW,CAAA,GAAI,CAAA;AACpE,EAAA,MAAM,CAAA,GAAI,KAAK,GAAA,CAAI,CAAA,EAAG,KAAK,GAAA,CAAI,CAAA,EAAG,QAAQ,CAAC,CAAA;AAC3C,EAAA,MAAM,GAAA,GAAM,IAAI,CAAA,GAAI,CA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SAAA;AAAA,EACA,SAAA;AAAA,EACA,UAAA;AAAA,EACA,SAAA;AAAA,EACA,eAAA;AAAA,EACA,QAAA;AAAA,EACA,sBAAA;AAAA,EACA,uBAAA;AAAA,EACA,kBAAA;AAAA,EACA,qBAAA;AAAA,EACA,qBAAA;AAAA,EACA;AACF","file":"canonical.js","sourcesContent":["import type { SLOpinion } from \"../../types\";\n\nexport function opinion(\n belief: number,\n disbelief: number,\n uncertainty: number,\n baseRate: number\n): SLOpinion {\n const b = Number.isFinite(belief) ? Math.max(0, belief) : 0;\n const d = Number.isFinite(disbelief) ? Math.max(0, disbelief) : 0;\n const u = Number.isFinite(uncertainty) ? Math.max(0, uncertainty) : 0;\n const a = Math.max(0, Math.min(1, baseRate));\n const sum = b + d + u;\n\n if (sum === 0) {\n return { b: 0, d: 0, u: 1, a } as SLOpinion;\n }\n\n return {\n b: b / sum,\n d: d / sum,\n u: u / sum,\n a,\n } as SLOpinion;\n}\n\nexport function mkOpinion(\n belief: number,\n disbelief: number,\n uncertainty: number,\n baseRate: number\n): SLOpinion {\n return opinion(belief, disbelief, uncertainty, baseRate);\n}\n\nexport function vacuous(baseRate: number): SLOpinion {\n return mkOpinion(0, 0, 1, baseRate);\n}\n\nexport function dogmatic(probability: number, baseRate: number): SLOpinion {\n const p = Math.max(0, Math.min(1, probability));\n return mkOpinion(p, 1 - p, 0, baseRate);\n}\n\nexport function project(o: SLOpinion): number {\n return o.b + o.a * o.u;\n}\n\nexport function confidenceLevel(o: SLOpinion): \"high\" | \"medium\" | \"low\" {\n const projected = project(o);\n if (o.u > 0.5) {\n return \"low\";\n }\n if (projected >= 0.8 && o.u < 0.2) {\n return \"high\";\n }\n if (projected >= 0.6) {\n return \"medium\";\n }\n return \"low\";\n}\n\nconst VACUOUS_IDENTITY_EPSILON = 1e-12;\n\n/**\n * Associative, vacuous-identity-preserving base rate for a fused opinion.\n *\n * The legacy `(left.a + right.a) / 2` arithmetic mean was the shared root of\n * RR.7 F1 (projected-confidence non-associativity) and F2 (a vacuous opinion of\n * a different base rate was not a fusion identity): averaging always pulled the\n * fused base rate toward the other operand even when that operand carried no\n * evidence. Subjective Logic requires every opinion over the same frame to share\n * one canonical base rate, so a correct fusion never *invents* a new base rate\n * from the operands' priors. We therefore:\n *\n * - return the informative operand's base rate when exactly one operand is\n * vacuous (the vacuous operand contributes no prior), making `vacuous(a)` a\n * true identity for any `a`; and\n * - require equal base rates otherwise (the canonical-frame contract). When\n * they coincide the result is that shared value — trivially associative.\n *\n * If two informative opinions carry genuinely different base rates they are not\n * opinions over the same frame and must be reconciled before fusion; we fall\n * back to the arithmetic mean ONLY in that ill-posed case to stay total, and the\n * property suite documents that this path is outside the order-independence\n * guarantee.\n */\nfunction fusedBaseRate(left: SLOpinion, right: SLOpinion): number {\n const leftVacuous = 1 - left.u <= VACUOUS_IDENTITY_EPSILON;\n const rightVacuous = 1 - right.u <= VACUOUS_IDENTITY_EPSILON;\n if (leftVacuous && !rightVacuous) {\n return right.a;\n }\n if (rightVacuous && !leftVacuous) {\n return left.a;\n }\n if (Math.abs(left.a - right.a) <= VACUOUS_IDENTITY_EPSILON) {\n return left.a;\n }\n return (left.a + right.a) / 2;\n}\n\nexport function cumulativeFusion(left: SLOpinion, right: SLOpinion): SLOpinion {\n const a = fusedBaseRate(left, right);\n\n // F2: a vacuous operand is the identity element of cumulative fusion. Return\n // the other operand verbatim (including its base rate) so fusion with the\n // vacuous opinion is a true no-op regardless of differing priors.\n if (1 - left.u <= VACUOUS_IDENTITY_EPSILON) {\n return opinion(right.b, right.d, right.u, a);\n }\n if (1 - right.u <= VACUOUS_IDENTITY_EPSILON) {\n return opinion(left.b, left.d, left.u, a);\n }\n\n // F4: dogmatic pair handled via the ε-limit of the cumulative rule rather than\n // the standalone `(b+d)/2` shortcut. As both uncertainties shrink at the same\n // rate, the cumulative formula's `(b_L·u_R + b_R·u_L)/k` term converges to the\n // arithmetic mean of the masses; deriving it from the same limit the interior\n // formula uses keeps mass-associativity intact (no special-case discontinuity).\n if (left.u <= VACUOUS_IDENTITY_EPSILON && right.u <= VACUOUS_IDENTITY_EPSILON) {\n return opinion((left.b + right.b) / 2, (left.d + right.d) / 2, 0, a);\n }\n\n const k = left.u + right.u - left.u * right.u;\n if (k === 0) {\n return vacuous(a);\n }\n\n return opinion(\n (left.b * right.u + right.b * left.u) / k,\n (left.d * right.u + right.d * left.u) / k,\n (left.u * right.u) / k,\n a\n );\n}\n\nexport function averagingFusion(left: SLOpinion, right: SLOpinion): SLOpinion {\n const a = fusedBaseRate(left, right);\n\n // F2: vacuous identity, mirroring cumulativeFusion.\n if (1 - left.u <= VACUOUS_IDENTITY_EPSILON) {\n return opinion(right.b, right.d, right.u, a);\n }\n if (1 - right.u <= VACUOUS_IDENTITY_EPSILON) {\n return opinion(left.b, left.d, left.u, a);\n }\n\n // F4: dogmatic pair via the ε-limit of the averaging rule.\n if (left.u <= VACUOUS_IDENTITY_EPSILON && right.u <= VACUOUS_IDENTITY_EPSILON) {\n return opinion((left.b + right.b) / 2, (left.d + right.d) / 2, 0, a);\n }\n\n const k = left.u + right.u;\n if (k === 0) {\n return vacuous(a);\n }\n\n return opinion(\n (left.b * right.u + right.b * left.u) / k,\n (left.d * right.u + right.d * left.u) / k,\n (2 * left.u * right.u) / k,\n a\n );\n}\n\nexport function trustDiscount(sourceOpinion: SLOpinion, trust: number): SLOpinion {\n const weight = Math.max(0, Math.min(1, Math.abs(trust)));\n return opinion(\n weight * sourceOpinion.b,\n weight * sourceOpinion.d,\n 1 - weight * (sourceOpinion.b + sourceOpinion.d),\n sourceOpinion.a\n );\n}\n\nconst EPSILON = 1e-9;\n\nfunction childBaseRateFallback(\n ifTrue: SLOpinion,\n ifFalse: SLOpinion,\n fallbackBaseRate: number | undefined\n): number {\n if (fallbackBaseRate !== undefined) {\n return Math.max(0, Math.min(1, fallbackBaseRate));\n }\n\n if (Math.abs(ifTrue.a - ifFalse.a) <= EPSILON) {\n return ifTrue.a;\n }\n\n return (ifTrue.a + ifFalse.a) / 2;\n}\n\nfunction computeConditionalDeductionBaseRate(\n opinionA: SLOpinion,\n ifTrue: SLOpinion,\n ifFalse: SLOpinion,\n fallbackBaseRate: number\n): number {\n const denominator =\n 1 - opinionA.a * ifTrue.u - (1 - opinionA.a) * ifFalse.u;\n\n if (ifTrue.u + ifFalse.u < 2 - EPSILON && Math.abs(denominator) > EPSILON) {\n const baseRate =\n (opinionA.a * ifTrue.b + (1 - opinionA.a) * ifFalse.b) / denominator;\n if (baseRate >= -EPSILON && baseRate <= 1 + EPSILON) {\n return Math.max(0, Math.min(1, baseRate));\n }\n }\n\n return fallbackBaseRate;\n}\n\nfunction safeCorrectionTerm(\n numerator: number,\n denominator: number\n): number | undefined {\n if (Math.abs(denominator) <= EPSILON) {\n return undefined;\n }\n\n const value = numerator / denominator;\n if (!Number.isFinite(value)) {\n return undefined;\n }\n\n return Math.max(0, value);\n}\n\nexport function conditionalDeduction(\n opinionA: SLOpinion,\n ifTrue: SLOpinion,\n ifFalse: SLOpinion,\n fallbackBaseRate?: number\n): SLOpinion {\n const fallbackChildBaseRate = childBaseRateFallback(\n ifTrue,\n ifFalse,\n fallbackBaseRate\n );\n const childBaseRate = computeConditionalDeductionBaseRate(\n opinionA,\n ifTrue,\n ifFalse,\n fallbackChildBaseRate\n );\n const projectedAntecedent = project(opinionA);\n const projectedAntecedentComplement = 1 - projectedAntecedent;\n const intermediateBelief =\n opinionA.b * ifTrue.b +\n opinionA.d * ifFalse.b +\n opinionA.u * (ifTrue.b * opinionA.a + ifFalse.b * (1 - opinionA.a));\n const intermediateDisbelief =\n opinionA.b * ifTrue.d +\n opinionA.d * ifFalse.d +\n opinionA.u * (ifTrue.d * opinionA.a + ifFalse.d * (1 - opinionA.a));\n const intermediateUncertainty =\n opinionA.b * ifTrue.u +\n opinionA.d * ifFalse.u +\n opinionA.u * (ifTrue.u * opinionA.a + ifFalse.u * (1 - opinionA.a));\n const projectedVacuousDeduction =\n ifTrue.b * opinionA.a +\n ifFalse.b * (1 - opinionA.a) +\n childBaseRate *\n (ifTrue.u * opinionA.a + ifFalse.u * (1 - opinionA.a));\n const projectedConditionalA =\n ifTrue.b + childBaseRate * (1 - ifTrue.b - ifTrue.d);\n let correction = 0;\n\n if (\n (ifTrue.b > ifFalse.b && ifTrue.d > ifFalse.d) ||\n (ifTrue.b <= ifFalse.b && ifTrue.d <= ifFalse.d)\n ) {\n correction = 0;\n } else if (ifTrue.b > ifFalse.b && ifTrue.d <= ifFalse.d) {\n const beliefGap = ifTrue.b - ifFalse.b;\n const disbeliefGap = ifFalse.d - ifTrue.d;\n\n if (\n projectedVacuousDeduction <= projectedConditionalA &&\n projectedAntecedent <= opinionA.a\n ) {\n correction =\n safeCorrectionTerm(\n opinionA.a * opinionA.u * (intermediateBelief - ifTrue.b),\n projectedAntecedent * childBaseRate\n ) ?? 0;\n } else if (\n projectedVacuousDeduction <= projectedConditionalA &&\n projectedAntecedent > opinionA.a\n ) {\n correction =\n safeCorrectionTerm(\n opinionA.a * opinionA.u * (intermediateDisbelief - ifTrue.d) * beliefGap,\n projectedAntecedentComplement * childBaseRate * disbeliefGap\n ) ?? 0;\n } else if (\n projectedVacuousDeduction > projectedConditionalA &&\n projectedAntecedent <= opinionA.a\n ) {\n correction =\n safeCorrectionTerm(\n (1 - opinionA.a) *\n opinionA.u *\n (intermediateBelief - ifTrue.b) *\n disbeliefGap,\n projectedAntecedent * (1 - childBaseRate) * beliefGap\n ) ?? 0;\n } else {\n correction =\n safeCorrectionTerm(\n (1 - opinionA.a) * opinionA.u * (intermediateDisbelief - ifTrue.d),\n projectedAntecedentComplement * (1 - childBaseRate)\n ) ?? 0;\n }\n } else {\n const beliefGap = ifFalse.b - ifTrue.b;\n const disbeliefGap = ifTrue.d - ifFalse.d;\n\n if (\n projectedVacuousDeduction <= projectedConditionalA &&\n projectedAntecedent <= opinionA.a\n ) {\n correction =\n safeCorrectionTerm(\n (1 - opinionA.a) *\n opinionA.u *\n (intermediateDisbelief - ifTrue.d) *\n beliefGap,\n projectedAntecedent * childBaseRate * disbeliefGap\n ) ?? 0;\n } else if (\n projectedVacuousDeduction <= projectedConditionalA &&\n projectedAntecedent > opinionA.a\n ) {\n correction =\n safeCorrectionTerm(\n (1 - opinionA.a) * opinionA.u * (intermediateBelief - ifTrue.b),\n projectedAntecedentComplement * childBaseRate\n ) ?? 0;\n } else if (\n projectedVacuousDeduction > projectedConditionalA &&\n projectedAntecedent <= opinionA.a\n ) {\n correction =\n safeCorrectionTerm(\n opinionA.a * opinionA.u * (intermediateDisbelief - ifTrue.d),\n projectedAntecedent * (1 - childBaseRate)\n ) ?? 0;\n } else {\n correction =\n safeCorrectionTerm(\n opinionA.a *\n opinionA.u *\n (intermediateBelief - ifTrue.b) *\n disbeliefGap,\n projectedAntecedentComplement * (1 - childBaseRate) * beliefGap\n ) ?? 0;\n }\n }\n\n return opinion(\n intermediateBelief - childBaseRate * correction,\n intermediateDisbelief - (1 - childBaseRate) * correction,\n intermediateUncertainty + correction,\n childBaseRate\n );\n}\n\n/**\n * Abductive inference over a conditional.\n * Given an opinion on Y and conditionals P(Y|X), P(Y|~X), infer an opinion on X.\n */\nexport function conditionalAbduction(\n opinionY: SLOpinion,\n ifTrue: SLOpinion,\n ifFalse: SLOpinion,\n baseRateX: number\n): SLOpinion {\n const priorX = Math.max(0, Math.min(1, baseRateX));\n const probabilityY = project(opinionY);\n const probabilityGivenTrue = project(ifTrue);\n const probabilityGivenFalse = project(ifFalse);\n\n const posteriorIfYDenominator =\n probabilityGivenTrue * priorX +\n probabilityGivenFalse * (1 - priorX);\n const posteriorIfY =\n posteriorIfYDenominator === 0\n ? priorX\n : (probabilityGivenTrue * priorX) / posteriorIfYDenominator;\n\n const posteriorIfNotYDenominator =\n (1 - probabilityGivenTrue) * priorX +\n (1 - probabilityGivenFalse) * (1 - priorX);\n const posteriorIfNotY =\n posteriorIfNotYDenominator === 0\n ? priorX\n : ((1 - probabilityGivenTrue) * priorX) / posteriorIfNotYDenominator;\n\n const projectedX =\n probabilityY * posteriorIfY + (1 - probabilityY) * posteriorIfNotY;\n const uncertainty = Math.max(\n opinionY.u * 0.5,\n probabilityY * ifTrue.u + (1 - probabilityY) * ifFalse.u\n );\n\n return opinion(\n projectedX * (1 - uncertainty),\n (1 - projectedX) * (1 - uncertainty),\n uncertainty,\n priorX\n );\n}\n\nexport function negate(o: SLOpinion): SLOpinion {\n return mkOpinion(o.d, o.b, o.u, 1 - o.a);\n}\n\nexport function constraintFusion(\n left: SLOpinion,\n right: SLOpinion,\n mode: \"pressure\" | \"redistribute\" = \"pressure\"\n): { o1: SLOpinion; o2: SLOpinion } {\n if (mode === \"redistribute\") {\n const leftProjected = project(left);\n const rightProjected = project(right);\n const total = leftProjected + rightProjected;\n\n if (total <= 1) {\n return { o1: left, o2: right };\n }\n\n const scale = 1 / total;\n return {\n o1: opinion(\n left.b * scale,\n left.d + left.b * (1 - scale),\n left.u,\n left.a\n ),\n o2: opinion(\n right.b * scale,\n right.d + right.b * (1 - scale),\n right.u,\n right.a\n ),\n };\n }\n\n const pressureLeft = right.b * 0.5;\n const pressureRight = left.b * 0.5;\n\n return {\n o1: opinion(\n left.b - pressureLeft * 0.3,\n left.d + pressureLeft * 0.3,\n left.u,\n left.a\n ),\n o2: opinion(\n right.b - pressureRight * 0.3,\n right.d + pressureRight * 0.3,\n right.u,\n right.a\n ),\n };\n}\n\nexport function evidenceBalance(o: SLOpinion): number {\n const total = o.b + o.d;\n if (total === 0) {\n return 0;\n }\n return (o.b - o.d) / total;\n}\n\nexport function areTensioned(left: SLOpinion, right: SLOpinion): boolean {\n return (\n project(left) > 0.5 &&\n project(right) > 0.5 &&\n (left.d > 0.2 || right.d > 0.2)\n );\n}\n\nexport function informationGain(o: SLOpinion): number {\n if (o.u === 0) {\n return 0;\n }\n if (o.u === 1) {\n return 1;\n }\n return o.u * (1 - Math.abs(o.b - o.d));\n}\n","import type { Opinion, SLOpinion, StoredOpinionFields } from \"../types\";\nimport { dogmatic, mkOpinion, vacuous } from \"./subjectiveLogic\";\n\nfunction finiteNumber(value: unknown): number | undefined {\n return typeof value === \"number\" && Number.isFinite(value) ? value : undefined;\n}\n\nfunction requiredOpinionNumber(label: string, ...values: unknown[]): number {\n for (const value of values) {\n const numberValue = finiteNumber(value);\n if (numberValue !== undefined) {\n return numberValue;\n }\n }\n throw new Error(`Opinion record is missing required ${label}.`);\n}\n\nexport function clamp01(value: number): number {\n return Math.max(0, Math.min(1, value));\n}\n\nexport function confidenceFromOpinion(opinion: Opinion): number {\n return clamp01(opinion.b + opinion.a * opinion.u);\n}\n\nexport function confidenceFromSL(\n belief: number,\n _disbelief: number,\n uncertainty: number,\n baseRate: number\n): number {\n return confidenceFromOpinion({\n b: belief,\n d: _disbelief,\n u: uncertainty,\n a: baseRate,\n });\n}\n\nexport function toStoredOpinionFields(opinion: Opinion): StoredOpinionFields {\n return {\n belief: opinion.b,\n disbelief: opinion.d,\n uncertainty: opinion.u,\n baseRate: opinion.a,\n };\n}\n\nexport function readOpinionFromRecord(\n source: unknown\n): SLOpinion {\n const record =\n source && typeof source === \"object\"\n ? (source as Record<string, unknown>)\n : {};\n\n return mkOpinion(\n requiredOpinionNumber(\n \"belief\",\n record.b,\n record.belief,\n record.slBelief,\n record.opinion_b\n ),\n requiredOpinionNumber(\n \"disbelief\",\n record.d,\n record.disbelief,\n record.slDisbelief,\n record.opinion_d\n ),\n requiredOpinionNumber(\n \"uncertainty\",\n record.u,\n record.uncertainty,\n record.slUncertainty,\n record.opinion_u\n ),\n requiredOpinionNumber(\n \"baseRate\",\n record.a,\n record.baseRate,\n record.slBaseRate,\n record.opinion_a\n )\n );\n}\n\nexport type OpinionFromScalarMode =\n | \"base_rate\"\n | \"dogmatic\"\n | \"projected_with_u\";\n\nexport type OpinionFromScalarOptions =\n | { baseRate?: never; uncertainty?: never }\n | { baseRate: number; uncertainty?: never }\n | { baseRate: number; uncertainty: number };\n\nexport function opinionFromScalar(\n value: number,\n mode: \"base_rate\",\n options?: { baseRate?: never; uncertainty?: never }\n): SLOpinion;\nexport function opinionFromScalar(\n value: number,\n mode: \"dogmatic\",\n options: { baseRate: number; uncertainty?: never }\n): SLOpinion;\nexport function opinionFromScalar(\n value: number,\n mode: \"projected_with_u\",\n options: { baseRate: number; uncertainty: number }\n): SLOpinion;\nexport function opinionFromScalar(\n value: number,\n mode: OpinionFromScalarMode,\n options?: OpinionFromScalarOptions\n): SLOpinion {\n const clampedValue = clamp01(value);\n const baseRate =\n options?.baseRate === undefined ? undefined : clamp01(options.baseRate);\n\n switch (mode) {\n case \"base_rate\":\n return mkOpinion(0, 0, 1, clampedValue);\n case \"dogmatic\":\n if (baseRate === undefined) {\n throw new Error(\"opinionFromScalar(value, \\\"dogmatic\\\") requires options.baseRate.\");\n }\n return mkOpinion(clampedValue, 1 - clampedValue, 0, baseRate);\n case \"projected_with_u\": {\n if (baseRate === undefined) {\n throw new Error(\n \"opinionFromScalar(value, \\\"projected_with_u\\\") requires options.baseRate.\"\n );\n }\n const uncertainty = options?.uncertainty;\n if (uncertainty === undefined) {\n throw new Error(\n \"opinionFromScalar(value, \\\"projected_with_u\\\") requires options.uncertainty.\"\n );\n }\n const clampedUncertainty = clamp01(uncertainty);\n const evidenceWeight = 1 - clampedUncertainty;\n return mkOpinion(\n clampedValue * evidenceWeight,\n (1 - clampedValue) * evidenceWeight,\n clampedUncertainty,\n baseRate\n );\n }\n }\n\n throw new Error(`Unsupported opinionFromScalar mode: ${mode}`);\n}\n\n/**\n * @deprecated Use opinionFromScalar(value, \"dogmatic\", { baseRate }) instead.\n */\nexport function toDogmaticOpinion(\n confidence: number,\n baseRate: number\n): SLOpinion {\n return opinionFromScalar(confidence, \"dogmatic\", { baseRate });\n}\n\n/** Interpret p as a prior with no observed evidence. */\nexport function opinionFromBaseRate(probability: number): SLOpinion {\n return vacuous(clamp01(probability));\n}\n\n/** Interpret p as a certainty-equivalent projected probability. */\nexport function opinionFromDogmatic(\n probability: number,\n baseRate: number\n): SLOpinion {\n return dogmatic(clamp01(probability), clamp01(baseRate));\n}\n\n/**\n * Interpret p as a projected probability with an explicit uncertainty bucket.\n * The resulting opinion always projects back to p.\n */\nexport function opinionFromProjected(\n probability: number,\n uncertainty: number,\n baseRate: number\n): SLOpinion {\n const p = clamp01(probability);\n const u = clamp01(uncertainty);\n const remainingMass = 1 - u;\n return mkOpinion(p * remainingMass, (1 - p) * remainingMass, u, clamp01(baseRate));\n}\n\nexport function hasProjectedOpinionChanged(\n current: Opinion,\n next: Opinion,\n tolerance: number = 0.01\n): boolean {\n return Math.abs(confidenceFromOpinion(next) - confidenceFromOpinion(current)) >=\n tolerance;\n}\n","export const SL_CANONICAL_OPERATOR_NAMES = [\n \"mkOpinion\",\n \"opinion\",\n \"vacuous\",\n \"dogmatic\",\n \"project\",\n \"trustDiscount\",\n \"negate\",\n \"conditionalDeduction\",\n \"confidenceFromOpinion\",\n \"confidenceFromSL\",\n \"opinionFromBaseRate\",\n \"opinionFromDogmatic\",\n \"opinionFromProjected\",\n] as const;\n\nexport {\n mkOpinion,\n opinion,\n vacuous,\n dogmatic,\n project,\n trustDiscount,\n negate,\n conditionalDeduction,\n} from \"./subjectiveLogic\";\nexport {\n confidenceFromOpinion,\n confidenceFromSL,\n opinionFromBaseRate,\n opinionFromDogmatic,\n opinionFromProjected,\n} from \"./scoring\";\n"]}
1
+ {"version":3,"sources":["../../../src/v1/operations/subjectiveLogic/index.ts","../../../src/v1/operations/scoring.ts","../../../src/v1/operations/canonical.ts"],"names":["opinion"],"mappings":";AAEO,SAAS,OAAA,CACd,MAAA,EACA,SAAA,EACA,WAAA,EACA,QAAA,EACW;AACX,EAAA,MAAM,CAAA,GAAI,OAAO,QAAA,CAAS,MAAM,IAAI,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,MAAM,CAAA,GAAI,CAAA;AAC1D,EAAA,MAAM,CAAA,GAAI,OAAO,QAAA,CAAS,SAAS,IAAI,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,SAAS,CAAA,GAAI,CAAA;AA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,QAAQ,CAAC,CAAA;AACzD;AAEA,SAAS,iCAAA,CACP,WAAA,EACA,WAAA,EACA,QAAA,EACQ;AACR,EAAA,MAAM,oBAAA,GACJ,QAAA,GAAW,CAAA,GAAI,WAAA,GAAc,WAAW,MAAA,CAAO,iBAAA;AACjD,EAAA,MAAM,0BACJ,QAAA,GAAW,CAAA,GAAA,CACN,IAAI,WAAA,KAAgB,CAAA,GAAI,YACzB,MAAA,CAAO,iBAAA;AAEb,EAAA,OAAO,OAAA;AAAA,IACL,IAAA,CAAK,GAAA,CAAI,WAAA,EAAa,oBAAA,EAAsB,uBAAuB;AAAA,GACrE;AACF;AAOO,SAAS,oBAAA,CACd,WAAA,EACA,WAAA,EACA,QAAA,EACW;AACX,EAAA,MAAM,CAAA,GAAI,QAAQ,WAAW,CAAA;AAC7B,EAAA,MAAM,CAAA,GAAI,QAAQ,QAAQ,CAAA;AAC1B,EAAA,MAAM,IAAI,iCAAA,CAAkC,CAAA,EAAG,OAAA,CAAQ,WAAW,GAAG,CAAC,CAAA;AACtE,EAAA,OAAO,SAAA;AAAA,IACL,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,CAAA,GAAI,IAAI,CAAC,CAAA;AAAA,IACrB,KAAK,GAAA,CAAI,CAAA,EAAG,IAAI,CAAA,GAAA,CAAK,CAAA,GAAI,KAAK,CAAC,CAAA;AAAA,IAC/B,CAAA;AAAA,IACA;AAAA,GACF;AACF;;;ACvNO,IAAM,2BAAA,GAA8B;AAAA,EACzC,WAAA;AAAA,EACA,SAAA;AAAA,EACA,SAAA;AAAA,EACA,UAAA;AAAA,EACA,SAAA;AAAA,EACA,eAAA;AAAA,EACA,QAAA;AAAA,EACA,sBAAA;AAAA,EACA,uBAAA;AAAA,EACA,kBAAA;AAAA,EACA,qBAAA;AAAA,EACA,qBAAA;AAAA,EACA;AACF","file":"canonical.js","sourcesContent":["import type { SLOpinion } from \"../../types\";\n\nexport function opinion(\n belief: number,\n disbelief: number,\n uncertainty: number,\n baseRate: number\n): SLOpinion {\n const b = Number.isFinite(belief) ? Math.max(0, belief) : 0;\n const d = Number.isFinite(disbelief) ? Math.max(0, disbelief) : 0;\n const u = Number.isFinite(uncertainty) ? Math.max(0, uncertainty) : 0;\n const a = Math.max(0, Math.min(1, baseRate));\n const sum = b + d + u;\n\n if (sum === 0) {\n return { b: 0, d: 0, u: 1, a } as SLOpinion;\n }\n\n return {\n b: b / sum,\n d: d / sum,\n u: u / sum,\n a,\n } as SLOpinion;\n}\n\nexport function mkOpinion(\n belief: number,\n disbelief: number,\n uncertainty: number,\n baseRate: number\n): SLOpinion {\n return opinion(belief, disbelief, uncertainty, baseRate);\n}\n\nexport function vacuous(baseRate: number): SLOpinion {\n return mkOpinion(0, 0, 1, baseRate);\n}\n\nexport function dogmatic(probability: number, baseRate: number): SLOpinion {\n const p = Math.max(0, Math.min(1, probability));\n return mkOpinion(p, 1 - p, 0, baseRate);\n}\n\nexport function project(o: SLOpinion): number {\n return o.b + o.a * o.u;\n}\n\nexport function confidenceLevel(o: SLOpinion): \"high\" | \"medium\" | \"low\" {\n const projected = project(o);\n if (o.u > 0.5) {\n return \"low\";\n }\n if (projected >= 0.8 && o.u < 0.2) {\n return \"high\";\n }\n if (projected >= 0.6) {\n return \"medium\";\n }\n return \"low\";\n}\n\nconst VACUOUS_IDENTITY_EPSILON = 1e-12;\n\n/**\n * Associative, vacuous-identity-preserving base rate for a fused opinion.\n *\n * The legacy `(left.a + right.a) / 2` arithmetic mean was the shared root of\n * RR.7 F1 (projected-confidence non-associativity) and F2 (a vacuous opinion of\n * a different base rate was not a fusion identity): averaging always pulled the\n * fused base rate toward the other operand even when that operand carried no\n * evidence. Subjective Logic requires every opinion over the same frame to share\n * one canonical base rate, so a correct fusion never *invents* a new base rate\n * from the operands' priors. We therefore:\n *\n * - return the informative operand's base rate when exactly one operand is\n * vacuous (the vacuous operand contributes no prior), making `vacuous(a)` a\n * true identity for any `a`; and\n * - require equal base rates otherwise (the canonical-frame contract). When\n * they coincide the result is that shared value — trivially associative.\n *\n * If two informative opinions carry genuinely different base rates they are not\n * opinions over the same frame and must be reconciled before fusion; we fall\n * back to the arithmetic mean ONLY in that ill-posed case to stay total, and the\n * property suite documents that this path is outside the order-independence\n * guarantee.\n */\nfunction fusedBaseRate(left: SLOpinion, right: SLOpinion): number {\n const leftVacuous = 1 - left.u <= VACUOUS_IDENTITY_EPSILON;\n const rightVacuous = 1 - right.u <= VACUOUS_IDENTITY_EPSILON;\n if (leftVacuous && !rightVacuous) {\n return right.a;\n }\n if (rightVacuous && !leftVacuous) {\n return left.a;\n }\n if (Math.abs(left.a - right.a) <= VACUOUS_IDENTITY_EPSILON) {\n return left.a;\n }\n return (left.a + right.a) / 2;\n}\n\nexport function cumulativeFusion(left: SLOpinion, right: SLOpinion): SLOpinion {\n const a = fusedBaseRate(left, right);\n\n // F2: a vacuous operand is the identity element of cumulative fusion. Return\n // the other operand verbatim (including its base rate) so fusion with the\n // vacuous opinion is a true no-op regardless of differing priors.\n if (1 - left.u <= VACUOUS_IDENTITY_EPSILON) {\n return opinion(right.b, right.d, right.u, a);\n }\n if (1 - right.u <= VACUOUS_IDENTITY_EPSILON) {\n return opinion(left.b, left.d, left.u, a);\n }\n\n // F4: dogmatic pair handled via the ε-limit of the cumulative rule rather than\n // the standalone `(b+d)/2` shortcut. As both uncertainties shrink at the same\n // rate, the cumulative formula's `(b_L·u_R + b_R·u_L)/k` term converges to the\n // arithmetic mean of the masses; deriving it from the same limit the interior\n // formula uses keeps mass-associativity intact (no special-case discontinuity).\n if (\n left.u <= VACUOUS_IDENTITY_EPSILON &&\n right.u <= VACUOUS_IDENTITY_EPSILON\n ) {\n return opinion((left.b + right.b) / 2, (left.d + right.d) / 2, 0, a);\n }\n\n const k = left.u + right.u - left.u * right.u;\n if (k === 0) {\n return vacuous(a);\n }\n\n return opinion(\n (left.b * right.u + right.b * left.u) / k,\n (left.d * right.u + right.d * left.u) / k,\n (left.u * right.u) / k,\n a\n );\n}\n\nexport function averagingFusion(left: SLOpinion, right: SLOpinion): SLOpinion {\n const a = fusedBaseRate(left, right);\n\n // F2: vacuous identity, mirroring cumulativeFusion.\n if (1 - left.u <= VACUOUS_IDENTITY_EPSILON) {\n return opinion(right.b, right.d, right.u, a);\n }\n if (1 - right.u <= VACUOUS_IDENTITY_EPSILON) {\n return opinion(left.b, left.d, left.u, a);\n }\n\n // F4: dogmatic pair via the ε-limit of the averaging rule.\n if (\n left.u <= VACUOUS_IDENTITY_EPSILON &&\n right.u <= VACUOUS_IDENTITY_EPSILON\n ) {\n return opinion((left.b + right.b) / 2, (left.d + right.d) / 2, 0, a);\n }\n\n const k = left.u + right.u;\n if (k === 0) {\n return vacuous(a);\n }\n\n return opinion(\n (left.b * right.u + right.b * left.u) / k,\n (left.d * right.u + right.d * left.u) / k,\n (2 * left.u * right.u) / k,\n a\n );\n}\n\nexport function trustDiscount(\n sourceOpinion: SLOpinion,\n trust: number\n): SLOpinion {\n const weight = Math.max(0, Math.min(1, Math.abs(trust)));\n return opinion(\n weight * sourceOpinion.b,\n weight * sourceOpinion.d,\n 1 - weight * (sourceOpinion.b + sourceOpinion.d),\n sourceOpinion.a\n );\n}\n\nconst EPSILON = 1e-9;\n\nfunction childBaseRateFallback(\n ifTrue: SLOpinion,\n ifFalse: SLOpinion,\n fallbackBaseRate: number | undefined\n): number {\n if (fallbackBaseRate !== undefined) {\n return Math.max(0, Math.min(1, fallbackBaseRate));\n }\n\n if (Math.abs(ifTrue.a - ifFalse.a) <= EPSILON) {\n return ifTrue.a;\n }\n\n return (ifTrue.a + ifFalse.a) / 2;\n}\n\nfunction computeConditionalDeductionBaseRate(\n opinionA: SLOpinion,\n ifTrue: SLOpinion,\n ifFalse: SLOpinion,\n fallbackBaseRate: number\n): number {\n const denominator = 1 - opinionA.a * ifTrue.u - (1 - opinionA.a) * ifFalse.u;\n\n if (ifTrue.u + ifFalse.u < 2 - EPSILON && Math.abs(denominator) > EPSILON) {\n const baseRate =\n (opinionA.a * ifTrue.b + (1 - opinionA.a) * ifFalse.b) / denominator;\n if (baseRate >= -EPSILON && baseRate <= 1 + EPSILON) {\n return Math.max(0, Math.min(1, baseRate));\n }\n }\n\n return fallbackBaseRate;\n}\n\nfunction safeCorrectionTerm(\n numerator: number,\n denominator: number\n): number | undefined {\n if (Math.abs(denominator) <= EPSILON) {\n return;\n }\n\n const value = numerator / denominator;\n if (!Number.isFinite(value)) {\n return;\n }\n\n return Math.max(0, value);\n}\n\ninterface ConditionalDeductionCorrectionContext {\n childBaseRate: number;\n ifFalse: SLOpinion;\n ifTrue: SLOpinion;\n intermediateBelief: number;\n intermediateDisbelief: number;\n opinionA: SLOpinion;\n projectedAntecedent: number;\n projectedAntecedentComplement: number;\n projectedConditionalA: number;\n projectedVacuousDeduction: number;\n}\n\nfunction correctionOrZero(numerator: number, denominator: number): number {\n return safeCorrectionTerm(numerator, denominator) ?? 0;\n}\n\nfunction hasNoConditionalDeductionCorrection(\n ifTrue: SLOpinion,\n ifFalse: SLOpinion\n): boolean {\n return (\n (ifTrue.b > ifFalse.b && ifTrue.d > ifFalse.d) ||\n (ifTrue.b <= ifFalse.b && ifTrue.d <= ifFalse.d)\n );\n}\n\nfunction usesLowerVacuousBranch(\n context: ConditionalDeductionCorrectionContext\n): boolean {\n return context.projectedVacuousDeduction <= context.projectedConditionalA;\n}\n\nfunction usesLowerAntecedentBranch(\n context: ConditionalDeductionCorrectionContext\n): boolean {\n return context.projectedAntecedent <= context.opinionA.a;\n}\n\nfunction computeTrueDominantDeductionCorrection(\n context: ConditionalDeductionCorrectionContext\n): number {\n const beliefGap = context.ifTrue.b - context.ifFalse.b;\n const disbeliefGap = context.ifFalse.d - context.ifTrue.d;\n const lowerVacuous = usesLowerVacuousBranch(context);\n const lowerAntecedent = usesLowerAntecedentBranch(context);\n\n if (lowerVacuous && lowerAntecedent) {\n return correctionOrZero(\n context.opinionA.a *\n context.opinionA.u *\n (context.intermediateBelief - context.ifTrue.b),\n context.projectedAntecedent * context.childBaseRate\n );\n }\n\n if (lowerVacuous) {\n return correctionOrZero(\n context.opinionA.a *\n context.opinionA.u *\n (context.intermediateDisbelief - context.ifTrue.d) *\n beliefGap,\n context.projectedAntecedentComplement *\n context.childBaseRate *\n disbeliefGap\n );\n }\n\n if (lowerAntecedent) {\n return correctionOrZero(\n (1 - context.opinionA.a) *\n context.opinionA.u *\n (context.intermediateBelief - context.ifTrue.b) *\n disbeliefGap,\n context.projectedAntecedent * (1 - context.childBaseRate) * beliefGap\n );\n }\n\n return correctionOrZero(\n (1 - context.opinionA.a) *\n context.opinionA.u *\n (context.intermediateDisbelief - context.ifTrue.d),\n context.projectedAntecedentComplement * (1 - context.childBaseRate)\n );\n}\n\nfunction computeFalseDominantDeductionCorrection(\n context: ConditionalDeductionCorrectionContext\n): number {\n const beliefGap = context.ifFalse.b - context.ifTrue.b;\n const disbeliefGap = context.ifTrue.d - context.ifFalse.d;\n const lowerVacuous = usesLowerVacuousBranch(context);\n const lowerAntecedent = usesLowerAntecedentBranch(context);\n\n if (lowerVacuous && lowerAntecedent) {\n return correctionOrZero(\n (1 - context.opinionA.a) *\n context.opinionA.u *\n (context.intermediateDisbelief - context.ifTrue.d) *\n beliefGap,\n context.projectedAntecedent * context.childBaseRate * disbeliefGap\n );\n }\n\n if (lowerVacuous) {\n return correctionOrZero(\n (1 - context.opinionA.a) *\n context.opinionA.u *\n (context.intermediateBelief - context.ifTrue.b),\n context.projectedAntecedentComplement * context.childBaseRate\n );\n }\n\n if (lowerAntecedent) {\n return correctionOrZero(\n context.opinionA.a *\n context.opinionA.u *\n (context.intermediateDisbelief - context.ifTrue.d),\n context.projectedAntecedent * (1 - context.childBaseRate)\n );\n }\n\n return correctionOrZero(\n context.opinionA.a *\n context.opinionA.u *\n (context.intermediateBelief - context.ifTrue.b) *\n disbeliefGap,\n context.projectedAntecedentComplement *\n (1 - context.childBaseRate) *\n beliefGap\n );\n}\n\nfunction computeConditionalDeductionCorrection(\n context: ConditionalDeductionCorrectionContext\n): number {\n if (hasNoConditionalDeductionCorrection(context.ifTrue, context.ifFalse)) {\n return 0;\n }\n\n if (\n context.ifTrue.b > context.ifFalse.b &&\n context.ifTrue.d <= context.ifFalse.d\n ) {\n return computeTrueDominantDeductionCorrection(context);\n }\n\n return computeFalseDominantDeductionCorrection(context);\n}\n\nexport function conditionalDeduction(\n opinionA: SLOpinion,\n ifTrue: SLOpinion,\n ifFalse: SLOpinion,\n fallbackBaseRate?: number\n): SLOpinion {\n const fallbackChildBaseRate = childBaseRateFallback(\n ifTrue,\n ifFalse,\n fallbackBaseRate\n );\n const childBaseRate = computeConditionalDeductionBaseRate(\n opinionA,\n ifTrue,\n ifFalse,\n fallbackChildBaseRate\n );\n const projectedAntecedent = project(opinionA);\n const projectedAntecedentComplement = 1 - projectedAntecedent;\n const intermediateBelief =\n opinionA.b * ifTrue.b +\n opinionA.d * ifFalse.b +\n opinionA.u * (ifTrue.b * opinionA.a + ifFalse.b * (1 - opinionA.a));\n const intermediateDisbelief =\n opinionA.b * ifTrue.d +\n opinionA.d * ifFalse.d +\n opinionA.u * (ifTrue.d * opinionA.a + ifFalse.d * (1 - opinionA.a));\n const intermediateUncertainty =\n opinionA.b * ifTrue.u +\n opinionA.d * ifFalse.u +\n opinionA.u * (ifTrue.u * opinionA.a + ifFalse.u * (1 - opinionA.a));\n const projectedVacuousDeduction =\n ifTrue.b * opinionA.a +\n ifFalse.b * (1 - opinionA.a) +\n childBaseRate * (ifTrue.u * opinionA.a + ifFalse.u * (1 - opinionA.a));\n const projectedConditionalA =\n ifTrue.b + childBaseRate * (1 - ifTrue.b - ifTrue.d);\n const correction = computeConditionalDeductionCorrection({\n childBaseRate,\n ifFalse,\n ifTrue,\n intermediateBelief,\n intermediateDisbelief,\n opinionA,\n projectedAntecedent,\n projectedAntecedentComplement,\n projectedConditionalA,\n projectedVacuousDeduction,\n });\n\n return opinion(\n intermediateBelief - childBaseRate * correction,\n intermediateDisbelief - (1 - childBaseRate) * correction,\n intermediateUncertainty + correction,\n childBaseRate\n );\n}\n\n/**\n * Abductive inference over a conditional.\n * Given an opinion on Y and conditionals P(Y|X), P(Y|~X), infer an opinion on X.\n */\nexport function conditionalAbduction(\n opinionY: SLOpinion,\n ifTrue: SLOpinion,\n ifFalse: SLOpinion,\n baseRateX: number\n): SLOpinion {\n const priorX = Math.max(0, Math.min(1, baseRateX));\n const probabilityY = project(opinionY);\n const probabilityGivenTrue = project(ifTrue);\n const probabilityGivenFalse = project(ifFalse);\n\n const posteriorIfYDenominator =\n probabilityGivenTrue * priorX + probabilityGivenFalse * (1 - priorX);\n const posteriorIfY =\n posteriorIfYDenominator === 0\n ? priorX\n : (probabilityGivenTrue * priorX) / posteriorIfYDenominator;\n\n const posteriorIfNotYDenominator =\n (1 - probabilityGivenTrue) * priorX +\n (1 - probabilityGivenFalse) * (1 - priorX);\n const posteriorIfNotY =\n posteriorIfNotYDenominator === 0\n ? priorX\n : ((1 - probabilityGivenTrue) * priorX) / posteriorIfNotYDenominator;\n\n const projectedX =\n probabilityY * posteriorIfY + (1 - probabilityY) * posteriorIfNotY;\n const uncertainty = Math.max(\n opinionY.u * 0.5,\n probabilityY * ifTrue.u + (1 - probabilityY) * ifFalse.u\n );\n\n return opinion(\n projectedX * (1 - uncertainty),\n (1 - projectedX) * (1 - uncertainty),\n uncertainty,\n priorX\n );\n}\n\nexport function negate(o: SLOpinion): SLOpinion {\n return mkOpinion(o.d, o.b, o.u, 1 - o.a);\n}\n\nexport function constraintFusion(\n left: SLOpinion,\n right: SLOpinion,\n mode: \"pressure\" | \"redistribute\" = \"pressure\"\n): { o1: SLOpinion; o2: SLOpinion } {\n if (mode === \"redistribute\") {\n const leftProjected = project(left);\n const rightProjected = project(right);\n const total = leftProjected + rightProjected;\n\n if (total <= 1) {\n return { o1: left, o2: right };\n }\n\n const scale = 1 / total;\n return {\n o1: opinion(\n left.b * scale,\n left.d + left.b * (1 - scale),\n left.u,\n left.a\n ),\n o2: opinion(\n right.b * scale,\n right.d + right.b * (1 - scale),\n right.u,\n right.a\n ),\n };\n }\n\n const pressureLeft = right.b * 0.5;\n const pressureRight = left.b * 0.5;\n\n return {\n o1: opinion(\n left.b - pressureLeft * 0.3,\n left.d + pressureLeft * 0.3,\n left.u,\n left.a\n ),\n o2: opinion(\n right.b - pressureRight * 0.3,\n right.d + pressureRight * 0.3,\n right.u,\n right.a\n ),\n };\n}\n\nexport function evidenceBalance(o: SLOpinion): number {\n const total = o.b + o.d;\n if (total === 0) {\n return 0;\n }\n return (o.b - o.d) / total;\n}\n\nexport function areTensioned(left: SLOpinion, right: SLOpinion): boolean {\n return (\n project(left) > 0.5 &&\n project(right) > 0.5 &&\n (left.d > 0.2 || right.d > 0.2)\n );\n}\n\nexport function informationGain(o: SLOpinion): number {\n if (o.u === 0) {\n return 0;\n }\n if (o.u === 1) {\n return 1;\n }\n return o.u * (1 - Math.abs(o.b - o.d));\n}\n","import type { Opinion, SLOpinion, StoredOpinionFields } from \"../types\";\nimport { dogmatic, mkOpinion, vacuous } from \"./subjectiveLogic\";\n\nfunction finiteNumber(value: unknown): number | undefined {\n return typeof value === \"number\" && Number.isFinite(value)\n ? value\n : undefined;\n}\n\nfunction requiredOpinionNumber(label: string, ...values: unknown[]): number {\n for (const value of values) {\n const numberValue = finiteNumber(value);\n if (numberValue !== undefined) {\n return numberValue;\n }\n }\n throw new Error(`Opinion record is missing required ${label}.`);\n}\n\nexport function clamp01(value: number): number {\n return Math.max(0, Math.min(1, value));\n}\n\nexport function confidenceFromOpinion(opinion: Opinion): number {\n return clamp01(opinion.b + opinion.a * opinion.u);\n}\n\nexport function confidenceFromSL(\n belief: number,\n _disbelief: number,\n uncertainty: number,\n baseRate: number\n): number {\n return confidenceFromOpinion({\n b: belief,\n d: _disbelief,\n u: uncertainty,\n a: baseRate,\n });\n}\n\nexport function toStoredOpinionFields(opinion: Opinion): StoredOpinionFields {\n return {\n belief: opinion.b,\n disbelief: opinion.d,\n uncertainty: opinion.u,\n baseRate: opinion.a,\n };\n}\n\nexport function readOpinionFromRecord(source: unknown): SLOpinion {\n const record =\n source && typeof source === \"object\"\n ? (source as Record<string, unknown>)\n : {};\n\n return mkOpinion(\n requiredOpinionNumber(\n \"belief\",\n record.b,\n record.belief,\n record.slBelief,\n record.opinion_b\n ),\n requiredOpinionNumber(\n \"disbelief\",\n record.d,\n record.disbelief,\n record.slDisbelief,\n record.opinion_d\n ),\n requiredOpinionNumber(\n \"uncertainty\",\n record.u,\n record.uncertainty,\n record.slUncertainty,\n record.opinion_u\n ),\n requiredOpinionNumber(\n \"baseRate\",\n record.a,\n record.baseRate,\n record.slBaseRate,\n record.opinion_a\n )\n );\n}\n\nexport type OpinionFromScalarMode =\n | \"base_rate\"\n | \"dogmatic\"\n | \"projected_with_u\";\n\nexport type OpinionFromScalarOptions =\n | { baseRate?: never; uncertainty?: never }\n | { baseRate: number; uncertainty?: never }\n | { baseRate: number; uncertainty: number };\n\nexport function opinionFromScalar(\n value: number,\n mode: \"base_rate\",\n options?: { baseRate?: never; uncertainty?: never }\n): SLOpinion;\nexport function opinionFromScalar(\n value: number,\n mode: \"dogmatic\",\n options: { baseRate: number; uncertainty?: never }\n): SLOpinion;\nexport function opinionFromScalar(\n value: number,\n mode: \"projected_with_u\",\n options: { baseRate: number; uncertainty: number }\n): SLOpinion;\nexport function opinionFromScalar(\n value: number,\n mode: OpinionFromScalarMode,\n options?: OpinionFromScalarOptions\n): SLOpinion {\n const clampedValue = clamp01(value);\n const baseRate =\n options?.baseRate === undefined ? undefined : clamp01(options.baseRate);\n\n switch (mode) {\n case \"base_rate\":\n return mkOpinion(0, 0, 1, clampedValue);\n case \"dogmatic\":\n if (baseRate === undefined) {\n throw new Error(\n 'opinionFromScalar(value, \"dogmatic\") requires options.baseRate.'\n );\n }\n return mkOpinion(clampedValue, 1 - clampedValue, 0, baseRate);\n case \"projected_with_u\": {\n if (baseRate === undefined) {\n throw new Error(\n 'opinionFromScalar(value, \"projected_with_u\") requires options.baseRate.'\n );\n }\n const uncertainty = options?.uncertainty;\n if (uncertainty === undefined) {\n throw new Error(\n 'opinionFromScalar(value, \"projected_with_u\") requires options.uncertainty.'\n );\n }\n const clampedUncertainty = clamp01(uncertainty);\n const evidenceWeight = 1 - clampedUncertainty;\n return mkOpinion(\n clampedValue * evidenceWeight,\n (1 - clampedValue) * evidenceWeight,\n clampedUncertainty,\n baseRate\n );\n }\n default:\n throw new Error(`Unsupported opinionFromScalar mode: ${mode}`);\n }\n}\n\n/**\n * @deprecated Use opinionFromScalar(value, \"dogmatic\", { baseRate }) instead.\n */\nexport function toDogmaticOpinion(\n confidence: number,\n baseRate: number\n): SLOpinion {\n return opinionFromScalar(confidence, \"dogmatic\", { baseRate });\n}\n\n/** Interpret p as a prior with no observed evidence. */\nexport function opinionFromBaseRate(probability: number): SLOpinion {\n return vacuous(clamp01(probability));\n}\n\n/** Interpret p as a certainty-equivalent projected probability. */\nexport function opinionFromDogmatic(\n probability: number,\n baseRate: number\n): SLOpinion {\n return dogmatic(clamp01(probability), clamp01(baseRate));\n}\n\nfunction representableProjectedUncertainty(\n probability: number,\n uncertainty: number,\n baseRate: number\n): number {\n const maxBeliefUncertainty =\n baseRate > 0 ? probability / baseRate : Number.POSITIVE_INFINITY;\n const maxDisbeliefUncertainty =\n baseRate < 1\n ? (1 - probability) / (1 - baseRate)\n : Number.POSITIVE_INFINITY;\n\n return clamp01(\n Math.min(uncertainty, maxBeliefUncertainty, maxDisbeliefUncertainty)\n );\n}\n\n/**\n * Interpret p as a projected probability with an explicit uncertainty bucket.\n * Uses the requested uncertainty when representable; otherwise lowers it so the\n * resulting opinion stays valid and projects back to p.\n */\nexport function opinionFromProjected(\n probability: number,\n uncertainty: number,\n baseRate: number\n): SLOpinion {\n const p = clamp01(probability);\n const a = clamp01(baseRate);\n const u = representableProjectedUncertainty(p, clamp01(uncertainty), a);\n return mkOpinion(\n Math.max(0, p - a * u),\n Math.max(0, 1 - p - (1 - a) * u),\n u,\n a\n );\n}\n\nexport function hasProjectedOpinionChanged(\n current: Opinion,\n next: Opinion,\n tolerance = 0.01\n): boolean {\n return (\n Math.abs(confidenceFromOpinion(next) - confidenceFromOpinion(current)) >=\n tolerance\n );\n}\n","// biome-ignore-all lint/performance/noBarrelFile: Public confidence canonical facade; splitting requires an export-map migration.\n\nexport const SL_CANONICAL_OPERATOR_NAMES = [\n \"mkOpinion\",\n \"opinion\",\n \"vacuous\",\n \"dogmatic\",\n \"project\",\n \"trustDiscount\",\n \"negate\",\n \"conditionalDeduction\",\n \"confidenceFromOpinion\",\n \"confidenceFromSL\",\n \"opinionFromBaseRate\",\n \"opinionFromDogmatic\",\n \"opinionFromProjected\",\n] as const;\n\nexport {\n confidenceFromOpinion,\n confidenceFromSL,\n opinionFromBaseRate,\n opinionFromDogmatic,\n opinionFromProjected,\n} from \"./scoring\";\nexport {\n conditionalDeduction,\n dogmatic,\n mkOpinion,\n negate,\n opinion,\n project,\n trustDiscount,\n vacuous,\n} from \"./subjectiveLogic\";\n"]}
@@ -14,7 +14,7 @@ declare function deriveContractModulationPlan(args: {
14
14
  result: EpistemicContractEvaluationResult;
15
15
  resultConfidence?: number;
16
16
  }): ContractModulationPlan | null;
17
- declare function createInheritedContractRecord<TBeliefId = string, TTopicId = string | undefined>(contract: EpistemicContractRecord<any, any>, args: {
17
+ declare function createInheritedContractRecord<TBeliefId = string, TTopicId = string | undefined>(contract: EpistemicContractRecord<unknown, unknown>, args: {
18
18
  beliefNodeId: TBeliefId;
19
19
  topicId?: TTopicId;
20
20
  createdBy: string;
@@ -33,7 +33,10 @@ function deriveContractStatus(result, currentStatus) {
33
33
  case "expired":
34
34
  return "expired";
35
35
  default:
36
- return currentStatus === "satisfied" || currentStatus === "violated" || currentStatus === "expired" ? "active" : currentStatus;
36
+ if (currentStatus === "satisfied" || currentStatus === "violated" || currentStatus === "expired") {
37
+ return "active";
38
+ }
39
+ return currentStatus;
37
40
  }
38
41
  }
39
42
  function deriveVerificationTrigger(result) {
@@ -159,7 +162,7 @@ function pickFiniteNumber(config, keys) {
159
162
  return value;
160
163
  }
161
164
  }
162
- return void 0;
165
+ return;
163
166
  }
164
167
  function getEvaluatorInputRecord(inputData, nestedKey) {
165
168
  if (!isRecord(inputData)) {
@@ -219,7 +222,10 @@ function compareMetricValue(operator, left, right) {
219
222
  }
220
223
  }
221
224
  function resolveComparisonResult(direction, comparisonSatisfied) {
222
- return direction === "falsifies" ? comparisonSatisfied ? "disconfirmed" : "confirmed" : comparisonSatisfied ? "confirmed" : "disconfirmed";
225
+ if (direction === "falsifies") {
226
+ return comparisonSatisfied ? "disconfirmed" : "confirmed";
227
+ }
228
+ return comparisonSatisfied ? "confirmed" : "disconfirmed";
223
229
  }
224
230
  function buildComparisonRationale(args) {
225
231
  const renderedObserved = args.observedValue === null ? "no data" : `${args.observedValue}${args.unit ? ` ${args.unit}` : ""}`;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/v1/operations/contracts/epistemicContract.ts"],"names":[],"mappings":";AAkBO,IAAM,6BAAA,GAAgC;AACtC,IAAM,2BAAA,uBAAkC,GAAA,CAAI;AAAA,EACjD,6BAAA;AAAA,EACA,qBAAA;AAAA,EACA;AACF,CAAC;AACM,IAAM,uBAAA,GAA0B;AAChC,IAAM,gCAAA,GAAmC;AACzC,IAAM,0BAAA,GAA6B;AACnC,IAAM,gCAAA,GAAmC;AAEhD,SAAS,gBAAgB,KAAA,EAAuB;AAC9C,EAAA,OAAO,KAAK,GAAA,CAAI,CAAA,EAAG,KAAK,GAAA,CAAI,CAAA,EAAG,KAAK,CAAC,CAAA;AACvC;AAEA,SAAS,kBAAA,GAA6B;AACpC,EAAA,IAAI,OAAO,MAAA,KAAW,WAAA,IAAe,OAAO,MAAA,CAAO,eAAe,UAAA,EAAY;AAC5E,IAAA,OAAO,OAAO,UAAA,EAAW;AAAA,EAC3B;AACA,EAAA,OAAO,CAAA,SAAA,EAAY,IAAA,CAAK,GAAA,EAAK,IAAI,IAAA,CAAK,MAAA,EAAO,CAAE,QAAA,CAAS,EAAE,CAA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AAAA,IACN,cAAc,gBAAA,CAAiB,MAAA,EAAQ,CAAC,cAAA,EAAgB,WAAW,CAAC,CAAA;AAAA,IACpE,YAAA,EAAc,gBAAA,CAAiB,MAAA,EAAQ,CAAC,cAAc,CAAC,CAAA;AAAA,IACvD,SAAA,EACE,OAAO,MAAA,CAAO,SAAA,KAAc,QAAA,IAAY,OAAO,SAAA,CAAU,MAAA,GAAS,CAAA,GAC9D,MAAA,CAAO,SAAA,GACP,MAAA;AAAA,IACN,gBAAgB,gBAAA,CAAiB,MAAA,EAAQ,CAAC,gBAAA,EAAkB,YAAY,CAAC,CAAA;AAAA,IACzE,eAAA,EAAiB,gBAAA,CAAiB,MAAA,EAAQ,CAAC,iBAAiB,CAAC,CAAA;AAAA,IAC7D,QAAA,EAAU,uBAAA;AAAA,MACR,MAAA,CAAO,QAAA;AAAA,MACP;AAAA,KACF;AAAA,IACA,SAAA,EAAW,qBAAA;AAAA,MACT,MAAA,CAAO,SAAA;AAAA,MACP;AAAA;AACF,GACF;AACF","file":"epistemicContract.js","sourcesContent":["import type {\n ContractModulationPlan,\n EpistemicContractDirection,\n EpistemicContractEvaluationResult,\n EpistemicContractModulation,\n EpistemicContractRecord,\n EpistemicContractStatus,\n EvidentialAction,\n EvidentialEvaluatorConfig,\n EvidentialMetricSnapshot,\n EvidentialOperator,\n MarketIndexComparatorConfig,\n MetricCheckerEvaluatorConfig,\n ReferenceCheckCounterConfig,\n TemporalDeadlineEvaluatorConfig,\n VerificationConfidenceTrigger,\n} from \"../../types\";\n\nexport const BUILT_IN_EVIDENTIAL_EVALUATOR = \"evidential\";\nexport const BUILT_IN_EVIDENTIAL_ALIASES = new Set([\n BUILT_IN_EVIDENTIAL_EVALUATOR,\n \"built_in_evidential\",\n \"builtin_evidential\",\n]);\nexport const BUILT_IN_METRIC_CHECKER = \"metric_checker\";\nexport const BUILT_IN_REFERENCE_CHECK_COUNTER = \"reference_check_counter\";\nexport const BUILT_IN_TEMPORAL_DEADLINE = \"temporal_deadline\";\nexport const BUILT_IN_MARKET_INDEX_COMPARATOR = \"market_index_comparator\";\n\nfunction clampConfidence(value: number): number {\n return Math.max(0, Math.min(1, value));\n}\n\nfunction generateContractId(): string {\n if (typeof crypto !== \"undefined\" && typeof crypto.randomUUID === \"function\") {\n return crypto.randomUUID();\n }\n return `contract-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return Boolean(value) && typeof value === \"object\" && !Array.isArray(value);\n}\n\nexport function deriveContractStatus(\n result: EpistemicContractEvaluationResult,\n currentStatus: EpistemicContractStatus\n): EpistemicContractStatus {\n if (currentStatus === \"archived\") {\n return currentStatus;\n }\n\n switch (result) {\n case \"confirmed\":\n return \"satisfied\";\n case \"disconfirmed\":\n return \"violated\";\n case \"expired\":\n return \"expired\";\n default:\n return currentStatus === \"satisfied\" ||\n currentStatus === \"violated\" ||\n currentStatus === \"expired\"\n ? \"active\"\n : currentStatus;\n }\n}\n\nexport function deriveVerificationTrigger(\n result: EpistemicContractEvaluationResult\n): VerificationConfidenceTrigger | null {\n switch (result) {\n case \"confirmed\":\n return \"verification_confirmed\";\n case \"disconfirmed\":\n return \"verification_disconfirmed\";\n case \"expired\":\n return \"verification_expired\";\n case \"partial\":\n return \"verification_partial\";\n default:\n return null;\n }\n}\n\nexport function deriveContractModulationPlan(args: {\n currentConfidence: number;\n modulation: EpistemicContractModulation;\n result: EpistemicContractEvaluationResult;\n resultConfidence?: number;\n}): ContractModulationPlan | null {\n const trigger = deriveVerificationTrigger(args.result);\n if (!trigger) {\n return null;\n }\n\n if (args.result === \"confirmed\") {\n const rawNext = args.currentConfidence + args.modulation.onConfirmed.delta;\n const confidenceAfter = clampConfidence(\n Math.min(\n args.modulation.onConfirmed.ceiling ?? Number.POSITIVE_INFINITY,\n rawNext\n )\n );\n return {\n trigger,\n confidenceBefore: args.currentConfidence,\n confidenceAfter,\n confidenceDelta: confidenceAfter - args.currentConfidence,\n };\n }\n\n if (args.result === \"disconfirmed\") {\n const rawNext =\n args.currentConfidence + args.modulation.onDisconfirmed.delta;\n const confidenceAfter = clampConfidence(\n Math.max(args.modulation.onDisconfirmed.floor ?? 0, rawNext)\n );\n return {\n trigger,\n confidenceBefore: args.currentConfidence,\n confidenceAfter,\n confidenceDelta: confidenceAfter - args.currentConfidence,\n };\n }\n\n if (args.result === \"expired\" && args.modulation.onExpired) {\n const confidenceAfter = clampConfidence(\n args.currentConfidence + args.modulation.onExpired.delta\n );\n return {\n trigger,\n confidenceBefore: args.currentConfidence,\n confidenceAfter,\n confidenceDelta: confidenceAfter - args.currentConfidence,\n };\n }\n\n if (args.result === \"partial\" && args.modulation.onPartial) {\n if ((args.resultConfidence ?? 0) < args.modulation.onPartial.threshold) {\n return null;\n }\n const confidenceAfter = clampConfidence(\n args.currentConfidence + args.modulation.onPartial.delta\n );\n return {\n trigger,\n confidenceBefore: args.currentConfidence,\n confidenceAfter,\n confidenceDelta: confidenceAfter - args.currentConfidence,\n };\n }\n\n return null;\n}\n\nexport function createInheritedContractRecord<\n TBeliefId = string,\n TTopicId = string | undefined,\n>(\n contract: EpistemicContractRecord<any, any>,\n args: {\n beliefNodeId: TBeliefId;\n topicId?: TTopicId;\n createdBy: string;\n now: number;\n }\n): EpistemicContractRecord<TBeliefId, TTopicId> {\n return {\n beliefNodeId: args.beliefNodeId,\n contractId: generateContractId(),\n title: contract.title,\n description: contract.description,\n conditionType: contract.conditionType,\n direction: contract.direction,\n condition: contract.condition,\n deadline: contract.deadline,\n compositeOf: contract.compositeOf,\n compositeOperator: contract.compositeOperator,\n modulation: contract.modulation,\n evaluationSchedule: contract.evaluationSchedule,\n periodicIntervalMs: contract.periodicIntervalMs,\n status: \"active\",\n lineageSource: \"inherited\",\n inheritedFromContractId: contract.contractId,\n inheritedFromBeliefNodeId: contract.beliefNodeId as TBeliefId,\n inheritedAt: args.now,\n topicId: args.topicId,\n createdAt: args.now,\n createdBy: args.createdBy,\n updatedAt: args.now,\n };\n}\n\nexport function normalizeEvidentialAction(\n value: unknown\n): EvidentialAction | undefined {\n return value === \"append_sl_scoring\" ||\n value === \"flag_review\" ||\n value === \"archive\"\n ? value\n : undefined;\n}\n\nexport function parseComparisonOperator(\n value: unknown,\n evaluatorName: string\n): EvidentialOperator {\n if (\n value === \"gte\" ||\n value === \"lte\" ||\n value === \"eq\" ||\n value === \"gt\" ||\n value === \"lt\"\n ) {\n return value;\n }\n throw new Error(\n `${evaluatorName} requires operator to be one of gte, lte, eq, gt, or lt.`\n );\n}\n\nexport function parseNumericThreshold(\n value: unknown,\n evaluatorName: string\n): number {\n if (typeof value === \"number\" && Number.isFinite(value)) {\n return value;\n }\n throw new Error(`${evaluatorName} requires a finite numeric threshold.`);\n}\n\nexport function pickFiniteNumber(\n config: Record<string, unknown>,\n keys: string[]\n): number | undefined {\n for (const key of keys) {\n const value = config[key];\n if (typeof value === \"number\" && Number.isFinite(value)) {\n return value;\n }\n }\n return undefined;\n}\n\nexport function getEvaluatorInputRecord(\n inputData: unknown,\n nestedKey: string\n): Record<string, unknown> {\n if (!isRecord(inputData)) {\n return {};\n }\n\n const nested = inputData[nestedKey];\n if (isRecord(nested)) {\n return nested;\n }\n return inputData;\n}\n\nexport function parseEvidentialEvaluatorConfig(\n value: unknown\n): EvidentialEvaluatorConfig {\n if (!isRecord(value)) {\n throw new Error(\n \"Evidential contracts require condition.evaluatorConfig with metric/operator/threshold.\"\n );\n }\n\n const config = value;\n const metric = config.metric;\n const operator = config.operator;\n const threshold = config.threshold;\n\n if (\n metric !== \"evidence_count\" &&\n metric !== \"contradiction_status\" &&\n metric !== \"edge_freshness\" &&\n metric !== \"dependent_count\"\n ) {\n throw new Error(`Unsupported evidential metric: ${String(metric)}`);\n }\n\n if (\n operator !== \"gte\" &&\n operator !== \"lte\" &&\n operator !== \"eq\" &&\n operator !== \"gt\" &&\n operator !== \"lt\"\n ) {\n throw new Error(`Unsupported evidential operator: ${String(operator)}`);\n }\n\n if (typeof threshold !== \"number\" || !Number.isFinite(threshold)) {\n throw new Error(\"Evidential contracts require a numeric threshold.\");\n }\n\n const actionParams =\n isRecord(config.actionParams) ? config.actionParams : undefined;\n\n return {\n metric,\n operator,\n threshold,\n action: normalizeEvidentialAction(config.action),\n actionParams:\n actionParams &&\n (typeof actionParams.targetConfidence === \"number\" ||\n typeof actionParams.rationale === \"string\")\n ? {\n targetConfidence:\n typeof actionParams.targetConfidence === \"number\"\n ? actionParams.targetConfidence\n : undefined,\n rationale:\n typeof actionParams.rationale === \"string\"\n ? actionParams.rationale\n : undefined,\n }\n : undefined,\n };\n}\n\nexport function compareMetricValue(\n operator: EvidentialOperator,\n left: number,\n right: number\n): boolean {\n switch (operator) {\n case \"gte\":\n return left >= right;\n case \"lte\":\n return left <= right;\n case \"eq\":\n return left === right;\n case \"gt\":\n return left > right;\n case \"lt\":\n return left < right;\n default:\n return false;\n }\n}\n\nexport function resolveComparisonResult(\n direction: EpistemicContractDirection,\n comparisonSatisfied: boolean\n): EpistemicContractEvaluationResult {\n return direction === \"falsifies\"\n ? comparisonSatisfied\n ? \"disconfirmed\"\n : \"confirmed\"\n : comparisonSatisfied\n ? \"confirmed\"\n : \"disconfirmed\";\n}\n\nexport function buildComparisonRationale(args: {\n label: string;\n observedValue: number | null;\n operator: EvidentialOperator;\n threshold: number;\n comparisonSatisfied: boolean;\n result: EpistemicContractEvaluationResult;\n unit?: string;\n}): string {\n const renderedObserved =\n args.observedValue === null\n ? \"no data\"\n : `${args.observedValue}${args.unit ? ` ${args.unit}` : \"\"}`;\n const renderedThreshold = `${args.threshold}${args.unit ? ` ${args.unit}` : \"\"}`;\n const clause = `${args.label} observed ${renderedObserved} against ${args.operator} ${renderedThreshold}`;\n\n if (args.observedValue === null) {\n return `${clause}; evaluator returned ${args.result} because no current data was available.`;\n }\n\n return `${clause}; comparison ${\n args.comparisonSatisfied ? \"passed\" : \"failed\"\n }, resulting in ${args.result}.`;\n}\n\nexport function buildEvidentialRationale(args: {\n config: EvidentialEvaluatorConfig;\n snapshot: EvidentialMetricSnapshot;\n comparisonSatisfied: boolean;\n result: EpistemicContractEvaluationResult;\n}): string {\n const observed =\n args.snapshot.value === null ? \"no data\" : String(args.snapshot.value);\n const clause = `${args.snapshot.metric} observed ${observed} against ${args.config.operator} ${args.config.threshold}`;\n\n if (args.snapshot.value === null) {\n return `${clause}; evidential evaluator treated the comparison as unmet, resulting in ${args.result}.`;\n }\n\n return `${clause}; comparison ${\n args.comparisonSatisfied ? \"passed\" : \"failed\"\n }, resulting in ${args.result}.`;\n}\n\nexport function parseMetricCheckerConfig(\n value: unknown\n): MetricCheckerEvaluatorConfig {\n if (!isRecord(value)) {\n throw new Error(\n \"metric_checker requires condition.evaluatorConfig with observedValue/operator/threshold.\"\n );\n }\n\n const config = value;\n return {\n metric:\n typeof config.metric === \"string\" && config.metric.length > 0\n ? config.metric\n : undefined,\n operator: parseComparisonOperator(config.operator, BUILT_IN_METRIC_CHECKER),\n threshold: parseNumericThreshold(config.threshold, BUILT_IN_METRIC_CHECKER),\n observedValue: pickFiniteNumber(config, [\"observedValue\", \"value\"]),\n currentValue: pickFiniteNumber(config, [\"currentValue\"]),\n metricValue: pickFiniteNumber(config, [\"metricValue\"]),\n unit:\n typeof config.unit === \"string\" && config.unit.length > 0\n ? config.unit\n : undefined,\n };\n}\n\nexport function parseReferenceCheckCounterConfig(\n value: unknown\n): ReferenceCheckCounterConfig {\n if (!isRecord(value)) {\n throw new Error(\n \"reference_check_counter requires condition.evaluatorConfig with tag/operator/threshold.\"\n );\n }\n\n const config = value;\n if (typeof config.tag !== \"string\" || config.tag.trim().length === 0) {\n throw new Error(\"reference_check_counter requires a non-empty tag.\");\n }\n\n return {\n tag: config.tag.trim(),\n operator: parseComparisonOperator(\n config.operator,\n BUILT_IN_REFERENCE_CHECK_COUNTER\n ),\n threshold: parseNumericThreshold(\n config.threshold,\n BUILT_IN_REFERENCE_CHECK_COUNTER\n ),\n caseSensitive: config.caseSensitive === true,\n };\n}\n\nexport function parseTemporalDeadlineConfig(\n value: unknown\n): TemporalDeadlineEvaluatorConfig {\n if (!isRecord(value)) {\n return {};\n }\n\n const config = value;\n return {\n label:\n typeof config.label === \"string\" && config.label.length > 0\n ? config.label\n : undefined,\n completed: config.completed === true,\n completedAt: pickFiniteNumber(config, [\"completedAt\"]),\n observedAt: pickFiniteNumber(config, [\"observedAt\"]),\n satisfiedAt: pickFiniteNumber(config, [\"satisfiedAt\"]),\n achievedAt: pickFiniteNumber(config, [\"achievedAt\"]),\n };\n}\n\nexport function parseMarketIndexComparatorConfig(\n value: unknown\n): MarketIndexComparatorConfig {\n if (!isRecord(value)) {\n throw new Error(\n \"market_index_comparator requires condition.evaluatorConfig with subjectValue/benchmarkValue/operator/threshold.\"\n );\n }\n\n const config = value;\n return {\n subject:\n typeof config.subject === \"string\" && config.subject.length > 0\n ? config.subject\n : undefined,\n subjectValue: pickFiniteNumber(config, [\"subjectValue\", \"leftValue\"]),\n primaryValue: pickFiniteNumber(config, [\"primaryValue\"]),\n benchmark:\n typeof config.benchmark === \"string\" && config.benchmark.length > 0\n ? config.benchmark\n : undefined,\n benchmarkValue: pickFiniteNumber(config, [\"benchmarkValue\", \"rightValue\"]),\n comparisonValue: pickFiniteNumber(config, [\"comparisonValue\"]),\n operator: parseComparisonOperator(\n config.operator,\n BUILT_IN_MARKET_INDEX_COMPARATOR\n ),\n threshold: parseNumericThreshold(\n config.threshold,\n BUILT_IN_MARKET_INDEX_COMPARATOR\n ),\n };\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/v1/operations/contracts/epistemicContract.ts"],"names":[],"mappings":";AAoBO,IAAM,6BAAA,GAAgC;AACtC,IAAM,2BAAA,uBAAkC,GAAA,CAAI;AAAA,EACjD,6BAAA;AAAA,EACA,qBAAA;AAAA,EACA;AACF,CAAC;AACM,IAAM,uBAAA,GAA0B;AAChC,IAAM,gCAAA,GAAmC;AACzC,IAAM,0BAAA,GAA6B;AACnC,IAAM,gCAAA,GAAmC;AAEhD,SAAS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,EAAa,gBAAA,CAAiB,MAAA,EAAQ,CAAC,aAAa,CAAC,CAAA;AAAA,IACrD,UAAA,EAAY,gBAAA,CAAiB,MAAA,EAAQ,CAAC,YAAY,CAAC;AAAA,GACrD;AACF;AAEO,SAAS,iCACd,KAAA,EAC6B;AAC7B,EAAA,IAAI,CAAC,QAAA,CAAS,KAAK,CAAA,EAAG;AACpB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AAEA,EAAA,MAAM,MAAA,GAAS,KAAA;AACf,EAAA,OAAO;AAAA,IACL,OAAA,EACE,OAAO,MAAA,CAAO,OAAA,KAAY,QAAA,IAAY,OAAO,OAAA,CAAQ,MAAA,GAAS,CAAA,GAC1D,MAAA,CAAO,OAAA,GACP,MAAA;AAAA,IACN,cAAc,gBAAA,CAAiB,MAAA,EAAQ,CAAC,cAAA,EAAgB,WAAW,CAAC,CAAA;AAAA,IACpE,YAAA,EAAc,gBAAA,CAAiB,MAAA,EAAQ,CAAC,cAAc,CAAC,CAAA;AAAA,IACvD,SAAA,EACE,OAAO,MAAA,CAAO,SAAA,KAAc,QAAA,IAAY,OAAO,SAAA,CAAU,MAAA,GAAS,CAAA,GAC9D,MAAA,CAAO,SAAA,GACP,MAAA;AAAA,IACN,gBAAgB,gBAAA,CAAiB,MAAA,EAAQ,CAAC,gBAAA,EAAkB,YAAY,CAAC,CAAA;AAAA,IACzE,eAAA,EAAiB,gBAAA,CAAiB,MAAA,EAAQ,CAAC,iBAAiB,CAAC,CAAA;AAAA,IAC7D,QAAA,EAAU,uBAAA;AAAA,MACR,MAAA,CAAO,QAAA;AAAA,MACP;AAAA,KACF;AAAA,IACA,SAAA,EAAW,qBAAA;AAAA,MACT,MAAA,CAAO,SAAA;AAAA,MACP;AAAA;AACF,GACF;AACF","file":"epistemicContract.js","sourcesContent":["// biome-ignore-all lint/style/useFilenamingConvention: Published @lucern/confidence contract subpath; rename needs an export-map migration.\n\nimport type {\n ContractModulationPlan,\n EpistemicContractDirection,\n EpistemicContractEvaluationResult,\n EpistemicContractModulation,\n EpistemicContractRecord,\n EpistemicContractStatus,\n EvidentialAction,\n EvidentialEvaluatorConfig,\n EvidentialMetricSnapshot,\n EvidentialOperator,\n MarketIndexComparatorConfig,\n MetricCheckerEvaluatorConfig,\n ReferenceCheckCounterConfig,\n TemporalDeadlineEvaluatorConfig,\n VerificationConfidenceTrigger,\n} from \"../../types\";\n\nexport const BUILT_IN_EVIDENTIAL_EVALUATOR = \"evidential\";\nexport const BUILT_IN_EVIDENTIAL_ALIASES = new Set([\n BUILT_IN_EVIDENTIAL_EVALUATOR,\n \"built_in_evidential\",\n \"builtin_evidential\",\n]);\nexport const BUILT_IN_METRIC_CHECKER = \"metric_checker\";\nexport const BUILT_IN_REFERENCE_CHECK_COUNTER = \"reference_check_counter\";\nexport const BUILT_IN_TEMPORAL_DEADLINE = \"temporal_deadline\";\nexport const BUILT_IN_MARKET_INDEX_COMPARATOR = \"market_index_comparator\";\n\nfunction clampConfidence(value: number): number {\n return Math.max(0, Math.min(1, value));\n}\n\nfunction generateContractId(): string {\n if (\n typeof crypto !== \"undefined\" &&\n typeof crypto.randomUUID === \"function\"\n ) {\n return crypto.randomUUID();\n }\n return `contract-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return Boolean(value) && typeof value === \"object\" && !Array.isArray(value);\n}\n\nexport function deriveContractStatus(\n result: EpistemicContractEvaluationResult,\n currentStatus: EpistemicContractStatus\n): EpistemicContractStatus {\n if (currentStatus === \"archived\") {\n return currentStatus;\n }\n\n switch (result) {\n case \"confirmed\":\n return \"satisfied\";\n case \"disconfirmed\":\n return \"violated\";\n case \"expired\":\n return \"expired\";\n default:\n if (\n currentStatus === \"satisfied\" ||\n currentStatus === \"violated\" ||\n currentStatus === \"expired\"\n ) {\n return \"active\";\n }\n return currentStatus;\n }\n}\n\nexport function deriveVerificationTrigger(\n result: EpistemicContractEvaluationResult\n): VerificationConfidenceTrigger | null {\n switch (result) {\n case \"confirmed\":\n return \"verification_confirmed\";\n case \"disconfirmed\":\n return \"verification_disconfirmed\";\n case \"expired\":\n return \"verification_expired\";\n case \"partial\":\n return \"verification_partial\";\n default:\n return null;\n }\n}\n\nexport function deriveContractModulationPlan(args: {\n currentConfidence: number;\n modulation: EpistemicContractModulation;\n result: EpistemicContractEvaluationResult;\n resultConfidence?: number;\n}): ContractModulationPlan | null {\n const trigger = deriveVerificationTrigger(args.result);\n if (!trigger) {\n return null;\n }\n\n if (args.result === \"confirmed\") {\n const rawNext = args.currentConfidence + args.modulation.onConfirmed.delta;\n const confidenceAfter = clampConfidence(\n Math.min(\n args.modulation.onConfirmed.ceiling ?? Number.POSITIVE_INFINITY,\n rawNext\n )\n );\n return {\n trigger,\n confidenceBefore: args.currentConfidence,\n confidenceAfter,\n confidenceDelta: confidenceAfter - args.currentConfidence,\n };\n }\n\n if (args.result === \"disconfirmed\") {\n const rawNext =\n args.currentConfidence + args.modulation.onDisconfirmed.delta;\n const confidenceAfter = clampConfidence(\n Math.max(args.modulation.onDisconfirmed.floor ?? 0, rawNext)\n );\n return {\n trigger,\n confidenceBefore: args.currentConfidence,\n confidenceAfter,\n confidenceDelta: confidenceAfter - args.currentConfidence,\n };\n }\n\n if (args.result === \"expired\" && args.modulation.onExpired) {\n const confidenceAfter = clampConfidence(\n args.currentConfidence + args.modulation.onExpired.delta\n );\n return {\n trigger,\n confidenceBefore: args.currentConfidence,\n confidenceAfter,\n confidenceDelta: confidenceAfter - args.currentConfidence,\n };\n }\n\n if (args.result === \"partial\" && args.modulation.onPartial) {\n if ((args.resultConfidence ?? 0) < args.modulation.onPartial.threshold) {\n return null;\n }\n const confidenceAfter = clampConfidence(\n args.currentConfidence + args.modulation.onPartial.delta\n );\n return {\n trigger,\n confidenceBefore: args.currentConfidence,\n confidenceAfter,\n confidenceDelta: confidenceAfter - args.currentConfidence,\n };\n }\n\n return null;\n}\n\nexport function createInheritedContractRecord<\n TBeliefId = string,\n TTopicId = string | undefined,\n>(\n contract: EpistemicContractRecord<unknown, unknown>,\n args: {\n beliefNodeId: TBeliefId;\n topicId?: TTopicId;\n createdBy: string;\n now: number;\n }\n): EpistemicContractRecord<TBeliefId, TTopicId> {\n return {\n beliefNodeId: args.beliefNodeId,\n contractId: generateContractId(),\n title: contract.title,\n description: contract.description,\n conditionType: contract.conditionType,\n direction: contract.direction,\n condition: contract.condition,\n deadline: contract.deadline,\n compositeOf: contract.compositeOf,\n compositeOperator: contract.compositeOperator,\n modulation: contract.modulation,\n evaluationSchedule: contract.evaluationSchedule,\n periodicIntervalMs: contract.periodicIntervalMs,\n status: \"active\",\n lineageSource: \"inherited\",\n inheritedFromContractId: contract.contractId,\n inheritedFromBeliefNodeId: contract.beliefNodeId as TBeliefId,\n inheritedAt: args.now,\n topicId: args.topicId,\n createdAt: args.now,\n createdBy: args.createdBy,\n updatedAt: args.now,\n };\n}\n\nexport function normalizeEvidentialAction(\n value: unknown\n): EvidentialAction | undefined {\n return value === \"append_sl_scoring\" ||\n value === \"flag_review\" ||\n value === \"archive\"\n ? value\n : undefined;\n}\n\nexport function parseComparisonOperator(\n value: unknown,\n evaluatorName: string\n): EvidentialOperator {\n if (\n value === \"gte\" ||\n value === \"lte\" ||\n value === \"eq\" ||\n value === \"gt\" ||\n value === \"lt\"\n ) {\n return value;\n }\n throw new Error(\n `${evaluatorName} requires operator to be one of gte, lte, eq, gt, or lt.`\n );\n}\n\nexport function parseNumericThreshold(\n value: unknown,\n evaluatorName: string\n): number {\n if (typeof value === \"number\" && Number.isFinite(value)) {\n return value;\n }\n throw new Error(`${evaluatorName} requires a finite numeric threshold.`);\n}\n\nexport function pickFiniteNumber(\n config: Record<string, unknown>,\n keys: string[]\n): number | undefined {\n for (const key of keys) {\n const value = config[key];\n if (typeof value === \"number\" && Number.isFinite(value)) {\n return value;\n }\n }\n return;\n}\n\nexport function getEvaluatorInputRecord(\n inputData: unknown,\n nestedKey: string\n): Record<string, unknown> {\n if (!isRecord(inputData)) {\n return {};\n }\n\n const nested = inputData[nestedKey];\n if (isRecord(nested)) {\n return nested;\n }\n return inputData;\n}\n\nexport function parseEvidentialEvaluatorConfig(\n value: unknown\n): EvidentialEvaluatorConfig {\n if (!isRecord(value)) {\n throw new Error(\n \"Evidential contracts require condition.evaluatorConfig with metric/operator/threshold.\"\n );\n }\n\n const config = value;\n const metric = config.metric;\n const operator = config.operator;\n const threshold = config.threshold;\n\n if (\n metric !== \"evidence_count\" &&\n metric !== \"contradiction_status\" &&\n metric !== \"edge_freshness\" &&\n metric !== \"dependent_count\"\n ) {\n throw new Error(`Unsupported evidential metric: ${String(metric)}`);\n }\n\n if (\n operator !== \"gte\" &&\n operator !== \"lte\" &&\n operator !== \"eq\" &&\n operator !== \"gt\" &&\n operator !== \"lt\"\n ) {\n throw new Error(`Unsupported evidential operator: ${String(operator)}`);\n }\n\n if (typeof threshold !== \"number\" || !Number.isFinite(threshold)) {\n throw new Error(\"Evidential contracts require a numeric threshold.\");\n }\n\n const actionParams = isRecord(config.actionParams)\n ? config.actionParams\n : undefined;\n\n return {\n metric,\n operator,\n threshold,\n action: normalizeEvidentialAction(config.action),\n actionParams:\n actionParams &&\n (typeof actionParams.targetConfidence === \"number\" ||\n typeof actionParams.rationale === \"string\")\n ? {\n targetConfidence:\n typeof actionParams.targetConfidence === \"number\"\n ? actionParams.targetConfidence\n : undefined,\n rationale:\n typeof actionParams.rationale === \"string\"\n ? actionParams.rationale\n : undefined,\n }\n : undefined,\n };\n}\n\nexport function compareMetricValue(\n operator: EvidentialOperator,\n left: number,\n right: number\n): boolean {\n switch (operator) {\n case \"gte\":\n return left >= right;\n case \"lte\":\n return left <= right;\n case \"eq\":\n return left === right;\n case \"gt\":\n return left > right;\n case \"lt\":\n return left < right;\n default:\n return false;\n }\n}\n\nexport function resolveComparisonResult(\n direction: EpistemicContractDirection,\n comparisonSatisfied: boolean\n): EpistemicContractEvaluationResult {\n if (direction === \"falsifies\") {\n return comparisonSatisfied ? \"disconfirmed\" : \"confirmed\";\n }\n\n return comparisonSatisfied ? \"confirmed\" : \"disconfirmed\";\n}\n\nexport function buildComparisonRationale(args: {\n label: string;\n observedValue: number | null;\n operator: EvidentialOperator;\n threshold: number;\n comparisonSatisfied: boolean;\n result: EpistemicContractEvaluationResult;\n unit?: string;\n}): string {\n const renderedObserved =\n args.observedValue === null\n ? \"no data\"\n : `${args.observedValue}${args.unit ? ` ${args.unit}` : \"\"}`;\n const renderedThreshold = `${args.threshold}${args.unit ? ` ${args.unit}` : \"\"}`;\n const clause = `${args.label} observed ${renderedObserved} against ${args.operator} ${renderedThreshold}`;\n\n if (args.observedValue === null) {\n return `${clause}; evaluator returned ${args.result} because no current data was available.`;\n }\n\n return `${clause}; comparison ${\n args.comparisonSatisfied ? \"passed\" : \"failed\"\n }, resulting in ${args.result}.`;\n}\n\nexport function buildEvidentialRationale(args: {\n config: EvidentialEvaluatorConfig;\n snapshot: EvidentialMetricSnapshot;\n comparisonSatisfied: boolean;\n result: EpistemicContractEvaluationResult;\n}): string {\n const observed =\n args.snapshot.value === null ? \"no data\" : String(args.snapshot.value);\n const clause = `${args.snapshot.metric} observed ${observed} against ${args.config.operator} ${args.config.threshold}`;\n\n if (args.snapshot.value === null) {\n return `${clause}; evidential evaluator treated the comparison as unmet, resulting in ${args.result}.`;\n }\n\n return `${clause}; comparison ${\n args.comparisonSatisfied ? \"passed\" : \"failed\"\n }, resulting in ${args.result}.`;\n}\n\nexport function parseMetricCheckerConfig(\n value: unknown\n): MetricCheckerEvaluatorConfig {\n if (!isRecord(value)) {\n throw new Error(\n \"metric_checker requires condition.evaluatorConfig with observedValue/operator/threshold.\"\n );\n }\n\n const config = value;\n return {\n metric:\n typeof config.metric === \"string\" && config.metric.length > 0\n ? config.metric\n : undefined,\n operator: parseComparisonOperator(config.operator, BUILT_IN_METRIC_CHECKER),\n threshold: parseNumericThreshold(config.threshold, BUILT_IN_METRIC_CHECKER),\n observedValue: pickFiniteNumber(config, [\"observedValue\", \"value\"]),\n currentValue: pickFiniteNumber(config, [\"currentValue\"]),\n metricValue: pickFiniteNumber(config, [\"metricValue\"]),\n unit:\n typeof config.unit === \"string\" && config.unit.length > 0\n ? config.unit\n : undefined,\n };\n}\n\nexport function parseReferenceCheckCounterConfig(\n value: unknown\n): ReferenceCheckCounterConfig {\n if (!isRecord(value)) {\n throw new Error(\n \"reference_check_counter requires condition.evaluatorConfig with tag/operator/threshold.\"\n );\n }\n\n const config = value;\n if (typeof config.tag !== \"string\" || config.tag.trim().length === 0) {\n throw new Error(\"reference_check_counter requires a non-empty tag.\");\n }\n\n return {\n tag: config.tag.trim(),\n operator: parseComparisonOperator(\n config.operator,\n BUILT_IN_REFERENCE_CHECK_COUNTER\n ),\n threshold: parseNumericThreshold(\n config.threshold,\n BUILT_IN_REFERENCE_CHECK_COUNTER\n ),\n caseSensitive: config.caseSensitive === true,\n };\n}\n\nexport function parseTemporalDeadlineConfig(\n value: unknown\n): TemporalDeadlineEvaluatorConfig {\n if (!isRecord(value)) {\n return {};\n }\n\n const config = value;\n return {\n label:\n typeof config.label === \"string\" && config.label.length > 0\n ? config.label\n : undefined,\n completed: config.completed === true,\n completedAt: pickFiniteNumber(config, [\"completedAt\"]),\n observedAt: pickFiniteNumber(config, [\"observedAt\"]),\n satisfiedAt: pickFiniteNumber(config, [\"satisfiedAt\"]),\n achievedAt: pickFiniteNumber(config, [\"achievedAt\"]),\n };\n}\n\nexport function parseMarketIndexComparatorConfig(\n value: unknown\n): MarketIndexComparatorConfig {\n if (!isRecord(value)) {\n throw new Error(\n \"market_index_comparator requires condition.evaluatorConfig with subjectValue/benchmarkValue/operator/threshold.\"\n );\n }\n\n const config = value;\n return {\n subject:\n typeof config.subject === \"string\" && config.subject.length > 0\n ? config.subject\n : undefined,\n subjectValue: pickFiniteNumber(config, [\"subjectValue\", \"leftValue\"]),\n primaryValue: pickFiniteNumber(config, [\"primaryValue\"]),\n benchmark:\n typeof config.benchmark === \"string\" && config.benchmark.length > 0\n ? config.benchmark\n : undefined,\n benchmarkValue: pickFiniteNumber(config, [\"benchmarkValue\", \"rightValue\"]),\n comparisonValue: pickFiniteNumber(config, [\"comparisonValue\"]),\n operator: parseComparisonOperator(\n config.operator,\n BUILT_IN_MARKET_INDEX_COMPARATOR\n ),\n threshold: parseNumericThreshold(\n config.threshold,\n BUILT_IN_MARKET_INDEX_COMPARATOR\n ),\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/v1/operations/scoring.ts","../../../../src/v1/operations/contradiction/detectTupleContradiction.ts"],"names":[],"mappings":";AAiBO,SAAS,QAAQ,KAAA,EAAuB;AAC7C,EAAA,OAAO,KAAK,GAAA,CAAI,CAAA,EAAG,KAAK,GAAA,CAAI,CAAA,EAAG,KAAK,CAAC,CAAA;AACvC;;;ACZO,IAAM,4CAAA,GAA+C;AACrD,IAAM,+CAAA,GAAkD;AAExD,SAAS,iCAAA,CACd,MAAA,GAA4C,EAAC,EACnB;AAC1B,EAAA,OAAO;AAAA,IACL,eAAA,EAAiB,OAAA;AAAA,MACf,OAAO,eAAA,IAAmB;AAAA,KAC5B;AAAA,IACA,kBAAA,EAAoB,OAAA;AAAA,MAClB,OAAO,kBAAA,IACL;AAAA;AACJ,GACF;AACF;AAEO,SAAS,wBAAA,CACd,OAAA,EACA,IAAA,GAAe,4CAAA,EACf,OAAe,+CAAA,EACN;AACT,EAAA,OAAO,OAAA,CAAQ,CAAA,GAAI,IAAA,IAAQ,OAAA,CAAQ,CAAA,GAAI,IAAA;AACzC;AAEO,SAAS,qCAAqC,IAAA,EAIpB;AAC/B,EAAA,MAAM,MAAA,GAAS,iCAAA,CAAkC,IAAA,CAAK,MAAM,CAAA;AAC5D,EAAA,MAAM,iBAAA,GAAoB,wBAAA;AAAA,IACxB,IAAA,CAAK,OAAA;AAAA,IACL,MAAA,CAAO,eAAA;AAAA,IACP,MAAA,CAAO;AAAA,GACT;AACA,EAAA,MAAM,yBAAA,GAA4B,OAAA,CAAQ,IAAA,CAAK,yBAAyB,CAAA;AAExE,EAAA,OAAO;AAAA,IACL,iBAAA;AAAA,IACA,6BAAA,EACE,CAAC,yBAAA,IAA6B,iBAAA;AAAA,IAChC,8BAAA,EACE,6BAA6B,CAAC,iBAAA;AAAA,IAChC;AAAA,GACF;AACF","file":"detectTupleContradiction.js","sourcesContent":["import type { Opinion, SLOpinion, StoredOpinionFields } from \"../types\";\nimport { dogmatic, mkOpinion, vacuous } from \"./subjectiveLogic\";\n\nfunction finiteNumber(value: unknown): number | undefined {\n return typeof value === \"number\" && Number.isFinite(value) ? value : undefined;\n}\n\nfunction requiredOpinionNumber(label: string, ...values: unknown[]): number {\n for (const value of values) {\n const numberValue = finiteNumber(value);\n if (numberValue !== undefined) {\n return numberValue;\n }\n }\n throw new Error(`Opinion record is missing required ${label}.`);\n}\n\nexport function clamp01(value: number): number {\n return Math.max(0, Math.min(1, value));\n}\n\nexport function confidenceFromOpinion(opinion: Opinion): number {\n return clamp01(opinion.b + opinion.a * opinion.u);\n}\n\nexport function confidenceFromSL(\n belief: number,\n _disbelief: number,\n uncertainty: number,\n baseRate: number\n): number {\n return confidenceFromOpinion({\n b: belief,\n d: _disbelief,\n u: uncertainty,\n a: baseRate,\n });\n}\n\nexport function toStoredOpinionFields(opinion: Opinion): StoredOpinionFields {\n return {\n belief: opinion.b,\n disbelief: opinion.d,\n uncertainty: opinion.u,\n baseRate: opinion.a,\n };\n}\n\nexport function readOpinionFromRecord(\n source: unknown\n): SLOpinion {\n const record =\n source && typeof source === \"object\"\n ? (source as Record<string, unknown>)\n : {};\n\n return mkOpinion(\n requiredOpinionNumber(\n \"belief\",\n record.b,\n record.belief,\n record.slBelief,\n record.opinion_b\n ),\n requiredOpinionNumber(\n \"disbelief\",\n record.d,\n record.disbelief,\n record.slDisbelief,\n record.opinion_d\n ),\n requiredOpinionNumber(\n \"uncertainty\",\n record.u,\n record.uncertainty,\n record.slUncertainty,\n record.opinion_u\n ),\n requiredOpinionNumber(\n \"baseRate\",\n record.a,\n record.baseRate,\n record.slBaseRate,\n record.opinion_a\n )\n );\n}\n\nexport type OpinionFromScalarMode =\n | \"base_rate\"\n | \"dogmatic\"\n | \"projected_with_u\";\n\nexport type OpinionFromScalarOptions =\n | { baseRate?: never; uncertainty?: never }\n | { baseRate: number; uncertainty?: never }\n | { baseRate: number; uncertainty: number };\n\nexport function opinionFromScalar(\n value: number,\n mode: \"base_rate\",\n options?: { baseRate?: never; uncertainty?: never }\n): SLOpinion;\nexport function opinionFromScalar(\n value: number,\n mode: \"dogmatic\",\n options: { baseRate: number; uncertainty?: never }\n): SLOpinion;\nexport function opinionFromScalar(\n value: number,\n mode: \"projected_with_u\",\n options: { baseRate: number; uncertainty: number }\n): SLOpinion;\nexport function opinionFromScalar(\n value: number,\n mode: OpinionFromScalarMode,\n options?: OpinionFromScalarOptions\n): SLOpinion {\n const clampedValue = clamp01(value);\n const baseRate =\n options?.baseRate === undefined ? undefined : clamp01(options.baseRate);\n\n switch (mode) {\n case \"base_rate\":\n return mkOpinion(0, 0, 1, clampedValue);\n case \"dogmatic\":\n if (baseRate === undefined) {\n throw new Error(\"opinionFromScalar(value, \\\"dogmatic\\\") requires options.baseRate.\");\n }\n return mkOpinion(clampedValue, 1 - clampedValue, 0, baseRate);\n case \"projected_with_u\": {\n if (baseRate === undefined) {\n throw new Error(\n \"opinionFromScalar(value, \\\"projected_with_u\\\") requires options.baseRate.\"\n );\n }\n const uncertainty = options?.uncertainty;\n if (uncertainty === undefined) {\n throw new Error(\n \"opinionFromScalar(value, \\\"projected_with_u\\\") requires options.uncertainty.\"\n );\n }\n const clampedUncertainty = clamp01(uncertainty);\n const evidenceWeight = 1 - clampedUncertainty;\n return mkOpinion(\n clampedValue * evidenceWeight,\n (1 - clampedValue) * evidenceWeight,\n clampedUncertainty,\n baseRate\n );\n }\n }\n\n throw new Error(`Unsupported opinionFromScalar mode: ${mode}`);\n}\n\n/**\n * @deprecated Use opinionFromScalar(value, \"dogmatic\", { baseRate }) instead.\n */\nexport function toDogmaticOpinion(\n confidence: number,\n baseRate: number\n): SLOpinion {\n return opinionFromScalar(confidence, \"dogmatic\", { baseRate });\n}\n\n/** Interpret p as a prior with no observed evidence. */\nexport function opinionFromBaseRate(probability: number): SLOpinion {\n return vacuous(clamp01(probability));\n}\n\n/** Interpret p as a certainty-equivalent projected probability. */\nexport function opinionFromDogmatic(\n probability: number,\n baseRate: number\n): SLOpinion {\n return dogmatic(clamp01(probability), clamp01(baseRate));\n}\n\n/**\n * Interpret p as a projected probability with an explicit uncertainty bucket.\n * The resulting opinion always projects back to p.\n */\nexport function opinionFromProjected(\n probability: number,\n uncertainty: number,\n baseRate: number\n): SLOpinion {\n const p = clamp01(probability);\n const u = clamp01(uncertainty);\n const remainingMass = 1 - u;\n return mkOpinion(p * remainingMass, (1 - p) * remainingMass, u, clamp01(baseRate));\n}\n\nexport function hasProjectedOpinionChanged(\n current: Opinion,\n next: Opinion,\n tolerance: number = 0.01\n): boolean {\n return Math.abs(confidenceFromOpinion(next) - confidenceFromOpinion(current)) >=\n tolerance;\n}\n","import type {\n Opinion,\n TupleContradictionPolicy,\n TupleContradictionTransition,\n} from \"../../types\";\nimport { clamp01 } from \"../scoring\";\n\nexport const DEFAULT_TUPLE_CONTRADICTION_BELIEF_THRESHOLD = 0.7;\nexport const DEFAULT_TUPLE_CONTRADICTION_DISBELIEF_THRESHOLD = 0.7;\n\nexport function normalizeTupleContradictionPolicy(\n policy: Partial<TupleContradictionPolicy> = {}\n): TupleContradictionPolicy {\n return {\n beliefThreshold: clamp01(\n policy.beliefThreshold ?? DEFAULT_TUPLE_CONTRADICTION_BELIEF_THRESHOLD\n ),\n disbeliefThreshold: clamp01(\n policy.disbeliefThreshold ??\n DEFAULT_TUPLE_CONTRADICTION_DISBELIEF_THRESHOLD\n ),\n };\n}\n\nexport function detectTupleContradiction(\n opinion: Opinion,\n tauB: number = DEFAULT_TUPLE_CONTRADICTION_BELIEF_THRESHOLD,\n tauD: number = DEFAULT_TUPLE_CONTRADICTION_DISBELIEF_THRESHOLD\n): boolean {\n return opinion.b > tauB && opinion.d > tauD;\n}\n\nexport function evaluateTupleContradictionTransition(args: {\n previousTupleContradicted?: boolean;\n opinion: Opinion;\n policy?: Partial<TupleContradictionPolicy>;\n}): TupleContradictionTransition {\n const policy = normalizeTupleContradictionPolicy(args.policy);\n const tupleContradicted = detectTupleContradiction(\n args.opinion,\n policy.beliefThreshold,\n policy.disbeliefThreshold\n );\n const previousTupleContradicted = Boolean(args.previousTupleContradicted);\n\n return {\n tupleContradicted,\n crossedIntoTupleContradiction:\n !previousTupleContradicted && tupleContradicted,\n crossedOutOfTupleContradiction:\n previousTupleContradicted && !tupleContradicted,\n policy,\n };\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/v1/operations/scoring.ts","../../../../src/v1/operations/contradiction/detectTupleContradiction.ts"],"names":[],"mappings":";AAmBO,SAAS,QAAQ,KAAA,EAAuB;AAC7C,EAAA,OAAO,KAAK,GAAA,CAAI,CAAA,EAAG,KAAK,GAAA,CAAI,CAAA,EAAG,KAAK,CAAC,CAAA;AACvC;;;ACZO,IAAM,4CAAA,GAA+C;AACrD,IAAM,+CAAA,GAAkD;AAExD,SAAS,iCAAA,CACd,MAAA,GAA4C,EAAC,EACnB;AAC1B,EAAA,OAAO;AAAA,IACL,eAAA,EAAiB,OAAA;AAAA,MACf,OAAO,eAAA,IAAmB;AAAA,KAC5B;AAAA,IACA,kBAAA,EAAoB,OAAA;AAAA,MAClB,OAAO,kBAAA,IACL;AAAA;AACJ,GACF;AACF;AAEO,SAAS,wBAAA,CACd,OAAA,EACA,IAAA,GAAe,4CAAA,EACf,OAAe,+CAAA,EACN;AACT,EAAA,OAAO,OAAA,CAAQ,CAAA,GAAI,IAAA,IAAQ,OAAA,CAAQ,CAAA,GAAI,IAAA;AACzC;AAEO,SAAS,qCAAqC,IAAA,EAIpB;AAC/B,EAAA,MAAM,MAAA,GAAS,iCAAA,CAAkC,IAAA,CAAK,MAAM,CAAA;AAC5D,EAAA,MAAM,iBAAA,GAAoB,wBAAA;AAAA,IACxB,IAAA,CAAK,OAAA;AAAA,IACL,MAAA,CAAO,eAAA;AAAA,IACP,MAAA,CAAO;AAAA,GACT;AACA,EAAA,MAAM,yBAAA,GAA4B,OAAA,CAAQ,IAAA,CAAK,yBAAyB,CAAA;AAExE,EAAA,OAAO;AAAA,IACL,iBAAA;AAAA,IACA,6BAAA,EACE,CAAC,yBAAA,IAA6B,iBAAA;AAAA,IAChC,8BAAA,EACE,6BAA6B,CAAC,iBAAA;AAAA,IAChC;AAAA,GACF;AACF","file":"detectTupleContradiction.js","sourcesContent":["import type { Opinion, SLOpinion, StoredOpinionFields } from \"../types\";\nimport { dogmatic, mkOpinion, vacuous } from \"./subjectiveLogic\";\n\nfunction finiteNumber(value: unknown): number | undefined {\n return typeof value === \"number\" && Number.isFinite(value)\n ? value\n : undefined;\n}\n\nfunction requiredOpinionNumber(label: string, ...values: unknown[]): number {\n for (const value of values) {\n const numberValue = finiteNumber(value);\n if (numberValue !== undefined) {\n return numberValue;\n }\n }\n throw new Error(`Opinion record is missing required ${label}.`);\n}\n\nexport function clamp01(value: number): number {\n return Math.max(0, Math.min(1, value));\n}\n\nexport function confidenceFromOpinion(opinion: Opinion): number {\n return clamp01(opinion.b + opinion.a * opinion.u);\n}\n\nexport function confidenceFromSL(\n belief: number,\n _disbelief: number,\n uncertainty: number,\n baseRate: number\n): number {\n return confidenceFromOpinion({\n b: belief,\n d: _disbelief,\n u: uncertainty,\n a: baseRate,\n });\n}\n\nexport function toStoredOpinionFields(opinion: Opinion): StoredOpinionFields {\n return {\n belief: opinion.b,\n disbelief: opinion.d,\n uncertainty: opinion.u,\n baseRate: opinion.a,\n };\n}\n\nexport function readOpinionFromRecord(source: unknown): SLOpinion {\n const record =\n source && typeof source === \"object\"\n ? (source as Record<string, unknown>)\n : {};\n\n return mkOpinion(\n requiredOpinionNumber(\n \"belief\",\n record.b,\n record.belief,\n record.slBelief,\n record.opinion_b\n ),\n requiredOpinionNumber(\n \"disbelief\",\n record.d,\n record.disbelief,\n record.slDisbelief,\n record.opinion_d\n ),\n requiredOpinionNumber(\n \"uncertainty\",\n record.u,\n record.uncertainty,\n record.slUncertainty,\n record.opinion_u\n ),\n requiredOpinionNumber(\n \"baseRate\",\n record.a,\n record.baseRate,\n record.slBaseRate,\n record.opinion_a\n )\n );\n}\n\nexport type OpinionFromScalarMode =\n | \"base_rate\"\n | \"dogmatic\"\n | \"projected_with_u\";\n\nexport type OpinionFromScalarOptions =\n | { baseRate?: never; uncertainty?: never }\n | { baseRate: number; uncertainty?: never }\n | { baseRate: number; uncertainty: number };\n\nexport function opinionFromScalar(\n value: number,\n mode: \"base_rate\",\n options?: { baseRate?: never; uncertainty?: never }\n): SLOpinion;\nexport function opinionFromScalar(\n value: number,\n mode: \"dogmatic\",\n options: { baseRate: number; uncertainty?: never }\n): SLOpinion;\nexport function opinionFromScalar(\n value: number,\n mode: \"projected_with_u\",\n options: { baseRate: number; uncertainty: number }\n): SLOpinion;\nexport function opinionFromScalar(\n value: number,\n mode: OpinionFromScalarMode,\n options?: OpinionFromScalarOptions\n): SLOpinion {\n const clampedValue = clamp01(value);\n const baseRate =\n options?.baseRate === undefined ? undefined : clamp01(options.baseRate);\n\n switch (mode) {\n case \"base_rate\":\n return mkOpinion(0, 0, 1, clampedValue);\n case \"dogmatic\":\n if (baseRate === undefined) {\n throw new Error(\n 'opinionFromScalar(value, \"dogmatic\") requires options.baseRate.'\n );\n }\n return mkOpinion(clampedValue, 1 - clampedValue, 0, baseRate);\n case \"projected_with_u\": {\n if (baseRate === undefined) {\n throw new Error(\n 'opinionFromScalar(value, \"projected_with_u\") requires options.baseRate.'\n );\n }\n const uncertainty = options?.uncertainty;\n if (uncertainty === undefined) {\n throw new Error(\n 'opinionFromScalar(value, \"projected_with_u\") requires options.uncertainty.'\n );\n }\n const clampedUncertainty = clamp01(uncertainty);\n const evidenceWeight = 1 - clampedUncertainty;\n return mkOpinion(\n clampedValue * evidenceWeight,\n (1 - clampedValue) * evidenceWeight,\n clampedUncertainty,\n baseRate\n );\n }\n default:\n throw new Error(`Unsupported opinionFromScalar mode: ${mode}`);\n }\n}\n\n/**\n * @deprecated Use opinionFromScalar(value, \"dogmatic\", { baseRate }) instead.\n */\nexport function toDogmaticOpinion(\n confidence: number,\n baseRate: number\n): SLOpinion {\n return opinionFromScalar(confidence, \"dogmatic\", { baseRate });\n}\n\n/** Interpret p as a prior with no observed evidence. */\nexport function opinionFromBaseRate(probability: number): SLOpinion {\n return vacuous(clamp01(probability));\n}\n\n/** Interpret p as a certainty-equivalent projected probability. */\nexport function opinionFromDogmatic(\n probability: number,\n baseRate: number\n): SLOpinion {\n return dogmatic(clamp01(probability), clamp01(baseRate));\n}\n\nfunction representableProjectedUncertainty(\n probability: number,\n uncertainty: number,\n baseRate: number\n): number {\n const maxBeliefUncertainty =\n baseRate > 0 ? probability / baseRate : Number.POSITIVE_INFINITY;\n const maxDisbeliefUncertainty =\n baseRate < 1\n ? (1 - probability) / (1 - baseRate)\n : Number.POSITIVE_INFINITY;\n\n return clamp01(\n Math.min(uncertainty, maxBeliefUncertainty, maxDisbeliefUncertainty)\n );\n}\n\n/**\n * Interpret p as a projected probability with an explicit uncertainty bucket.\n * Uses the requested uncertainty when representable; otherwise lowers it so the\n * resulting opinion stays valid and projects back to p.\n */\nexport function opinionFromProjected(\n probability: number,\n uncertainty: number,\n baseRate: number\n): SLOpinion {\n const p = clamp01(probability);\n const a = clamp01(baseRate);\n const u = representableProjectedUncertainty(p, clamp01(uncertainty), a);\n return mkOpinion(\n Math.max(0, p - a * u),\n Math.max(0, 1 - p - (1 - a) * u),\n u,\n a\n );\n}\n\nexport function hasProjectedOpinionChanged(\n current: Opinion,\n next: Opinion,\n tolerance = 0.01\n): boolean {\n return (\n Math.abs(confidenceFromOpinion(next) - confidenceFromOpinion(current)) >=\n tolerance\n );\n}\n","// biome-ignore-all lint/style/useFilenamingConvention: Published @lucern/confidence contradiction subpath; rename needs an export-map migration.\n\nimport type {\n Opinion,\n TupleContradictionPolicy,\n TupleContradictionTransition,\n} from \"../../types\";\nimport { clamp01 } from \"../scoring\";\n\nexport const DEFAULT_TUPLE_CONTRADICTION_BELIEF_THRESHOLD = 0.7;\nexport const DEFAULT_TUPLE_CONTRADICTION_DISBELIEF_THRESHOLD = 0.7;\n\nexport function normalizeTupleContradictionPolicy(\n policy: Partial<TupleContradictionPolicy> = {}\n): TupleContradictionPolicy {\n return {\n beliefThreshold: clamp01(\n policy.beliefThreshold ?? DEFAULT_TUPLE_CONTRADICTION_BELIEF_THRESHOLD\n ),\n disbeliefThreshold: clamp01(\n policy.disbeliefThreshold ??\n DEFAULT_TUPLE_CONTRADICTION_DISBELIEF_THRESHOLD\n ),\n };\n}\n\nexport function detectTupleContradiction(\n opinion: Opinion,\n tauB: number = DEFAULT_TUPLE_CONTRADICTION_BELIEF_THRESHOLD,\n tauD: number = DEFAULT_TUPLE_CONTRADICTION_DISBELIEF_THRESHOLD\n): boolean {\n return opinion.b > tauB && opinion.d > tauD;\n}\n\nexport function evaluateTupleContradictionTransition(args: {\n previousTupleContradicted?: boolean;\n opinion: Opinion;\n policy?: Partial<TupleContradictionPolicy>;\n}): TupleContradictionTransition {\n const policy = normalizeTupleContradictionPolicy(args.policy);\n const tupleContradicted = detectTupleContradiction(\n args.opinion,\n policy.beliefThreshold,\n policy.disbeliefThreshold\n );\n const previousTupleContradicted = Boolean(args.previousTupleContradicted);\n\n return {\n tupleContradicted,\n crossedIntoTupleContradiction:\n !previousTupleContradicted && tupleContradicted,\n crossedOutOfTupleContradiction:\n previousTupleContradicted && !tupleContradicted,\n policy,\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/v1/operations/scoring.ts","../../../../src/v1/operations/contradiction/detectTupleContradiction.ts"],"names":[],"mappings":";AAiBO,SAAS,QAAQ,KAAA,EAAuB;AAC7C,EAAA,OAAO,KAAK,GAAA,CAAI,CAAA,EAAG,KAAK,GAAA,CAAI,CAAA,EAAG,KAAK,CAAC,CAAA;AACvC;;;ACZO,IAAM,4CAAA,GAA+C;AACrD,IAAM,+CAAA,GAAkD;AAExD,SAAS,iCAAA,CACd,MAAA,GAA4C,EAAC,EACnB;AAC1B,EAAA,OAAO;AAAA,IACL,eAAA,EAAiB,OAAA;AAAA,MACf,OAAO,eAAA,IAAmB;AAAA,KAC5B;AAAA,IACA,kBAAA,EAAoB,OAAA;AAAA,MAClB,OAAO,kBAAA,IACL;AAAA;AACJ,GACF;AACF;AAEO,SAAS,wBAAA,CACd,OAAA,EACA,IAAA,GAAe,4CAAA,EACf,OAAe,+CAAA,EACN;AACT,EAAA,OAAO,OAAA,CAAQ,CAAA,GAAI,IAAA,IAAQ,OAAA,CAAQ,CAAA,GAAI,IAAA;AACzC;AAEO,SAAS,qCAAqC,IAAA,EAIpB;AAC/B,EAAA,MAAM,MAAA,GAAS,iCAAA,CAAkC,IAAA,CAAK,MAAM,CAAA;AAC5D,EAAA,MAAM,iBAAA,GAAoB,wBAAA;AAAA,IACxB,IAAA,CAAK,OAAA;AAAA,IACL,MAAA,CAAO,eAAA;AAAA,IACP,MAAA,CAAO;AAAA,GACT;AACA,EAAA,MAAM,yBAAA,GAA4B,OAAA,CAAQ,IAAA,CAAK,yBAAyB,CAAA;AAExE,EAAA,OAAO;AAAA,IACL,iBAAA;AAAA,IACA,6BAAA,EACE,CAAC,yBAAA,IAA6B,iBAAA;AAAA,IAChC,8BAAA,EACE,6BAA6B,CAAC,iBAAA;AAAA,IAChC;AAAA,GACF;AACF","file":"index.js","sourcesContent":["import type { Opinion, SLOpinion, StoredOpinionFields } from \"../types\";\nimport { dogmatic, mkOpinion, vacuous } from \"./subjectiveLogic\";\n\nfunction finiteNumber(value: unknown): number | undefined {\n return typeof value === \"number\" && Number.isFinite(value) ? value : undefined;\n}\n\nfunction requiredOpinionNumber(label: string, ...values: unknown[]): number {\n for (const value of values) {\n const numberValue = finiteNumber(value);\n if (numberValue !== undefined) {\n return numberValue;\n }\n }\n throw new Error(`Opinion record is missing required ${label}.`);\n}\n\nexport function clamp01(value: number): number {\n return Math.max(0, Math.min(1, value));\n}\n\nexport function confidenceFromOpinion(opinion: Opinion): number {\n return clamp01(opinion.b + opinion.a * opinion.u);\n}\n\nexport function confidenceFromSL(\n belief: number,\n _disbelief: number,\n uncertainty: number,\n baseRate: number\n): number {\n return confidenceFromOpinion({\n b: belief,\n d: _disbelief,\n u: uncertainty,\n a: baseRate,\n });\n}\n\nexport function toStoredOpinionFields(opinion: Opinion): StoredOpinionFields {\n return {\n belief: opinion.b,\n disbelief: opinion.d,\n uncertainty: opinion.u,\n baseRate: opinion.a,\n };\n}\n\nexport function readOpinionFromRecord(\n source: unknown\n): SLOpinion {\n const record =\n source && typeof source === \"object\"\n ? (source as Record<string, unknown>)\n : {};\n\n return mkOpinion(\n requiredOpinionNumber(\n \"belief\",\n record.b,\n record.belief,\n record.slBelief,\n record.opinion_b\n ),\n requiredOpinionNumber(\n \"disbelief\",\n record.d,\n record.disbelief,\n record.slDisbelief,\n record.opinion_d\n ),\n requiredOpinionNumber(\n \"uncertainty\",\n record.u,\n record.uncertainty,\n record.slUncertainty,\n record.opinion_u\n ),\n requiredOpinionNumber(\n \"baseRate\",\n record.a,\n record.baseRate,\n record.slBaseRate,\n record.opinion_a\n )\n );\n}\n\nexport type OpinionFromScalarMode =\n | \"base_rate\"\n | \"dogmatic\"\n | \"projected_with_u\";\n\nexport type OpinionFromScalarOptions =\n | { baseRate?: never; uncertainty?: never }\n | { baseRate: number; uncertainty?: never }\n | { baseRate: number; uncertainty: number };\n\nexport function opinionFromScalar(\n value: number,\n mode: \"base_rate\",\n options?: { baseRate?: never; uncertainty?: never }\n): SLOpinion;\nexport function opinionFromScalar(\n value: number,\n mode: \"dogmatic\",\n options: { baseRate: number; uncertainty?: never }\n): SLOpinion;\nexport function opinionFromScalar(\n value: number,\n mode: \"projected_with_u\",\n options: { baseRate: number; uncertainty: number }\n): SLOpinion;\nexport function opinionFromScalar(\n value: number,\n mode: OpinionFromScalarMode,\n options?: OpinionFromScalarOptions\n): SLOpinion {\n const clampedValue = clamp01(value);\n const baseRate =\n options?.baseRate === undefined ? undefined : clamp01(options.baseRate);\n\n switch (mode) {\n case \"base_rate\":\n return mkOpinion(0, 0, 1, clampedValue);\n case \"dogmatic\":\n if (baseRate === undefined) {\n throw new Error(\"opinionFromScalar(value, \\\"dogmatic\\\") requires options.baseRate.\");\n }\n return mkOpinion(clampedValue, 1 - clampedValue, 0, baseRate);\n case \"projected_with_u\": {\n if (baseRate === undefined) {\n throw new Error(\n \"opinionFromScalar(value, \\\"projected_with_u\\\") requires options.baseRate.\"\n );\n }\n const uncertainty = options?.uncertainty;\n if (uncertainty === undefined) {\n throw new Error(\n \"opinionFromScalar(value, \\\"projected_with_u\\\") requires options.uncertainty.\"\n );\n }\n const clampedUncertainty = clamp01(uncertainty);\n const evidenceWeight = 1 - clampedUncertainty;\n return mkOpinion(\n clampedValue * evidenceWeight,\n (1 - clampedValue) * evidenceWeight,\n clampedUncertainty,\n baseRate\n );\n }\n }\n\n throw new Error(`Unsupported opinionFromScalar mode: ${mode}`);\n}\n\n/**\n * @deprecated Use opinionFromScalar(value, \"dogmatic\", { baseRate }) instead.\n */\nexport function toDogmaticOpinion(\n confidence: number,\n baseRate: number\n): SLOpinion {\n return opinionFromScalar(confidence, \"dogmatic\", { baseRate });\n}\n\n/** Interpret p as a prior with no observed evidence. */\nexport function opinionFromBaseRate(probability: number): SLOpinion {\n return vacuous(clamp01(probability));\n}\n\n/** Interpret p as a certainty-equivalent projected probability. */\nexport function opinionFromDogmatic(\n probability: number,\n baseRate: number\n): SLOpinion {\n return dogmatic(clamp01(probability), clamp01(baseRate));\n}\n\n/**\n * Interpret p as a projected probability with an explicit uncertainty bucket.\n * The resulting opinion always projects back to p.\n */\nexport function opinionFromProjected(\n probability: number,\n uncertainty: number,\n baseRate: number\n): SLOpinion {\n const p = clamp01(probability);\n const u = clamp01(uncertainty);\n const remainingMass = 1 - u;\n return mkOpinion(p * remainingMass, (1 - p) * remainingMass, u, clamp01(baseRate));\n}\n\nexport function hasProjectedOpinionChanged(\n current: Opinion,\n next: Opinion,\n tolerance: number = 0.01\n): boolean {\n return Math.abs(confidenceFromOpinion(next) - confidenceFromOpinion(current)) >=\n tolerance;\n}\n","import type {\n Opinion,\n TupleContradictionPolicy,\n TupleContradictionTransition,\n} from \"../../types\";\nimport { clamp01 } from \"../scoring\";\n\nexport const DEFAULT_TUPLE_CONTRADICTION_BELIEF_THRESHOLD = 0.7;\nexport const DEFAULT_TUPLE_CONTRADICTION_DISBELIEF_THRESHOLD = 0.7;\n\nexport function normalizeTupleContradictionPolicy(\n policy: Partial<TupleContradictionPolicy> = {}\n): TupleContradictionPolicy {\n return {\n beliefThreshold: clamp01(\n policy.beliefThreshold ?? DEFAULT_TUPLE_CONTRADICTION_BELIEF_THRESHOLD\n ),\n disbeliefThreshold: clamp01(\n policy.disbeliefThreshold ??\n DEFAULT_TUPLE_CONTRADICTION_DISBELIEF_THRESHOLD\n ),\n };\n}\n\nexport function detectTupleContradiction(\n opinion: Opinion,\n tauB: number = DEFAULT_TUPLE_CONTRADICTION_BELIEF_THRESHOLD,\n tauD: number = DEFAULT_TUPLE_CONTRADICTION_DISBELIEF_THRESHOLD\n): boolean {\n return opinion.b > tauB && opinion.d > tauD;\n}\n\nexport function evaluateTupleContradictionTransition(args: {\n previousTupleContradicted?: boolean;\n opinion: Opinion;\n policy?: Partial<TupleContradictionPolicy>;\n}): TupleContradictionTransition {\n const policy = normalizeTupleContradictionPolicy(args.policy);\n const tupleContradicted = detectTupleContradiction(\n args.opinion,\n policy.beliefThreshold,\n policy.disbeliefThreshold\n );\n const previousTupleContradicted = Boolean(args.previousTupleContradicted);\n\n return {\n tupleContradicted,\n crossedIntoTupleContradiction:\n !previousTupleContradicted && tupleContradicted,\n crossedOutOfTupleContradiction:\n previousTupleContradicted && !tupleContradicted,\n policy,\n };\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/v1/operations/scoring.ts","../../../../src/v1/operations/contradiction/detectTupleContradiction.ts"],"names":[],"mappings":";AAmBO,SAAS,QAAQ,KAAA,EAAuB;AAC7C,EAAA,OAAO,KAAK,GAAA,CAAI,CAAA,EAAG,KAAK,GAAA,CAAI,CAAA,EAAG,KAAK,CAAC,CAAA;AACvC;;;ACZO,IAAM,4CAAA,GAA+C;AACrD,IAAM,+CAAA,GAAkD;AAExD,SAAS,iCAAA,CACd,MAAA,GAA4C,EAAC,EACnB;AAC1B,EAAA,OAAO;AAAA,IACL,eAAA,EAAiB,OAAA;AAAA,MACf,OAAO,eAAA,IAAmB;AAAA,KAC5B;AAAA,IACA,kBAAA,EAAoB,OAAA;AAAA,MAClB,OAAO,kBAAA,IACL;AAAA;AACJ,GACF;AACF;AAEO,SAAS,wBAAA,CACd,OAAA,EACA,IAAA,GAAe,4CAAA,EACf,OAAe,+CAAA,EACN;AACT,EAAA,OAAO,OAAA,CAAQ,CAAA,GAAI,IAAA,IAAQ,OAAA,CAAQ,CAAA,GAAI,IAAA;AACzC;AAEO,SAAS,qCAAqC,IAAA,EAIpB;AAC/B,EAAA,MAAM,MAAA,GAAS,iCAAA,CAAkC,IAAA,CAAK,MAAM,CAAA;AAC5D,EAAA,MAAM,iBAAA,GAAoB,wBAAA;AAAA,IACxB,IAAA,CAAK,OAAA;AAAA,IACL,MAAA,CAAO,eAAA;AAAA,IACP,MAAA,CAAO;AAAA,GACT;AACA,EAAA,MAAM,yBAAA,GAA4B,OAAA,CAAQ,IAAA,CAAK,yBAAyB,CAAA;AAExE,EAAA,OAAO;AAAA,IACL,iBAAA;AAAA,IACA,6BAAA,EACE,CAAC,yBAAA,IAA6B,iBAAA;AAAA,IAChC,8BAAA,EACE,6BAA6B,CAAC,iBAAA;AAAA,IAChC;AAAA,GACF;AACF","file":"index.js","sourcesContent":["import type { Opinion, SLOpinion, StoredOpinionFields } from \"../types\";\nimport { dogmatic, mkOpinion, vacuous } from \"./subjectiveLogic\";\n\nfunction finiteNumber(value: unknown): number | undefined {\n return typeof value === \"number\" && Number.isFinite(value)\n ? value\n : undefined;\n}\n\nfunction requiredOpinionNumber(label: string, ...values: unknown[]): number {\n for (const value of values) {\n const numberValue = finiteNumber(value);\n if (numberValue !== undefined) {\n return numberValue;\n }\n }\n throw new Error(`Opinion record is missing required ${label}.`);\n}\n\nexport function clamp01(value: number): number {\n return Math.max(0, Math.min(1, value));\n}\n\nexport function confidenceFromOpinion(opinion: Opinion): number {\n return clamp01(opinion.b + opinion.a * opinion.u);\n}\n\nexport function confidenceFromSL(\n belief: number,\n _disbelief: number,\n uncertainty: number,\n baseRate: number\n): number {\n return confidenceFromOpinion({\n b: belief,\n d: _disbelief,\n u: uncertainty,\n a: baseRate,\n });\n}\n\nexport function toStoredOpinionFields(opinion: Opinion): StoredOpinionFields {\n return {\n belief: opinion.b,\n disbelief: opinion.d,\n uncertainty: opinion.u,\n baseRate: opinion.a,\n };\n}\n\nexport function readOpinionFromRecord(source: unknown): SLOpinion {\n const record =\n source && typeof source === \"object\"\n ? (source as Record<string, unknown>)\n : {};\n\n return mkOpinion(\n requiredOpinionNumber(\n \"belief\",\n record.b,\n record.belief,\n record.slBelief,\n record.opinion_b\n ),\n requiredOpinionNumber(\n \"disbelief\",\n record.d,\n record.disbelief,\n record.slDisbelief,\n record.opinion_d\n ),\n requiredOpinionNumber(\n \"uncertainty\",\n record.u,\n record.uncertainty,\n record.slUncertainty,\n record.opinion_u\n ),\n requiredOpinionNumber(\n \"baseRate\",\n record.a,\n record.baseRate,\n record.slBaseRate,\n record.opinion_a\n )\n );\n}\n\nexport type OpinionFromScalarMode =\n | \"base_rate\"\n | \"dogmatic\"\n | \"projected_with_u\";\n\nexport type OpinionFromScalarOptions =\n | { baseRate?: never; uncertainty?: never }\n | { baseRate: number; uncertainty?: never }\n | { baseRate: number; uncertainty: number };\n\nexport function opinionFromScalar(\n value: number,\n mode: \"base_rate\",\n options?: { baseRate?: never; uncertainty?: never }\n): SLOpinion;\nexport function opinionFromScalar(\n value: number,\n mode: \"dogmatic\",\n options: { baseRate: number; uncertainty?: never }\n): SLOpinion;\nexport function opinionFromScalar(\n value: number,\n mode: \"projected_with_u\",\n options: { baseRate: number; uncertainty: number }\n): SLOpinion;\nexport function opinionFromScalar(\n value: number,\n mode: OpinionFromScalarMode,\n options?: OpinionFromScalarOptions\n): SLOpinion {\n const clampedValue = clamp01(value);\n const baseRate =\n options?.baseRate === undefined ? undefined : clamp01(options.baseRate);\n\n switch (mode) {\n case \"base_rate\":\n return mkOpinion(0, 0, 1, clampedValue);\n case \"dogmatic\":\n if (baseRate === undefined) {\n throw new Error(\n 'opinionFromScalar(value, \"dogmatic\") requires options.baseRate.'\n );\n }\n return mkOpinion(clampedValue, 1 - clampedValue, 0, baseRate);\n case \"projected_with_u\": {\n if (baseRate === undefined) {\n throw new Error(\n 'opinionFromScalar(value, \"projected_with_u\") requires options.baseRate.'\n );\n }\n const uncertainty = options?.uncertainty;\n if (uncertainty === undefined) {\n throw new Error(\n 'opinionFromScalar(value, \"projected_with_u\") requires options.uncertainty.'\n );\n }\n const clampedUncertainty = clamp01(uncertainty);\n const evidenceWeight = 1 - clampedUncertainty;\n return mkOpinion(\n clampedValue * evidenceWeight,\n (1 - clampedValue) * evidenceWeight,\n clampedUncertainty,\n baseRate\n );\n }\n default:\n throw new Error(`Unsupported opinionFromScalar mode: ${mode}`);\n }\n}\n\n/**\n * @deprecated Use opinionFromScalar(value, \"dogmatic\", { baseRate }) instead.\n */\nexport function toDogmaticOpinion(\n confidence: number,\n baseRate: number\n): SLOpinion {\n return opinionFromScalar(confidence, \"dogmatic\", { baseRate });\n}\n\n/** Interpret p as a prior with no observed evidence. */\nexport function opinionFromBaseRate(probability: number): SLOpinion {\n return vacuous(clamp01(probability));\n}\n\n/** Interpret p as a certainty-equivalent projected probability. */\nexport function opinionFromDogmatic(\n probability: number,\n baseRate: number\n): SLOpinion {\n return dogmatic(clamp01(probability), clamp01(baseRate));\n}\n\nfunction representableProjectedUncertainty(\n probability: number,\n uncertainty: number,\n baseRate: number\n): number {\n const maxBeliefUncertainty =\n baseRate > 0 ? probability / baseRate : Number.POSITIVE_INFINITY;\n const maxDisbeliefUncertainty =\n baseRate < 1\n ? (1 - probability) / (1 - baseRate)\n : Number.POSITIVE_INFINITY;\n\n return clamp01(\n Math.min(uncertainty, maxBeliefUncertainty, maxDisbeliefUncertainty)\n );\n}\n\n/**\n * Interpret p as a projected probability with an explicit uncertainty bucket.\n * Uses the requested uncertainty when representable; otherwise lowers it so the\n * resulting opinion stays valid and projects back to p.\n */\nexport function opinionFromProjected(\n probability: number,\n uncertainty: number,\n baseRate: number\n): SLOpinion {\n const p = clamp01(probability);\n const a = clamp01(baseRate);\n const u = representableProjectedUncertainty(p, clamp01(uncertainty), a);\n return mkOpinion(\n Math.max(0, p - a * u),\n Math.max(0, 1 - p - (1 - a) * u),\n u,\n a\n );\n}\n\nexport function hasProjectedOpinionChanged(\n current: Opinion,\n next: Opinion,\n tolerance = 0.01\n): boolean {\n return (\n Math.abs(confidenceFromOpinion(next) - confidenceFromOpinion(current)) >=\n tolerance\n );\n}\n","// biome-ignore-all lint/style/useFilenamingConvention: Published @lucern/confidence contradiction subpath; rename needs an export-map migration.\n\nimport type {\n Opinion,\n TupleContradictionPolicy,\n TupleContradictionTransition,\n} from \"../../types\";\nimport { clamp01 } from \"../scoring\";\n\nexport const DEFAULT_TUPLE_CONTRADICTION_BELIEF_THRESHOLD = 0.7;\nexport const DEFAULT_TUPLE_CONTRADICTION_DISBELIEF_THRESHOLD = 0.7;\n\nexport function normalizeTupleContradictionPolicy(\n policy: Partial<TupleContradictionPolicy> = {}\n): TupleContradictionPolicy {\n return {\n beliefThreshold: clamp01(\n policy.beliefThreshold ?? DEFAULT_TUPLE_CONTRADICTION_BELIEF_THRESHOLD\n ),\n disbeliefThreshold: clamp01(\n policy.disbeliefThreshold ??\n DEFAULT_TUPLE_CONTRADICTION_DISBELIEF_THRESHOLD\n ),\n };\n}\n\nexport function detectTupleContradiction(\n opinion: Opinion,\n tauB: number = DEFAULT_TUPLE_CONTRADICTION_BELIEF_THRESHOLD,\n tauD: number = DEFAULT_TUPLE_CONTRADICTION_DISBELIEF_THRESHOLD\n): boolean {\n return opinion.b > tauB && opinion.d > tauD;\n}\n\nexport function evaluateTupleContradictionTransition(args: {\n previousTupleContradicted?: boolean;\n opinion: Opinion;\n policy?: Partial<TupleContradictionPolicy>;\n}): TupleContradictionTransition {\n const policy = normalizeTupleContradictionPolicy(args.policy);\n const tupleContradicted = detectTupleContradiction(\n args.opinion,\n policy.beliefThreshold,\n policy.disbeliefThreshold\n );\n const previousTupleContradicted = Boolean(args.previousTupleContradicted);\n\n return {\n tupleContradicted,\n crossedIntoTupleContradiction:\n !previousTupleContradicted && tupleContradicted,\n crossedOutOfTupleContradiction:\n previousTupleContradicted && !tupleContradicted,\n policy,\n };\n}\n"]}
@@ -43,7 +43,7 @@ function dampedDependencyOpinion(dependencyOpinion, beliefOpinion, mode = "conti
43
43
  }
44
44
  return beliefOpinion;
45
45
  }
46
- const dampingFactor = Math.pow(dependencyProjection, 0.5);
46
+ const dampingFactor = dependencyProjection ** 0.5;
47
47
  return opinion(
48
48
  beliefOpinion.b * dampingFactor,
49
49
  beliefOpinion.d + beliefOpinion.b * (1 - dampingFactor) * 0.3,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/v1/operations/subjectiveLogic/index.ts","../../../../src/v1/operations/dynamics/cascade.ts"],"names":[],"mappings":";AAEO,SAAS,OAAA,CACd,MAAA,EACA,SAAA,EACA,WAAA,EACA,QAAA,EACW;AACX,EAAA,MAAM,CAAA,GAAI,OAAO,QAAA,CAAS,MAAM,IAAI,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,MAAM,CAAA,GAAI,CAAA;AAC1D,EAAA,MAAM,CAAA,GAAI,OAAO,QAAA,CAAS,SAAS,IAAI,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,SAAS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AW;AACpC,MAAA,OAAO,OAAA;AAAA,QACL,CAAA;AAAA,QACA,aAAA,CAAc,CAAA,GAAI,aAAA,CAAc,CAAA,GAAI,GAAA;AAAA,QACpC,GAAA;AAAA,QACA,aAAA,CAAc;AAAA,OAChB;AAAA,IACF;AACA,IAAA,OAAO,aAAA;AAAA,EACT;AAEA,EAAA,MAAM,aAAA,GAAgB,IAAA,CAAK,GAAA,CAAI,oBAAA,EAAsB,GAAG,CAAA;AACxD,EAAA,OAAO,OAAA;AAAA,IACL,cAAc,CAAA,GAAI,aAAA;AAAA,IAClB,aAAA,CAAc,CAAA,GAAI,aAAA,CAAc,CAAA,IAAK,IAAI,aAAA,CAAA,GAAiB,GAAA;AAAA,IAC1D,aAAA,CAAc,CAAA,GAAI,aAAA,CAAc,CAAA,IAAK,IAAI,aAAA,CAAA,GAAiB,GAAA;AAAA,IAC1D,aAAA,CAAc;AAAA,GAChB;AACF;AAEO,SAAS,uBAAA,CACd,iBAAA,EACA,aAAA,EACA,IAAA,GAAwB,YAAA,EACL;AACnB,EAAA,OAAO;AAAA,IACL,OAAA,EAAS,uBAAA,CAAwB,iBAAA,EAAmB,aAAA,EAAe,IAAI,CAAA;AAAA,IACvE,QAAA,EAAU,oBAAA;AAAA,IACV,SAAA,EAAW,CAAA,2BAAA,EAA8B,IAAI,CAAA,mBAAA,EAAsB,OAAA;AAAA,MACjE,SAAA;AAAA,QACE,iBAAA,CAAkB,CAAA;AAAA,QAClB,iBAAA,CAAkB,CAAA;AAAA,QAClB,iBAAA,CAAkB,CAAA;AAAA,QAClB,iBAAA,CAAkB;AAAA;AACpB,KACF,CAAE,OAAA,CAAQ,CAAC,CAAC,CAAA;AAAA,GACd;AACF","file":"cascade.js","sourcesContent":["import type { SLOpinion } from \"../../types\";\n\nexport function opinion(\n belief: number,\n disbelief: number,\n uncertainty: number,\n baseRate: number\n): SLOpinion {\n const b = Number.isFinite(belief) ? Math.max(0, belief) : 0;\n const d = Number.isFinite(disbelief) ? Math.max(0, disbelief) : 0;\n const u = Number.isFinite(uncertainty) ? Math.max(0, uncertainty) : 0;\n const a = Math.max(0, Math.min(1, baseRate));\n const sum = b + d + u;\n\n if (sum === 0) {\n return { b: 0, d: 0, u: 1, a } as SLOpinion;\n }\n\n return {\n b: b / sum,\n d: d / sum,\n u: u / sum,\n a,\n } as SLOpinion;\n}\n\nexport function mkOpinion(\n belief: number,\n disbelief: number,\n uncertainty: number,\n baseRate: number\n): SLOpinion {\n return opinion(belief, disbelief, uncertainty, baseRate);\n}\n\nexport function vacuous(baseRate: number): SLOpinion {\n return mkOpinion(0, 0, 1, baseRate);\n}\n\nexport function dogmatic(probability: number, baseRate: number): SLOpinion {\n const p = Math.max(0, Math.min(1, probability));\n return mkOpinion(p, 1 - p, 0, baseRate);\n}\n\nexport function project(o: SLOpinion): number {\n return o.b + o.a * o.u;\n}\n\nexport function confidenceLevel(o: SLOpinion): \"high\" | \"medium\" | \"low\" {\n const projected = project(o);\n if (o.u > 0.5) {\n return \"low\";\n }\n if (projected >= 0.8 && o.u < 0.2) {\n return \"high\";\n }\n if (projected >= 0.6) {\n return \"medium\";\n }\n return \"low\";\n}\n\nconst VACUOUS_IDENTITY_EPSILON = 1e-12;\n\n/**\n * Associative, vacuous-identity-preserving base rate for a fused opinion.\n *\n * The legacy `(left.a + right.a) / 2` arithmetic mean was the shared root of\n * RR.7 F1 (projected-confidence non-associativity) and F2 (a vacuous opinion of\n * a different base rate was not a fusion identity): averaging always pulled the\n * fused base rate toward the other operand even when that operand carried no\n * evidence. Subjective Logic requires every opinion over the same frame to share\n * one canonical base rate, so a correct fusion never *invents* a new base rate\n * from the operands' priors. We therefore:\n *\n * - return the informative operand's base rate when exactly one operand is\n * vacuous (the vacuous operand contributes no prior), making `vacuous(a)` a\n * true identity for any `a`; and\n * - require equal base rates otherwise (the canonical-frame contract). When\n * they coincide the result is that shared value — trivially associative.\n *\n * If two informative opinions carry genuinely different base rates they are not\n * opinions over the same frame and must be reconciled before fusion; we fall\n * back to the arithmetic mean ONLY in that ill-posed case to stay total, and the\n * property suite documents that this path is outside the order-independence\n * guarantee.\n */\nfunction fusedBaseRate(left: SLOpinion, right: SLOpinion): number {\n const leftVacuous = 1 - left.u <= VACUOUS_IDENTITY_EPSILON;\n const rightVacuous = 1 - right.u <= VACUOUS_IDENTITY_EPSILON;\n if (leftVacuous && !rightVacuous) {\n return right.a;\n }\n if (rightVacuous && !leftVacuous) {\n return left.a;\n }\n if (Math.abs(left.a - right.a) <= VACUOUS_IDENTITY_EPSILON) {\n return left.a;\n }\n return (left.a + right.a) / 2;\n}\n\nexport function cumulativeFusion(left: SLOpinion, right: SLOpinion): SLOpinion {\n const a = fusedBaseRate(left, right);\n\n // F2: a vacuous operand is the identity element of cumulative fusion. Return\n // the other operand verbatim (including its base rate) so fusion with the\n // vacuous opinion is a true no-op regardless of differing priors.\n if (1 - left.u <= VACUOUS_IDENTITY_EPSILON) {\n return opinion(right.b, right.d, right.u, a);\n }\n if (1 - right.u <= VACUOUS_IDENTITY_EPSILON) {\n return opinion(left.b, left.d, left.u, a);\n }\n\n // F4: dogmatic pair handled via the ε-limit of the cumulative rule rather than\n // the standalone `(b+d)/2` shortcut. As both uncertainties shrink at the same\n // rate, the cumulative formula's `(b_L·u_R + b_R·u_L)/k` term converges to the\n // arithmetic mean of the masses; deriving it from the same limit the interior\n // formula uses keeps mass-associativity intact (no special-case discontinuity).\n if (left.u <= VACUOUS_IDENTITY_EPSILON && right.u <= VACUOUS_IDENTITY_EPSILON) {\n return opinion((left.b + right.b) / 2, (left.d + right.d) / 2, 0, a);\n }\n\n const k = left.u + right.u - left.u * right.u;\n if (k === 0) {\n return vacuous(a);\n }\n\n return opinion(\n (left.b * right.u + right.b * left.u) / k,\n (left.d * right.u + right.d * left.u) / k,\n (left.u * right.u) / k,\n a\n );\n}\n\nexport function averagingFusion(left: SLOpinion, right: SLOpinion): SLOpinion {\n const a = fusedBaseRate(left, right);\n\n // F2: vacuous identity, mirroring cumulativeFusion.\n if (1 - left.u <= VACUOUS_IDENTITY_EPSILON) {\n return opinion(right.b, right.d, right.u, a);\n }\n if (1 - right.u <= VACUOUS_IDENTITY_EPSILON) {\n return opinion(left.b, left.d, left.u, a);\n }\n\n // F4: dogmatic pair via the ε-limit of the averaging rule.\n if (left.u <= VACUOUS_IDENTITY_EPSILON && right.u <= VACUOUS_IDENTITY_EPSILON) {\n return opinion((left.b + right.b) / 2, (left.d + right.d) / 2, 0, a);\n }\n\n const k = left.u + right.u;\n if (k === 0) {\n return vacuous(a);\n }\n\n return opinion(\n (left.b * right.u + right.b * left.u) / k,\n (left.d * right.u + right.d * left.u) / k,\n (2 * left.u * right.u) / k,\n a\n );\n}\n\nexport function trustDiscount(sourceOpinion: SLOpinion, trust: number): SLOpinion {\n const weight = Math.max(0, Math.min(1, Math.abs(trust)));\n return opinion(\n weight * sourceOpinion.b,\n weight * sourceOpinion.d,\n 1 - weight * (sourceOpinion.b + sourceOpinion.d),\n sourceOpinion.a\n );\n}\n\nconst EPSILON = 1e-9;\n\nfunction childBaseRateFallback(\n ifTrue: SLOpinion,\n ifFalse: SLOpinion,\n fallbackBaseRate: number | undefined\n): number {\n if (fallbackBaseRate !== undefined) {\n return Math.max(0, Math.min(1, fallbackBaseRate));\n }\n\n if (Math.abs(ifTrue.a - ifFalse.a) <= EPSILON) {\n return ifTrue.a;\n }\n\n return (ifTrue.a + ifFalse.a) / 2;\n}\n\nfunction computeConditionalDeductionBaseRate(\n opinionA: SLOpinion,\n ifTrue: SLOpinion,\n ifFalse: SLOpinion,\n fallbackBaseRate: number\n): number {\n const denominator =\n 1 - opinionA.a * ifTrue.u - (1 - opinionA.a) * ifFalse.u;\n\n if (ifTrue.u + ifFalse.u < 2 - EPSILON && Math.abs(denominator) > EPSILON) {\n const baseRate =\n (opinionA.a * ifTrue.b + (1 - opinionA.a) * ifFalse.b) / denominator;\n if (baseRate >= -EPSILON && baseRate <= 1 + EPSILON) {\n return Math.max(0, Math.min(1, baseRate));\n }\n }\n\n return fallbackBaseRate;\n}\n\nfunction safeCorrectionTerm(\n numerator: number,\n denominator: number\n): number | undefined {\n if (Math.abs(denominator) <= EPSILON) {\n return undefined;\n }\n\n const value = numerator / denominator;\n if (!Number.isFinite(value)) {\n return undefined;\n }\n\n return Math.max(0, value);\n}\n\nexport function conditionalDeduction(\n opinionA: SLOpinion,\n ifTrue: SLOpinion,\n ifFalse: SLOpinion,\n fallbackBaseRate?: number\n): SLOpinion {\n const fallbackChildBaseRate = childBaseRateFallback(\n ifTrue,\n ifFalse,\n fallbackBaseRate\n );\n const childBaseRate = computeConditionalDeductionBaseRate(\n opinionA,\n ifTrue,\n ifFalse,\n fallbackChildBaseRate\n );\n const projectedAntecedent = project(opinionA);\n const projectedAntecedentComplement = 1 - projectedAntecedent;\n const intermediateBelief =\n opinionA.b * ifTrue.b +\n opinionA.d * ifFalse.b +\n opinionA.u * (ifTrue.b * opinionA.a + ifFalse.b * (1 - opinionA.a));\n const intermediateDisbelief =\n opinionA.b * ifTrue.d +\n opinionA.d * ifFalse.d +\n opinionA.u * (ifTrue.d * opinionA.a + ifFalse.d * (1 - opinionA.a));\n const intermediateUncertainty =\n opinionA.b * ifTrue.u +\n opinionA.d * ifFalse.u +\n opinionA.u * (ifTrue.u * opinionA.a + ifFalse.u * (1 - opinionA.a));\n const projectedVacuousDeduction =\n ifTrue.b * opinionA.a +\n ifFalse.b * (1 - opinionA.a) +\n childBaseRate *\n (ifTrue.u * opinionA.a + ifFalse.u * (1 - opinionA.a));\n const projectedConditionalA =\n ifTrue.b + childBaseRate * (1 - ifTrue.b - ifTrue.d);\n let correction = 0;\n\n if (\n (ifTrue.b > ifFalse.b && ifTrue.d > ifFalse.d) ||\n (ifTrue.b <= ifFalse.b && ifTrue.d <= ifFalse.d)\n ) {\n correction = 0;\n } else if (ifTrue.b > ifFalse.b && ifTrue.d <= ifFalse.d) {\n const beliefGap = ifTrue.b - ifFalse.b;\n const disbeliefGap = ifFalse.d - ifTrue.d;\n\n if (\n projectedVacuousDeduction <= projectedConditionalA &&\n projectedAntecedent <= opinionA.a\n ) {\n correction =\n safeCorrectionTerm(\n opinionA.a * opinionA.u * (intermediateBelief - ifTrue.b),\n projectedAntecedent * childBaseRate\n ) ?? 0;\n } else if (\n projectedVacuousDeduction <= projectedConditionalA &&\n projectedAntecedent > opinionA.a\n ) {\n correction =\n safeCorrectionTerm(\n opinionA.a * opinionA.u * (intermediateDisbelief - ifTrue.d) * beliefGap,\n projectedAntecedentComplement * childBaseRate * disbeliefGap\n ) ?? 0;\n } else if (\n projectedVacuousDeduction > projectedConditionalA &&\n projectedAntecedent <= opinionA.a\n ) {\n correction =\n safeCorrectionTerm(\n (1 - opinionA.a) *\n opinionA.u *\n (intermediateBelief - ifTrue.b) *\n disbeliefGap,\n projectedAntecedent * (1 - childBaseRate) * beliefGap\n ) ?? 0;\n } else {\n correction =\n safeCorrectionTerm(\n (1 - opinionA.a) * opinionA.u * (intermediateDisbelief - ifTrue.d),\n projectedAntecedentComplement * (1 - childBaseRate)\n ) ?? 0;\n }\n } else {\n const beliefGap = ifFalse.b - ifTrue.b;\n const disbeliefGap = ifTrue.d - ifFalse.d;\n\n if (\n projectedVacuousDeduction <= projectedConditionalA &&\n projectedAntecedent <= opinionA.a\n ) {\n correction =\n safeCorrectionTerm(\n (1 - opinionA.a) *\n opinionA.u *\n (intermediateDisbelief - ifTrue.d) *\n beliefGap,\n projectedAntecedent * childBaseRate * disbeliefGap\n ) ?? 0;\n } else if (\n projectedVacuousDeduction <= projectedConditionalA &&\n projectedAntecedent > opinionA.a\n ) {\n correction =\n safeCorrectionTerm(\n (1 - opinionA.a) * opinionA.u * (intermediateBelief - ifTrue.b),\n projectedAntecedentComplement * childBaseRate\n ) ?? 0;\n } else if (\n projectedVacuousDeduction > projectedConditionalA &&\n projectedAntecedent <= opinionA.a\n ) {\n correction =\n safeCorrectionTerm(\n opinionA.a * opinionA.u * (intermediateDisbelief - ifTrue.d),\n projectedAntecedent * (1 - childBaseRate)\n ) ?? 0;\n } else {\n correction =\n safeCorrectionTerm(\n opinionA.a *\n opinionA.u *\n (intermediateBelief - ifTrue.b) *\n disbeliefGap,\n projectedAntecedentComplement * (1 - childBaseRate) * beliefGap\n ) ?? 0;\n }\n }\n\n return opinion(\n intermediateBelief - childBaseRate * correction,\n intermediateDisbelief - (1 - childBaseRate) * correction,\n intermediateUncertainty + correction,\n childBaseRate\n );\n}\n\n/**\n * Abductive inference over a conditional.\n * Given an opinion on Y and conditionals P(Y|X), P(Y|~X), infer an opinion on X.\n */\nexport function conditionalAbduction(\n opinionY: SLOpinion,\n ifTrue: SLOpinion,\n ifFalse: SLOpinion,\n baseRateX: number\n): SLOpinion {\n const priorX = Math.max(0, Math.min(1, baseRateX));\n const probabilityY = project(opinionY);\n const probabilityGivenTrue = project(ifTrue);\n const probabilityGivenFalse = project(ifFalse);\n\n const posteriorIfYDenominator =\n probabilityGivenTrue * priorX +\n probabilityGivenFalse * (1 - priorX);\n const posteriorIfY =\n posteriorIfYDenominator === 0\n ? priorX\n : (probabilityGivenTrue * priorX) / posteriorIfYDenominator;\n\n const posteriorIfNotYDenominator =\n (1 - probabilityGivenTrue) * priorX +\n (1 - probabilityGivenFalse) * (1 - priorX);\n const posteriorIfNotY =\n posteriorIfNotYDenominator === 0\n ? priorX\n : ((1 - probabilityGivenTrue) * priorX) / posteriorIfNotYDenominator;\n\n const projectedX =\n probabilityY * posteriorIfY + (1 - probabilityY) * posteriorIfNotY;\n const uncertainty = Math.max(\n opinionY.u * 0.5,\n probabilityY * ifTrue.u + (1 - probabilityY) * ifFalse.u\n );\n\n return opinion(\n projectedX * (1 - uncertainty),\n (1 - projectedX) * (1 - uncertainty),\n uncertainty,\n priorX\n );\n}\n\nexport function negate(o: SLOpinion): SLOpinion {\n return mkOpinion(o.d, o.b, o.u, 1 - o.a);\n}\n\nexport function constraintFusion(\n left: SLOpinion,\n right: SLOpinion,\n mode: \"pressure\" | \"redistribute\" = \"pressure\"\n): { o1: SLOpinion; o2: SLOpinion } {\n if (mode === \"redistribute\") {\n const leftProjected = project(left);\n const rightProjected = project(right);\n const total = leftProjected + rightProjected;\n\n if (total <= 1) {\n return { o1: left, o2: right };\n }\n\n const scale = 1 / total;\n return {\n o1: opinion(\n left.b * scale,\n left.d + left.b * (1 - scale),\n left.u,\n left.a\n ),\n o2: opinion(\n right.b * scale,\n right.d + right.b * (1 - scale),\n right.u,\n right.a\n ),\n };\n }\n\n const pressureLeft = right.b * 0.5;\n const pressureRight = left.b * 0.5;\n\n return {\n o1: opinion(\n left.b - pressureLeft * 0.3,\n left.d + pressureLeft * 0.3,\n left.u,\n left.a\n ),\n o2: opinion(\n right.b - pressureRight * 0.3,\n right.d + pressureRight * 0.3,\n right.u,\n right.a\n ),\n };\n}\n\nexport function evidenceBalance(o: SLOpinion): number {\n const total = o.b + o.d;\n if (total === 0) {\n return 0;\n }\n return (o.b - o.d) / total;\n}\n\nexport function areTensioned(left: SLOpinion, right: SLOpinion): boolean {\n return (\n project(left) > 0.5 &&\n project(right) > 0.5 &&\n (left.d > 0.2 || right.d > 0.2)\n );\n}\n\nexport function informationGain(o: SLOpinion): number {\n if (o.u === 0) {\n return 0;\n }\n if (o.u === 1) {\n return 1;\n }\n return o.u * (1 - Math.abs(o.b - o.d));\n}\n","import type { Opinion, PropagationMode, PropagationResult } from \"../../types\";\nimport { mkOpinion, opinion, project } from \"../subjectiveLogic\";\n\nexport function dampedDependencyOpinion(\n dependencyOpinion: Opinion,\n beliefOpinion: Opinion,\n mode: PropagationMode = \"continuous\",\n threshold: number = 0.3\n): Opinion {\n const dependencyProjection = project(\n mkOpinion(\n dependencyOpinion.b,\n dependencyOpinion.d,\n dependencyOpinion.u,\n dependencyOpinion.a\n )\n );\n\n if (mode === \"threshold\") {\n if (dependencyProjection < threshold) {\n return opinion(\n 0,\n beliefOpinion.d + beliefOpinion.b * 0.5,\n 0.5,\n beliefOpinion.a\n );\n }\n return beliefOpinion;\n }\n\n const dampingFactor = Math.pow(dependencyProjection, 0.5);\n return opinion(\n beliefOpinion.b * dampingFactor,\n beliefOpinion.d + beliefOpinion.b * (1 - dampingFactor) * 0.3,\n beliefOpinion.u + beliefOpinion.b * (1 - dampingFactor) * 0.7,\n beliefOpinion.a\n );\n}\n\nexport function dampedDependencyCascade(\n dependencyOpinion: Opinion,\n beliefOpinion: Opinion,\n mode: PropagationMode = \"continuous\"\n): PropagationResult {\n return {\n opinion: dampedDependencyOpinion(dependencyOpinion, beliefOpinion, mode),\n operator: \"dependency_cascade\",\n rationale: `Damped dependency cascade (${mode}): prerequisite at ${project(\n mkOpinion(\n dependencyOpinion.b,\n dependencyOpinion.d,\n dependencyOpinion.u,\n dependencyOpinion.a\n )\n ).toFixed(2)}`,\n };\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/v1/operations/subjectiveLogic/index.ts","../../../../src/v1/operations/dynamics/cascade.ts"],"names":[],"mappings":";AAEO,SAAS,OAAA,CACd,MAAA,EACA,SAAA,EACA,WAAA,EACA,QAAA,EACW;AACX,EAAA,MAAM,CAAA,GAAI,OAAO,QAAA,CAAS,MAAM,IAAI,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,MAAM,CAAA,GAAI,CAAA;AAC1D,EAAA,MAAM,CAAA,GAAI,OAAO,QAAA,CAAS,SAAS,IAAI,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,SAAS,CAAA,GAAI,CAAA;AAChE,EAAA,MAAM,CAAA,GAAI,OAAO,QAAA,CAAS,WAAW,IAAI,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,WAAW,CAAA,GAAI,CAAA;AACpE,EAAA,MAAM,CAAA,GAAI,KAAK,GAAA,CAAI,CAAA,EAAG,KAAK,GAAA,CAAI,CAAA,EAAG,QAAQ,CAAC,CAAA;AAC3C,EAAA,MAAM,GAAA,GAAM,IAAI,CAAA,GAAI,CAAA;AAEpB,EAAA,IAAI,QAAQ,CAAA,EAAG;AACb,IAAA,OAAO,EAAE,CAAA,EAAG,CAAA,EAAG,G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GAAiB,GAAA;AAAA,IAC1D,aAAA,CAAc,CAAA,GAAI,aAAA,CAAc,CAAA,IAAK,IAAI,aAAA,CAAA,GAAiB,GAAA;AAAA,IAC1D,aAAA,CAAc;AAAA,GAChB;AACF;AAEO,SAAS,uBAAA,CACd,iBAAA,EACA,aAAA,EACA,IAAA,GAAwB,YAAA,EACL;AACnB,EAAA,OAAO;AAAA,IACL,OAAA,EAAS,uBAAA,CAAwB,iBAAA,EAAmB,aAAA,EAAe,IAAI,CAAA;AAAA,IACvE,QAAA,EAAU,oBAAA;AAAA,IACV,SAAA,EAAW,CAAA,2BAAA,EAA8B,IAAI,CAAA,mBAAA,EAAsB,OAAA;AAAA,MACjE,SAAA;AAAA,QACE,iBAAA,CAAkB,CAAA;AAAA,QAClB,iBAAA,CAAkB,CAAA;AAAA,QAClB,iBAAA,CAAkB,CAAA;AAAA,QAClB,iBAAA,CAAkB;AAAA;AACpB,KACF,CAAE,OAAA,CAAQ,CAAC,CAAC,CAAA;AAAA,GACd;AACF","file":"cascade.js","sourcesContent":["import type { SLOpinion } from \"../../types\";\n\nexport function opinion(\n belief: number,\n disbelief: number,\n uncertainty: number,\n baseRate: number\n): SLOpinion {\n const b = Number.isFinite(belief) ? Math.max(0, belief) : 0;\n const d = Number.isFinite(disbelief) ? Math.max(0, disbelief) : 0;\n const u = Number.isFinite(uncertainty) ? Math.max(0, uncertainty) : 0;\n const a = Math.max(0, Math.min(1, baseRate));\n const sum = b + d + u;\n\n if (sum === 0) {\n return { b: 0, d: 0, u: 1, a } as SLOpinion;\n }\n\n return {\n b: b / sum,\n d: d / sum,\n u: u / sum,\n a,\n } as SLOpinion;\n}\n\nexport function mkOpinion(\n belief: number,\n disbelief: number,\n uncertainty: number,\n baseRate: number\n): SLOpinion {\n return opinion(belief, disbelief, uncertainty, baseRate);\n}\n\nexport function vacuous(baseRate: number): SLOpinion {\n return mkOpinion(0, 0, 1, baseRate);\n}\n\nexport function dogmatic(probability: number, baseRate: number): SLOpinion {\n const p = Math.max(0, Math.min(1, probability));\n return mkOpinion(p, 1 - p, 0, baseRate);\n}\n\nexport function project(o: SLOpinion): number {\n return o.b + o.a * o.u;\n}\n\nexport function confidenceLevel(o: SLOpinion): \"high\" | \"medium\" | \"low\" {\n const projected = project(o);\n if (o.u > 0.5) {\n return \"low\";\n }\n if (projected >= 0.8 && o.u < 0.2) {\n return \"high\";\n }\n if (projected >= 0.6) {\n return \"medium\";\n }\n return \"low\";\n}\n\nconst VACUOUS_IDENTITY_EPSILON = 1e-12;\n\n/**\n * Associative, vacuous-identity-preserving base rate for a fused opinion.\n *\n * The legacy `(left.a + right.a) / 2` arithmetic mean was the shared root of\n * RR.7 F1 (projected-confidence non-associativity) and F2 (a vacuous opinion of\n * a different base rate was not a fusion identity): averaging always pulled the\n * fused base rate toward the other operand even when that operand carried no\n * evidence. Subjective Logic requires every opinion over the same frame to share\n * one canonical base rate, so a correct fusion never *invents* a new base rate\n * from the operands' priors. We therefore:\n *\n * - return the informative operand's base rate when exactly one operand is\n * vacuous (the vacuous operand contributes no prior), making `vacuous(a)` a\n * true identity for any `a`; and\n * - require equal base rates otherwise (the canonical-frame contract). When\n * they coincide the result is that shared value — trivially associative.\n *\n * If two informative opinions carry genuinely different base rates they are not\n * opinions over the same frame and must be reconciled before fusion; we fall\n * back to the arithmetic mean ONLY in that ill-posed case to stay total, and the\n * property suite documents that this path is outside the order-independence\n * guarantee.\n */\nfunction fusedBaseRate(left: SLOpinion, right: SLOpinion): number {\n const leftVacuous = 1 - left.u <= VACUOUS_IDENTITY_EPSILON;\n const rightVacuous = 1 - right.u <= VACUOUS_IDENTITY_EPSILON;\n if (leftVacuous && !rightVacuous) {\n return right.a;\n }\n if (rightVacuous && !leftVacuous) {\n return left.a;\n }\n if (Math.abs(left.a - right.a) <= VACUOUS_IDENTITY_EPSILON) {\n return left.a;\n }\n return (left.a + right.a) / 2;\n}\n\nexport function cumulativeFusion(left: SLOpinion, right: SLOpinion): SLOpinion {\n const a = fusedBaseRate(left, right);\n\n // F2: a vacuous operand is the identity element of cumulative fusion. Return\n // the other operand verbatim (including its base rate) so fusion with the\n // vacuous opinion is a true no-op regardless of differing priors.\n if (1 - left.u <= VACUOUS_IDENTITY_EPSILON) {\n return opinion(right.b, right.d, right.u, a);\n }\n if (1 - right.u <= VACUOUS_IDENTITY_EPSILON) {\n return opinion(left.b, left.d, left.u, a);\n }\n\n // F4: dogmatic pair handled via the ε-limit of the cumulative rule rather than\n // the standalone `(b+d)/2` shortcut. As both uncertainties shrink at the same\n // rate, the cumulative formula's `(b_L·u_R + b_R·u_L)/k` term converges to the\n // arithmetic mean of the masses; deriving it from the same limit the interior\n // formula uses keeps mass-associativity intact (no special-case discontinuity).\n if (\n left.u <= VACUOUS_IDENTITY_EPSILON &&\n right.u <= VACUOUS_IDENTITY_EPSILON\n ) {\n return opinion((left.b + right.b) / 2, (left.d + right.d) / 2, 0, a);\n }\n\n const k = left.u + right.u - left.u * right.u;\n if (k === 0) {\n return vacuous(a);\n }\n\n return opinion(\n (left.b * right.u + right.b * left.u) / k,\n (left.d * right.u + right.d * left.u) / k,\n (left.u * right.u) / k,\n a\n );\n}\n\nexport function averagingFusion(left: SLOpinion, right: SLOpinion): SLOpinion {\n const a = fusedBaseRate(left, right);\n\n // F2: vacuous identity, mirroring cumulativeFusion.\n if (1 - left.u <= VACUOUS_IDENTITY_EPSILON) {\n return opinion(right.b, right.d, right.u, a);\n }\n if (1 - right.u <= VACUOUS_IDENTITY_EPSILON) {\n return opinion(left.b, left.d, left.u, a);\n }\n\n // F4: dogmatic pair via the ε-limit of the averaging rule.\n if (\n left.u <= VACUOUS_IDENTITY_EPSILON &&\n right.u <= VACUOUS_IDENTITY_EPSILON\n ) {\n return opinion((left.b + right.b) / 2, (left.d + right.d) / 2, 0, a);\n }\n\n const k = left.u + right.u;\n if (k === 0) {\n return vacuous(a);\n }\n\n return opinion(\n (left.b * right.u + right.b * left.u) / k,\n (left.d * right.u + right.d * left.u) / k,\n (2 * left.u * right.u) / k,\n a\n );\n}\n\nexport function trustDiscount(\n sourceOpinion: SLOpinion,\n trust: number\n): SLOpinion {\n const weight = Math.max(0, Math.min(1, Math.abs(trust)));\n return opinion(\n weight * sourceOpinion.b,\n weight * sourceOpinion.d,\n 1 - weight * (sourceOpinion.b + sourceOpinion.d),\n sourceOpinion.a\n );\n}\n\nconst EPSILON = 1e-9;\n\nfunction childBaseRateFallback(\n ifTrue: SLOpinion,\n ifFalse: SLOpinion,\n fallbackBaseRate: number | undefined\n): number {\n if (fallbackBaseRate !== undefined) {\n return Math.max(0, Math.min(1, fallbackBaseRate));\n }\n\n if (Math.abs(ifTrue.a - ifFalse.a) <= EPSILON) {\n return ifTrue.a;\n }\n\n return (ifTrue.a + ifFalse.a) / 2;\n}\n\nfunction computeConditionalDeductionBaseRate(\n opinionA: SLOpinion,\n ifTrue: SLOpinion,\n ifFalse: SLOpinion,\n fallbackBaseRate: number\n): number {\n const denominator = 1 - opinionA.a * ifTrue.u - (1 - opinionA.a) * ifFalse.u;\n\n if (ifTrue.u + ifFalse.u < 2 - EPSILON && Math.abs(denominator) > EPSILON) {\n const baseRate =\n (opinionA.a * ifTrue.b + (1 - opinionA.a) * ifFalse.b) / denominator;\n if (baseRate >= -EPSILON && baseRate <= 1 + EPSILON) {\n return Math.max(0, Math.min(1, baseRate));\n }\n }\n\n return fallbackBaseRate;\n}\n\nfunction safeCorrectionTerm(\n numerator: number,\n denominator: number\n): number | undefined {\n if (Math.abs(denominator) <= EPSILON) {\n return;\n }\n\n const value = numerator / denominator;\n if (!Number.isFinite(value)) {\n return;\n }\n\n return Math.max(0, value);\n}\n\ninterface ConditionalDeductionCorrectionContext {\n childBaseRate: number;\n ifFalse: SLOpinion;\n ifTrue: SLOpinion;\n intermediateBelief: number;\n intermediateDisbelief: number;\n opinionA: SLOpinion;\n projectedAntecedent: number;\n projectedAntecedentComplement: number;\n projectedConditionalA: number;\n projectedVacuousDeduction: number;\n}\n\nfunction correctionOrZero(numerator: number, denominator: number): number {\n return safeCorrectionTerm(numerator, denominator) ?? 0;\n}\n\nfunction hasNoConditionalDeductionCorrection(\n ifTrue: SLOpinion,\n ifFalse: SLOpinion\n): boolean {\n return (\n (ifTrue.b > ifFalse.b && ifTrue.d > ifFalse.d) ||\n (ifTrue.b <= ifFalse.b && ifTrue.d <= ifFalse.d)\n );\n}\n\nfunction usesLowerVacuousBranch(\n context: ConditionalDeductionCorrectionContext\n): boolean {\n return context.projectedVacuousDeduction <= context.projectedConditionalA;\n}\n\nfunction usesLowerAntecedentBranch(\n context: ConditionalDeductionCorrectionContext\n): boolean {\n return context.projectedAntecedent <= context.opinionA.a;\n}\n\nfunction computeTrueDominantDeductionCorrection(\n context: ConditionalDeductionCorrectionContext\n): number {\n const beliefGap = context.ifTrue.b - context.ifFalse.b;\n const disbeliefGap = context.ifFalse.d - context.ifTrue.d;\n const lowerVacuous = usesLowerVacuousBranch(context);\n const lowerAntecedent = usesLowerAntecedentBranch(context);\n\n if (lowerVacuous && lowerAntecedent) {\n return correctionOrZero(\n context.opinionA.a *\n context.opinionA.u *\n (context.intermediateBelief - context.ifTrue.b),\n context.projectedAntecedent * context.childBaseRate\n );\n }\n\n if (lowerVacuous) {\n return correctionOrZero(\n context.opinionA.a *\n context.opinionA.u *\n (context.intermediateDisbelief - context.ifTrue.d) *\n beliefGap,\n context.projectedAntecedentComplement *\n context.childBaseRate *\n disbeliefGap\n );\n }\n\n if (lowerAntecedent) {\n return correctionOrZero(\n (1 - context.opinionA.a) *\n context.opinionA.u *\n (context.intermediateBelief - context.ifTrue.b) *\n disbeliefGap,\n context.projectedAntecedent * (1 - context.childBaseRate) * beliefGap\n );\n }\n\n return correctionOrZero(\n (1 - context.opinionA.a) *\n context.opinionA.u *\n (context.intermediateDisbelief - context.ifTrue.d),\n context.projectedAntecedentComplement * (1 - context.childBaseRate)\n );\n}\n\nfunction computeFalseDominantDeductionCorrection(\n context: ConditionalDeductionCorrectionContext\n): number {\n const beliefGap = context.ifFalse.b - context.ifTrue.b;\n const disbeliefGap = context.ifTrue.d - context.ifFalse.d;\n const lowerVacuous = usesLowerVacuousBranch(context);\n const lowerAntecedent = usesLowerAntecedentBranch(context);\n\n if (lowerVacuous && lowerAntecedent) {\n return correctionOrZero(\n (1 - context.opinionA.a) *\n context.opinionA.u *\n (context.intermediateDisbelief - context.ifTrue.d) *\n beliefGap,\n context.projectedAntecedent * context.childBaseRate * disbeliefGap\n );\n }\n\n if (lowerVacuous) {\n return correctionOrZero(\n (1 - context.opinionA.a) *\n context.opinionA.u *\n (context.intermediateBelief - context.ifTrue.b),\n context.projectedAntecedentComplement * context.childBaseRate\n );\n }\n\n if (lowerAntecedent) {\n return correctionOrZero(\n context.opinionA.a *\n context.opinionA.u *\n (context.intermediateDisbelief - context.ifTrue.d),\n context.projectedAntecedent * (1 - context.childBaseRate)\n );\n }\n\n return correctionOrZero(\n context.opinionA.a *\n context.opinionA.u *\n (context.intermediateBelief - context.ifTrue.b) *\n disbeliefGap,\n context.projectedAntecedentComplement *\n (1 - context.childBaseRate) *\n beliefGap\n );\n}\n\nfunction computeConditionalDeductionCorrection(\n context: ConditionalDeductionCorrectionContext\n): number {\n if (hasNoConditionalDeductionCorrection(context.ifTrue, context.ifFalse)) {\n return 0;\n }\n\n if (\n context.ifTrue.b > context.ifFalse.b &&\n context.ifTrue.d <= context.ifFalse.d\n ) {\n return computeTrueDominantDeductionCorrection(context);\n }\n\n return computeFalseDominantDeductionCorrection(context);\n}\n\nexport function conditionalDeduction(\n opinionA: SLOpinion,\n ifTrue: SLOpinion,\n ifFalse: SLOpinion,\n fallbackBaseRate?: number\n): SLOpinion {\n const fallbackChildBaseRate = childBaseRateFallback(\n ifTrue,\n ifFalse,\n fallbackBaseRate\n );\n const childBaseRate = computeConditionalDeductionBaseRate(\n opinionA,\n ifTrue,\n ifFalse,\n fallbackChildBaseRate\n );\n const projectedAntecedent = project(opinionA);\n const projectedAntecedentComplement = 1 - projectedAntecedent;\n const intermediateBelief =\n opinionA.b * ifTrue.b +\n opinionA.d * ifFalse.b +\n opinionA.u * (ifTrue.b * opinionA.a + ifFalse.b * (1 - opinionA.a));\n const intermediateDisbelief =\n opinionA.b * ifTrue.d +\n opinionA.d * ifFalse.d +\n opinionA.u * (ifTrue.d * opinionA.a + ifFalse.d * (1 - opinionA.a));\n const intermediateUncertainty =\n opinionA.b * ifTrue.u +\n opinionA.d * ifFalse.u +\n opinionA.u * (ifTrue.u * opinionA.a + ifFalse.u * (1 - opinionA.a));\n const projectedVacuousDeduction =\n ifTrue.b * opinionA.a +\n ifFalse.b * (1 - opinionA.a) +\n childBaseRate * (ifTrue.u * opinionA.a + ifFalse.u * (1 - opinionA.a));\n const projectedConditionalA =\n ifTrue.b + childBaseRate * (1 - ifTrue.b - ifTrue.d);\n const correction = computeConditionalDeductionCorrection({\n childBaseRate,\n ifFalse,\n ifTrue,\n intermediateBelief,\n intermediateDisbelief,\n opinionA,\n projectedAntecedent,\n projectedAntecedentComplement,\n projectedConditionalA,\n projectedVacuousDeduction,\n });\n\n return opinion(\n intermediateBelief - childBaseRate * correction,\n intermediateDisbelief - (1 - childBaseRate) * correction,\n intermediateUncertainty + correction,\n childBaseRate\n );\n}\n\n/**\n * Abductive inference over a conditional.\n * Given an opinion on Y and conditionals P(Y|X), P(Y|~X), infer an opinion on X.\n */\nexport function conditionalAbduction(\n opinionY: SLOpinion,\n ifTrue: SLOpinion,\n ifFalse: SLOpinion,\n baseRateX: number\n): SLOpinion {\n const priorX = Math.max(0, Math.min(1, baseRateX));\n const probabilityY = project(opinionY);\n const probabilityGivenTrue = project(ifTrue);\n const probabilityGivenFalse = project(ifFalse);\n\n const posteriorIfYDenominator =\n probabilityGivenTrue * priorX + probabilityGivenFalse * (1 - priorX);\n const posteriorIfY =\n posteriorIfYDenominator === 0\n ? priorX\n : (probabilityGivenTrue * priorX) / posteriorIfYDenominator;\n\n const posteriorIfNotYDenominator =\n (1 - probabilityGivenTrue) * priorX +\n (1 - probabilityGivenFalse) * (1 - priorX);\n const posteriorIfNotY =\n posteriorIfNotYDenominator === 0\n ? priorX\n : ((1 - probabilityGivenTrue) * priorX) / posteriorIfNotYDenominator;\n\n const projectedX =\n probabilityY * posteriorIfY + (1 - probabilityY) * posteriorIfNotY;\n const uncertainty = Math.max(\n opinionY.u * 0.5,\n probabilityY * ifTrue.u + (1 - probabilityY) * ifFalse.u\n );\n\n return opinion(\n projectedX * (1 - uncertainty),\n (1 - projectedX) * (1 - uncertainty),\n uncertainty,\n priorX\n );\n}\n\nexport function negate(o: SLOpinion): SLOpinion {\n return mkOpinion(o.d, o.b, o.u, 1 - o.a);\n}\n\nexport function constraintFusion(\n left: SLOpinion,\n right: SLOpinion,\n mode: \"pressure\" | \"redistribute\" = \"pressure\"\n): { o1: SLOpinion; o2: SLOpinion } {\n if (mode === \"redistribute\") {\n const leftProjected = project(left);\n const rightProjected = project(right);\n const total = leftProjected + rightProjected;\n\n if (total <= 1) {\n return { o1: left, o2: right };\n }\n\n const scale = 1 / total;\n return {\n o1: opinion(\n left.b * scale,\n left.d + left.b * (1 - scale),\n left.u,\n left.a\n ),\n o2: opinion(\n right.b * scale,\n right.d + right.b * (1 - scale),\n right.u,\n right.a\n ),\n };\n }\n\n const pressureLeft = right.b * 0.5;\n const pressureRight = left.b * 0.5;\n\n return {\n o1: opinion(\n left.b - pressureLeft * 0.3,\n left.d + pressureLeft * 0.3,\n left.u,\n left.a\n ),\n o2: opinion(\n right.b - pressureRight * 0.3,\n right.d + pressureRight * 0.3,\n right.u,\n right.a\n ),\n };\n}\n\nexport function evidenceBalance(o: SLOpinion): number {\n const total = o.b + o.d;\n if (total === 0) {\n return 0;\n }\n return (o.b - o.d) / total;\n}\n\nexport function areTensioned(left: SLOpinion, right: SLOpinion): boolean {\n return (\n project(left) > 0.5 &&\n project(right) > 0.5 &&\n (left.d > 0.2 || right.d > 0.2)\n );\n}\n\nexport function informationGain(o: SLOpinion): number {\n if (o.u === 0) {\n return 0;\n }\n if (o.u === 1) {\n return 1;\n }\n return o.u * (1 - Math.abs(o.b - o.d));\n}\n","import type { Opinion, PropagationMode, PropagationResult } from \"../../types\";\nimport { mkOpinion, opinion, project } from \"../subjectiveLogic\";\n\nexport function dampedDependencyOpinion(\n dependencyOpinion: Opinion,\n beliefOpinion: Opinion,\n mode: PropagationMode = \"continuous\",\n threshold = 0.3\n): Opinion {\n const dependencyProjection = project(\n mkOpinion(\n dependencyOpinion.b,\n dependencyOpinion.d,\n dependencyOpinion.u,\n dependencyOpinion.a\n )\n );\n\n if (mode === \"threshold\") {\n if (dependencyProjection < threshold) {\n return opinion(\n 0,\n beliefOpinion.d + beliefOpinion.b * 0.5,\n 0.5,\n beliefOpinion.a\n );\n }\n return beliefOpinion;\n }\n\n const dampingFactor = dependencyProjection ** 0.5;\n return opinion(\n beliefOpinion.b * dampingFactor,\n beliefOpinion.d + beliefOpinion.b * (1 - dampingFactor) * 0.3,\n beliefOpinion.u + beliefOpinion.b * (1 - dampingFactor) * 0.7,\n beliefOpinion.a\n );\n}\n\nexport function dampedDependencyCascade(\n dependencyOpinion: Opinion,\n beliefOpinion: Opinion,\n mode: PropagationMode = \"continuous\"\n): PropagationResult {\n return {\n opinion: dampedDependencyOpinion(dependencyOpinion, beliefOpinion, mode),\n operator: \"dependency_cascade\",\n rationale: `Damped dependency cascade (${mode}): prerequisite at ${project(\n mkOpinion(\n dependencyOpinion.b,\n dependencyOpinion.d,\n dependencyOpinion.u,\n dependencyOpinion.a\n )\n ).toFixed(2)}`,\n };\n}\n"]}