diff --git a/docs/assertions-module/3-nrr.html b/docs/assertions-module/3-nrr.html index 814e0d1d2..b5e6928ab 100644 --- a/docs/assertions-module/3-nrr.html +++ b/docs/assertions-module/3-nrr.html @@ -134,8 +134,8 @@ of subsequent sentences, which also happens in the pre-pass. "this is too long a name for a single relation to have", "and would become unwieldy."); else Node::set_new_relation_here(V->next, - BinaryPredicates::make_pair_sketchily(explicit_bp_family, - WordAssemblages::from_wording(RW), Relation_OtoO)); + Relations::Explicit::make_pair_sketchily( + WordAssemblages::from_wording(RW))); return TRUE; } break; @@ -485,6 +485,8 @@ splitting into cases. kind *storage_kind = NULL; what kind, if any, might be stored in it inference_subject *storage_infs = NULL; summing these up + explicit_bp_data *ED = RETRIEVE_POINTER_explicit_bp_data(bp->family_specific); + int rvno = FALSE, relate values not objects? dynamic = FALSE, use dynamic memory allocation for storage? provide_prn = FALSE, allocate the storage property to the kind? @@ -497,7 +499,7 @@ splitting into cases. if (rvno) { bp->relates_values_not_objects = TRUE; bpr->relates_values_not_objects = TRUE; } if (RR->frf) { bp->fast_route_finding = TRUE; bpr->fast_route_finding = TRUE; } if (prn) { - bp->i6_storage_property = prn; bpr->i6_storage_property = prn; + ED->i6_storage_property = prn; Properties::Valued::set_stored_relation(prn, bp); } if (dynamic) { @@ -576,8 +578,6 @@ splitting into cases. } } - bpr->form_of_relation = bp->form_of_relation; - LOGIF(RELATION_DEFINITIONS, "Defined the binary predicate:\n$2\n", bp); } @@ -690,7 +690,6 @@ omitted from the index. if ((PK) && (Kinds::Behaviour::is_object(PK) == FALSE)) Properties::Valued::set_kind(prn, PK); if (storage_kind) storage_infs = Kinds::Knowledge::as_subject(storage_kind); else storage_infs = NULL; - if (Kinds::Behaviour::is_object(storage_kind) == FALSE) bp->storage_kind = storage_kind; if (((RR->terms[0].unique) || (RR->terms[1].unique)) && (PK) && (Kinds::Behaviour::is_object(PK) == FALSE)) Properties::Valued::now_used_for_non_typesafe_relation(prn); @@ -726,7 +725,7 @@ and \(14D\) bytes on Glulx, where \(D\) is the size of the domain...
- bp->form_of_relation = Relation_OtoO; + ED->form_of_relation = Relation_OtoO; provide_prn = TRUE; if (Kinds::Behaviour::is_object(storage_kind)) { bp->task_functions[NOW_ATOM_TRUE_TASK] = Calculus::Schemas::new("Relation_Now1to1(*2,%n,*1)", i6_prn_name); @@ -746,7 +745,7 @@ and \(14D\) bytes on Glulx, where \(D\) is the size of the domain...- bp->form_of_relation = Relation_OtoV; + ED->form_of_relation = Relation_OtoV; provide_prn = TRUE; if (Kinds::Behaviour::is_object(storage_kind)) { bp->task_functions[NOW_ATOM_TRUE_TASK] = Calculus::Schemas::new("*2.%n = *1", i6_prn_name); @@ -766,7 +765,7 @@ and \(14D\) bytes on Glulx, where \(D\) is the size of the domain...- bp->form_of_relation = Relation_VtoO; + ED->form_of_relation = Relation_VtoO; provide_prn = TRUE; if (Kinds::Behaviour::is_object(storage_kind)) { bp->task_functions[NOW_ATOM_TRUE_TASK] = Calculus::Schemas::new("*1.%n = *2", i6_prn_name); @@ -787,7 +786,7 @@ various K".- bp->form_of_relation = Relation_VtoV; + ED->form_of_relation = Relation_VtoV; BinaryPredicates::mark_as_needed(bp); bp->task_functions[TEST_ATOM_TASK] = Calculus::Schemas::new("(Relation_TestVtoV(*1,%n,*2,false))", BinaryPredicates::iname(bp)); @@ -805,7 +804,7 @@ another".- bp->form_of_relation = Relation_Sym_OtoO; + ED->form_of_relation = Relation_Sym_OtoO; provide_prn = TRUE; if (Kinds::Behaviour::is_object(storage_kind)) { bp->task_functions[NOW_ATOM_TRUE_TASK] = Calculus::Schemas::new("Relation_NowS1to1(*2,%n,*1)", i6_prn_name); @@ -826,7 +825,7 @@ to each other".- bp->form_of_relation = Relation_Sym_VtoV; + ED->form_of_relation = Relation_Sym_VtoV; BinaryPredicates::mark_as_needed(bp); bp->task_functions[TEST_ATOM_TASK] = Calculus::Schemas::new("(Relation_TestVtoV(*1,%n,*2,true))", BinaryPredicates::iname(bp)); @@ -844,10 +843,10 @@ other in groups".- bp->form_of_relation = Relation_Equiv; + ED->form_of_relation = Relation_Equiv; equivalence_bp_data *D = CREATE(equivalence_bp_data); D->equivalence_partition = NULL; - bp->family_specific = STORE_POINTER_equivalence_bp_data(D); + ED->equiv_data = D; provide_prn = TRUE; if (Kinds::Behaviour::is_object(storage_kind)) { bp->task_functions[TEST_ATOM_TASK] = Calculus::Schemas::new("(*1.%n == *2.%n)", i6_prn_name, i6_prn_name); @@ -865,15 +864,16 @@ other in groups". Properties::Valued::set_kind(prn, K_number);
§5.11. The Relation_ByRoutine case, or relation tested by a routine: "R relates -K to L when (some condition)". +
§5.11. The case of a relation tested by a routine: "R relates K to L when (some +condition)".
Complete as a relation-by-routine BP5.11 =
- bp->form_of_relation = Relation_ByRoutine; + bp->relation_family = by_routine_bp_family; + bp->reversal->relation_family = by_routine_bp_family; package_request *P = BinaryPredicates::package(bp); by_routine_bp_data *D = CREATE(by_routine_bp_data); D->condition_defn_text = RR->CONW; diff --git a/docs/assertions-module/5-er.html b/docs/assertions-module/5-er.html index 3b3e94b5d..265db3b51 100644 --- a/docs/assertions-module/5-er.html +++ b/docs/assertions-module/5-er.html @@ -95,75 +95,160 @@ there are none.bp_family *explicit_bp_family = NULL; +bp_family *by_routine_bp_family = NULL; typedef struct explicit_bp_data { + int form_of_relation; one of the Relation_* constants defined below + struct property *i6_storage_property; provides run-time storage + struct equivalence_bp_data *equiv_data; only used for Relation_Equiv + struct inter_name *v2v_bitmap_iname; only used for Relation_VtoV and Relation_Sym_VtoV CLASS_DEFINITION } explicit_bp_data;-
void Relations::Explicit::start(void) { explicit_bp_family = BinaryPredicateFamilies::new(); - METHOD_ADD(explicit_bp_family, TYPECHECK_BPF_MTID, Relations::Explicit::REL_typecheck); - METHOD_ADD(explicit_bp_family, ASSERT_BPF_MTID, Relations::Explicit::REL_assert); - METHOD_ADD(explicit_bp_family, SCHEMA_BPF_MTID, Relations::Explicit::REL_compile); - METHOD_ADD(explicit_bp_family, DESCRIBE_FOR_PROBLEMS_BPF_MTID, Relations::Explicit::REL_describe_for_problems); - METHOD_ADD(explicit_bp_family, DESCRIBE_FOR_INDEX_BPF_MTID, Relations::Explicit::REL_describe_briefly); + METHOD_ADD(explicit_bp_family, TYPECHECK_BPF_MTID, Relations::Explicit::REL_typecheck); + METHOD_ADD(explicit_bp_family, ASSERT_BPF_MTID, Relations::Explicit::REL_assert); + METHOD_ADD(explicit_bp_family, SCHEMA_BPF_MTID, Relations::Explicit::REL_compile); + METHOD_ADD(explicit_bp_family, DESCRIBE_FOR_PROBLEMS_BPF_MTID, Relations::Explicit::REL_describe_for_problems); + METHOD_ADD(explicit_bp_family, DESCRIBE_FOR_INDEX_BPF_MTID, Relations::Explicit::REL_describe_briefly); + by_routine_bp_family = BinaryPredicateFamilies::new(); + METHOD_ADD(by_routine_bp_family, TYPECHECK_BPF_MTID, Relations::Explicit::REL_typecheck); + METHOD_ADD(by_routine_bp_family, ASSERT_BPF_MTID, Relations::Explicit::REL_assert); + METHOD_ADD(by_routine_bp_family, SCHEMA_BPF_MTID, Relations::Explicit::REL_compile); + METHOD_ADD(by_routine_bp_family, DESCRIBE_FOR_PROBLEMS_BPF_MTID, Relations::Explicit::REL_describe_for_problems); + METHOD_ADD(by_routine_bp_family, DESCRIBE_FOR_INDEX_BPF_MTID, Relations::Explicit::REL_br_describe_briefly); +} + +int Relations::Explicit::is_explicit_with_runtime_storage(binary_predicate *bp) { + if (bp->relation_family == explicit_bp_family) return TRUE; + return TRUE; }-
§3. They typecheck by the default rule only: +
§3. The following constants are numbered in a way which corresponds to some +run-time code supporting relations. +
+ +define Relation_Implicit -1 used to mean "none of the below" +define Relation_OtoO 1 one to one: "R relates one K to one K" +define Relation_OtoV 2 one to various: "R relates one K to various K" +define Relation_VtoO 3 various to one: "R relates various K to one K" +define Relation_VtoV 4 various to various: "R relates various K to various K" +define Relation_Sym_OtoO 5 symmetric one to one: "R relates one K to another" +define Relation_Sym_VtoV 6 symmetric various to various: "R relates K to each other" +define Relation_Equiv 7 equivalence relation: "R relates K to each other in groups" ++ + +
+int Relations::Explicit::allow_arbitrary_assertions(binary_predicate *bp) { + int f = Relations::Explicit::get_form_of_relation(bp); + if (f == Relation_Equiv) return TRUE; + if (f == Relation_VtoV) return TRUE; + if (f == Relation_Sym_VtoV) return TRUE; + return FALSE; +} ++
§5. When the source text declares new relations, it turns out to be convenient +to make their BPs in a two-stage process: to make sketchy, mostly-blank BP +structures for them early on — but getting their names registered — and +then fill in the correct details later. This is where such sketchy pairs are +made:
-int Relations::Explicit::REL_typecheck(bp_family *self, binary_predicate *bp, +binary_predicate *Relations::Explicit::make_pair_sketchily(word_assemblage wa) { + TEMPORARY_TEXT(relname) + WRITE_TO(relname, "%V", WordAssemblages::first_word(&wa)); + binary_predicate *bp = + BinaryPredicates::make_pair(explicit_bp_family, + BPTerms::new(NULL), BPTerms::new(NULL), + relname, NULL, NULL, NULL, wa); + DISCARD_TEXT(relname) + explicit_bp_data *ED = CREATE(explicit_bp_data); + bp->family_specific = STORE_POINTER_explicit_bp_data(ED); + bp->reversal->family_specific = STORE_POINTER_explicit_bp_data(ED); + + ED->equiv_data = NULL; + ED->i6_storage_property = NULL; + ED->form_of_relation = Relation_OtoO; + ED->v2v_bitmap_iname = NULL; + + return bp; +} + +property *Relations::Explicit::get_i6_storage_property(binary_predicate *bp) { + if (bp->relation_family != explicit_bp_family) return NULL; + explicit_bp_data *ED = RETRIEVE_POINTER_explicit_bp_data(bp->family_specific); + return ED->i6_storage_property; +} + +int Relations::Explicit::get_form_of_relation(binary_predicate *bp) { + if (bp->relation_family != explicit_bp_family) return Relation_Implicit; + explicit_bp_data *ED = RETRIEVE_POINTER_explicit_bp_data(bp->family_specific); + return ED->form_of_relation; +} +char *Relations::Explicit::form_to_text(binary_predicate *bp) { + switch(Relations::Explicit::get_form_of_relation(bp)) { + case Relation_OtoO: return "Relation_OtoO"; + case Relation_OtoV: return "Relation_OtoV"; + case Relation_VtoO: return "Relation_VtoO"; + case Relation_VtoV: return "Relation_VtoV"; + case Relation_Sym_OtoO: return "Relation_Sym_OtoO"; + case Relation_Sym_VtoV: return "Relation_Sym_VtoV"; + case Relation_Equiv: return "Relation_Equiv"; + default: return "Relation_Implicit"; + } +} ++
§6. They typecheck by the default rule only: +
+ ++int Relations::Explicit::REL_typecheck(bp_family *self, binary_predicate *bp, kind **kinds_of_terms, kind **kinds_required, tc_problem_kit *tck) { return DECLINE_TO_MATCH; }-
§4. They are asserted thus. Note that if we have a symmetric relation then we need +
§7. They are asserted thus. Note that if we have a symmetric relation then we need to behave as if \(B(y, x)\) had also been asserted whenever \(B(x, y)\) has, if \(x\neq y\).
-int Relations::Explicit::REL_assert(bp_family *self, binary_predicate *bp, +int Relations::Explicit::REL_assert(bp_family *self, binary_predicate *bp, inference_subject *infs0, parse_node *spec0, inference_subject *infs1, parse_node *spec1) { - Reject non-assertable relations4.1; + Reject non-assertable relations7.1; if (BinaryPredicates::store_dynamically(bp)) { World::Inferences::draw_relation_spec(bp, spec0, spec1); return TRUE; } else { - if ((infs0 == NULL) || (infs1 == NULL)) Reject relationship with nothing4.2; + if ((infs0 == NULL) || (infs1 == NULL)) Reject relationship with nothing7.2; if (Relations::Explicit::allow_arbitrary_assertions(bp)) { World::Inferences::draw_relation(bp, infs0, infs1); - if ((BinaryPredicates::get_form_of_relation(bp) == Relation_Sym_VtoV) && (infs0 != infs1)) + if ((Relations::Explicit::get_form_of_relation(bp) == Relation_Sym_VtoV) && (infs0 != infs1)) World::Inferences::draw_relation(bp, infs1, infs0); return TRUE; } - if (BinaryPredicates::is_explicit_with_runtime_storage(bp)) { - Relations::Explicit::infer_property_based_relation(bp, infs1, infs0); - if ((BinaryPredicates::get_form_of_relation(bp) == Relation_Sym_OtoO) && (infs0 != infs1)) - Relations::Explicit::infer_property_based_relation(bp, infs0, infs1); + if (Relations::Explicit::is_explicit_with_runtime_storage(bp)) { + Relations::Explicit::infer_property_based_relation(bp, infs1, infs0); + if ((Relations::Explicit::get_form_of_relation(bp) == Relation_Sym_OtoO) && (infs0 != infs1)) + Relations::Explicit::infer_property_based_relation(bp, infs0, infs1); return TRUE; } } return FALSE; } - -int Relations::Explicit::allow_arbitrary_assertions(binary_predicate *bp) { - if (bp->form_of_relation == Relation_Equiv) return TRUE; - if (bp->form_of_relation == Relation_VtoV) return TRUE; - if (bp->form_of_relation == Relation_Sym_VtoV) return TRUE; - return FALSE; -}-
§4.1. This is the point at which non-assertable relations are thrown out. +
§7.1. This is the point at which non-assertable relations are thrown out.
-Reject non-assertable relations4.1 = +
Reject non-assertable relations7.1 =
@@ -177,8 +262,8 @@ to behave as if \(B(y, x)\) had also been asserted whenever \(B(x, y)\) has, if return TRUE; }-
§4.2. Reject relationship with nothing4.2 = +
§7.2. Reject relationship with nothing7.2 =
@@ -190,8 +275,8 @@ to behave as if \(B(y, x)\) had also been asserted whenever \(B(x, y)\) has, if "to try to put 'Mr Cogito' and 'nothing' into a relationship."); return TRUE;-
§5. This routine converts the knowledge that \(R(ox, oy)\) into a single +
§8. This routine converts the knowledge that \(R(ox, oy)\) into a single inference. It can only be used for a simple subclass of the relations: those which store oy, the only thing related to ox, in a given property of ox. The beauty of this is that the "only thing related to" business @@ -201,32 +286,32 @@ inferences for \(y\) and \(z\).
-void Relations::Explicit::infer_property_based_relation(binary_predicate *relation, +void Relations::Explicit::infer_property_based_relation(binary_predicate *bp, inference_subject *infs0, inference_subject *infs1) { - if (BinaryPredicates::get_form_of_relation(relation) == Relation_VtoO) { + if (Relations::Explicit::get_form_of_relation(bp) == Relation_VtoO) { inference_subject *swap=infs0; infs0=infs1; infs1=swap; } - property *prn = BinaryPredicates::get_i6_storage_property(relation); + property *prn = Relations::Explicit::get_i6_storage_property(bp); World::Inferences::draw_property(infs0, prn, InferenceSubjects::as_constant(infs1)); }-
§6. We need do nothing special: these relations can be compiled from their schemas. +
§9. We need do nothing special: these relations can be compiled from their schemas.
-int Relations::Explicit::REL_compile(bp_family *self, int task, binary_predicate *bp, annotated_i6_schema *asch) { +int Relations::Explicit::REL_compile(bp_family *self, int task, binary_predicate *bp, annotated_i6_schema *asch) { return FALSE; }-
-int Relations::Explicit::REL_describe_for_problems(bp_family *self, OUTPUT_STREAM, binary_predicate *bp) { +int Relations::Explicit::REL_describe_for_problems(bp_family *self, OUTPUT_STREAM, binary_predicate *bp) { return FALSE; } -void Relations::Explicit::REL_describe_briefly(bp_family *self, OUTPUT_STREAM, binary_predicate *bp) { - switch (bp->form_of_relation) { +void Relations::Explicit::REL_describe_briefly(bp_family *self, OUTPUT_STREAM, binary_predicate *bp) { + switch (Relations::Explicit::get_form_of_relation(bp)) { case Relation_OtoO: WRITE("one-to-one"); break; case Relation_OtoV: WRITE("one-to-various"); break; case Relation_VtoO: WRITE("various-to-one"); break; @@ -234,9 +319,11 @@ inferences for \(y\) and \(z\). case Relation_Sym_OtoO: WRITE("one-to-another"); break; case Relation_Sym_VtoV: WRITE("various-to-each-other"); break; case Relation_Equiv: WRITE("in groups"); break; - case Relation_ByRoutine: WRITE("defined"); break; } } +void Relations::Explicit::REL_br_describe_briefly(bp_family *self, OUTPUT_STREAM, binary_predicate *bp) { + WRITE("defined"); +}