+++ /dev/null
-import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND;
-import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND_Array;
-
-import java.util.Arrays;
-import java.util.List;
-
-public class TM_SR_ND_Array_CLI {
- public static void main( String[] args ){
- // Create an Array
- List<String> label_array = Arrays.asList( "A", "B", "C", "D" );
-
- // Attach TM_SR_ND to the array
- Ariadne_TM_SR_ND_Array<String> srm = Ariadne_TM_SR_ND_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);
- }
- }
-}
+++ /dev/null
-Reading: A
-Topology: SEGMENT
-Reading: B
-Topology: SEGMENT
-Reading: C
-Topology: SEGMENT
-Reading: D
-Topology: RIGHTMOST
+++ /dev/null
-import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND;
-import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND_List;
-
-import java.util.LinkedList;
-
-public class TM_SR_ND_List_CLI {
- 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" );
-
- // Attach TM_SR_ND to the linked list and traverse
- Ariadne_TM_SR_ND_List<String> srm = Ariadne_TM_SR_ND_List.make(label_list);
- 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);
- }
- }
-}
+++ /dev/null
-Reading: A
-Topology: SEGMENT
-Reading: B
-Topology: SEGMENT
-Reading: C
-Topology: RIGHTMOST
+++ /dev/null
-import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND_Set;
-
-import java.util.HashSet;
-import java.util.Set;
-
-public class TM_SR_ND_Set_CLI {
- public static void main( String[] args ){
- // Create a Set
- Set<String> label_set = new HashSet<>();
- label_set.add("A");
- label_set.add("B");
- label_set.add("C");
-
- // Attach TM_SR_ND to the set and traverse
- Ariadne_TM_SR_ND_Set<String> srm = Ariadne_TM_SR_ND_Set.make(label_set);
- 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);
- }
- }
-}
--- /dev/null
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND;
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND_Array;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class TM_SR_ND_Array_CLI {
+ public static void main( String[] args ){
+ // Create an Array
+ List<String> label_array = Arrays.asList( "A", "B", "C", "D" );
+
+ // Attach TM_SR_ND to the array
+ Ariadne_TM_SR_ND_Array<String> srm = Ariadne_TM_SR_ND_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);
+ }
+ }
+}
--- /dev/null
+Reading: A
+Topology: SEGMENT
+Reading: B
+Topology: SEGMENT
+Reading: C
+Topology: SEGMENT
+Reading: D
+Topology: RIGHTMOST
--- /dev/null
+import java.util.LinkedList;
+
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND;
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND_List;
+
+public class TM_SR_ND_List_CLI {
+ 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" );
+
+ // Attach TM_SR_ND to the linked list and traverse
+ Ariadne_TM_SR_ND_List<String> srm = Ariadne_TM_SR_ND_List.make(label_list);
+ 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);
+ }
+ }
+}
--- /dev/null
+Reading: A
+Topology: SEGMENT
+Reading: B
+Topology: SEGMENT
+Reading: C
+Topology: RIGHTMOST
--- /dev/null
+/*
+Example of the TM_SR_ND's toString function.
+
+*/
+
+import java.util.Arrays;
+import java.util.List;
+
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND;
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND_List;
+
+public class TM_SR_ND_Print_CLI{
+
+ public static void main(String[] args){
+ List<Object> data = Arrays.asList(42 ,null ,"" ,"World" ,1000);
+ Ariadne_TM_SR_ND tm = Ariadne_TM_SR_ND_List.make(data);
+ tm.step();
+ tm.step();
+ System.out.println(tm.toString());
+ }
+}
--- /dev/null
+TM_SR_ND(SEGMENT( 42 World 1000 )
+ |dd||-|<e>|ddddd||dddd|
--- /dev/null
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND_Set;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class TM_SR_ND_Set_CLI {
+ public static void main( String[] args ){
+ // Create a Set
+ Set<String> label_set = new HashSet<>();
+ label_set.add("A");
+ label_set.add("B");
+ label_set.add("C");
+
+ // Attach TM_SR_ND to the set and traverse
+ Ariadne_TM_SR_ND_Set<String> srm = Ariadne_TM_SR_ND_Set.make(label_set);
+ 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);
+ }
+ }
+}
// static
//
+ protected static int id_well = 100;
+
public enum Topology{
NULL
,CYCLIC
// instance data
//
+ private int id;
+ Ariadne_Test test = null;
protected TopoIface current_topology;
- public final TopoIface not_mounted = new NotMounted();
protected BigInteger index;
// constructor(s)
//
public Ariadne_TM_SR_ND(){
+ id = id_well++;
+ test = Ariadne_Test.make("Ariadne_TM_SR_ND::" + id + "::");
+ test.switch_test(false);
set_topology( not_mounted );
this.index = BigInteger.ZERO;
}
// Implementation of instance interface.
//
+ public int id(){
+ return this.id;
+ }
+
public BigInteger head_address(){
return index;
}
}
public boolean head_on_same_cell(Ariadne_TM_SR_ND tm){
- return this.index.equals(tm.index);
+ boolean p = this.index.equals(tm.index);
+ if( test.is_on() ){
+ test.print("head_on_same_cell this id/index: " + this.id() + "/" + this.index );
+ test.print("head_on_same_cell tm id/index: " + tm.id() + "/" + tm.index );
+ test.print("head_on_same_cell returning: " + p );
+ }
+ return p;
}
- public Ariadne_TM_SR_ND entangle(){
- Ariadne_TM_SR_ND copy = make();
-
- // entangled copy shares the same tape
- copy.current_topology = this.current_topology; // Shares the same reference
-
+ protected void entangle(Ariadne_TM_SR_ND copy){
+ copy.current_topology = this.current_topology;
// Nuance here, BigInteger is immutable, so operation on the original
// index, and the copy index, will be independent, which is what we want.
copy.index = this.index;
-
- return copy;
+ }
+ public Ariadne_TM_SR_ND entangle(){
+ throw new UnsupportedOperationException("Ariadne_TM_SR_ND::entangle not implemented.");
}
public boolean is_mounted(){
return
current_topology != null
- && current_topology != not_mounted;
+ && current_topology != not_mounted
+ ;
+ }
+
+ public boolean can_rewind(){
+ return false;
+ }
+
+ public void rewind(){
+ index = BigInteger.ZERO;
}
public boolean can_read(){
- return current_topology.can_read();
+ boolean p = current_topology.can_read();
+ if( test.is_on() ) test.print("can_read " + p);
+ return p;
}
public Object read(){
- return current_topology.read();
+ Object o = current_topology.read();
+ if( test.is_on() ) test.print("read: " + o);
+ return o;
}
public boolean can_step(){
- return current_topology.can_step();
+ boolean p = current_topology.can_step();
+ if( test.is_on() ) test.print("can_step " + p);
+ return p;
}
public void step(){
- current_topology.step();
increment();
+ if( test.is_on() ) test.print("step: " + index);
+ current_topology.step();
}
public Topology topology(){
// Sets the tape access methods to be used.
protected void set_topology(TopoIface new_topology){
current_topology = new_topology;
+ if( test.is_on() ){
+ test.print("set_topology i: " + index);
+ if(is_mounted()){
+ test.print("set_topology to: " + new_topology.topology());
+ }else{
+ test.print("set_topology to: Unmounted");
+ }
+ }
}
protected interface TopoIface{
Topology topology();
}
- // Initially, the tape has not been mounted.
- protected class NotMounted implements TopoIface{
+ protected final TopoIface not_mounted = new TopoIface(){
@Override public boolean can_read(){
return false;
}
@Override public Topology topology(){
throw new UnsupportedOperationException("Ariadne_TM_SR_ND::NotMounted::topology.");
}
- }
+ };
+ protected final TopoIface topo_null = new TopoIface(){
+ @Override public boolean can_read(){
+ return false;
+ }
+ @Override public Object read(){
+ throw new UnsupportedOperationException( "Cannot read from null topology." );
+ }
+ @Override public boolean can_step(){
+ return false;
+ }
+ @Override public void step(){
+ throw new UnsupportedOperationException( "Cannot step over null topology." );
+ }
+ @Override public Topology topology(){
+ return Topology.NULL;
+ }
+ };
// good citizen
//
if(!is_mounted()) return "TM_SR_ND(NotMounted)";
if(!can_read()) return "TM_SR_ND(Null)";
- StringBuilder data_channel = new StringBuilder(" ");
- StringBuilder control_channel = new StringBuilder("|");
+ StringBuilder data_channel = new StringBuilder("");
+ StringBuilder control_channel = new StringBuilder("");
data_channel.append( "TM_SR_ND(" ).append( topology().name()).append("( " );
control_channel.append( " ".repeat(data_channel.length()) );
String element = null;
- Ariadne_TM_SR_ND copy = (Ariadne_TM_SR_ND) this.entangle();
+ Ariadne_TM_SR_ND copy = this.entangle();
+ if( copy.can_rewind() ) copy.rewind();
+
Object o = null;
do{
+
o = copy.read();
if(o == null){
data_channel.append( " ".repeat(3) );
- if(head_on_same_cell(copy)){
+ if( head_on_same_cell(copy) ){
control_channel.append("<->");
}else{
control_channel.append("|-|");
}
}else if(o.toString().isEmpty()){
data_channel.append( " ".repeat(3) );
- if(head_on_same_cell(copy)){
+ if( head_on_same_cell(copy) ){
control_channel.append("<e>");
}else{
control_channel.append("|e|");
}
}
- if(!copy.can_step()) break;
+ if( !copy.can_step() ) break;
copy.step();
+
}while(true);
data_channel.append(" )");
data_channel
.append("\n")
.append(control_channel)
- .append("\n")
.toString();
}
private final List<T> array;
- private final TopoIface topo_null = new TopoNull();
- private final TopoIface topo_segment = new TopoSegment();
- private final TopoIface topo_rightmost = new TopoRightmost();
-
// Constructor
protected Ariadne_TM_SR_ND_Array(List<T> array){
super();
set_topology( topo_segment );
}
- // TopoNull
- private class TopoNull implements TopoIface{
- @Override public boolean can_read(){
- return false;
- }
- @Override public Object read(){
- throw new UnsupportedOperationException( "Cannot read from NULL topo." );
- }
- @Override public boolean can_step(){
- return false;
- }
- @Override public void step(){
- throw new UnsupportedOperationException( "Cannot step from NULL topo." );
- }
- @Override public Topology topology(){
- return Topology.NULL;
+ // instance interface implementation
+
+ @Override public boolean can_rewind(){
+ return true;
+ }
+
+ @Override public void rewind() {
+ super.rewind();
+ if (array == null || array.isEmpty()) {
+ set_topology(topo_null); // Null topology for empty or null arrays
+ return;
}
+ set_topology(array.size() == 1 ? topo_rightmost : topo_segment); // Adjust topology
}
- // TopoSegment
- private class TopoSegment implements TopoIface{
+ protected final TopoIface topo_segment = new TopoIface(){
@Override public boolean can_read(){
return true;
}
@Override public Topology topology(){
return Topology.SEGMENT;
}
- }
+ };
- // TopoRightmost
- private class TopoRightmost implements TopoIface{
+ protected final TopoIface topo_rightmost = new TopoIface(){
@Override public boolean can_read(){
return true;
}
@Override public Topology topology(){
return Topology.RIGHTMOST;
}
- }
+ };
+
}
private ListIterator<T> iterator; // Iterator for traversal
private T read_value; // Stores the current cell value
- private final TopoIface topo_null = new TopoNull();
- private final TopoIface topo_segment = new TopoSegment();
- private final TopoIface topo_rightmost = new TopoRightmost();
-
// constructor(s)
//
// instance interface implementation
//
+ protected void entangle(Ariadne_TM_SR_ND_List<T> copy){
+ super.entangle(copy);
+ copy.read_value = this.read_value;
+ copy.iterator = this.list.listIterator(this.iterator.nextIndex());
+ }
+
+ @Override public Ariadne_TM_SR_ND_List<T> entangle(){
+ Ariadne_TM_SR_ND_List<T> copy = Ariadne_TM_SR_ND_List.make(this.list);
+
+ // Copy shared fields
+ copy.index = this.index; // Copy the step count
+ copy.read_value = this.read_value; // Synchronize the current read value
+ copy.iterator = this.list.listIterator(this.iterator.nextIndex()); // Align iterator
+
+ // Set the appropriate topology in the copy based on the current topology
+ switch (this.current_topology.topology()) {
+ case NULL:
+ copy.current_topology = copy.topo_null;
+ break;
+ case SEGMENT:
+ copy.current_topology = copy.topo_segment;
+ break;
+ case RIGHTMOST:
+ copy.current_topology = copy.topo_rightmost;
+ break;
+ default:
+ throw new IllegalStateException("Unexpected topology: " + this.current_topology.topology());
+ }
+
+ return copy;
+ }
+
+ @Override public boolean can_rewind(){
+ return true;
+ }
+
+ @Override public void rewind(){
+ super.rewind();
+ if(list == null || list.isEmpty()){
+ set_topology(topo_null);
+ return;
+ }
+ iterator = list.listIterator(); // Reset the iterator
+ read_value = iterator.next(); // Sync the read value
+ set_topology(list.size() == 1 ? topo_rightmost : topo_segment); // Adjust topology
+ }
+
@Override
@SuppressWarnings("unchecked")
public T read(){
return (T) current_topology.read(); // Cast to ensure T is returned
}
- private class TopoNull implements TopoIface{
- @Override public boolean can_read(){
- return false;
- }
- @Override public T read(){
- throw new UnsupportedOperationException( "Cannot read from NULL topo." );
- }
- @Override public boolean can_step(){
- return false;
- }
- @Override public void step(){
- throw new UnsupportedOperationException( "Cannot step over NULL topo." );
- }
- @Override public Topology topology(){
- return Topology.NULL;
- }
- }
-
- private class TopoSegment implements TopoIface{
+ protected final TopoIface topo_segment = new TopoIface(){
@Override public boolean can_read(){
return true;
}
@Override public Topology topology(){
return Topology.SEGMENT;
}
- }
+ };
- private class TopoRightmost implements TopoIface{
+ protected final TopoIface topo_rightmost = new TopoIface(){
@Override public boolean can_read(){
return true;
}
@Override public Topology topology(){
return Topology.RIGHTMOST;
}
- }
+ };
}
protected Ariadne_Test(){
}
+ public boolean is_on(){
+ return test;
+ }
+
public void switch_test(boolean enable){
if( test && !enable ){
print("test messages off");