/*
Step Right Tape Machine
- Depending how the undefined methods here are defined, the ND_SR_TM can
+ Depending how the undefined methods here are defined, the TM_SR_ND can
equally be a finite iterator, a generator, or an infinite stream.
This is for single-threaded execution. The multi-threaded model
*/
package com.ReasoningTechnology.Ariadne;
-public class Ariadne_ND_SR_TM{
+public class Ariadne_TM_SR_ND{
// static
//
,INFINITE
}
- public static Ariadne_ND_SR_TM make(){
- return new Ariadne_ND_SR_TM();
+ public static Ariadne_TM_SR_ND make(){
+ return new Ariadne_TM_SR_ND();
}
// instance data
// constructor(s)
//
- protected Ariadne_ND_SR_TM(){
+ protected Ariadne_TM_SR_ND(){
set_topology( not_mounted );
}
return false;
}
@Override public Object read(){
- throw new UnsupportedOperationException("Ariadne_ND_SR_TM::NotMounted::read.");
+ throw new UnsupportedOperationException("Ariadne_TM_SR_ND::NotMounted::read.");
}
@Override public boolean can_step(){
return false;
}
@Override public void step(){
- throw new UnsupportedOperationException("Ariadne_ND_SR_TM::NotMounted::step.");
+ throw new UnsupportedOperationException("Ariadne_TM_SR_ND::NotMounted::step.");
}
@Override public Topology topology(){
- throw new UnsupportedOperationException("Ariadne_ND_SR_TM::NotMounted::topology.");
+ throw new UnsupportedOperationException("Ariadne_TM_SR_ND::NotMounted::topology.");
}
}
Aeloria
/*
- IndexTree_ND_SR_TM_Diagonal
+ IndexTree_TM_SR_ND_Diagonal
An index tree is infinite.
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
-import com.ReasoningTechnology.Ariadne.Ariadne_ND_SR_TM;
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND;
import com.ReasoningTechnology.Ariadne.IndexTree_Node;
-public class IndexTree_ND_SR_TM_Diagonal extends Ariadne_ND_SR_TM_Label {
+public class IndexTree_TM_SR_ND_Diagonal extends Ariadne_TM_SR_ND_Label {
// Static
- public static IndexTree_ND_SR_TM_Diagonal make(){
- return new IndexTree_ND_SR_TM_Diagonal();
+ public static IndexTree_TM_SR_ND_Diagonal make(){
+ return new IndexTree_TM_SR_ND_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_ND_SR_TM_Label breadth_srm;
+ private final Ariadne_TM_SR_ND_Label breadth_srm;
// Constructor
- protected IndexTree_ND_SR_TM_Diagonal(){
+ protected IndexTree_TM_SR_ND_Diagonal(){
list_of__unopened_node = new ArrayList<>();
list_of__opened_incomplete_child_list = new ArrayList<>();
read_list = new ArrayList<>();
- breadth_srm = Ariadne_ND_SR_TM_Label.make();
+ breadth_srm = Ariadne_TM_SR_ND_Label.make();
enqueue_root();
}Aeloria
// Retrieve the node using lookup
IndexTree_Node node = lookup( label );
- // Mount a new breadth-first ND_SR_TM for children
+ // Mount a new breadth-first TM_SR_ND for children
breadth_srm.mount( node.neighbor() );
if( breadth_srm.can_read() ){
-import com.ReasoningTechnology.Ariadne.Ariadne_ND_SR_TM;
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND;
import java.math.BigInteger;
-public class CountingNumber extends Ariadne_ND_SR_TM{
+public class CountingNumber extends Ariadne_TM_SR_ND{
// Static
//
-import com.ReasoningTechnology.Ariadne.Ariadne_ND_SR_TM;
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND;
import java.math.BigInteger;
public class CountingNumber_0_CLI{
if( !n.can_read() ) return;
- if( n.topology() == Ariadne_ND_SR_TM.Topology.SEGMENT ){
+ if( n.topology() == Ariadne_TM_SR_ND.Topology.SEGMENT ){
do{
System.out.println("Current Number: " + n.read());
if( !n.can_step() ) break;
n.step();
}while( true );
- }else if( n.topology() == Ariadne_ND_SR_TM.Topology.INFINITE ){
+ }else if( n.topology() == Ariadne_TM_SR_ND.Topology.INFINITE ){
int count = 0;
do{
System.out.println("Current Number: " + n.read());
+++ /dev/null
-package com.ReasoningTechnology.Ariadne;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class SRTM_Depth extends Ariadne_SRTM {
-
- // Static method to create a depth traversal SRTM
- public static SRTM_Depth make(Ariadne_Graph graph){
- SRTM_Depth depth = new SRTM_Depth();
- depth.path.add(graph.start());
- depth.descent();
- return depth;
- }
-
- // Instance data
- private final List<Ariadne_SRTM> path;
-
- private final TopoIface topo_null = new TopoNull();
- private final TopoIface topo_segment = new TopoSegment();
-
- // Constructor
- protected SRTM_Depth(){
- this.path = new ArrayList<>();
- set_topology(topo_null);
- }
-
- // Descends to the leftmost unvisited node
- protected void descent(){
- while( true ){
- Ariadne_SRTM current = path.get(path.size() - 1);
- if( !current.can_read() ){
- backtrack();
- if( path.isEmpty() ) return; // No more nodes to traverse
- continue;
- }
-
- Ariadne_SRTM neighbors = current.read(); // Get neighbor SRTM
- if( neighbors == null || !neighbors.can_read() ){
- backtrack();
- if( path.isEmpty() ) return;
- continue;
- }
-
- path.add(neighbors);
- set_topology(topo_segment);
- }
- }
-
- // Backtracks to the previous node
- protected void backtrack(){
- while( !path.isEmpty() ){
- Ariadne_SRTM last = path.get(path.size() - 1);
- last.step();
- if( last.can_step() ){
- return;
- }
- path.remove(path.size() - 1);
- }
- set_topology(topo_null);
- }
-
- // Steps to the next node in the traversal
- @Override
- public void step(){
- descent();
- }
-
- // Reads the current node
- @Override
- public Ariadne_SRTM read(){
- return path.isEmpty() ? null : path.get(path.size() - 1);
- }
-
- // Checks if traversal can continue
- @Override
- public boolean can_read(){
- return current_topology.can_read();
- }
-
- // Topology: Null
- private class TopoNull implements 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 from NULL topology.");
- }
- @Override public Topology topology(){
- return Topology.NULL;
- }
- }
-
- // Topology: Segment
- private class TopoSegment implements TopoIface{
- @Override public boolean can_read(){
- return true;
- }
- @Override public Object read(){
- return path.get(path.size() - 1);
- }
- @Override public boolean can_step(){
- return !path.isEmpty();
- }
- @Override public void step(){
- descent();
- }
- @Override public Topology topology(){
- return Topology.SEGMENT;
- }
- }
-}
+++ /dev/null
-/*
-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 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
-`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 `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
-descending again.
-
-Nodes are referenced by label.
-
-A null valued label is flagged as an error, though we still look it up
-in the graph. It is a fatal error, `exit(1)` if `lookup` returns a
-null node.
-
-A `path` is a list of nodes (each referenced by a label). `context_path`
-carries with it the child list for each node in the path. The child
-list is represented as a srtm, and the head of the tape machine marks
-the child node that is no the path.
-
-*/
-
-import java.util.HashMap;
-
-import com.ReasoningTechnology.Ariadne.Ariadne_ND_SR_TM;
-import com.ReasoningTechnology.Ariadne.Ariadne_Graph;
-
-class ND_SR_TM_Depth{
-
- // static
- //
- 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() );
- boolean flag = complete_context_path();
- if( flag ) return depth;
- return null;
- }
-
- // instance data
- //
- protected Graph graph = null;
- protected List<Ariadne_ND_SR_TM> context_path = new ArrayList<>();
- protected Label cycle_node_label = null;
-
- // constructor
- //
- 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("ND_SR_TM_Depth::complete_context_path empty context_path");
- return false;
- }
-
- private final HashSet<Label> path_node_label_set = new HashSet<>();
- boolean is_cycle_node = false;
-
- // should add cycle check for anomalous case caller fed us an initial path with a cycle
- // initialize the path_node set
- 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
- do{
- child_srtm = context_path_srtm.read();
- path_node_label = child_srtm.read();
- if(path_node_label == null){
- 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
- (
- "ND_SR_TM_Depth::complete_context_path: cycle found in initial context_path"
- );
- cycle_node_label = path_node_label;
- return false;
- }
- path_node_label_set.add( path_node_label );
- // when completing from the `start()`, this will be break out on the first try
- if( !context_path_srtm.can_step() ) break;
- context_path_srtm.step();
- }while(true);
-
- // path descends down the left side of the unvisted portion of the tree.
- // extend the context_path downward until leftmost is a leaf node or a cycle node
- Ariadne_Node path_node = null;
- boolean is_leaf_node = null;
- do{
- path_node = graph.lookup(path_node_label);
- if(path_node == null){
- System.out.println
- (
- "ND_SR_TM_Depth::complete_context_path node not found in graph for: label(\""
- + path_node_label
- + "\")"
- );
- return false;
- }
-
- // descend
- child_srtm = path_node.neighbor();
-
- // exit conditions
- //
- is_leaf_node = child_srtm == null || !child_srtm.can_read();
- if(is_leaf_node) return true;
- //
- path_node_label = child_srtm.read();
- is_cycle_node = path_node_label_set.contains(path_node_label);
- if( is_cycle_node ){
- // caller needs to check for cycle found before each new step
- cycle_node_label = path_node_label;
- return true;
- }
-
- // path_node_label has now been visited
- path_node_label_set.add(path_node_label);
-
- }while(true);
- }
-
- // being a good object citizen
- //
-
-
-}
--- /dev/null
+/*
+TM_SR_ND_Depth is a list of neighbor TM_SR_NDs 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 TM_SR_ND for iterating over the
+node's neighbors. An TM_SR_ND 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
+`TM_SR_ND_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 `TM_SR_ND_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
+descending again.
+
+Nodes are referenced by label.
+
+A null valued label is flagged as an error, though we still look it up
+in the graph. It is a fatal error, `exit(1)` if `lookup` returns a
+null node.
+
+A `path` is a list of nodes (each referenced by a label). `context_path`
+carries with it the child list for each node in the path. The child
+list is represented as a srtm, and the head of the tape machine marks
+the child node that is no the path.
+
+*/
+
+import java.util.HashMap;
+
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND;
+import com.ReasoningTechnology.Ariadne.Ariadne_Graph;
+
+class TM_SR_ND_Depth{
+
+ // static
+ //
+ TM_SR_ND_Depth make(Graph graph){
+ TM_SR_ND_Depth depth = new TM_SR_ND_Depth();
+ if(graph == null) return null;
+ depth.graph = graph;
+ depth.context_path.add( graph.start() );
+ boolean flag = complete_context_path();
+ if( flag ) return depth;
+ return null;
+ }
+
+ // instance data
+ //
+ protected Graph graph = null;
+ protected List<Ariadne_TM_SR_ND> context_path = new ArrayList<>();
+ protected Label cycle_node_label = null;
+
+ // constructor
+ //
+ protected TM_SR_ND_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("TM_SR_ND_Depth::complete_context_path empty context_path");
+ return false;
+ }
+
+ private final HashSet<Label> path_node_label_set = new HashSet<>();
+ boolean is_cycle_node = false;
+
+ // should add cycle check for anomalous case caller fed us an initial path with a cycle
+ // initialize the path_node set
+ Ariadne_TM_SR_ND_Array<Ariadne_TM_SR_ND> context_path_srtm = Ariadne_TM_SR_ND_Array.make(context_path);
+ Ariadne_TM_SR_ND_List<label> child_srtm = null;
+ Label path_node_label = null;
+
+ // context_path is known not to be empty, so can_read() is true
+ do{
+ child_srtm = context_path_srtm.read();
+ path_node_label = child_srtm.read();
+ if(path_node_label == null){
+ System.out.println("TM_SR_ND_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
+ (
+ "TM_SR_ND_Depth::complete_context_path: cycle found in initial context_path"
+ );
+ cycle_node_label = path_node_label;
+ return false;
+ }
+ path_node_label_set.add( path_node_label );
+ // when completing from the `start()`, this will be break out on the first try
+ if( !context_path_srtm.can_step() ) break;
+ context_path_srtm.step();
+ }while(true);
+
+ // path descends down the left side of the unvisted portion of the tree.
+ // extend the context_path downward until leftmost is a leaf node or a cycle node
+ Ariadne_Node path_node = null;
+ boolean is_leaf_node = null;
+ do{
+ path_node = graph.lookup(path_node_label);
+ if(path_node == null){
+ System.out.println
+ (
+ "TM_SR_ND_Depth::complete_context_path node not found in graph for: label(\""
+ + path_node_label
+ + "\")"
+ );
+ return false;
+ }
+
+ // descend
+ child_srtm = path_node.neighbor();
+
+ // exit conditions
+ //
+ is_leaf_node = child_srtm == null || !child_srtm.can_read();
+ if(is_leaf_node) return true;
+ //
+ path_node_label = child_srtm.read();
+ is_cycle_node = path_node_label_set.contains(path_node_label);
+ if( is_cycle_node ){
+ // caller needs to check for cycle found before each new step
+ cycle_node_label = path_node_label;
+ return true;
+ }
+
+ // path_node_label has now been visited
+ path_node_label_set.add(path_node_label);
+
+ }while(true);
+ }
+
+ // being a good object citizen
+ //
+
+
+}
protected Graph(){
}
- @Override public ND_SR_TM_Child start(){
+ @Override public TM_SR_ND_Child start(){
Label root_label = Label.root();
- return ND_SR_TM_Child.make(root_label);
+ return TM_SR_ND_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_ND_SR_TM_List;
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND_List;
public class Label implements Ariadne_Label{
StringBuilder formatted = new StringBuilder("Label([");
- // 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));
+ // Use precise loop with TM_SR_ND_List to iterate
+ Ariadne_TM_SR_ND_List<BigInteger> value_srtm = Ariadne_TM_SR_ND_List.make(Arrays.asList(value));
if(value_srtm.can_read()){
do{
formatted.append(value_srtm.read().toString());
first_child_label.inc_down();
}
- @Override public ND_SR_TM_Child neighbor(){
- return ND_SR_TM_Child.make(first_child_label);
+ @Override public TM_SR_ND_Child neighbor(){
+ return TM_SR_ND_Child.make(first_child_label);
}
}
+++ /dev/null
-/*
-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.
-
-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_ND_SR_TM_Label;
-
-public class ND_SR_TM_Child extends Ariadne_ND_SR_TM_Label{
-
- // Static
- //
-
- public static ND_SR_TM_Child make( Label leftmost_child_label ){
- return new ND_SR_TM_Child( leftmost_child_label );
- }
-
- // Instance data
- //
-
- // Label is a container of co-ordinates to a node, so the only thing 'final'
- // is the container, not its contents.
- private final Label label;
-
- // Constructor(s)
- //
-
- protected ND_SR_TM_Child( Label leftmost_child_label ){
- this.label = leftmost_child_label.copy();
-
- if( label == null ){
- set_topology(topo_null);
- return;
- }
-
- // the label for the root node is an empty array, "[]"
- if( label.length() == 0){
- set_topology(topo_rightmost);
- return;
- }
-
- set_topology(topo_infinite_right);
- }
-
- // Implementation of the instance interface
- //
-
- @Override public Label read(){
- return (Label)super.read();
- }
-
- private 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 from NULL topology." );
- }
- @Override public Topology topology(){
- return Topology.NULL;
- }
- };
-
- private final TopoIface topo_infinite_right = new TopoIface(){
- @Override public boolean can_read(){
- return true;
- }
- @Override public Object read(){
- return label;
- }
- @Override public boolean can_step(){
- return true;
- }
- @Override public void step(){
- label.inc_across();
- }
- @Override public Topology topology(){
- return Topology.INFINITE;
- }
- };
-
- private final TopoIface topo_rightmost = new TopoIface(){
- @Override public boolean can_read(){
- return true;
- }
- @Override public Object read(){
- return label;
- }
- @Override public boolean can_step(){
- return false;
- }
- @Override public void step(){
- throw new UnsupportedOperationException( "Cannot step from RIGHTMOST topology." );
- }
- @Override public Topology topology(){
- return Topology.RIGHTMOST;
- }
- };
-
-}
+++ /dev/null
-/*
-Diagonal traversal is guaranteed to reach any given node in the IndexTree
-in a finite number of steps. Neither depth first, nor breadth first
-can do this. This guarantee also applies to a pruned IndexTree.
-
-This implementation is nearly ready, to be included in the Ariadne
-library for generalized diagonal traversal. I have abstracted out all
-references to the IndexTree. It still needs to remove child lists that
-have been completely reversed from the child_srtm_list. This was not
-needed for the IndexTree because it is infinite, so they will never be
-completely traversed. Also needed, is to stop when a node does not
-have a child list. Again, this is not needed here because the
-IndexTree has infinite depth. When the generalized diagonal iterator
-is ready, it could be used in place of this one.
-
-*/
-
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.List;
-
-import com.ReasoningTechnology.Ariadne.Ariadne_Test;
-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 ND_SR_TM_Diagonal extends Ariadne_ND_SR_TM{
-
- // Static
- //
-
- 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<ND_SR_TM_Child> child_srtm_list = new ArrayList<>();
-
- // Constructor(s)
- //
-
- // the diagonal will never be null nor empty
- protected ND_SR_TM_Diagonal(Label start_node){
-
- if( start_node == null ){
- set_topology(topo_null);
- return;
- }
-
- set_topology(topo_infinite_right);
- diagonal.add(start_node);
- }
-
- // Implementation of instance interface
- //
-
- @Override
- public String toString(){
- 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{
- formatted.append(diagonal_srtm.read().toString());
- if( !diagonal_srtm.can_step() ) break;
- diagonal_srtm.step();
- formatted.append(" ,");
- }while(true);
- }
-
- formatted.append(")");
- return formatted.toString();
- }
-
-
- @Override
- @SuppressWarnings("unchecked")
- public List<Label> read(){
- return (List<Label>)super.read(); // Cast to ensure type consistency
- }
-
- private 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 from NULL topology." );
- }
- @Override public Topology topology(){
- return Topology.NULL;
- }
- };
-
- private final TopoIface topo_infinite_right = new TopoIface(){
- @Override public boolean can_read(){
- return true;
- }
- @Override public List read(){
- return diagonal;
- }
- @Override public boolean can_step(){
- return true;
- }
-
- @Override public void step(){
-
- List<Label> diagonal_1 = new ArrayList<>();
-
- // inc_down from each node on diagonal_0 -> entry on child_srtm list
- 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());
- child_srtm_list.add(node.neighbor()); // graph node neighbor == tree node child
- if( !diagonal_srtm.can_step() ) break;
- diagonal_srtm.step();
- }while(true);
- }
-
- // add to diagonal_1 from each on entry on the 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{
- ND_SR_TM_Child child_srtm = child_srtm_srtm.read();
- Label label = child_srtm.read();
- diagonal_1.add(label.copy());
- child_srtm.step();
- if( !child_srtm_srtm.can_step() ) break;
- child_srtm_srtm.step();
- }while(true);
- }
-
- // Update the state for the next step
- diagonal = diagonal_1;
- }
-
- @Override public Topology topology(){
- return Topology.INFINITE;
- }
-
- };
-}
-
+++ /dev/null
-import java.util.List;
-
-public class ND_SR_TM_Diagonal_CLI{
-
- public static void main(String[] args){
- System.out.println("Starting IndexTree ND_SR_TM Example");
-
- // Instantiate the IndexTree Diagonal ND_SR_TM
- Graph g = Graph.make();
- 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);
- ND_SR_TM_Diagonal srtm = ND_SR_TM_Diagonal.make(start_label);
- int step_count = 0;
- if( srtm.can_read() ){
- do{
- System.out.println(step_count + ": " + srtm.read());
- if( !srtm.can_step() ) break;
- if( step_count == 4 ) break; // Stop after 5 diagonals
- step_count++;
- srtm.step();
- }while(true);
- }
- if( !start_srtm.can_step() ) break;
- System.out.println();
- start_srtm.step();
- }while(true);
-
- }
-
-}
-
+++ /dev/null
-Starting IndexTree SRTM Example
-Graph diagonalization starting from: Label([])
-0: [Label([])]
-1: [Label([0])]
-2: [Label([1]), Label([0 ,0])]
-3: [Label([2]), Label([0 ,1]), Label([1 ,0]), Label([0 ,0 ,0])]
-4: [Label([3]), Label([0 ,2]), Label([1 ,1]), Label([0 ,0 ,1]), Label([2 ,0]), Label([0 ,1 ,0]), Label([1 ,0 ,0]), Label([0 ,0 ,0 ,0])]
--- /dev/null
+/*
+TM_SR_ND_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.
+
+TM_SR_ND_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_TM_SR_ND_Label;
+
+public class TM_SR_ND_Child extends Ariadne_TM_SR_ND_Label{
+
+ // Static
+ //
+
+ public static TM_SR_ND_Child make( Label leftmost_child_label ){
+ return new TM_SR_ND_Child( leftmost_child_label );
+ }
+
+ // Instance data
+ //
+
+ // Label is a container of co-ordinates to a node, so the only thing 'final'
+ // is the container, not its contents.
+ private final Label label;
+
+ // Constructor(s)
+ //
+
+ protected TM_SR_ND_Child( Label leftmost_child_label ){
+ this.label = leftmost_child_label.copy();
+
+ if( label == null ){
+ set_topology(topo_null);
+ return;
+ }
+
+ // the label for the root node is an empty array, "[]"
+ if( label.length() == 0){
+ set_topology(topo_rightmost);
+ return;
+ }
+
+ set_topology(topo_infinite_right);
+ }
+
+ // Implementation of the instance interface
+ //
+
+ @Override public Label read(){
+ return (Label)super.read();
+ }
+
+ private 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 from NULL topology." );
+ }
+ @Override public Topology topology(){
+ return Topology.NULL;
+ }
+ };
+
+ private final TopoIface topo_infinite_right = new TopoIface(){
+ @Override public boolean can_read(){
+ return true;
+ }
+ @Override public Object read(){
+ return label;
+ }
+ @Override public boolean can_step(){
+ return true;
+ }
+ @Override public void step(){
+ label.inc_across();
+ }
+ @Override public Topology topology(){
+ return Topology.INFINITE;
+ }
+ };
+
+ private final TopoIface topo_rightmost = new TopoIface(){
+ @Override public boolean can_read(){
+ return true;
+ }
+ @Override public Object read(){
+ return label;
+ }
+ @Override public boolean can_step(){
+ return false;
+ }
+ @Override public void step(){
+ throw new UnsupportedOperationException( "Cannot step from RIGHTMOST topology." );
+ }
+ @Override public Topology topology(){
+ return Topology.RIGHTMOST;
+ }
+ };
+
+}
--- /dev/null
+/*
+Diagonal traversal is guaranteed to reach any given node in the IndexTree
+in a finite number of steps. Neither depth first, nor breadth first
+can do this. This guarantee also applies to a pruned IndexTree.
+
+This implementation is nearly ready, to be included in the Ariadne
+library for generalized diagonal traversal. I have abstracted out all
+references to the IndexTree. It still needs to remove child lists that
+have been completely reversed from the child_srtm_list. This was not
+needed for the IndexTree because it is infinite, so they will never be
+completely traversed. Also needed, is to stop when a node does not
+have a child list. Again, this is not needed here because the
+IndexTree has infinite depth. When the generalized diagonal iterator
+is ready, it could be used in place of this one.
+
+*/
+
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.List;
+
+import com.ReasoningTechnology.Ariadne.Ariadne_Test;
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND;
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND_Label;
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND_List;
+import com.ReasoningTechnology.Ariadne.Ariadne_Node;
+import com.ReasoningTechnology.Ariadne.Ariadne_Label;
+
+public class TM_SR_ND_Diagonal extends Ariadne_TM_SR_ND{
+
+ // Static
+ //
+
+ public static TM_SR_ND_Diagonal make(Label start_node){
+ return new TM_SR_ND_Diagonal(start_node);
+ }
+
+ // Instance data
+ //
+
+ private List<Label> diagonal = new ArrayList<>(); // the read value
+ private final List<TM_SR_ND_Child> child_srtm_list = new ArrayList<>();
+
+ // Constructor(s)
+ //
+
+ // the diagonal will never be null nor empty
+ protected TM_SR_ND_Diagonal(Label start_node){
+
+ if( start_node == null ){
+ set_topology(topo_null);
+ return;
+ }
+
+ set_topology(topo_infinite_right);
+ diagonal.add(start_node);
+ }
+
+ // Implementation of instance interface
+ //
+
+ @Override
+ public String toString(){
+ StringBuilder formatted = new StringBuilder("TM_SR_ND_Diagonal(");
+ Ariadne_TM_SR_ND_List<Label> diagonal_srtm = Ariadne_TM_SR_ND_List.make(diagonal);
+
+ if( diagonal_srtm.can_read() ){
+ do{
+ formatted.append(diagonal_srtm.read().toString());
+ if( !diagonal_srtm.can_step() ) break;
+ diagonal_srtm.step();
+ formatted.append(" ,");
+ }while(true);
+ }
+
+ formatted.append(")");
+ return formatted.toString();
+ }
+
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public List<Label> read(){
+ return (List<Label>)super.read(); // Cast to ensure type consistency
+ }
+
+ private 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 from NULL topology." );
+ }
+ @Override public Topology topology(){
+ return Topology.NULL;
+ }
+ };
+
+ private final TopoIface topo_infinite_right = new TopoIface(){
+ @Override public boolean can_read(){
+ return true;
+ }
+ @Override public List read(){
+ return diagonal;
+ }
+ @Override public boolean can_step(){
+ return true;
+ }
+
+ @Override public void step(){
+
+ List<Label> diagonal_1 = new ArrayList<>();
+
+ // inc_down from each node on diagonal_0 -> entry on child_srtm list
+ Ariadne_TM_SR_ND_List<Label> diagonal_srtm = Ariadne_TM_SR_ND_List.make(diagonal);
+ if( diagonal_srtm.can_read() ){
+ do{
+ Node node = Node.make(diagonal_srtm.read());
+ child_srtm_list.add(node.neighbor()); // graph node neighbor == tree node child
+ if( !diagonal_srtm.can_step() ) break;
+ diagonal_srtm.step();
+ }while(true);
+ }
+
+ // add to diagonal_1 from each on entry on the child_srtm list
+ Ariadne_TM_SR_ND_List<TM_SR_ND_Child> child_srtm_srtm = Ariadne_TM_SR_ND_List.make(child_srtm_list);
+ if( child_srtm_srtm.can_read() ){
+ do{
+ TM_SR_ND_Child child_srtm = child_srtm_srtm.read();
+ Label label = child_srtm.read();
+ diagonal_1.add(label.copy());
+ child_srtm.step();
+ if( !child_srtm_srtm.can_step() ) break;
+ child_srtm_srtm.step();
+ }while(true);
+ }
+
+ // Update the state for the next step
+ diagonal = diagonal_1;
+ }
+
+ @Override public Topology topology(){
+ return Topology.INFINITE;
+ }
+
+ };
+}
+
--- /dev/null
+import java.util.List;
+
+public class TM_SR_ND_Diagonal_CLI{
+
+ public static void main(String[] args){
+ System.out.println("Starting IndexTree TM_SR_ND Example");
+
+ // Instantiate the IndexTree Diagonal TM_SR_ND
+ Graph g = Graph.make();
+ TM_SR_ND_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);
+ TM_SR_ND_Diagonal srtm = TM_SR_ND_Diagonal.make(start_label);
+ int step_count = 0;
+ if( srtm.can_read() ){
+ do{
+ System.out.println(step_count + ": " + srtm.read());
+ if( !srtm.can_step() ) break;
+ if( step_count == 4 ) break; // Stop after 5 diagonals
+ step_count++;
+ srtm.step();
+ }while(true);
+ }
+ if( !start_srtm.can_step() ) break;
+ System.out.println();
+ start_srtm.step();
+ }while(true);
+
+ }
+
+}
+
--- /dev/null
+Starting IndexTree SRTM Example
+Graph diagonalization starting from: Label([])
+0: [Label([])]
+1: [Label([0])]
+2: [Label([1]), Label([0 ,0])]
+3: [Label([2]), Label([0 ,1]), Label([1 ,0]), Label([0 ,0 ,0])]
+4: [Label([3]), Label([0 ,2]), Label([1 ,1]), Label([0 ,0 ,1]), Label([2 ,0]), Label([0 ,1 ,0]), Label([1 ,0 ,0]), Label([0 ,0 ,0 ,0])]
-import com.ReasoningTechnology.Ariadne.Ariadne_ND_SR_TM;
-import com.ReasoningTechnology.Ariadne.Ariadne_ND_SR_TM_List;
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND;
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND_List;
public class four_down_four_across_CLI{
// Initialize graph and start at root
Graph graph = Graph.make();
- ND_SR_TM_Child start = graph.start();
+ TM_SR_ND_Child start = graph.start();
Label label = start.read();
Node node;
- ND_SR_TM_Child child_srm;
+ TM_SR_ND_Child child_srm;
System.out.println("starting at: " + start.read());
+++ /dev/null
-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 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 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() );
- 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_ND_SR_TM;
-import com.ReasoningTechnology.Ariadne.Ariadne_ND_SR_TM_List;
-
-import java.util.LinkedList;
-
-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( "A" );
- label_list.add( "B" );
- label_list.add( "C" );
-
- // 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() );
- 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_ND_SR_TM_Set;
-
-import java.util.HashSet;
-import java.util.Set;
-
-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("A");
- label_set.add("B");
- label_set.add("C");
-
- // 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() );
- 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 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);
+ }
+ }
+}
protected Ariadne_Graph(){
}
- public Ariadne_ND_SR_TM start(){
+ public Ariadne_TM_SR_ND 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_ND_SR_TM_Label neighbor(){
+ public Ariadne_TM_SR_ND_Label neighbor(){
throw new UnsupportedOperationException("Ariadne_Node::neighbor not implemented in the base class.");
}
// Marks representation
if( !mark_set.isEmpty() ){
- Ariadne_ND_SR_TM_Set srm = Ariadne_ND_SR_TM_Set.make(mark_set);
+ Ariadne_TM_SR_ND_Set srm = Ariadne_TM_SR_ND_Set.make(mark_set);
output.append( " Mark(" );
do{
--- /dev/null
+/*
+An TM_SR_ND with indexing == TM_SR_ND
+
+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 TM_SR_ND machine extensions
+to file system objects.
+
+*/
+
+package com.ReasoningTechnology.Ariadne;
+import java.math.BigInteger;
+
+public abstract class Ariadne_TM_SR_ND extends Ariadne_TM_SR_ND{
+
+ // static
+ //
+
+ public enum Topology{
+ NULL
+ ,CYCLIC
+ ,SEGMENT
+ ,RIGHTMOST
+ ,INFINITE
+ }
+
+ public static Ariadne_TM_SR_ND make(){
+ return new Ariadne_TM_SR_ND();
+ }
+
+ // instance data
+ //
+
+ protected TopoIface current_topology;
+ public final TopoIface not_mounted = new NotMounted();
+ private BigInteger index;
+
+ // constructor(s)
+ //
+
+ public Ariadne_TM_SR_ND(){
+ set_topology( not_mounted );
+ this.index = BigInteger.ZERO;
+ }
+
+ // Implementation of instance interface.
+ //
+
+ public BigInteger head_address(){
+ return index;
+ }
+
+ public Ariadne_TM_SR_ND entangle(){
+ try{
+ Ariadne_TM_SR_ND copy = (Ariadne_TM_SR_ND) 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_TM_SR_ND::NotMounted::read.");
+ }
+ @Override public boolean can_step(){
+ return false;
+ }
+ @Override public void step(){
+ throw new UnsupportedOperationException("Ariadne_TM_SR_ND::NotMounted::step.");
+ }
+ @Override public Topology topology(){
+ throw new UnsupportedOperationException("Ariadne_TM_SR_ND::NotMounted::topology.");
+ }
+ }
+
+
+ // good citizen
+ //
+
+ @Override public String toString(){
+ if(!is_mounted()) return "TM_SR_ND(NotMounted)";
+ if(!can_read()) return "TM_SR_ND(Null)";
+
+ StringBuilder sb = new StringBuilder();
+ sb.append("TM_SR_ND(").append(topology().name()).append("(");
+
+ try{
+ // Clone for traversal
+ Ariadne_TM_SR_ND copy = (Ariadne_TM_SR_ND) 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_TM_SR_ND_Array<T> extends Ariadne_TM_SR_ND{
+
+ // Static methods
+ //
+
+ public static <T> Ariadne_TM_SR_ND_Array<T> make(List<T> array){
+ return new Ariadne_TM_SR_ND_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_TM_SR_ND_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_TM_SR_ND_Label extends Ariadne_TM_SR_ND {
+
+ public static Ariadne_TM_SR_ND_Label make(){
+ return new Ariadne_TM_SR_ND_Label();
+ }
+
+ @Override public Ariadne_Label read(){
+ return (Ariadne_Label)super.read();
+ }
+
+}
--- /dev/null
+/*
+ By convention an TM_SR_ND is named after the type of values found in the tape cells.
+ However, in this case the name reflects the type that that TM_SR_ND is made from.
+ The type of values found in the TM_SR_ND 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_TM_SR_ND_List<T> extends Ariadne_TM_SR_ND{
+
+ // Static methods
+ //
+
+ public static <T> Ariadne_TM_SR_ND_List<T> make(List<T> list) {
+ return new Ariadne_TM_SR_ND_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_TM_SR_ND_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_TM_SR_ND_Set<T> extends Ariadne_TM_SR_ND{
+
+ // Static factory method
+ public static <T> Ariadne_TM_SR_ND_Set<T> make(Set<T> set){
+ return new Ariadne_TM_SR_ND_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_TM_SR_ND_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;
+ }
+ }
+}