--- /dev/null
+/*
+ Step Right Tape Machine
+
+ Depending how the undefined methods here are defined, the ND_SR_TM can
+ equally be a finite iterator, a generator, or an infinite stream.
+
+ This is for single-threaded execution. The multi-threaded model
+ uses `mount` and `dismount` to lock the resources being iterated over.
+*/
+package com.ReasoningTechnology.Ariadne;
+
+public class Ariadne_ND_SR_TM{
+
+ // static
+ //
+
+ public enum Topology{
+ NULL
+ ,CYCLIC
+ ,SEGMENT
+ ,RIGHTMOST
+ ,INFINITE
+ }
+
+ public static Ariadne_ND_SR_TM make(){
+ return new Ariadne_ND_SR_TM();
+ }
+
+ // instance data
+ //
+
+ protected TopoIface current_topology;
+ public final TopoIface not_mounted = new NotMounted();
+
+ // constructor(s)
+ //
+
+ protected Ariadne_ND_SR_TM(){
+ set_topology( not_mounted );
+ }
+
+ // Implementation of instance interface.
+ //
+
+ public boolean is_mounted(){
+ return
+ current_topology != null
+ && current_topology != not_mounted;
+ }
+
+ public boolean can_read(){
+ return current_topology.can_read();
+ }
+
+ public Object read(){
+ return current_topology.read();
+ }
+
+ public boolean can_step(){
+ return current_topology.can_step();
+ }
+
+ public void step(){
+ current_topology.step();
+ }
+
+ public Topology topology(){
+ return current_topology.topology();
+ }
+
+ // Sets the tape access methods to be used.
+ protected void set_topology(TopoIface new_topology){
+ current_topology = new_topology;
+ }
+
+ protected interface TopoIface{
+ boolean can_read();
+ Object read();
+ boolean can_step();
+ void step();
+ Topology topology();
+ }
+
+ // Initially, the tape has not been mounted.
+ protected class NotMounted implements TopoIface{
+ @Override public boolean can_read(){
+ return false;
+ }
+ @Override public Object read(){
+ throw new UnsupportedOperationException("Ariadne_ND_SR_TM::NotMounted::read.");
+ }
+ @Override public boolean can_step(){
+ return false;
+ }
+ @Override public void step(){
+ throw new UnsupportedOperationException("Ariadne_ND_SR_TM::NotMounted::step.");
+ }
+ @Override public Topology topology(){
+ throw new UnsupportedOperationException("Ariadne_ND_SR_TM::NotMounted::topology.");
+ }
+ }
+
+
+ // good citizen
+ //
+
+
+}
+
Aeloria
/*
- IndexTree_SRTM_Diagonal
+ IndexTree_ND_SR_TM_Diagonal
An index tree is infinite.
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
-import com.ReasoningTechnology.Ariadne.Ariadne_SRTM;
+import com.ReasoningTechnology.Ariadne.Ariadne_ND_SR_TM;
import com.ReasoningTechnology.Ariadne.IndexTree_Node;
-public class IndexTree_SRTM_Diagonal extends Ariadne_SRTM_Label {
+public class IndexTree_ND_SR_TM_Diagonal extends Ariadne_ND_SR_TM_Label {
// Static
- public static IndexTree_SRTM_Diagonal make(){
- return new IndexTree_SRTM_Diagonal();
+ public static IndexTree_ND_SR_TM_Diagonal make(){
+ return new IndexTree_ND_SR_TM_Diagonal();
}
// Instance Data
private final List<Ariadne_Label> list_of__unopened_node;
private final List<List<Ariadne_Label>> list_of__opened_incomplete_child_list;
private final List<Ariadne_Label> read_list;
- private final Ariadne_SRTM_Label breadth_srm;
+ private final Ariadne_ND_SR_TM_Label breadth_srm;
// Constructor
- protected IndexTree_SRTM_Diagonal(){
+ protected IndexTree_ND_SR_TM_Diagonal(){
list_of__unopened_node = new ArrayList<>();
list_of__opened_incomplete_child_list = new ArrayList<>();
read_list = new ArrayList<>();
- breadth_srm = Ariadne_SRTM_Label.make();
+ breadth_srm = Ariadne_ND_SR_TM_Label.make();
enqueue_root();
}Aeloria
// Retrieve the node using lookup
IndexTree_Node node = lookup( label );
- // Mount a new breadth-first SRTM for children
+ // Mount a new breadth-first ND_SR_TM for children
breadth_srm.mount( node.neighbor() );
if( breadth_srm.can_read() ){
-import com.ReasoningTechnology.Ariadne.Ariadne_SRTM;
+import com.ReasoningTechnology.Ariadne.Ariadne_ND_SR_TM;
import java.math.BigInteger;
-public class CountingNumber extends Ariadne_SRTM{
+public class CountingNumber extends Ariadne_ND_SR_TM{
// Static
//
-import com.ReasoningTechnology.Ariadne.Ariadne_SRTM;
+import com.ReasoningTechnology.Ariadne.Ariadne_ND_SR_TM;
import java.math.BigInteger;
public class CountingNumber_0_CLI{
if( !n.can_read() ) return;
- if( n.topology() == Ariadne_SRTM.Topology.SEGMENT ){
+ if( n.topology() == Ariadne_ND_SR_TM.Topology.SEGMENT ){
do{
System.out.println("Current Number: " + n.read());
if( !n.can_step() ) break;
n.step();
}while( true );
- }else if( n.topology() == Ariadne_SRTM.Topology.INFINITE ){
+ }else if( n.topology() == Ariadne_ND_SR_TM.Topology.INFINITE ){
int count = 0;
do{
System.out.println("Current Number: " + n.read());
/*
-SRTM_Depth is a list of neighbor SRTMs going down the leftmost side of
+ND_SR_TM_Depth is a list of neighbor ND_SR_TMs going down the leftmost side of
a graph traversal. A leftmost traversal is one characterized by
following leftmost not yet visited node on the most recently visited
node's neighbor list.
Depth traversal from a start node, ends when reaching a node that has
no neighbors, or when reaching encountering a cycle.
-The `Node::neighbor()` function returns an SRTM for iterating over the
-node's neighbors. An SRTM is returned rather than a list, because in
+The `Node::neighbor()` function returns an ND_SR_TM for iterating over the
+node's neighbors. An ND_SR_TM is returned rather than a list, because in
general a neighbor list is allowed to be unbounded. Though with a
finite graph, that can not happen. (See IndexTree for an example of an
infinite depth and infinite breadth graph traveral.)
It is possible to construct and infinite graph such that the
-`SRTM_Depth::make()` function would never return.
+`ND_SR_TM_Depth::make()` function would never return.
For a finite graph, this depth traversal will provably terminate, due
to running out unique (non cycle) nodes to visit. More generally, if
graph traversal from a start node is guaranteed to reach a leaf node
(has no neighbors), or a a cycle, within a finite number of node
-traversal steps, then `SRTM_Depth::make()` will always return.
+traversal steps, then `ND_SR_TM_Depth::make()` will always return.
Each call to step causes the TM read head to move to the next lowest
depth, leftmost unvisited node. This might require backtracking and
import java.util.HashMap;
-import com.ReasoningTechnology.Ariadne.Ariadne_SRTM;
+import com.ReasoningTechnology.Ariadne.Ariadne_ND_SR_TM;
import com.ReasoningTechnology.Ariadne.Ariadne_Graph;
-class SRTM_Depth{
+class ND_SR_TM_Depth{
// static
//
-
- SRTM_Depth make(Graph graph){
- SRTM_Depth depth = new SRTM_Depth();
+ ND_SR_TM_Depth make(Graph graph){
+ ND_SR_TM_Depth depth = new ND_SR_TM_Depth();
if(graph == null) return null;
depth.graph = graph;
depth.context_path.add( graph.start() );
// instance data
//
protected Graph graph = null;
- protected List<Ariadne_SRTM> context_path = new ArrayList<>();
+ protected List<Ariadne_ND_SR_TM> context_path = new ArrayList<>();
protected Label cycle_node_label = null;
// constructor
//
- protected SRTM_Depth(){
+ protected ND_SR_TM_Depth(){
set_topography(topo_null);
}
// instance interface implementation
//
-
// A path is terminated by a leaf node or upon discovering a cycle.
// Return false iff can not complete the context path. This is generally a fatal error.
protected boolean complete_context_path(){
if( context_path.isEmpty() ){
- System.out.println("SRTM_Depth::complete_context_path empty context_path");
+ System.out.println("ND_SR_TM_Depth::complete_context_path empty context_path");
return false;
}
// should add cycle check for anomalous case caller fed us an initial path with a cycle
// initialize the path_node set
- Ariadne_SRTMI_Array<Ariadne_SRTM> context_path_srtm = Ariadne_SRTMI_Array.make(context_path);
- Ariadne_SRTM_List<label> child_srtm = null;
+ Ariadne_ND_SR_TM_Array<Ariadne_ND_SR_TM> context_path_srtm = Ariadne_ND_SR_TM_Array.make(context_path);
+ Ariadne_ND_SR_TM_List<label> child_srtm = null;
Label path_node_label = null;
// context_path is known not to be empty, so can_read() is true
child_srtm = context_path_srtm.read();
path_node_label = child_srtm.read();
if(path_node_label == null){
- System.out.println("SRTM_Depth::complete_context_path null path label");
+ System.out.println("ND_SR_TM_Depth::complete_context_path null path label");
return false;
}
is_cycle_node = path_node_label_set.contains(path_node_label);
if( is_cycle_node ){
System.out.println
(
- "SRTM_Depth::complete_context_path: cycle found in initial context_path"
+ "ND_SR_TM_Depth::complete_context_path: cycle found in initial context_path"
);
cycle_node_label = path_node_label;
return false;
if(path_node == null){
System.out.println
(
- "SRTM_Depth::complete_context_path node not found in graph for: label(\""
+ "ND_SR_TM_Depth::complete_context_path node not found in graph for: label(\""
+ path_node_label
+ "\")"
);
protected Graph(){
}
- @Override public SRTM_Child start(){
+ @Override public ND_SR_TM_Child start(){
Label root_label = Label.root();
- return SRTM_Child.make(root_label);
+ return ND_SR_TM_Child.make(root_label);
}
// no override, this graph does not lookup Ariadne_Label, only Label
import java.util.Arrays;
import com.ReasoningTechnology.Ariadne.Ariadne_Label;
-import com.ReasoningTechnology.Ariadne.Ariadne_SRTM_List;
+import com.ReasoningTechnology.Ariadne.Ariadne_ND_SR_TM_List;
public class Label implements Ariadne_Label{
StringBuilder formatted = new StringBuilder("Label([");
- // Use precise loop with SRTM_List to iterate
- Ariadne_SRTM_List<BigInteger> value_srtm = Ariadne_SRTM_List.make(Arrays.asList(value));
+ // Use precise loop with ND_SR_TM_List to iterate
+ Ariadne_ND_SR_TM_List<BigInteger> value_srtm = Ariadne_ND_SR_TM_List.make(Arrays.asList(value));
if(value_srtm.can_read()){
do{
formatted.append(value_srtm.read().toString());
first_child_label.inc_down();
}
- @Override public SRTM_Child neighbor(){
- return SRTM_Child.make(first_child_label);
+ @Override public ND_SR_TM_Child neighbor(){
+ return ND_SR_TM_Child.make(first_child_label);
}
}
/*
-SRTM_Child represents in the abstract the infinite child list of an
+ND_SR_TM_Child represents in the abstract the infinite child list of an
IndexTree node. Index tree node labels are paths through the tree, so
labels can be computed.
-SRTM_Child is made from the leftmost child label. Then step() takes
+ND_SR_TM_Child is made from the leftmost child label. Then step() takes
the current label and computes from it the right neighbor sibling
node's label.
*/
-import com.ReasoningTechnology.Ariadne.Ariadne_SRTM_Label;
+import com.ReasoningTechnology.Ariadne.Ariadne_ND_SR_TM_Label;
-public class SRTM_Child extends Ariadne_SRTM_Label{
+public class ND_SR_TM_Child extends Ariadne_ND_SR_TM_Label{
// Static
//
- public static SRTM_Child make( Label leftmost_child_label ){
- return new SRTM_Child( leftmost_child_label );
+ public static ND_SR_TM_Child make( Label leftmost_child_label ){
+ return new ND_SR_TM_Child( leftmost_child_label );
}
// Instance data
// Constructor(s)
//
- protected SRTM_Child( Label leftmost_child_label ){
+ protected ND_SR_TM_Child( Label leftmost_child_label ){
this.label = leftmost_child_label.copy();
if( label == null ){
import java.util.List;
import com.ReasoningTechnology.Ariadne.Ariadne_Test;
-import com.ReasoningTechnology.Ariadne.Ariadne_SRTM;
-import com.ReasoningTechnology.Ariadne.Ariadne_SRTM_Label;
-import com.ReasoningTechnology.Ariadne.Ariadne_SRTM_List;
+import com.ReasoningTechnology.Ariadne.Ariadne_ND_SR_TM;
+import com.ReasoningTechnology.Ariadne.Ariadne_ND_SR_TM_Label;
+import com.ReasoningTechnology.Ariadne.Ariadne_ND_SR_TM_List;
import com.ReasoningTechnology.Ariadne.Ariadne_Node;
import com.ReasoningTechnology.Ariadne.Ariadne_Label;
-public class SRTM_Diagonal extends Ariadne_SRTM{
+public class ND_SR_TM_Diagonal extends Ariadne_ND_SR_TM{
// Static
//
- public static SRTM_Diagonal make(Label start_node){
- return new SRTM_Diagonal(start_node);
+ public static ND_SR_TM_Diagonal make(Label start_node){
+ return new ND_SR_TM_Diagonal(start_node);
}
// Instance data
//
private List<Label> diagonal = new ArrayList<>(); // the read value
- private final List<SRTM_Child> child_srtm_list = new ArrayList<>();
+ private final List<ND_SR_TM_Child> child_srtm_list = new ArrayList<>();
// Constructor(s)
//
// the diagonal will never be null nor empty
- protected SRTM_Diagonal(Label start_node){
+ protected ND_SR_TM_Diagonal(Label start_node){
if( start_node == null ){
set_topology(topo_null);
@Override
public String toString(){
- StringBuilder formatted = new StringBuilder("SRTM_Diagonal(");
- Ariadne_SRTM_List<Label> diagonal_srtm = Ariadne_SRTM_List.make(diagonal);
+ StringBuilder formatted = new StringBuilder("ND_SR_TM_Diagonal(");
+ Ariadne_ND_SR_TM_List<Label> diagonal_srtm = Ariadne_ND_SR_TM_List.make(diagonal);
if( diagonal_srtm.can_read() ){
do{
List<Label> diagonal_1 = new ArrayList<>();
// inc_down from each node on diagonal_0 -> entry on child_srtm list
- Ariadne_SRTM_List<Label> diagonal_srtm = Ariadne_SRTM_List.make(diagonal);
+ Ariadne_ND_SR_TM_List<Label> diagonal_srtm = Ariadne_ND_SR_TM_List.make(diagonal);
if( diagonal_srtm.can_read() ){
do{
Node node = Node.make(diagonal_srtm.read());
}
// add to diagonal_1 from each on entry on the child_srtm list
- Ariadne_SRTM_List<SRTM_Child> child_srtm_srtm = Ariadne_SRTM_List.make(child_srtm_list);
+ Ariadne_ND_SR_TM_List<ND_SR_TM_Child> child_srtm_srtm = Ariadne_ND_SR_TM_List.make(child_srtm_list);
if( child_srtm_srtm.can_read() ){
do{
- SRTM_Child child_srtm = child_srtm_srtm.read();
+ ND_SR_TM_Child child_srtm = child_srtm_srtm.read();
Label label = child_srtm.read();
diagonal_1.add(label.copy());
child_srtm.step();
import java.util.List;
-public class SRTM_Diagonal_CLI{
+public class ND_SR_TM_Diagonal_CLI{
public static void main(String[] args){
- System.out.println("Starting IndexTree SRTM Example");
+ System.out.println("Starting IndexTree ND_SR_TM Example");
- // Instantiate the IndexTree Diagonal SRTM
+ // Instantiate the IndexTree Diagonal ND_SR_TM
Graph g = Graph.make();
- SRTM_Child start_srtm = g.start();
+ ND_SR_TM_Child start_srtm = g.start();
if( !start_srtm.can_read() ){
System.out.println("Graph provides no start nodes. Thought you might want to know.");
return;
do{
Label start_label = start_srtm.read();
System.out.println("Graph diagonalization starting from: " + start_label);
- SRTM_Diagonal srtm = SRTM_Diagonal.make(start_label);
+ ND_SR_TM_Diagonal srtm = ND_SR_TM_Diagonal.make(start_label);
int step_count = 0;
if( srtm.can_read() ){
do{
-import com.ReasoningTechnology.Ariadne.Ariadne_SRTM;
-import com.ReasoningTechnology.Ariadne.Ariadne_SRTM_List;
+import com.ReasoningTechnology.Ariadne.Ariadne_ND_SR_TM;
+import com.ReasoningTechnology.Ariadne.Ariadne_ND_SR_TM_List;
public class four_down_four_across_CLI{
// Initialize graph and start at root
Graph graph = Graph.make();
- SRTM_Child start = graph.start();
+ ND_SR_TM_Child start = graph.start();
Label label = start.read();
Node node;
- SRTM_Child child_srm;
+ ND_SR_TM_Child child_srm;
System.out.println("starting at: " + start.read());
-import com.ReasoningTechnology.Ariadne.Ariadne_SRTM;
-import com.ReasoningTechnology.Ariadne.Ariadne_SRTMI_Array;
+import com.ReasoningTechnology.Ariadne.Ariadne_ND_SR_TM;
+import com.ReasoningTechnology.Ariadne.Ariadne_ND_SR_TM_Array;
import java.util.Arrays;
import java.util.List;
-public class SRTMI_Array_CLI {
+public class ND_SR_TM_Array_CLI {
public static void main( String[] args ){
// Create an Array
List<String> label_array = Arrays.asList( "A", "B", "C", "D" );
- // Attach SRTMI to the array
- Ariadne_SRTMI_Array<String> srm = Ariadne_SRTMI_Array.make(label_array);
+ // Attach ND_SR_TM to the array
+ Ariadne_ND_SR_TM_Array<String> srm = Ariadne_ND_SR_TM_Array.make(label_array);
if( srm.can_read() ){
do{
System.out.println( "Reading: " + srm.read() );
-import com.ReasoningTechnology.Ariadne.Ariadne_SRTM;
-import com.ReasoningTechnology.Ariadne.Ariadne_SRTM_List;
+import com.ReasoningTechnology.Ariadne.Ariadne_ND_SR_TM;
+import com.ReasoningTechnology.Ariadne.Ariadne_ND_SR_TM_List;
import java.util.LinkedList;
-public class SRTM_List_CLI {
+public class ND_SR_TM_List_CLI {
public static void main( String[] args ){
// Create a linked list
LinkedList<String> label_list = new LinkedList<>();
label_list.add( "B" );
label_list.add( "C" );
- // Attach SRTM to the linked list and traverse
- Ariadne_SRTM_List<String> srm = Ariadne_SRTM_List.make(label_list);
+ // Attach ND_SR_TM to the linked list and traverse
+ Ariadne_ND_SR_TM_List<String> srm = Ariadne_ND_SR_TM_List.make(label_list);
if( srm.can_read() ){
do{
System.out.println( "Reading: " + srm.read() );
-import com.ReasoningTechnology.Ariadne.Ariadne_SRTM_Set;
+import com.ReasoningTechnology.Ariadne.Ariadne_ND_SR_TM_Set;
import java.util.HashSet;
import java.util.Set;
-public class SRTM_Set_CLI {
+public class ND_SR_TM_Set_CLI {
public static void main( String[] args ){
// Create a Set
Set<String> label_set = new HashSet<>();
label_set.add("B");
label_set.add("C");
- // Attach SRTM to the set and traverse
- Ariadne_SRTM_Set<String> srm = Ariadne_SRTM_Set.make(label_set);
+ // Attach ND_SR_TM to the set and traverse
+ Ariadne_ND_SR_TM_Set<String> srm = Ariadne_ND_SR_TM_Set.make(label_set);
if( srm.can_read() ){
do{
System.out.println( "Reading: " + srm.read() );
protected Ariadne_Graph(){
}
- public Ariadne_SRTM start(){
+ public Ariadne_ND_SR_TM start(){
throw new UnsupportedOperationException("Ariadne_Graph::start.");
}
--- /dev/null
+/*
+An ND_SR_TM with indexing == ND_SR_TM
+
+An index is indicates where the head is located on the tape. This is done by
+tracking the cell address for the head.
+
+BigInteger is used so that it will be possible to bind ND_SR_TM machine extensions
+to file system objects.
+
+*/
+
+package com.ReasoningTechnology.Ariadne;
+import java.math.BigInteger;
+
+public abstract class Ariadne_ND_SR_TM extends Ariadne_ND_SR_TM{
+
+ // static
+ //
+
+ public enum Topology{
+ NULL
+ ,CYCLIC
+ ,SEGMENT
+ ,RIGHTMOST
+ ,INFINITE
+ }
+
+ public static Ariadne_ND_SR_TM make(){
+ return new Ariadne_ND_SR_TM();
+ }
+
+ // instance data
+ //
+
+ protected TopoIface current_topology;
+ public final TopoIface not_mounted = new NotMounted();
+ private BigInteger index;
+
+ // constructor(s)
+ //
+
+ public Ariadne_ND_SR_TM(){
+ set_topology( not_mounted );
+ this.index = BigInteger.ZERO;
+ }
+
+ // Implementation of instance interface.
+ //
+
+ public BigInteger head_address(){
+ return index;
+ }
+
+ public Ariadne_ND_SR_TM entangle(){
+ try{
+ Ariadne_ND_SR_TM copy = (Ariadne_ND_SR_TM) this.clone();
+
+ // entangled copy shares the same tape
+ copy.tape_list = this.tape_list; // Shares the same reference
+ copy.current_topology = this.current_topology; // Shares the same reference
+
+ // nuance here, BigInteger is immutable, so any operation on the original
+ // index, and the copy index will be independent without having to do a deep copy.
+ copy.index = this.index;
+
+ return copy;
+ }catch(CloneNotSupportedException e){
+ throw new AssertionError( "Clone not supported: " + e.getMessage() );
+ }
+ }
+
+ public boolean is_mounted(){
+ return
+ current_topology != null
+ && current_topology != not_mounted;
+ }
+
+ public boolean can_read(){
+ return current_topology.can_read();
+ }
+
+ public Object read(){
+ return current_topology.read();
+ }
+
+ public boolean can_step(){
+ return current_topology.can_step();
+ }
+
+ public void step(){
+ current_topology.step();
+ }
+
+ public Topology topology(){
+ return current_topology.topology();
+ }
+
+ // Sets the tape access methods to be used.
+ protected void set_topology(TopoIface new_topology){
+ current_topology = new_topology;
+ }
+
+ protected interface TopoIface{
+ boolean can_read();
+ Object read();
+ boolean can_step();
+ void step();
+ Topology topology();
+ }
+
+ // Initially, the tape has not been mounted.
+ protected class NotMounted implements TopoIface{
+ @Override public boolean can_read(){
+ return false;
+ }
+ @Override public Object read(){
+ throw new UnsupportedOperationException("Ariadne_ND_SR_TM::NotMounted::read.");
+ }
+ @Override public boolean can_step(){
+ return false;
+ }
+ @Override public void step(){
+ throw new UnsupportedOperationException("Ariadne_ND_SR_TM::NotMounted::step.");
+ }
+ @Override public Topology topology(){
+ throw new UnsupportedOperationException("Ariadne_ND_SR_TM::NotMounted::topology.");
+ }
+ }
+
+
+ // good citizen
+ //
+
+ @Override public String toString(){
+ if(!is_mounted()) return "ND_SR_TM(NotMounted)";
+ if(!can_read()) return "ND_SR_TM(Null)";
+
+ StringBuilder sb = new StringBuilder();
+ sb.append("ND_SR_TM(").append(topology().name()).append("(");
+
+ try{
+ // Clone for traversal
+ Ariadne_ND_SR_TM copy = (Ariadne_ND_SR_TM) this.clone();
+
+ Object o = null;
+ do{
+ o = copy.read();
+ if(o == null){
+ sb.append("null");
+ }else if(!copy.can_step()){
+ sb.append("[");
+ sb.append(o.toString());
+ sb.append("]");
+ }else{
+ sb.append(o.toString());
+ }
+
+ if(!copy.can_step()) break;
+ sb.append(" ,");
+ copy.step();
+ }while(true);
+
+ }catch(CloneNotSupportedException e){
+ throw new AssertionError("Clone not supported: " + e.getMessage());
+ }
+
+ sb.append("))");
+ return sb.toString();
+ }
+
+}
--- /dev/null
+package com.ReasoningTechnology.Ariadne;
+
+import java.math.BigInteger;
+import java.util.List;
+
+public class Ariadne_ND_SR_TM_Array<T> extends Ariadne_ND_SR_TM{
+
+ // Static methods
+ //
+
+ public static <T> Ariadne_ND_SR_TM_Array<T> make(List<T> array){
+ return new Ariadne_ND_SR_TM_Array<>(array);
+ }
+
+ // Instance data
+ //
+
+ 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_ND_SR_TM_Array(List<T> array){
+ super();
+ this.array = array;
+
+ if( array == null || array.isEmpty() ){
+ set_topology( topo_null );
+ return;
+ }
+
+ if( array.size() == 1 ){
+ set_topology( topo_rightmost );
+ return;
+ }
+
+ 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;
+ }
+ }
+
+ // TopoSegment
+ private class TopoSegment implements TopoIface{
+ @Override public boolean can_read(){
+ return true;
+ }
+ @Override public Object read(){
+ return array.get( head_address().intValueExact() );
+ }
+ @Override public boolean can_step(){
+ return true;
+ }
+ @Override public void step(){
+ increment();
+ if( head_address().compareTo(BigInteger.valueOf(array.size() - 1)) == 0 )
+ set_topology(topo_rightmost);
+ }
+ @Override public Topology topology(){
+ return Topology.SEGMENT;
+ }
+ }
+
+ // TopoRightmost
+ private class TopoRightmost implements TopoIface{
+ @Override public boolean can_read(){
+ return true;
+ }
+ @Override public Object read(){
+ return array.get( head_address().intValueExact() );
+ }
+ @Override public boolean can_step(){
+ return false;
+ }
+ @Override public void step(){
+ throw new UnsupportedOperationException( "Cannot step from RIGHTMOST topo." );
+ }
+ @Override public Topology topology(){
+ return Topology.RIGHTMOST;
+ }
+ }
+}
--- /dev/null
+/*
+Graph nodes are referenced by their labels.
+
+*/
+
+package com.ReasoningTechnology.Ariadne;
+
+public class Ariadne_ND_SR_TM_Label extends Ariadne_ND_SR_TM {
+
+ public static Ariadne_ND_SR_TM_Label make(){
+ return new Ariadne_ND_SR_TM_Label();
+ }
+
+ @Override public Ariadne_Label read(){
+ return (Ariadne_Label)super.read();
+ }
+
+}
--- /dev/null
+/*
+ By convention an ND_SR_TM is named after the type of values found in the tape cells.
+ However, in this case the name reflects the type that that ND_SR_TM is made from.
+ The type of values found in the ND_SR_TM cells is abstracted as "T".
+
+ This implementation uses Java's ListIterator, which lacks a direct
+ method to read the current cell value, rather it yields the next
+ cell value upon advancing the iterator.
+*/
+package com.ReasoningTechnology.Ariadne;
+import java.util.List;
+import java.util.ListIterator;
+
+public class Ariadne_ND_SR_TM_List<T> extends Ariadne_ND_SR_TM{
+
+ // Static methods
+ //
+
+ public static <T> Ariadne_ND_SR_TM_List<T> make(List<T> list) {
+ return new Ariadne_ND_SR_TM_List<>(list);
+ }
+
+ // instance data
+ //
+
+ 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 topo_null = new TopoNull();
+ private final TopoIface topo_segment = new TopoSegment();
+ private final TopoIface topo_rightmost = new TopoRightmost();
+
+ // constructor(s)
+ //
+
+ protected Ariadne_ND_SR_TM_List(List<T> list){
+ this.list = list;
+
+ if( list == null || list.isEmpty() ){
+ this.iterator = null;
+ set_topology(topo_null);
+ return;
+ }
+
+ this.iterator = list.listIterator();
+ read_value = iterator.next();
+
+ if( list.size() == 1 ){
+ set_topology(topo_rightmost);
+ return;
+ }
+
+ set_topology(topo_segment);
+ }
+
+ // instance interface implementation
+ //
+
+ @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{
+ @Override public boolean can_read(){
+ return true;
+ }
+ @Override public T read(){
+ return (T)read_value;
+ }
+ @Override public boolean can_step(){
+ return true;
+ }
+ @Override public void step(){
+ read_value = iterator.next();
+ if( !iterator.hasNext() ) set_topology(topo_rightmost);
+ }
+ @Override public Topology topology(){
+ return Topology.SEGMENT;
+ }
+ }
+
+ private class TopoRightmost implements TopoIface{
+ @Override public boolean can_read(){
+ return true;
+ }
+ @Override public T read(){
+ return read_value;
+ }
+ @Override public boolean can_step(){
+ return false;
+ }
+ @Override public void step(){
+ throw new UnsupportedOperationException( "Cannot step from RIGHTMOST topo." );
+ }
+ @Override public Topology topology(){
+ return Topology.RIGHTMOST;
+ }
+ }
+}
+
+
--- /dev/null
+package com.ReasoningTechnology.Ariadne;
+
+import java.util.Iterator;
+import java.util.Set;
+
+public class Ariadne_ND_SR_TM_Set<T> extends Ariadne_ND_SR_TM{
+
+ // Static factory method
+ public static <T> Ariadne_ND_SR_TM_Set<T> make(Set<T> set){
+ return new Ariadne_ND_SR_TM_Set<>(set);
+ }
+
+ // Instance data
+ private final Set<T> set;
+ private final Iterator<T> iterator;
+ private T current_value;
+
+ private final TopoIface topo_null = new TopoNull();
+ private final TopoIface topo_segment = new TopoSegment();
+ private final TopoIface topo_rightmost = new TopoRightmost();
+
+ // Constructor
+ protected Ariadne_ND_SR_TM_Set(Set<T> set){
+ this.set = set;
+
+ if( set == null || set.isEmpty() ){
+ this.iterator = null;
+ set_topology(topo_null);
+ return;
+ }
+
+ this.iterator = set.iterator();
+ this.current_value = iterator.hasNext() ? iterator.next() : null;
+
+ if( set.size() == 1 ){
+ set_topology(topo_rightmost);
+ }else{
+ set_topology(topo_segment);
+ }
+ }
+
+ // Instance interface implementation
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public T read(){
+ return (T)current_topology.read();
+ }
+
+ 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 from NULL topo.");
+ }
+ @Override public Topology topology(){
+ return Topology.NULL;
+ }
+ }
+
+ private class TopoSegment implements TopoIface{
+ @Override public boolean can_read(){
+ return true;
+ }
+ @Override public T read(){
+ return current_value;
+ }
+ @Override public boolean can_step(){
+ return iterator.hasNext();
+ }
+ @Override public void step(){
+ current_value = iterator.next();
+ if( !iterator.hasNext() ) set_topology(topo_rightmost);
+ }
+ @Override public Topology topology(){
+ return Topology.SEGMENT;
+ }
+ }
+
+ private class TopoRightmost implements TopoIface{
+ @Override public boolean can_read(){
+ return true;
+ }
+ @Override public T read(){
+ return current_value;
+ }
+ @Override public boolean can_step(){
+ return false;
+ }
+ @Override public void step(){
+ throw new UnsupportedOperationException("Cannot step from RIGHTMOST topo.");
+ }
+ @Override public Topology topology(){
+ return Topology.RIGHTMOST;
+ }
+ }
+}
return this.label;
}
- public Ariadne_SRTM_Label neighbor(){
+ public Ariadne_ND_SR_TM_Label neighbor(){
throw new UnsupportedOperationException("Ariadne_Node::neighbor not implemented in the base class.");
}
// Marks representation
if( !mark_set.isEmpty() ){
- Ariadne_SRTM_Set srm = Ariadne_SRTM_Set.make(mark_set);
+ Ariadne_ND_SR_TM_Set srm = Ariadne_ND_SR_TM_Set.make(mark_set);
output.append( " Mark(" );
do{
+++ /dev/null
-/*
- Step Right Tape Machine
-
- Depending how the undefined methods here are defined, the SRTM can
- equally be a finite iterator, a generator, or an infinite stream.
-
- This is for single-threaded execution. The multi-threaded model
- uses `mount` and `dismount` to lock the resources being iterated over.
-*/
-package com.ReasoningTechnology.Ariadne;
-
-public class Ariadne_SRTM{
-
- // static
- //
-
- public enum Topology{
- NULL
- ,CYCLIC
- ,SEGMENT
- ,RIGHTMOST
- ,INFINITE
- }
-
- public static Ariadne_SRTM make(){
- return new Ariadne_SRTM();
- }
-
- // instance data
- //
-
- protected TopoIface current_topology;
- public final TopoIface not_mounted = new NotMounted();
-
- // constructor(s)
- //
-
- protected Ariadne_SRTM(){
- set_topology( not_mounted );
- }
-
- public boolean is_mounted(){
- return
- current_topology != null
- && current_topology != not_mounted;
- }
-
- // Implementation of instance interface.
-
- protected interface TopoIface{
- boolean can_read();
- Object read();
- boolean can_step();
- void step();
- Topology topology();
- }
-
- // Initially, the tape has not been mounted.
- protected class NotMounted implements TopoIface{
- @Override public boolean can_read(){
- return false;
- }
- @Override public Object read(){
- throw new UnsupportedOperationException("Ariadne_SRTM::NotMounted::read.");
- }
- @Override public boolean can_step(){
- return false;
- }
- @Override public void step(){
- throw new UnsupportedOperationException("Ariadne_SRTM::NotMounted::step.");
- }
- @Override public Topology topology(){
- throw new UnsupportedOperationException("Ariadne_SRTM::NotMounted::topology.");
- }
- }
-
- // Sets the tape access methods to be used.
- protected void set_topology(TopoIface new_topology){
- current_topology = new_topology;
- }
-
- public boolean can_read(){
- return current_topology.can_read();
- }
-
- public Object read(){
- return current_topology.read();
- }
-
- public boolean can_step(){
- return current_topology.can_step();
- }
-
- public void step(){
- current_topology.step();
- }
-
- public Topology topology(){
- return current_topology.topology();
- }
-
-}
-
+++ /dev/null
-/*
-Ariadne_SRTM with index
-
-*/
-
-package com.ReasoningTechnology.Ariadne;
-import java.math.BigInteger;
-
-public abstract class Ariadne_SRTMI extends Ariadne_SRTM{
-
- private BigInteger current_index;
-
- public Ariadne_SRTMI(){
- this.current_index = BigInteger.ZERO;
- }
-
- public BigInteger index(){
- return current_index;
- }
-
- public void increment(){
- current_index = current_index.add(BigInteger.ONE);
- }
-}
+++ /dev/null
-package com.ReasoningTechnology.Ariadne;
-
-import java.math.BigInteger;
-import java.util.List;
-
-public class Ariadne_SRTMI_Array<T> extends Ariadne_SRTMI{
-
- // Static methods
- //
-
- public static <T> Ariadne_SRTMI_Array<T> make(List<T> array){
- return new Ariadne_SRTMI_Array<>(array);
- }
-
- // Instance data
- //
-
- 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_SRTMI_Array(List<T> array){
- super();
- this.array = array;
-
- if( array == null || array.isEmpty() ){
- set_topology( topo_null );
- return;
- }
-
- if( array.size() == 1 ){
- set_topology( topo_rightmost );
- return;
- }
-
- 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;
- }
- }
-
- // TopoSegment
- private class TopoSegment implements TopoIface{
- @Override public boolean can_read(){
- return true;
- }
- @Override public Object read(){
- return array.get( index().intValueExact() );
- }
- @Override public boolean can_step(){
- return true;
- }
- @Override public void step(){
- increment();
- if( index().compareTo(BigInteger.valueOf(array.size() - 1)) == 0 )
- set_topology(topo_rightmost);
- }
- @Override public Topology topology(){
- return Topology.SEGMENT;
- }
- }
-
- // TopoRightmost
- private class TopoRightmost implements TopoIface{
- @Override public boolean can_read(){
- return true;
- }
- @Override public Object read(){
- return array.get( index().intValueExact() );
- }
- @Override public boolean can_step(){
- return false;
- }
- @Override public void step(){
- throw new UnsupportedOperationException( "Cannot step from RIGHTMOST topo." );
- }
- @Override public Topology topology(){
- return Topology.RIGHTMOST;
- }
- }
-}
+++ /dev/null
-/*
-Graph nodes are referenced by their labels.
-
-*/
-
-package com.ReasoningTechnology.Ariadne;
-
-public class Ariadne_SRTM_Label extends Ariadne_SRTM {
-
- public static Ariadne_SRTM_Label make(){
- return new Ariadne_SRTM_Label();
- }
-
- @Override public Ariadne_Label read(){
- return (Ariadne_Label)super.read();
- }
-
-}
+++ /dev/null
-/*
- By convention an SRTM is named after the type of values found in the tape cells.
- However, in this case the name reflects the type that that SRTM is made from.
- The type of values found in the SRTM cells is abstracted as "T".
-
- This implementation uses Java's ListIterator, which lacks a direct
- method to read the current cell value, rather it yields the next
- cell value upon advancing the iterator.
-*/
-package com.ReasoningTechnology.Ariadne;
-import java.util.List;
-import java.util.ListIterator;
-
-public class Ariadne_SRTM_List<T> extends Ariadne_SRTM{
-
- // Static methods
- //
-
- public static <T> Ariadne_SRTM_List<T> make(List<T> list) {
- return new Ariadne_SRTM_List<>(list);
- }
-
- // instance data
- //
-
- 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 topo_null = new TopoNull();
- private final TopoIface topo_segment = new TopoSegment();
- private final TopoIface topo_rightmost = new TopoRightmost();
-
- // constructor(s)
- //
-
- protected Ariadne_SRTM_List(List<T> list){
- this.list = list;
-
- if( list == null || list.isEmpty() ){
- this.iterator = null;
- set_topology(topo_null);
- return;
- }
-
- this.iterator = list.listIterator();
- read_value = iterator.next();
-
- if( list.size() == 1 ){
- set_topology(topo_rightmost);
- return;
- }
-
- set_topology(topo_segment);
- }
-
- // instance interface implementation
- //
-
- @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{
- @Override public boolean can_read(){
- return true;
- }
- @Override public T read(){
- return (T)read_value;
- }
- @Override public boolean can_step(){
- return true;
- }
- @Override public void step(){
- read_value = iterator.next();
- if( !iterator.hasNext() ) set_topology(topo_rightmost);
- }
- @Override public Topology topology(){
- return Topology.SEGMENT;
- }
- }
-
- private class TopoRightmost implements TopoIface{
- @Override public boolean can_read(){
- return true;
- }
- @Override public T read(){
- return read_value;
- }
- @Override public boolean can_step(){
- return false;
- }
- @Override public void step(){
- throw new UnsupportedOperationException( "Cannot step from RIGHTMOST topo." );
- }
- @Override public Topology topology(){
- return Topology.RIGHTMOST;
- }
- }
-}
-
-
+++ /dev/null
-package com.ReasoningTechnology.Ariadne;
-
-import java.util.Iterator;
-import java.util.Set;
-
-public class Ariadne_SRTM_Set<T> extends Ariadne_SRTM{
-
- // Static factory method
- public static <T> Ariadne_SRTM_Set<T> make(Set<T> set){
- return new Ariadne_SRTM_Set<>(set);
- }
-
- // Instance data
- private final Set<T> set;
- private final Iterator<T> iterator;
- private T current_value;
-
- private final TopoIface topo_null = new TopoNull();
- private final TopoIface topo_segment = new TopoSegment();
- private final TopoIface topo_rightmost = new TopoRightmost();
-
- // Constructor
- protected Ariadne_SRTM_Set(Set<T> set){
- this.set = set;
-
- if( set == null || set.isEmpty() ){
- this.iterator = null;
- set_topology(topo_null);
- return;
- }
-
- this.iterator = set.iterator();
- this.current_value = iterator.hasNext() ? iterator.next() : null;
-
- if( set.size() == 1 ){
- set_topology(topo_rightmost);
- }else{
- set_topology(topo_segment);
- }
- }
-
- // Instance interface implementation
-
- @Override
- @SuppressWarnings("unchecked")
- public T read(){
- return (T)current_topology.read();
- }
-
- 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 from NULL topo.");
- }
- @Override public Topology topology(){
- return Topology.NULL;
- }
- }
-
- private class TopoSegment implements TopoIface{
- @Override public boolean can_read(){
- return true;
- }
- @Override public T read(){
- return current_value;
- }
- @Override public boolean can_step(){
- return iterator.hasNext();
- }
- @Override public void step(){
- current_value = iterator.next();
- if( !iterator.hasNext() ) set_topology(topo_rightmost);
- }
- @Override public Topology topology(){
- return Topology.SEGMENT;
- }
- }
-
- private class TopoRightmost implements TopoIface{
- @Override public boolean can_read(){
- return true;
- }
- @Override public T read(){
- return current_value;
- }
- @Override public boolean can_step(){
- return false;
- }
- @Override public void step(){
- throw new UnsupportedOperationException("Cannot step from RIGHTMOST topo.");
- }
- @Override public Topology topology(){
- return Topology.RIGHTMOST;
- }
- }
-}