From: Thomas Walker Lynch Date: Mon, 6 Jan 2025 15:34:29 +0000 (+0000) Subject: didn't finish getting IndexTree running again X-Git-Url: https://git.reasoningtechnology.com/home/twl/Documents/subuser/test_env.py?a=commitdiff_plain;h=4f86e71e104029c699940ce997b4370aab458d98;p=Ariadne didn't finish getting IndexTree running again --- diff --git a/developer/bash/Build b/developer/bash/Build deleted file mode 100755 index 2a18026..0000000 --- a/developer/bash/Build +++ /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 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 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 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 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 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 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 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 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 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 index bd48be2..0000000 Binary files a/developer/example/CountingNumber.class and /dev/null differ diff --git a/developer/example/CountingNumber.java b/developer/example/CountingNumber.java index c9717ee..0536304 100644 --- a/developer/example/CountingNumber.java +++ b/developer/example/CountingNumber.java @@ -1,3 +1,4 @@ +import com.ReasoningTechnology.Ariadne.Ariadne_SRM; import java.math.BigInteger; public class CountingNumber extends Ariadne_SRM{ @@ -38,11 +39,7 @@ public class CountingNumber extends Ariadne_SRM{ 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{ } } - 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{ } } - 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{ } } - 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 index 3c6f542..0000000 --- a/developer/example/Example_* +++ /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 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 index 0000000..3d425c2 --- /dev/null +++ b/developer/example/Example_IndexTree_4x4.java @@ -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 root = graph.start(); + + Ariadne_IndexTree_Node label; + Ariadne_IndexTree_Node node; + Ariadne_SRM 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 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 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 index 1b3e05c..0000000 Binary files a/developer/example/Example_SRM_List.class and /dev/null differ diff --git a/developer/example/Example_SRM_List.java b/developer/example/Example_SRM_List.java index 4aa315a..8bd2959 100644 --- a/developer/example/Example_SRM_List.java +++ b/developer/example/Example_SRM_List.java @@ -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 label_list = new LinkedList<>(); diff --git a/developer/example/IndexTree_Diagonal_SRM.class b/developer/example/IndexTree_Diagonal_SRM.class deleted file mode 100644 index c6d1d1a..0000000 Binary files a/developer/example/IndexTree_Diagonal_SRM.class and /dev/null differ diff --git "a/developer/javac\360\237\226\211/Ariadne_IndexTree_Child_SRM.java" "b/developer/javac\360\237\226\211/Ariadne_IndexTree_Child_SRM.java" index 2226a0f..23fc658 100644 --- "a/developer/javac\360\237\226\211/Ariadne_IndexTree_Child_SRM.java" +++ "b/developer/javac\360\237\226\211/Ariadne_IndexTree_Child_SRM.java" @@ -2,7 +2,7 @@ package com.ReasoningTechnology.Ariadne; import java.math.BigInteger; -public class Ariadne_IndexTree_Child_SRM extends Ariadne_SRM { +public class Ariadne_IndexTree_Child_SRM extends Ariadne_SRMI{ private BigInteger[] label; @@ -11,28 +11,39 @@ public class Ariadne_IndexTree_Child_SRM extends Ariadne_SRM { } 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; + } } diff --git "a/developer/javac\360\237\226\211/Ariadne_IndexTree_Node.java" "b/developer/javac\360\237\226\211/Ariadne_IndexTree_Node.java" index 44a4eb5..ceb1739 100644 --- "a/developer/javac\360\237\226\211/Ariadne_IndexTree_Node.java" +++ "b/developer/javac\360\237\226\211/Ariadne_IndexTree_Node.java" @@ -3,26 +3,24 @@ package com.ReasoningTechnology.Ariadne; import java.math.BigInteger; import java.util.Arrays; -public class Ariadne_IndexTree_Node extends Ariadne_Node { +public class Ariadne_IndexTree_Node extends Ariadne_Node{ 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 diff --git "a/developer/javac\360\237\226\211/Ariadne_Node.java" "b/developer/javac\360\237\226\211/Ariadne_Node.java" index 2aa34d1..5384b06 100644 --- "a/developer/javac\360\237\226\211/Ariadne_Node.java" +++ "b/developer/javac\360\237\226\211/Ariadne_Node.java" @@ -55,8 +55,8 @@ public class Ariadne_Node extends HashMap { return this.label; } - public Ariadne_SRM neighbor() { - return Ariadne_SRM.make(); + public Ariadne_SRM neighbor(){ + throw new UnsupportedOperationException("Neighbor is not implemented in the base class."); } public void mark(Ariadne_Token token) { diff --git "a/developer/javac\360\237\226\211/Ariadne_SRM.java" "b/developer/javac\360\237\226\211/Ariadne_SRM.java" index 7301b5b..562073d 100644 --- "a/developer/javac\360\237\226\211/Ariadne_SRM.java" +++ "b/developer/javac\360\237\226\211/Ariadne_SRM.java" @@ -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{ @@ -25,7 +26,7 @@ public abstract class Ariadne_SRM{ abstract MachineState state(); } - private State current_state; + protected State current_state; protected void set_state(State new_state){ this.current_state = new_state; diff --git "a/developer/javac\360\237\226\211/Ariadne_SRMI.java" "b/developer/javac\360\237\226\211/Ariadne_SRMI.java" index c4b3dfe..e7b2e29 100644 --- "a/developer/javac\360\237\226\211/Ariadne_SRMI.java" +++ "b/developer/javac\360\237\226\211/Ariadne_SRMI.java" @@ -4,28 +4,48 @@ Ariadne_SRM with index */ package com.ReasoningTechnology.Ariadne; - -public class Ariadne_SRMI extends Ariadne_SRM{ - - public static Ariadne_SRMI make(){ - return new Ariadne_SRMI(); - } - protected Ariadne_SRMI(){ +import java.math.BigInteger; + +public abstract class Ariadne_SRMI extends Ariadne_SRM{ + + 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); + } } diff --git "a/developer/javac\360\237\226\211/Ariadne_SRMI_Array.java" "b/developer/javac\360\237\226\211/Ariadne_SRMI_Array.java" index f5b5c92..bccefa0 100644 --- "a/developer/javac\360\237\226\211/Ariadne_SRMI_Array.java" +++ "b/developer/javac\360\237\226\211/Ariadne_SRMI_Array.java" @@ -1,70 +1,92 @@ package com.ReasoningTechnology.Ariadne; -import java.util.List; - -public class Ariadne_SRMI_Array extends Ariadne_SRMI{ - - public static Ariadne_SRMI_Array make(List array){ - return new Ariadne_SRMI_Array<>(array); - } - private List _array; - private int _index; - private Topology _topology; - private Location _location; - - protected Ariadne_SRMI_Array(List 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 extends Ariadne_SRMI { - if(_topology == Topology.SEGMENT) - _location = Location.LEFTMOST; - else - _location = Location.OTHER; + private final List array; - _index = 0; - } + public Ariadne_SRMI_Array(List 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; + } + }; } diff --git "a/developer/javac\360\237\226\211/Ariadne_SRM_List.java" "b/developer/javac\360\237\226\211/Ariadne_SRM_List.java" index 45a11c3..b884f98 100644 --- "a/developer/javac\360\237\226\211/Ariadne_SRM_List.java" +++ "b/developer/javac\360\237\226\211/Ariadne_SRM_List.java" @@ -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 extends Ariadne_SRM { - - public static Ariadne_SRM_List make(List list){ - return new Ariadne_SRM_List<>(list); - } - - private List _list; // The attached linked list - private ListIterator 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 list){ - init(list); - } - private void init(List 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 extends Ariadne_SRM{ - if(_topology == Topology.SEGMENT) - _location = Location.LEFTMOST; - else - _location = Location.OTHER; + private final List list; + private int current_index; - if(_topology.ordinal() >= Topology.SINGLETON.ordinal()){ - iterator = _list.listIterator(); - read_value = iterator.next(); + public Ariadne_SRM_List(List 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); } - }