aboutsummaryrefslogtreecommitdiffstats
path: root/lib/prelude/standard.ml
diff options
context:
space:
mode:
authorMarcos Magueta <maguetamarcos@gmail.com>2026-03-08 20:48:14 -0300
committerMarcos Magueta <maguetamarcos@gmail.com>2026-03-08 20:48:14 -0300
commitcce3bfba31b32c13ea116a214306d96fe1eb27eb (patch)
treea572e969d7c53686e047764b7fba3e52d3589215 /lib/prelude/standard.ml
parent88dc315e454a695426becf928aef46668f9db0dc (diff)
downloadSakura-cce3bfba31b32c13ea116a214306d96fe1eb27eb.tar.gz
Sakura-cce3bfba31b32c13ea116a214306d96fe1eb27eb.zip
format todos and comment improvement
Diffstat (limited to 'lib/prelude/standard.ml')
-rw-r--r--lib/prelude/standard.ml34
1 files changed, 9 insertions, 25 deletions
diff --git a/lib/prelude/standard.ml b/lib/prelude/standard.ml
index efcb7ae..68012fc 100644
--- a/lib/prelude/standard.ml
+++ b/lib/prelude/standard.ml
@@ -1,18 +1,14 @@
-(** Domain-parameterized comparison and arithmetic relations.
+(** Comparison and arithmetic relations over the natural domain. *)
- All comparison relations use a two-attribute schema [(left, right)]
- with both attributes in the same domain. The domain's [compare] function
- is used for evaluation — no more spreading [Obj.magic]. *)
+(* TODO: all relations here are hardcoded to naturals. The make_comparison
+ factory accepts a domain_name string but membership_criteria always uses
+ Stdlib.compare on Obj.t, which only works correctly for unboxed integers.
+ Extending to other domains requires a proper typed comparison dispatch. *)
-(* Helper: wrap a native value in the Attribute.materialized record *)
let mk v = { Attribute.value = Obj.repr v }
-(* ============================================================================
- Comparison relation factory
- ============================================================================ *)
-
-(** Build a comparison relation parameterized by domain.
- [pred] receives the result of [Domain.compare left right]. *)
+(** Build a comparison relation over a single domain.
+ [pred] receives the result of [Stdlib.compare left right]. *)
let make_comparison ~name ~domain_name ~pred ~cardinality ~generator =
let schema =
Schema.empty |> Schema.add "left" domain_name
@@ -34,13 +30,7 @@ let make_comparison ~name ~domain_name ~pred ~cardinality ~generator =
~provenance:(Relation.Provenance.Base name)
~lineage:(Relation.Lineage.Base name)
-(* ============================================================================
- Pair enumeration for comparison generators
- ============================================================================ *)
-
-(** Enumerate pairs (a, b) from naturals where a < b.
- Uses triangular indexing: position n maps to row r, column c
- where a = c, b = r, and a < b. *)
+(** Enumerate pairs (a, b) where a < b using triangular indexing. *)
let pair_of_nat_lt n =
let nf = float_of_int n in
let r = int_of_float (floor ((1. +. sqrt (1. +. 8. *. nf)) /. 2.)) in
@@ -48,7 +38,7 @@ let pair_of_nat_lt n =
let left = n - t_prev in
(left, r)
-(** Enumerate all pairs (a, b) from naturals via Cantor pairing. *)
+(** Enumerate all pairs (a, b) via Cantor pairing. *)
let cantor_pair_of_nat n =
let w =
int_of_float (floor ((sqrt (float_of_int (8 * n + 1)) -. 1.) /. 2.))
@@ -58,9 +48,6 @@ let cantor_pair_of_nat n =
let a = w - b in
(a, b)
-(* ============================================================================
- Concrete comparison relations (natural domain)
- ============================================================================ *)
let less_than_natural : Relation.t =
let rec generator (position : int option) : Generator.result =
@@ -179,9 +166,6 @@ let not_equal_natural : Relation.t =
~pred:(fun c -> c <> 0)
~cardinality:Conventions.Cardinality.AlephZero ~generator
-(* ============================================================================
- Arithmetic relations (natural domain)
- ============================================================================ *)
let plus_natural : Relation.t =
let schema =