2024-12-31T01:47:53Z
The pencil on file names has been working well .. until yesterday. The jvm doesn't like the `exampleđź–‰` directory and refuses to run code in it, so I had to change it to `example`.
+
+ 2024-12-31T01:47:53Z
+
+ The example directory turns out to be mixed content anyway.
+
-Does there exist a node in the tree, such that if that node were marked before the diagonal generating algorithm is run, that that node will never be reached no matter how long the diagonal generating algorithm runs? Or perhaps you can't tell.
+An Index Tree is infinite both in depth and breadth. As a tree is a
+graph, and Index Tree is an infinite graph. The label for each node in
+an index tree is an array of integers that explain how to traverse the
+tree to arrive at the node. `[]` is the root node. `[[0] ,[1] ,[2]
+...] is a list of the children to the root node, etc.
+
+ All parts of a node can be computed from its label. Hence
+ the SRM_Diagonal only manipulates labels.
+
+ Label::inc_down turns a given label into the leftmost
+ child lavel.
+
+ Label::inc_across turns a child label into its right neighbor
+ sibling label.
+
+ An infinite child list is represented by an SRM_Child. The
+ SRM_Child is made from the label for the leftmost child in the
+ list. From each child label it is possible to generate the label for
+ the right neighbor child. This is be done by calling `inc_across()`.
+
+Diagonalization can be used to traverse the infinite Index Tree, while
+always enumerating a next layer of nodes nearest the root. This
+differs from depth first, which would never return to visit the child
+to the right of the leftmost child, and from breadth first, which
+would never descend to the grandchildren level of the tree.
+
+Diagonalization is guaranteed to reach any given node in the tree
+in a finite number of steps. Neither depth first, nor breadth first
+can do this. This guarantee also applies to a pruned IndexTree.
+
+/*
+How diagonalization works:
+
+ This is an infinite object, with each node having an infinite number
+ of children, and there being an infinite number of generations,
+ i.e., levels in the tree.
+
+ Given a label, `inc_across` will turn it into the label for the
+ right neighbor sibling, while `inc_down` will turn it into the label
+ for the leftmost child.
+
+ We compute each next diagonal based on the prior diagonal and a list
+ called 'child_srtm_list'. We do not modify labels in the diagonal
+ directly because the calling program might still be using it. Instead,
+ labels on the diagonal are copied before being modified.
+
+ The diagonalization algorithm systematically alternates between
+ expanding depth (via `inc_down`) and breadth (via `inc_across`),
+ ensuring that every node in the infinite tree is eventually included
+ in a diagonal.
+
+ Initially:
+
+ diagonal is the root node, '[]'.
+ child_srtm_list is empty.
+
+ Each time SRTM_Diagonal is stepped:
+
+ 1. Create a new diagonal_1 and expand the child_srtm_list:
+
+ 1.1 Bind diagonal (current diagonal) to an SRTM.
+ 1.2 For each label in diagonal:
+ 1.2.1 Copy the label.
+ 1.2.2 Apply `inc_down` to the copy to get the leftmost child.
+ 1.2.3 Append this child label to child_srtm_list as a new SRTM_Child.
+
+ 2. Populate diagonal_1 using child_srtm_list:
+
+ 2.1 Bind child_srtm_list to an SRTM.
+ 2.2 For each STRM in the list:
+ 2.2.1 Read the label from the SRTM.
+ 2.2.2 Append a copy of this label to diagonal_1.
+ 2.2.3 if can_step the STRM, the step the head to the next sibling.
+ else remove SRTM from the child_srtm_list. (This removal
+ will never happen on an infinite topology.)
+
+ 3. Update the state for the next step:
+
+ 3.1 Replace diagonal with diagonal_1.
+
+ This algorithm ensures that any given node in the infinite index
+ tree is eventually reached in a finite number of step. It traverses
+ the tree a diagonal manner that alternates between depth and breadth
+ expansion.
+
+
+--------------------------------------------------------------------------------
+What follows is GP providing an outline of a proof that diagonalization will reach any given node on the tree within a finite number of steps. This follows from the construction of the diagonalization, i.e. this was the design goal.
+
+ Does there exist a node in the tree, such that if that node were marked before the diagonal generating algorithm is run, that that node will never be reached no matter how long the diagonal generating algorithm runs? Or perhaps you can't tell.
+
ChatGPT said:
ChatGPT
This is an interesting and profound question that touches on the completeness of the diagonal traversal algorithm in enumerating all nodes in an infinite tree. Let’s analyze it step by step.
+++ /dev/null
-import com.ReasoningTechnology.Ariadne.Ariadne_Graph;
-
-public class Graph extends Ariadne_Graph{
-
- public static Graph make(){
- return new Graph();
- }
- protected Graph(){
- }
-
- @Override public SRTM_Child start(){
- Label root_label = Label.root();
- return SRTM_Child.make(root_label);
- }
-
- // no override, this graph does not lookup Ariadne_Label, only Label
- Node lookup(Label label){
- return Node.make(label);
- }
-
-}
-
+++ /dev/null
-/*
- Implementation of Ariadne_Label for BigInteger array-based labels.
-*/
-import java.math.BigInteger;
-import java.util.Arrays;
-
-import com.ReasoningTechnology.Ariadne.Ariadne_Label;
-import com.ReasoningTechnology.Ariadne.Ariadne_SRTM_List;
-
-
-public class Label implements Ariadne_Label{
-
- // Owned by class
- //
-
- public static Label make(BigInteger[] array){
- return new Label(array);
- }
-
- public static Label root(){
- return new Label(new BigInteger[0]);
- }
-
- // Instance data
- //
-
- private BigInteger[] value;
-
- // Constructor
- //
-
- private Label(BigInteger[] array){
- this.value = array.clone();
- }
-
- // Instance interface implementation
- //
-
- @Override public boolean is_null(){
- return value == null;
- }
- public int length(){
- return value.length;
- }
-
- @Override public Label copy(){
- return new Label(value);
- }
-
- // Increment last element by one, modifying in place
- public void inc_across(){
- if(value == null || value.length == 0){
- throw new UnsupportedOperationException("Cannot increment across an empty array.");
- }
- value[value.length - 1] = value[value.length - 1].add(BigInteger.ONE);
- }
-
- // Append a zero element, modifying in place
- public void inc_down(){
- if(value == null){
- throw new UnsupportedOperationException("Cannot append to a null array.");
- }
- BigInteger[] newValue = Arrays.copyOf(value, value.length + 1);
- newValue[newValue.length - 1] = BigInteger.ZERO;
- value = newValue;
- }
-
- // Good object citizenship
- //
-
- @Override public String toString(){
- if(is_null()) return "Label()";
- if(length() == 0) return "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));
- if(value_srtm.can_read()){
- do{
- formatted.append(value_srtm.read().toString());
- if( !value_srtm.can_step() ) break;
- value_srtm.step();
- formatted.append(" ,");
- }while(true);
- }
-
- formatted.append("])");
- return formatted.toString();
- }
-
- @Override public boolean equals(Object o){
- if(this == o) return true;
- if( o == null || getClass() != o.getClass() ) return false;
- Label that = (Label) o;
- return Arrays.equals(value, that.value);
- }
-
- @Override public int hashCode(){
- return Arrays.hashCode(value);
- }
-}
+++ /dev/null
-import java.util.Arrays;
-import com.ReasoningTechnology.Ariadne.Ariadne_Node;
-
-public class Node extends Ariadne_Node{
-
- public static Node make(Label label){
- return new Node(label);
- }
-
- private final Label first_child_label;
-
- public Node(Label label){
- super(label);
- first_child_label = label.copy();
- first_child_label.inc_down();
- }
-
- @Override public SRTM_Child neighbor(){
- return SRTM_Child.make(first_child_label);
- }
-
-}
+++ /dev/null
-/*
-SRTM_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
-the current label and computes from it the right neighbor sibling
-node's label.
-
-*/
-
-
-import com.ReasoningTechnology.Ariadne.Ariadne_SRTM_Label;
-
-public class SRTM_Child extends Ariadne_SRTM_Label{
-
- // Static
- //
-
- public static SRTM_Child make( Label first_child_label ){
- return new SRTM_Child( first_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 SRTM_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
-/*
-An Index Tree is infinite both in depth and breadth. As a tree is a
-graph, and Index Tree is an infinite graph. The label for each node in
-an index tree is an array of integers that explain how to traverse the
-tree to arrive at the node. `[]` is the root node. `[[0] ,[1] ,[2]
-...] is a list of the children to the root node, etc.
-
- All parts of a node can be computed from its label. Hence
- the SRM_Diagonal only manipulates labels.
-
- Label::inc_down turns a given label into the leftmost
- child lavel.
-
- Label::inc_across turns a child label into its right neighbor
- sibling label.
-
- An infinite child list is represented by an SRM_Child. The
- SRM_Child is made from the label for the leftmost child in the
- list. From each child label it is possible to generate the label for
- the right neighbor child. This is be done by calling `inc_across()`.
-
-Diagonalization can be used to traverse the infinite Index Tree, while
-always enumerating a next layer of nodes nearest the root. This
-differs from depth first, which would never return to visit the child
-to the right of the leftmost child, and from breadth first, which
-would never descend to the grandchildren level of the tree.
-
-/*
-How diagonalization works:
-
- This is an infinite object, with each node having an infinite number
- of children, and there being an infinite number of generations,
- i.e., levels in the tree.
-
- Given a label, `inc_across` will turn it into the label for the
- right neighbor sibling, while `inc_down` will turn it into the label
- for the leftmost child.
-
- We compute each next diagonal based on the prior diagonal and a list
- called 'child_srtm_list'. We do not modify labels in the diagonal
- directly because the calling program might still be using it. Instead,
- labels on the diagonal are copied before being modified.
-
- The diagonalization algorithm systematically alternates between
- expanding depth (via `inc_down`) and breadth (via `inc_across`),
- ensuring that every node in the infinite tree is eventually included
- in a diagonal.
-
- Initially:
-
- diagonal is the root node, '[]'.
- child_srtm_list is empty.
-
- Each time SRTM_Diagonal is stepped:
-
- 1. Create a new diagonal_1 and expand the child_srtm_list:
-
- 1.1 Bind diagonal (current diagonal) to an SRTM.
- 1.2 For each label in diagonal:
- 1.2.1 Copy the label.
- 1.2.2 Apply `inc_down` to the copy to get the leftmost child.
- 1.2.3 Append this child label to child_srtm_list as a new SRTM_Child.
-
- 2. Populate diagonal_1 using child_srtm_list:
-
- 2.1 Bind child_srtm_list to an SRTM.
- 2.2 For each STRM in the list:
- 2.2.1 Read the label from the SRTM.
- 2.2.2 Append a copy of this label to diagonal_1.
- 2.2.3 if can_step the STRM, the step the head to the next sibling.
- else remove SRTM from the child_srtm_list. (This removal
- will never happen on an infinite topology.)
-
- 3. Update the state for the next step:
-
- 3.1 Replace diagonal with diagonal_1.
-
- This algorithm ensures that any given node in the infinite index
- tree is eventually reached in a finite number of step. It traverses
- the tree a diagonal manner that alternates between depth and breadth
- expansion.
-*/
-
-import java.math.BigInteger;
-import java.util.ArrayList;
-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_Node;
-import com.ReasoningTechnology.Ariadne.Ariadne_Label;
-
-public class SRTM_Diagonal extends Ariadne_SRTM{
-
- // Static
- //
-
- public static SRTM_Diagonal make(Label start_node){
- return new SRTM_Diagonal(start_node);
- }
-
- // Instance data
- //
-
- private List<Label> diagonal = new ArrayList<>(); // the read value
- private final List<SRTM_Child> child_srtm_list = new ArrayList<>();
-
- // Constructor(s)
- //
-
- // the diagonal will never be null nor empty
- protected SRTM_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("SRTM_Diagonal(");
- Ariadne_SRTM_List<Label> diagonal_srtm = Ariadne_SRTM_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_strm list
- Ariadne_SRTM_List<Label> diagonal_srtm = Ariadne_SRTM_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_strm list
- Ariadne_SRTM_List<SRTM_Child> child_srtm_srtm = Ariadne_SRTM_List.make(child_srtm_list);
- if( child_srtm_srtm.can_read() ){
- do{
- SRTM_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 SRTM_Diagonal_CLI{
-
- public static void main(String[] args){
- System.out.println("Starting IndexTree SRTM Example");
-
- // Instantiate the IndexTree Diagonal SRTM
- Graph g = Graph.make();
- SRTM_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);
- 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
-import com.ReasoningTechnology.Ariadne.Ariadne_SRTM;
-import com.ReasoningTechnology.Ariadne.Ariadne_SRTM_List;
-
-public class four_down_four_across_CLI{
-
- public static void main(String[] args){
-
- System.out.println("Example_4x4");
-
- // Initialize graph and start at root
- Graph graph = Graph.make();
- SRTM_Child start = graph.start();
- Label label = start.read();
- Node node;
- SRTM_Child child_srm;
-
- System.out.println("starting at: " + start.read());
-
- // Descend 3 more levels
- int i = 1;
- do{
- node = graph.lookup(label);
- child_srm = node.neighbor();
- label = child_srm.read();
- System.out.println("Descended to: " + label.toString());
- if(i == 3) break;
- i++;
- }while(true);
-
- // Move across three more nodes
- i = 1;
- do{
- child_srm.step();
- label = child_srm.read();
- System.out.println("Across to: " + label.toString());
- if(i == 3) break;
- i++;
- }while(true);
-
- }
-}
+++ /dev/null
-Example_4x4
-starting at: Label([])
-Descended to: Label([0])
-Descended to: Label([0 ,0])
-Descended to: Label([0 ,0 ,0])
-Across to: Label([0 ,0 ,1])
-Across to: Label([0 ,0 ,2])
-Across to: Label([0 ,0 ,3])
--- /dev/null
+import com.ReasoningTechnology.Ariadne.Ariadne_Graph;
+
+public class Graph extends Ariadne_Graph{
+
+ public static Graph make(){
+ return new Graph();
+ }
+ protected Graph(){
+ }
+
+ @Override public SRTM_Child start(){
+ Label root_label = Label.root();
+ return SRTM_Child.make(root_label);
+ }
+
+ // no override, this graph does not lookup Ariadne_Label, only Label
+ Node lookup(Label label){
+ return Node.make(label);
+ }
+
+}
+
--- /dev/null
+/*
+ Implementation of Ariadne_Label for BigInteger array-based labels.
+*/
+import java.math.BigInteger;
+import java.util.Arrays;
+
+import com.ReasoningTechnology.Ariadne.Ariadne_Label;
+import com.ReasoningTechnology.Ariadne.Ariadne_SRTM_List;
+
+
+public class Label implements Ariadne_Label{
+
+ // Owned by class
+ //
+
+ public static Label make(BigInteger[] array){
+ return new Label(array);
+ }
+
+ public static Label root(){
+ return new Label(new BigInteger[0]);
+ }
+
+ // Instance data
+ //
+
+ private BigInteger[] value;
+
+ // Constructor
+ //
+
+ private Label(BigInteger[] array){
+ this.value = array.clone();
+ }
+
+ // Instance interface implementation
+ //
+
+ @Override public boolean is_null(){
+ return value == null;
+ }
+ public int length(){
+ return value.length;
+ }
+
+ @Override public Label copy(){
+ return new Label(value);
+ }
+
+ // Increment last element by one, modifying in place
+ public void inc_across(){
+ if(value == null || value.length == 0){
+ throw new UnsupportedOperationException("Cannot increment across an empty array.");
+ }
+ value[value.length - 1] = value[value.length - 1].add(BigInteger.ONE);
+ }
+
+ // Append a zero element, modifying in place
+ public void inc_down(){
+ if(value == null){
+ throw new UnsupportedOperationException("Cannot append to a null array.");
+ }
+ BigInteger[] newValue = Arrays.copyOf(value, value.length + 1);
+ newValue[newValue.length - 1] = BigInteger.ZERO;
+ value = newValue;
+ }
+
+ // Good object citizenship
+ //
+
+ @Override public String toString(){
+ if(is_null()) return "Label()";
+ if(length() == 0) return "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));
+ if(value_srtm.can_read()){
+ do{
+ formatted.append(value_srtm.read().toString());
+ if( !value_srtm.can_step() ) break;
+ value_srtm.step();
+ formatted.append(" ,");
+ }while(true);
+ }
+
+ formatted.append("])");
+ return formatted.toString();
+ }
+
+ @Override public boolean equals(Object o){
+ if(this == o) return true;
+ if( o == null || getClass() != o.getClass() ) return false;
+ Label that = (Label) o;
+ return Arrays.equals(value, that.value);
+ }
+
+ @Override public int hashCode(){
+ return Arrays.hashCode(value);
+ }
+}
--- /dev/null
+import java.util.Arrays;
+import com.ReasoningTechnology.Ariadne.Ariadne_Node;
+
+public class Node extends Ariadne_Node{
+
+ public static Node make(Label label){
+ return new Node(label);
+ }
+
+ private final Label first_child_label;
+
+ public Node(Label label){
+ super(label);
+ first_child_label = label.copy();
+ first_child_label.inc_down();
+ }
+
+ @Override public SRTM_Child neighbor(){
+ return SRTM_Child.make(first_child_label);
+ }
+
+}
--- /dev/null
+/*
+SRTM_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
+the current label and computes from it the right neighbor sibling
+node's label.
+
+*/
+
+
+import com.ReasoningTechnology.Ariadne.Ariadne_SRTM_Label;
+
+public class SRTM_Child extends Ariadne_SRTM_Label{
+
+ // Static
+ //
+
+ public static SRTM_Child make( Label first_child_label ){
+ return new SRTM_Child( first_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 SRTM_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_strm_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_SRTM;
+import com.ReasoningTechnology.Ariadne.Ariadne_SRTM_Label;
+import com.ReasoningTechnology.Ariadne.Ariadne_SRTM_List;
+import com.ReasoningTechnology.Ariadne.Ariadne_Node;
+import com.ReasoningTechnology.Ariadne.Ariadne_Label;
+
+public class SRTM_Diagonal extends Ariadne_SRTM{
+
+ // Static
+ //
+
+ public static SRTM_Diagonal make(Label start_node){
+ return new SRTM_Diagonal(start_node);
+ }
+
+ // Instance data
+ //
+
+ private List<Label> diagonal = new ArrayList<>(); // the read value
+ private final List<SRTM_Child> child_srtm_list = new ArrayList<>();
+
+ // Constructor(s)
+ //
+
+ // the diagonal will never be null nor empty
+ protected SRTM_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("SRTM_Diagonal(");
+ Ariadne_SRTM_List<Label> diagonal_srtm = Ariadne_SRTM_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_strm list
+ Ariadne_SRTM_List<Label> diagonal_srtm = Ariadne_SRTM_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_strm list
+ Ariadne_SRTM_List<SRTM_Child> child_srtm_srtm = Ariadne_SRTM_List.make(child_srtm_list);
+ if( child_srtm_srtm.can_read() ){
+ do{
+ SRTM_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 SRTM_Diagonal_CLI{
+
+ public static void main(String[] args){
+ System.out.println("Starting IndexTree SRTM Example");
+
+ // Instantiate the IndexTree Diagonal SRTM
+ Graph g = Graph.make();
+ SRTM_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);
+ 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
+import com.ReasoningTechnology.Ariadne.Ariadne_SRTM;
+import com.ReasoningTechnology.Ariadne.Ariadne_SRTM_List;
+
+public class four_down_four_across_CLI{
+
+ public static void main(String[] args){
+
+ System.out.println("Example_4x4");
+
+ // Initialize graph and start at root
+ Graph graph = Graph.make();
+ SRTM_Child start = graph.start();
+ Label label = start.read();
+ Node node;
+ SRTM_Child child_srm;
+
+ System.out.println("starting at: " + start.read());
+
+ // Descend 3 more levels
+ int i = 1;
+ do{
+ node = graph.lookup(label);
+ child_srm = node.neighbor();
+ label = child_srm.read();
+ System.out.println("Descended to: " + label.toString());
+ if(i == 3) break;
+ i++;
+ }while(true);
+
+ // Move across three more nodes
+ i = 1;
+ do{
+ child_srm.step();
+ label = child_srm.read();
+ System.out.println("Across to: " + label.toString());
+ if(i == 3) break;
+ i++;
+ }while(true);
+
+ }
+}
--- /dev/null
+Example_4x4
+starting at: Label([])
+Descended to: Label([0])
+Descended to: Label([0 ,0])
+Descended to: Label([0 ,0 ,0])
+Across to: Label([0 ,0 ,1])
+Across to: Label([0 ,0 ,2])
+Across to: Label([0 ,0 ,3])