As far as I can tell, case-based reasoning in Ergo requires one of these approaches:
- 1. Just load everything normally, and when you want to switch between cases, smash the Ergo process and restart. This feels gross, but it's simple (this is what the SARA project does when translating the tax code into Prolog).
- 2. Put stuff in modules, but then you need to pass module arguments all over the place. At this point, though, it's not side-effecting, so we can just use the tabling.
- 3. Put tags on facts. Again, no longer side-effecting, so you can use the tabling. The down side, similar to modules, is you need to decide which predicates get the tag arguments and which don't.
- 4. Some kind of case activation and deactivation that is accompanied by table smashing. I suppose one could put information in the descriptor that states which facts should be deleted when a case is deleted, but I don't claim to understand table smashing. I don't see anything in Chapter 24 ("Ergo and Tabling") that explains how to do this.
In some of the code that you (Theresa) distributed, you put tags on contextual things, but then only frames could be contextual.
It seems possible to me that one could treat cases modally, put case knowledge in modules and have a knowledge generalization meta rule (ϕ → Kϕ) -- everything that is true is true in the case world, too.
@!{caseTruth}
case(?Tag)(?x) :- ?x@?Tag.
@!{backgroundTruth}
case(?)(?x) :- ?x.
I have not tried the above and it might not work!
Since the cases we have been looking at often have facts asserted without the antecedent facts that justify them (e.g., "Mary has an eligible dependent."), I think we might want to have the case facts override the background facts:
\overrides{caseTruth, backgroundTruth}
But even doing this, there's no way for backgroundTruth to apply rules to case facts, or at least not without explicitly phrasing all of the rules in terms of the case higher-order predicate, which seems cumbersome and because cumbersome, error-prone, since we don't have the knowledge rule Kϕ→ϕ, since the "case" modality is not the same as the knowledge modality!
Again, this kind of contextual or conditional reasoning is extremely common, so I suspect I am simply ignorant of some standard idiom/code pattern.