SRM state model fixes
authorThomas Walker Lynch <eknp9n@reasoningtechnology.com>
Wed, 8 Jan 2025 06:59:28 +0000 (06:59 +0000)
committerThomas Walker Lynch <eknp9n@reasoningtechnology.com>
Wed, 8 Jan 2025 06:59:28 +0000 (06:59 +0000)
28 files changed:
developer/example/CountingNumber$ASRM_Infinite.class [new file with mode: 0644]
developer/example/CountingNumber$ASRM_Null.class [new file with mode: 0644]
developer/example/CountingNumber$ASRM_Rightmost.class [new file with mode: 0644]
developer/example/CountingNumber$ASRM_Segment.class [new file with mode: 0644]
developer/example/CountingNumber.class [new file with mode: 0644]
developer/example/Example_CountingNumber_0 [new file with mode: 0755]
developer/example/Example_CountingNumber_0.class [new file with mode: 0644]
developer/example/Example_CountingNumber_0.java
developer/example/Example_IndexTree_4x4 [new file with mode: 0755]
developer/example/Example_IndexTree_4x4.class [new file with mode: 0644]
developer/example/Example_IndexTree_4x4.java
developer/example/Example_IndexTree_Diagonal_SRM [new file with mode: 0755]
developer/example/Example_IndexTree_Diagonal_SRM.class [new file with mode: 0644]
developer/example/Example_SRMI_Array [new file with mode: 0755]
developer/example/Example_SRMI_Array.class [new file with mode: 0644]
developer/example/Example_SRMI_Array.java
developer/example/Example_SRM_List [new file with mode: 0755]
developer/example/Example_SRM_List.class [new file with mode: 0644]
developer/example/Example_SRM_List.java
developer/example/IndexTree_Diagonal_SRM.class [new file with mode: 0644]
developer/example/IndexTree_Diagonal_SRM.java
developer/javac🖉/Ariadne_IndexTree_Child_SRM.java
developer/javac🖉/Ariadne_SRMI.java
developer/javac🖉/Ariadne_SRMI_Array.java
developer/javac🖉/Ariadne_SRM_List.java
developer/tool🖉/clean
developer/tool🖉/clean_example [new file with mode: 0755]
developer/tool🖉/make_example

diff --git a/developer/example/CountingNumber$ASRM_Infinite.class b/developer/example/CountingNumber$ASRM_Infinite.class
new file mode 100644 (file)
index 0000000..4ce6eae
Binary files /dev/null and b/developer/example/CountingNumber$ASRM_Infinite.class differ
diff --git a/developer/example/CountingNumber$ASRM_Null.class b/developer/example/CountingNumber$ASRM_Null.class
new file mode 100644 (file)
index 0000000..90190a8
Binary files /dev/null and b/developer/example/CountingNumber$ASRM_Null.class differ
diff --git a/developer/example/CountingNumber$ASRM_Rightmost.class b/developer/example/CountingNumber$ASRM_Rightmost.class
new file mode 100644 (file)
index 0000000..663d38b
Binary files /dev/null and b/developer/example/CountingNumber$ASRM_Rightmost.class differ
diff --git a/developer/example/CountingNumber$ASRM_Segment.class b/developer/example/CountingNumber$ASRM_Segment.class
new file mode 100644 (file)
index 0000000..91da239
Binary files /dev/null and b/developer/example/CountingNumber$ASRM_Segment.class differ
diff --git a/developer/example/CountingNumber.class b/developer/example/CountingNumber.class
new file mode 100644 (file)
index 0000000..7e2f76b
Binary files /dev/null and b/developer/example/CountingNumber.class differ
diff --git a/developer/example/Example_CountingNumber_0 b/developer/example/Example_CountingNumber_0
new file mode 100755 (executable)
index 0000000..03434e8
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/bash
+java Example_CountingNumber_0
diff --git a/developer/example/Example_CountingNumber_0.class b/developer/example/Example_CountingNumber_0.class
new file mode 100644 (file)
index 0000000..37c012a
Binary files /dev/null and b/developer/example/Example_CountingNumber_0.class differ
index 1bc1ee9..0dab204 100644 (file)
@@ -1,3 +1,4 @@
+import com.ReasoningTechnology.Ariadne.Ariadne_SRM;
 import java.math.BigInteger;
 
 public class Example_CountingNumber_0{
@@ -7,14 +8,14 @@ public class Example_CountingNumber_0{
 
     if( !n.can_read() ) return;
 
-    if( n.state() == Ariadne_SRM.MachineState.SEGMENT ){
+    if( n.topology() == Ariadne_SRM.Topology.SEGMENT ){
       do{
         System.out.println("Current Number: " + n.read());
         if( !n.can_step() ) break;
         n.step();
       }while( true );
 
-    }else if( n.state() == Ariadne_SRM.MachineState.INFINITE ){
+    }else if( n.topology() == Ariadne_SRM.Topology.INFINITE ){
       int count = 0;
       do{
         System.out.println("Current Number: " + n.read());
diff --git a/developer/example/Example_IndexTree_4x4 b/developer/example/Example_IndexTree_4x4
new file mode 100755 (executable)
index 0000000..66b84a4
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/bash
+java Example_IndexTree_4x4
diff --git a/developer/example/Example_IndexTree_4x4.class b/developer/example/Example_IndexTree_4x4.class
new file mode 100644 (file)
index 0000000..fc79e76
Binary files /dev/null and b/developer/example/Example_IndexTree_4x4.class differ
index 3d425c2..79a00af 100644 (file)
@@ -1,6 +1,9 @@
 
 import com.ReasoningTechnology.Ariadne.Ariadne_SRM;
 import com.ReasoningTechnology.Ariadne.Ariadne_SRM_List;
+import com.ReasoningTechnology.Ariadne.Ariadne_IndexTree_Child_SRM;
+import com.ReasoningTechnology.Ariadne.Ariadne_IndexTree_Graph;
+import com.ReasoningTechnology.Ariadne.Ariadne_IndexTree_Node;
 
 import java.math.BigInteger;
 
@@ -11,7 +14,7 @@ public class Example_IndexTree_4x4{
     Ariadne_IndexTree_Graph graph = new Ariadne_IndexTree_Graph();
     Ariadne_SRM<BigInteger[]> root = graph.start();
 
-    Ariadne_IndexTree_Node label;
+    BigInteger  label[];
     Ariadne_IndexTree_Node node;
     Ariadne_SRM<BigInteger[]> child_srm;
 
diff --git a/developer/example/Example_IndexTree_Diagonal_SRM b/developer/example/Example_IndexTree_Diagonal_SRM
new file mode 100755 (executable)
index 0000000..5b45c16
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/bash
+java Example_IndexTree_Diagonal_SRM
diff --git a/developer/example/Example_IndexTree_Diagonal_SRM.class b/developer/example/Example_IndexTree_Diagonal_SRM.class
new file mode 100644 (file)
index 0000000..7f9b08e
Binary files /dev/null and b/developer/example/Example_IndexTree_Diagonal_SRM.class differ
diff --git a/developer/example/Example_SRMI_Array b/developer/example/Example_SRMI_Array
new file mode 100755 (executable)
index 0000000..80c5dbd
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/bash
+java Example_SRMI_Array
diff --git a/developer/example/Example_SRMI_Array.class b/developer/example/Example_SRMI_Array.class
new file mode 100644 (file)
index 0000000..c99942c
Binary files /dev/null and b/developer/example/Example_SRMI_Array.class differ
index 818a72f..d630176 100644 (file)
@@ -6,24 +6,18 @@ import java.util.List;
 
 public class Example_SRMI_Array {
   public static void main( String[] args ){
-    // Create a list
-    List<String> label_list = Arrays.asList( "A" ,"B" ,"C" ,"D" );
+    // Create an Array
+    List<String> label_array = Arrays.asList( "A", "B", "C", "D" );
 
-    // Attach SRMI to the list
-    Ariadne_SRMI_Array<String> srm = Ariadne_SRMI_Array.make( label_list );
-
-    // Use the SRMI
-    System.out.println( "Topology: " + srm.topology() );
-    System.out.println( "Location: " + srm.location() );
-
-    // Traverse the list
-    while( srm.location() != Ariadne_SRM.Location.RIGHTMOST ){
-      System.out.println( "Reading: " + srm.access() );
-      srm.step();
+    // Attach SRMI to the array
+    Ariadne_SRMI_Array<String> srm = Ariadne_SRMI_Array.make( label_array );
+    if( srm.can_read() ){
+      do{
+        System.out.println( "Reading: " + srm.read() );  
+        System.out.println( "Topology: " + srm.topology() );
+        if( !srm.can_step() ) break;
+        srm.step();
+      }while(true);
     }
-
-    // Final item
-    System.out.println( "Reading: " + srm.access() );
-    System.out.println( "Location: " + srm.location() );
   }
 }
diff --git a/developer/example/Example_SRM_List b/developer/example/Example_SRM_List
new file mode 100755 (executable)
index 0000000..e0d48dd
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/bash
+java Example_SRM_List
diff --git a/developer/example/Example_SRM_List.class b/developer/example/Example_SRM_List.class
new file mode 100644 (file)
index 0000000..5c8b1bc
Binary files /dev/null and b/developer/example/Example_SRM_List.class differ
index 8bd2959..197c1bf 100644 (file)
@@ -3,33 +3,23 @@ import com.ReasoningTechnology.Ariadne.Ariadne_SRM_List;
 
 import java.util.LinkedList;
 
-public class Example_SRM_List{
-  public static void main(String[] args){
+public class Example_SRM_List {
+  public static void main( String[] args ){
     // Create a linked list
     LinkedList<String> label_list = new LinkedList<>();
-    label_list.add("A");
-    label_list.add("B");
-    label_list.add("C");
+    label_list.add( "A" );
+    label_list.add( "B" );
+    label_list.add( "C" );
 
-    // Attach SRM to the linked list
+    // Attach SRM to the linked list and traverse
     Ariadne_SRM_List<String> srm = Ariadne_SRM_List.make(label_list);
-
-    // Use the SRM
-    System.out.println( "Topology: " + srm.topology() );
-    System.out.println( "Initial Location: " + srm.location() );
-
-    // Traverse the list
-    while( srm.location() != Ariadne_SRM.Location.RIGHTMOST ){
-      System.out.println("Reading: " + srm.access());
-      srm.step();
+    if( srm.can_read() ){
+      do{
+        System.out.println( "Reading: " + srm.read() );  
+        System.out.println( "Topology: " + srm.topology() );
+        if( !srm.can_step() ) break;
+        srm.step();
+      }while(true);
     }
-
-    // Final item
-    System.out.println(" Reading: " + srm.access() );
-    System.out.println(" Final Location: " + srm.location() );
-
-    // Rewind the SRM and traverse again
-    srm.rewind();
-    System.out.println( "After rewind: " + srm.access() );
   }
 }
diff --git a/developer/example/IndexTree_Diagonal_SRM.class b/developer/example/IndexTree_Diagonal_SRM.class
new file mode 100644 (file)
index 0000000..a9bf2ed
Binary files /dev/null and b/developer/example/IndexTree_Diagonal_SRM.class differ
index b3fb2b7..a9a653b 100644 (file)
@@ -5,35 +5,37 @@ import com.ReasoningTechnology.Ariadne.Ariadne_Test;
 import com.ReasoningTechnology.Ariadne.Ariadne_SRM;
 import com.ReasoningTechnology.Ariadne.Ariadne_IndexTree_Node;
 
-public class IndexTree_Diagonal_SRM extends Ariadne_SRM<List<BigInteger[]>> {
+public class IndexTree_Diagonal_SRM extends Ariadne_SRM<List<BigInteger[]>>{
 
+  // Instance data
   private final List<BigInteger[]> list_of__unopened_node;
   private final List<List<BigInteger[]>> list_of__opened_incomplete_child_list;
   private final List<BigInteger[]> read_list;
-  private final Ariadne_Test tester;
 
-  public static IndexTree_Diagonal_SRM make() {
-    return new IndexTree_Diagonal_SRM();
-  }
-
-  protected IndexTree_Diagonal_SRM() {
+  // Constructor
+  protected IndexTree_Diagonal_SRM(){
     this.list_of__unopened_node = new ArrayList<>();
     this.list_of__opened_incomplete_child_list = new ArrayList<>();
     this.read_list = new ArrayList<>();
-    this.tester = Ariadne_Test.make("IndexTree_Diagonal_SRM: ");
     enqueue_root();
   }
 
+  // Static factory method
+  public static IndexTree_Diagonal_SRM make(){
+    return new IndexTree_Diagonal_SRM();
+  }
+
   @Override
-  public List<BigInteger[]> access() {
+  public List<BigInteger[]> read(){
     return read_list;
   }
 
   @Override
-  public void step() {
+  public void step(){
     read_list.clear();
 
-    while (!list_of__unopened_node.isEmpty()) {
+    // Process unopened nodes
+    while( !list_of__unopened_node.isEmpty() ){
       BigInteger[] label = list_of__unopened_node.remove(0);
 
       // Retrieve the node using lookup
@@ -41,51 +43,48 @@ public class IndexTree_Diagonal_SRM extends Ariadne_SRM<List<BigInteger[]>> {
 
       // Descend by getting neighbors
       List<BigInteger[]> child_labels = fetch_child_labels(node);
-      if (!child_labels.isEmpty()) {
+      if( !child_labels.isEmpty() ){
         list_of__opened_incomplete_child_list.add(child_labels);
       }
     }
 
-    while (!list_of__opened_incomplete_child_list.isEmpty()) {
+    // Process incomplete child lists
+    while( !list_of__opened_incomplete_child_list.isEmpty() ){
       List<BigInteger[]> child_labels = list_of__opened_incomplete_child_list.remove(0);
-      if (!child_labels.isEmpty()) {
+      if( !child_labels.isEmpty() ){
         BigInteger[] label = child_labels.remove(0);
         read_list.add(label);
 
-        tester.print("Queued label: " + format_label(label));
-
         // Retrieve node and check its neighbors
         Ariadne_IndexTree_Node node = lookup(label);
-        if (!fetch_child_labels(node).isEmpty()) {
+        if( !fetch_child_labels(node).isEmpty() ){
           list_of__unopened_node.add(label);
         }
       }
     }
   }
 
-  private void enqueue_root() {
+  private void enqueue_root(){
     BigInteger[] root_label = new BigInteger[0];
     read_list.add(root_label);
 
-    tester.print("Queued root label: " + format_label(root_label));
-
     Ariadne_IndexTree_Node root_node = lookup(root_label);
-    if (!fetch_child_labels(root_node).isEmpty()) {
+    if( !fetch_child_labels(root_node).isEmpty() ){
       list_of__unopened_node.add(root_label);
     }
   }
 
-  private Ariadne_IndexTree_Node lookup(BigInteger[] label) {
+  private Ariadne_IndexTree_Node lookup(BigInteger[] label){
     // Perform a lookup to retrieve the node corresponding to the label
     return Ariadne_IndexTree_Node.make(label);
   }
 
-  private List<BigInteger[]> fetch_child_labels(Ariadne_IndexTree_Node node) {
+  private List<BigInteger[]> fetch_child_labels(Ariadne_IndexTree_Node node){
     List<BigInteger[]> child_labels = new ArrayList<>();
 
-    if (node != null) {
+    if(node != null){
       Ariadne_SRM<BigInteger[]> neighbor_srm = node.neighbor();
-      while (neighbor_srm.can_step()) {
+      while( neighbor_srm.can_step() ){
         child_labels.add(neighbor_srm.read());
         neighbor_srm.step();
       }
@@ -93,14 +92,4 @@ public class IndexTree_Diagonal_SRM extends Ariadne_SRM<List<BigInteger[]>> {
 
     return child_labels;
   }
-
-  private String format_label(BigInteger[] label) {
-    StringBuilder formatted = new StringBuilder("[");
-    for (int i = 0; i < label.length; i++) {
-      formatted.append(label[i].toString());
-      if (i < label.length - 1) formatted.append(",");
-    }
-    formatted.append("]");
-    return formatted.toString();
-  }
 }
index febd619..6dbec47 100644 (file)
@@ -36,6 +36,7 @@ public class Ariadne_IndexTree_Child_SRM extends Ariadne_SRMI<BigInteger[]>{
       return true;
     }
     @Override public void step(){
+      increment();
       label[label.length - 1] = index();
     }
     @Override public Topology topology(){
index 8d6b85c..ffecd86 100644 (file)
@@ -18,9 +18,7 @@ public abstract class Ariadne_SRMI<T> extends Ariadne_SRM<T>{
     return current_index;
   }
 
-  @Override
-  public void step(){
-    current_topology.step();
+  public void increment(){
     current_index = current_index.add(BigInteger.ONE);
   }
 }
index 993d233..a0c75c3 100644 (file)
@@ -75,8 +75,8 @@ public class Ariadne_SRMI_Array<T> extends Ariadne_SRMI<T>{
     }
     @Override
     public void step(){
-      Ariadne_SRMI_Array.super.step();
-      if( index().compareTo(BigInteger.valueOf(array.size() - 1)) < 0 )
+      increment();
+      if( index().compareTo(BigInteger.valueOf(array.size() - 1)) == 0 )
         set_topology(topo_rightmost);
     }
     @Override
index 458f784..061b3ca 100644 (file)
@@ -6,98 +6,94 @@
 */
 package com.ReasoningTechnology.Ariadne;
 import java.util.List;
+import java.util.ListIterator;
 
 public class Ariadne_SRM_List<T> extends Ariadne_SRM<T>{
 
-  private final List<T> list;
-  private int current_index;
+  // Static methods
+  public static <T> Ariadne_SRM_List<T> make(List<T> list){
+    return new Ariadne_SRM_List<>(list);
+  }
+
+  private List<T> list;  // The attached linked list
+  private ListIterator<T> iterator;  // Iterator for traversal
+  private T read_value;  // Stores the current cell value
 
   private final TopoIface<T> topo_null = new TopoNull();
   private final TopoIface<T> topo_segment = new TopoSegment();
   private final TopoIface<T> topo_rightmost = new TopoRightmost();
 
-  public Ariadne_SRM_List(List<T> list){
+  protected Ariadne_SRM_List(List<T> list){
+    this.list = list;
 
     if( list == null || list.isEmpty() ){
-      this.list = null;
-      set_topology( topo_null );
+      this.iterator = null;
+      set_topology(topo_null);
       return;
     }
 
-    this.list = list;
-    this.current_index = 0;
-    set_topology( topo_segment );
+    this.iterator = list.listIterator();
+    read_value = iterator.next();
+
+    if( list.size() == 1 ){
+      set_topology(topo_rightmost);
+      return;
+    }
+
+    set_topology(topo_segment);
   }
 
   private class TopoNull implements TopoIface<T>{
-    @Override
-    public boolean can_read(){
+    @Override public boolean can_read(){
       return false;
     }
-    @Override
-    public T read(){
+    @Override public T read(){
       throw new UnsupportedOperationException( "Cannot read from NULL topo." );
     }
-    @Override
-    public boolean can_step(){
+    @Override public boolean can_step(){
       return false;
     }
-    @Override
-    public void step(){
-      throw new UnsupportedOperationException( "Cannot step from NULL topo." );
+    @Override public void step(){
+      throw new UnsupportedOperationException( "Cannot step over NULL topo." );
     }
-    @Override
-    public Topology topology(){
+    @Override public Topology topology(){
       return Topology.NULL;
     }
   }
 
   private class TopoSegment implements TopoIface<T>{
-    @Override
-    public boolean can_read(){
+    @Override public boolean can_read(){
       return true;
     }
-    @Override
-    public T read(){
-      return list.get( current_index );
+    @Override public T read(){
+      return read_value;
     }
-    @Override
-    public boolean can_step(){
-      return current_index < list.size() - 1;
+    @Override public boolean can_step(){
+      return true;
     }
-    @Override
-    public void step(){
-      if( can_step() ){
-        current_index++;
-      }else{
-        set_topology( topo_rightmost );
-      }
+    @Override public void step(){
+      read_value = iterator.next();
+      if( !iterator.hasNext() ) set_topology(topo_rightmost);
     }
-    @Override
-    public Topology topology(){
+    @Override public Topology topology(){
       return Topology.SEGMENT;
     }
   }
 
   private class TopoRightmost implements TopoIface<T>{
-    @Override
-    public boolean can_read(){
+    @Override public boolean can_read(){
       return true;
     }
-    @Override
-    public T read(){
-      return list.get( current_index );
+    @Override public T read(){
+      return read_value;
     }
-    @Override
-    public boolean can_step(){
+    @Override public boolean can_step(){
       return false;
     }
-    @Override
-    public void step(){
+    @Override public void step(){
       throw new UnsupportedOperationException( "Cannot step from RIGHTMOST topo." );
     }
-    @Override
-    public Topology topology(){
+    @Override public Topology topology(){
       return Topology.RIGHTMOST;
     }
   }
index 687883e..c11bdba 100755 (executable)
@@ -18,19 +18,6 @@ set -x
   rm_na jvm/*
   rm_na bash/*
 
-
-# remove example class files
-
-  cd example || exit 1
-
-  for file in Example_*.class; do
-    echo "file: " $file
-    rm_na "$file"
-    wrapper_name=$(basename "$file" .class)
-    rm_na "$wrapper_name"
-  done
-
-
 set +x
 
 echo "$(script_fn) done."
diff --git a/developer/tool🖉/clean_example b/developer/tool🖉/clean_example
new file mode 100755 (executable)
index 0000000..bd0670b
--- /dev/null
@@ -0,0 +1,24 @@
+#!/usr/bin/env bash
+script_afp=$(realpath "${BASH_SOURCE[0]}")
+
+# Removes all files found in the build directories. It asks no questions as to
+# how or why the files got there. Be especially careful with the 'bash'
+# directory if you have authored scripts for release, add a `bash🖉`
+# directory instead of putting them in `bash`.
+
+cd "$REPO_HOME"/developer || exit 1
+source tool🖉/env_script
+
+# remove example class files
+
+  cd example || exit 1
+
+  for file in Example_*.class; do
+    echo "file: " $file
+    rm_na "$file"
+    wrapper_name=$(basename "$file" .class)
+    rm_na "$wrapper_name"
+  done
+
+echo "$(script_fn) done."
+
index 738770e..6eaf0c9 100755 (executable)
@@ -20,21 +20,16 @@ echo "Compiling example .java files..."
 
 echo "Creating bash wrappers..."
 
-set -x
-
-for file in Example_*.class; do
-  echo "file: " $file
-  wrapper_name=$(basename "$file" .class)
-  cat > "$wrapper_name" << EOL
+  for file in Example_*.class; do
+    echo "file: " $file
+    wrapper_name=$(basename "$file" .class)
+    cat > "$wrapper_name" << EOL
 #!/bin/bash
 java $wrapper_name
 EOL
-
-  # Make the wrapper executable
-  chmod +x "$wrapper_name"
-  done
-
-set +x
+    # Make the wrapper executable
+    chmod +x "$wrapper_name"
+    done
 
 echo "$(script_fp) done."