didn't finish getting IndexTree running again
authorThomas Walker Lynch <eknp9n@reasoningtechnology.com>
Mon, 6 Jan 2025 15:34:29 +0000 (15:34 +0000)
committerThomas Walker Lynch <eknp9n@reasoningtechnology.com>
Mon, 6 Jan 2025 15:34:29 +0000 (15:34 +0000)
27 files changed:
developer/bash/Build [deleted file]
developer/example/CountingNumber$BaseState.class [deleted file]
developer/example/CountingNumber$State.class [deleted file]
developer/example/CountingNumber$State_Infinite.class [deleted file]
developer/example/CountingNumber$State_InfiniteRight.class [deleted file]
developer/example/CountingNumber$State_InterimSegment.class [deleted file]
developer/example/CountingNumber$State_Leftmost.class [deleted file]
developer/example/CountingNumber$State_Null.class [deleted file]
developer/example/CountingNumber$State_Rightmost.class [deleted file]
developer/example/CountingNumber$State_Segment.class [deleted file]
developer/example/CountingNumber.class [deleted file]
developer/example/CountingNumber.java
developer/example/Example_* [deleted file]
developer/example/Example_CountingNumber_0.class [deleted file]
developer/example/Example_IndexTree_4x4.java [new file with mode: 0644]
developer/example/Example_IndexTree_Diagonal_SRM.class [deleted file]
developer/example/Example_SRMI_Array.class [deleted file]
developer/example/Example_SRM_List.class [deleted file]
developer/example/Example_SRM_List.java
developer/example/IndexTree_Diagonal_SRM.class [deleted file]
developer/javacđź–‰/Ariadne_IndexTree_Child_SRM.java
developer/javacđź–‰/Ariadne_IndexTree_Node.java
developer/javacđź–‰/Ariadne_Node.java
developer/javacđź–‰/Ariadne_SRM.java
developer/javacđź–‰/Ariadne_SRMI.java
developer/javacđź–‰/Ariadne_SRMI_Array.java
developer/javacđź–‰/Ariadne_SRM_List.java

diff --git a/developer/bash/Build b/developer/bash/Build
deleted file mode 100755 (executable)
index 2a18026..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/bash
-java com.ReasoningTechnology."Ariadne".Build
diff --git a/developer/example/CountingNumber$BaseState.class b/developer/example/CountingNumber$BaseState.class
deleted file mode 100644 (file)
index 9f5177a..0000000
Binary files a/developer/example/CountingNumber$BaseState.class and /dev/null differ
diff --git a/developer/example/CountingNumber$State.class b/developer/example/CountingNumber$State.class
deleted file mode 100644 (file)
index a34a9fc..0000000
Binary files a/developer/example/CountingNumber$State.class and /dev/null differ
diff --git a/developer/example/CountingNumber$State_Infinite.class b/developer/example/CountingNumber$State_Infinite.class
deleted file mode 100644 (file)
index e9433cd..0000000
Binary files a/developer/example/CountingNumber$State_Infinite.class and /dev/null differ
diff --git a/developer/example/CountingNumber$State_InfiniteRight.class b/developer/example/CountingNumber$State_InfiniteRight.class
deleted file mode 100644 (file)
index 8e706ff..0000000
Binary files a/developer/example/CountingNumber$State_InfiniteRight.class and /dev/null differ
diff --git a/developer/example/CountingNumber$State_InterimSegment.class b/developer/example/CountingNumber$State_InterimSegment.class
deleted file mode 100644 (file)
index 13e4d7e..0000000
Binary files a/developer/example/CountingNumber$State_InterimSegment.class and /dev/null differ
diff --git a/developer/example/CountingNumber$State_Leftmost.class b/developer/example/CountingNumber$State_Leftmost.class
deleted file mode 100644 (file)
index e2283d6..0000000
Binary files a/developer/example/CountingNumber$State_Leftmost.class and /dev/null differ
diff --git a/developer/example/CountingNumber$State_Null.class b/developer/example/CountingNumber$State_Null.class
deleted file mode 100644 (file)
index fdba8e4..0000000
Binary files a/developer/example/CountingNumber$State_Null.class and /dev/null differ
diff --git a/developer/example/CountingNumber$State_Rightmost.class b/developer/example/CountingNumber$State_Rightmost.class
deleted file mode 100644 (file)
index 5575f52..0000000
Binary files a/developer/example/CountingNumber$State_Rightmost.class and /dev/null differ
diff --git a/developer/example/CountingNumber$State_Segment.class b/developer/example/CountingNumber$State_Segment.class
deleted file mode 100644 (file)
index 9712266..0000000
Binary files a/developer/example/CountingNumber$State_Segment.class and /dev/null differ
diff --git a/developer/example/CountingNumber.class b/developer/example/CountingNumber.class
deleted file mode 100644 (file)
index bd48be2..0000000
Binary files a/developer/example/CountingNumber.class and /dev/null differ
index c9717ee..0536304 100644 (file)
@@ -1,3 +1,4 @@
+import com.ReasoningTechnology.Ariadne.Ariadne_SRM;
 import java.math.BigInteger;
 
 public class CountingNumber extends Ariadne_SRM<BigInteger>{
@@ -38,11 +39,7 @@ public class CountingNumber extends Ariadne_SRM<BigInteger>{
     return i;
   }
 
-  private abstract class BaseState extends State{
-    abstract MachineState state();
-  }
-
-  private class State_Null extends BaseState{
+  private class State_Null extends State{
     @Override
     boolean can_read(){
       return false;
@@ -61,7 +58,7 @@ public class CountingNumber extends Ariadne_SRM<BigInteger>{
     }
   }
 
-  private class State_Segment extends BaseState{
+  private class State_Segment extends State{
     @Override
     boolean can_read(){
       return true;
@@ -83,7 +80,7 @@ public class CountingNumber extends Ariadne_SRM<BigInteger>{
     }
   }
 
-  private class State_Rightmost extends BaseState{
+  private class State_Rightmost extends State{
     @Override
     boolean can_read(){
       return true;
@@ -102,7 +99,7 @@ public class CountingNumber extends Ariadne_SRM<BigInteger>{
     }
   }
 
-  private class State_Infinite extends BaseState{
+  private class State_Infinite extends State{
     @Override
     boolean can_read(){
       return true;
diff --git a/developer/example/Example_* b/developer/example/Example_*
deleted file mode 100755 (executable)
index 3c6f542..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/bash
-java Example_*
diff --git a/developer/example/Example_CountingNumber_0.class b/developer/example/Example_CountingNumber_0.class
deleted file mode 100644 (file)
index 44b2030..0000000
Binary files a/developer/example/Example_CountingNumber_0.class and /dev/null differ
diff --git a/developer/example/Example_IndexTree_4x4.java b/developer/example/Example_IndexTree_4x4.java
new file mode 100644 (file)
index 0000000..3d425c2
--- /dev/null
@@ -0,0 +1,43 @@
+
+import com.ReasoningTechnology.Ariadne.Ariadne_SRM;
+import com.ReasoningTechnology.Ariadne.Ariadne_SRM_List;
+
+import java.math.BigInteger;
+
+public class Example_IndexTree_4x4{
+
+  public static void main(String[] args){
+
+    Ariadne_IndexTree_Graph graph = new Ariadne_IndexTree_Graph();
+    Ariadne_SRM<BigInteger[]> root = graph.start();
+
+    Ariadne_IndexTree_Node label;
+    Ariadne_IndexTree_Node node;
+    Ariadne_SRM<BigInteger[]> child_srm;
+
+    // descend 3 more levels
+    label = root.read();
+    System.out.println(label);
+    int i = 1;
+    do{
+      node = graph.lookup(label);
+      child_srm = node.neighbor();
+      label = child_srm.read();
+      System.out.println(label);
+      if(i == 3) break;
+      i++;
+    }while(true);
+       
+    // move across three more nodes
+    i = 1;
+    do{
+      child_srm.step();
+      label = child_srm.read();
+      System.out.println(label);
+      if(i == 3) break;
+      i++;
+    }while(true);
+
+  }
+}
+
diff --git a/developer/example/Example_IndexTree_Diagonal_SRM.class b/developer/example/Example_IndexTree_Diagonal_SRM.class
deleted file mode 100644 (file)
index 7f9b08e..0000000
Binary files a/developer/example/Example_IndexTree_Diagonal_SRM.class and /dev/null differ
diff --git a/developer/example/Example_SRMI_Array.class b/developer/example/Example_SRMI_Array.class
deleted file mode 100644 (file)
index b66274f..0000000
Binary files a/developer/example/Example_SRMI_Array.class and /dev/null differ
diff --git a/developer/example/Example_SRM_List.class b/developer/example/Example_SRM_List.class
deleted file mode 100644 (file)
index 1b3e05c..0000000
Binary files a/developer/example/Example_SRM_List.class and /dev/null differ
index 4aa315a..8bd2959 100644 (file)
@@ -3,7 +3,7 @@ import com.ReasoningTechnology.Ariadne.Ariadne_SRM_List;
 
 import java.util.LinkedList;
 
-public class Example_SRM_List {
+public class Example_SRM_List{
   public static void main(String[] args){
     // Create a linked list
     LinkedList<String> label_list = new LinkedList<>();
diff --git a/developer/example/IndexTree_Diagonal_SRM.class b/developer/example/IndexTree_Diagonal_SRM.class
deleted file mode 100644 (file)
index c6d1d1a..0000000
Binary files a/developer/example/IndexTree_Diagonal_SRM.class and /dev/null differ
index 2226a0f..23fc658 100644 (file)
@@ -2,7 +2,7 @@ package com.ReasoningTechnology.Ariadne;
 
 import java.math.BigInteger;
 
-public class Ariadne_IndexTree_Child_SRM extends Ariadne_SRM<BigInteger[]> {
+public class Ariadne_IndexTree_Child_SRM extends Ariadne_SRMI<BigInteger[]>{
 
   private BigInteger[] label;
 
@@ -11,28 +11,39 @@ public class Ariadne_IndexTree_Child_SRM extends Ariadne_SRM<BigInteger[]> {
   }
 
   protected Ariadne_IndexTree_Child_SRM(BigInteger[] initial_label){
-    super();
-    if (initial_label == null || initial_label.length == 0) {
+    super(BigInteger.ZERO ,null);
+    if(initial_label == null || initial_label.length == 0){
       throw new IllegalArgumentException("Initial label must not be null or empty.");
     }
     this.label = initial_label;
+    set_state(state_infinite_right);
   }
 
-  @Override
-  public Topology topology(){
-    return Topology.INFINITE_RIGHT;
-  }
+  private final Ariadne_SRM.State state_infinite_right = new Ariadne_SRM.State(){
+    @Override boolean can_read(){
+      return true;
+    }
+    @Override boolean can_step(){
+      return true;
+    }
+    @Override void step(){
+      increment_label();
+    }
+    @Override Ariadne_SRM.MachineState state(){
+      return Ariadne_SRM.MachineState.INFINITE;
+    }
+  };
 
-  @Override
-  public BigInteger[] access(){
-    // Return a reference to the current label
-    return label;
+  private void increment_label(){
+    label[label.length - 1] = super.index();
   }
 
-  @Override
-  public void step(){
-    int max_index = label.length - 1;
-    label[max_index] = label[max_index].add(BigInteger.ONE);
+  @Override public void step(){
+    super.step();
+    label[label.length - 1] = super.index();
   }
 
+  @Override public BigInteger[] read(){
+    return label;
+  }
 }
index 44a4eb5..ceb1739 100644 (file)
@@ -3,26 +3,24 @@ package com.ReasoningTechnology.Ariadne;
 import java.math.BigInteger;
 import java.util.Arrays;
 
-public class Ariadne_IndexTree_Node extends Ariadne_Node<BigInteger[]> {
+public class Ariadne_IndexTree_Node extends Ariadne_Node<BigInteger[]>{
 
   public static Ariadne_IndexTree_Node make(BigInteger[] label){
     return new Ariadne_IndexTree_Node(label);
   }
 
+  private final BigInteger[] first_child_label;
   public Ariadne_IndexTree_Node(BigInteger[] label){
     super(label);
+    this.first_child_label = new BigInteger[label.length + 1];
+    System.arraycopy(label, 0, this.first_child_label, 0, label.length);
+    this.first_child_label[label.length] = BigInteger.ZERO;
   }
 
   @Override
   public Ariadne_IndexTree_Child_SRM neighbor(){
-    // Copy the current label
-    BigInteger[] parentLabel = this.label();
-    BigInteger[] childLabel = new BigInteger[parentLabel.length + 1];
-    System.arraycopy(parentLabel, 0, childLabel, 0, parentLabel.length);
-
-    childLabel[parentLabel.length] = BigInteger.ZERO;
-
-    return Ariadne_IndexTree_Child_SRM.make(childLabel);
+    return Ariadne_IndexTree_Child_SRM.make(first_child_label);
   }
 
   @Override
index 2aa34d1..5384b06 100644 (file)
@@ -55,8 +55,8 @@ public class Ariadne_Node<TLabel> extends HashMap<String, Object> {
     return this.label;
   }
 
-  public Ariadne_SRM<TLabel> neighbor() {
-    return Ariadne_SRM.make();
+  public Ariadne_SRM<TLabel> neighbor(){
+    throw new UnsupportedOperationException("Neighbor is not implemented in the base class.");
   }
 
   public void mark(Ariadne_Token token) {
index 7301b5b..562073d 100644 (file)
@@ -6,6 +6,7 @@
   This is for single-threaded execution. The multi-threaded model
   uses `mount` and `dismount` to lock the resources being iterated on.
 */
+package com.ReasoningTechnology.Ariadne;
 
 public abstract class Ariadne_SRM<T>{
 
@@ -25,7 +26,7 @@ public abstract class Ariadne_SRM<T>{
     abstract MachineState state();
   }
 
-  private State current_state;
+  protected State current_state;
 
   protected void set_state(State new_state){
     this.current_state = new_state;
index c4b3dfe..e7b2e29 100644 (file)
@@ -4,28 +4,48 @@ Ariadne_SRM with index
 */
 
 package com.ReasoningTechnology.Ariadne;
-
-public class Ariadne_SRMI<TElement> extends Ariadne_SRM<TElement>{
-
-  public static <TElement> Ariadne_SRMI<TElement> make(){
-    return new Ariadne_SRMI<TElement>();
-  }
-  protected Ariadne_SRMI(){
+import java.math.BigInteger;
+
+public abstract class Ariadne_SRMI<T> extends Ariadne_SRM<T>{
+
+  private BigInteger current_index;
+  private final BigInteger leftmost_index;
+  private final BigInteger rightmost_index;
+
+  public Ariadne_SRMI(BigInteger leftmost_index, BigInteger rightmost_index){
+    if(leftmost_index == null 
+       || rightmost_index == null 
+       || leftmost_index.compareTo(rightmost_index) > 0
+       ){
+      throw new IllegalArgumentException("Invalid tape bounds.");
+    }
+    this.leftmost_index = leftmost_index;
+    this.rightmost_index = rightmost_index;
+    this.current_index = leftmost_index;
   }
 
-  public int index(){
-    throw new UnsupportedOperationException("Ariadne_SRMI::index not implemented.");
+  public BigInteger index(){
+    return current_index;
   }
 
-  public int leftmost_index(){
-    throw new UnsupportedOperationException("Ariadne_SRMI::leftmost_index not implemented.");
+  public BigInteger leftmost_index(){
+    return leftmost_index;
   }
-  public int rightmost_index(){
-    throw new UnsupportedOperationException("Ariadne_SRMI::rightmost_index not implemented.");
+
+  public BigInteger rightmost_index(){
+    return rightmost_index;
   }
 
-  void seek(int i){
-    throw new UnsupportedOperationException("Ariadne_SRMI::seek not implemented.");
+  public void seek(BigInteger new_index){
+    if(new_index.compareTo(leftmost_index) < 0 || new_index.compareTo(rightmost_index) > 0){
+      throw new IndexOutOfBoundsException("Index out of bounds.");
+    }
+    this.current_index = new_index;
   }
 
+  @Override
+  public void step(){
+    current_state.step();
+    current_index = current_index.add(BigInteger.ONE);
+  }
 }
index f5b5c92..bccefa0 100644 (file)
@@ -1,70 +1,92 @@
 package com.ReasoningTechnology.Ariadne;
-import java.util.List;
-
-public class Ariadne_SRMI_Array<TElement> extends Ariadne_SRMI<TElement>{
-
-  public static <T> Ariadne_SRMI_Array<T> make(List<T> array){
-    return new Ariadne_SRMI_Array<>(array);
-  }
 
-  private List<TElement> _array;
-  private int _index;
-  private Topology _topology;
-  private Location _location;
-
-  protected Ariadne_SRMI_Array(List<TElement> array) {
-    _array = array;
+import java.math.BigInteger;
+import java.util.List;
 
-    if( _array == null || _array.isEmpty() ) 
-      _topology = Topology.NO_CELLS;
-    else if( _array.size() == 1 ) 
-      _topology = Topology.SINGLETON;
-    else
-      _topology = Topology.SEGMENT;
+public class Ariadne_SRMI_Array<TElement> extends Ariadne_SRMI<TElement> {
 
-    if(_topology == Topology.SEGMENT)
-      _location = Location.LEFTMOST;
-    else
-      _location = Location.OTHER;
+  private final List<TElement> array;
 
-    _index = 0;
-  }
+  public Ariadne_SRMI_Array(List<TElement> array) {
+    super(BigInteger.ZERO, array == null || array.isEmpty() ? BigInteger.ZERO : BigInteger.valueOf(array.size() - 1));
 
-  @Override
-  public Topology topology(){
-    return _topology;
-  }
-
-  @Override
-  public Location location(){
-    return _location;
-  }
+    if (array == null || array.isEmpty()) {
+      set_state(state_null);
+    } else if (array.size() == 1) {
+      set_state(state_rightmost);
+    } else {
+      set_state(state_segment);
+    }
 
-  @Override
-  public TElement access(){
-    if( can_read() ) return _array.get( _index );
-    throw new UnsupportedOperationException("Ariadne_SRMI_Array::read can not read tape.");
+    this.array = array;
   }
 
   @Override
-  public void step(){
-    if( can_step() ){
-      _index++;
-      if( _index == _array.size() - 1 ) _location = Location.RIGHTMOST;
-      return;
+  public TElement read() {
+    if (!can_read()) {
+      throw new UnsupportedOperationException("Cannot read from the current state.");
     }
-    throw new UnsupportedOperationException("Ariadne_SRMI_Array::step can not step.");
+    return array.get(index().intValueExact());
   }
 
-  @Override
-  public int leftmost_index(){
-    return 0;
-  }
+  private final State state_null = new State() {
+    @Override
+    boolean can_read() {
+      return false;
+    }
+    @Override
+    boolean can_step() {
+      return false;
+    }
+    @Override
+    void step() {
+      throw new UnsupportedOperationException("Cannot step from NULL state.");
+    }
+    @Override
+    MachineState state() {
+      return MachineState.NULL;
+    }
+  };
 
-  @Override
-  public int rightmost_index(){
-    if( can_read() ) return _array.size() - 1;
-    throw new UnsupportedOperationException("Ariadne_SRMI_Array::rightmost_index can not read array.");
-  }
+  private final State state_segment = new State() {
+    @Override
+    boolean can_read() {
+      return true;
+    }
+    @Override
+    boolean can_step() {
+      return index().compareTo(rightmost_index().subtract(BigInteger.ONE)) < 0;
+    }
+    @Override
+    void step() {
+      if (can_step()) {
+        seek(index().add(BigInteger.ONE));
+      } else {
+        set_state(state_rightmost);
+      }
+    }
+    @Override
+    MachineState state() {
+      return MachineState.SEGMENT;
+    }
+  };
 
+  private final State state_rightmost = new State() {
+    @Override
+    boolean can_read() {
+      return true;
+    }
+    @Override
+    boolean can_step() {
+      return false;
+    }
+    @Override
+    void step() {
+      throw new UnsupportedOperationException("Cannot step from RIGHTMOST state.");
+    }
+    @Override
+    MachineState state() {
+      return MachineState.RIGHTMOST;
+    }
+  };
 }
index 45a11c3..b884f98 100644 (file)
@@ -4,79 +4,91 @@
   to read the current element without advancing the iterator.
 
 */
-
 package com.ReasoningTechnology.Ariadne;
-
 import java.util.List;
-import java.util.ListIterator;
-
-public class Ariadne_SRM_List<TElement> extends Ariadne_SRM<TElement> {
-
-  public static <TElement> Ariadne_SRM_List<TElement> make(List<TElement> list){
-    return new Ariadne_SRM_List<>(list);
-  }
-
-  private List<TElement> _list;  // The attached linked list
-  private ListIterator<TElement> iterator;  // Iterator for traversal
-  private TElement read_value;  // Stores the current cell value
 
-  private Topology _topology;
-  private Location _location;
-
-  // Protected constructor for controlled instantiation
-  protected Ariadne_SRM_List(List<TElement> list){
-    init(list);
-  }
-  private void init(List<TElement> list){
-    _list = list;
-    
-    if( _list == null || _list.isEmpty() ) 
-      _topology = Topology.NO_CELLS;
-    else if( _list.size() == 1 ) 
-      _topology = Topology.SINGLETON;
-    else
-      _topology = Topology.SEGMENT;
+public class Ariadne_SRM_List<T> extends Ariadne_SRM<T>{
 
-    if(_topology == Topology.SEGMENT)
-      _location = Location.LEFTMOST;
-    else
-      _location = Location.OTHER;
+  private final List<T> list;
+  private int current_index;
 
-    if(_topology.ordinal() >= Topology.SINGLETON.ordinal()){
-      iterator = _list.listIterator();
-      read_value = iterator.next();
+  public Ariadne_SRM_List(List<T> list){
+    if(list == null || list.isEmpty()){
+      this.list = null; // not used, but what Java says, goes, if you want you code.
+      set_state(state_null);
+    }else{
+      this.list = list;
+      this.current_index = 0;
+      set_state(state_segment);
     }
   }
 
-  @Override
-  public Topology topology(){
-    return _topology;
-  }
-
-  @Override
-  public Location location(){
-    return _location;
-  }
+  private final State state_null = new State(){
+    @Override
+    boolean can_read(){
+      return false;
+    }
+    @Override
+    boolean can_step(){
+      return false;
+    }
+    @Override
+    void step(){
+      throw new UnsupportedOperationException("Cannot step from NULL state.");
+    }
+    @Override
+    MachineState state(){
+      return MachineState.NULL;
+    }
+  };
 
-  @Override
-  public TElement access(){
-    if( can_read() ) return read_value;
-    throw new UnsupportedOperationException("Ariadne_SRM_List::access can not read tape.");
-  }
+  private final State state_segment = new State(){
+    @Override
+    boolean can_read(){
+      return true;
+    }
+    @Override
+    boolean can_step(){
+      return current_index < list.size() - 1;
+    }
+    @Override
+    void step(){
+      if(can_step()){
+        current_index++;
+      }else{
+        set_state(state_rightmost);
+      }
+    }
+    @Override
+    MachineState state(){
+      return MachineState.SEGMENT;
+    }
+  };
 
-  @Override
-  public void step(){
-    if( can_step() ){
-      read_value = iterator.next();  // Move to the next cell and update current value
-      if( !iterator.hasNext() ) _location = Location.RIGHTMOST;
-      return;
+  private final State state_rightmost = new State(){
+    @Override
+    boolean can_read(){
+      return true;
     }
-    throw new UnsupportedOperationException("Ariadne_SRM_List::step can not step.");
-  }
+    @Override
+    boolean can_step(){
+      return false;
+    }
+    @Override
+    void step(){
+      throw new UnsupportedOperationException("Cannot step from RIGHTMOST state.");
+    }
+    @Override
+    MachineState state(){
+      return MachineState.RIGHTMOST;
+    }
+  };
 
   @Override
-  public void rewind(){
-    init(_list);
+  public T read(){
+    if(!can_read()){
+      throw new UnsupportedOperationException("Cannot read from NULL state.");
+    }
+    return list.get(current_index);
   }
-
 }