/*
Step Right Tape Machine
- Depending how the undefined methods here are defined, the TM_SR_ND can
+ Depending how the undefined methods here are defined, the TM_SR_NX 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_TM_SR_ND{
+public class Ariadne_TM_SR_NX{
// static
//
,INFINITE
}
- public static Ariadne_TM_SR_ND make(){
- return new Ariadne_TM_SR_ND();
+ public static Ariadne_TM_SR_NX make(){
+ return new Ariadne_TM_SR_NX();
}
// instance data
// constructor(s)
//
- protected Ariadne_TM_SR_ND(){
+ protected Ariadne_TM_SR_NX(){
set_topology( not_mounted );
}
return false;
}
@Override public Object read(){
- throw new UnsupportedOperationException("Ariadne_TM_SR_ND::NotMounted::read.");
+ throw new UnsupportedOperationException("Ariadne_TM_SR_NX::NotMounted::read.");
}
@Override public boolean can_step(){
return false;
}
@Override public void step(){
- throw new UnsupportedOperationException("Ariadne_TM_SR_ND::NotMounted::step.");
+ throw new UnsupportedOperationException("Ariadne_TM_SR_NX::NotMounted::step.");
}
@Override public Topology topology(){
- throw new UnsupportedOperationException("Ariadne_TM_SR_ND::NotMounted::topology.");
+ throw new UnsupportedOperationException("Ariadne_TM_SR_NX::NotMounted::topology.");
}
}
Aeloria
/*
- IndexTree_TM_SR_ND_Diagonal
+ IndexTree_TM_SR_NX_Diagonal
An index tree is infinite.
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
-import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND;
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_NX;
import com.ReasoningTechnology.Ariadne.IndexTree_Node;
-public class IndexTree_TM_SR_ND_Diagonal extends Ariadne_TM_SR_ND_Label {
+public class IndexTree_TM_SR_NX_Diagonal extends Ariadne_TM_SR_NX_Label {
// Static
- public static IndexTree_TM_SR_ND_Diagonal make(){
- return new IndexTree_TM_SR_ND_Diagonal();
+ public static IndexTree_TM_SR_NX_Diagonal make(){
+ return new IndexTree_TM_SR_NX_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_TM_SR_ND_Label breadth_srm;
+ private final Ariadne_TM_SR_NX_Label breadth_srm;
// Constructor
- protected IndexTree_TM_SR_ND_Diagonal(){
+ protected IndexTree_TM_SR_NX_Diagonal(){
list_of__unopened_node = new ArrayList<>();
list_of__opened_incomplete_child_list = new ArrayList<>();
read_list = new ArrayList<>();
- breadth_srm = Ariadne_TM_SR_ND_Label.make();
+ breadth_srm = Ariadne_TM_SR_NX_Label.make();
enqueue_root();
}Aeloria
// Retrieve the node using lookup
IndexTree_Node node = node( label );
- // Mount a new breadth-first TM_SR_ND for children
+ // Mount a new breadth-first TM_SR_NX for children
breadth_srm.mount( node.neighbor() );
if( breadth_srm.can_read() ){
However the compiler does not consider:
- `Ariadne_TM_SR_ND<Label>`
+ `Ariadne_TM_SR_NX<Label>`
To be a type of
- `Ariadne_TM_SR_ND<Ariadne_Label>`
+ `Ariadne_TM_SR_NX<Ariadne_Label>`
This is awkward because `Graph::start` returns a TM of labels,
where the labels are derived from `Ariadne_Label`
Java is inconsistent in its interpretation of generic types. For example
it considers these to be different types:
- Ariadne_TM_SR_ND<T>
- Ariadne_TM_SR_ND_Array<T> // extends Ariadne_TM_SR_ND<T>
+ Ariadne_TM_SR_NX<T>
+ Ariadne_TM_SR_NX_Array<T> // extends Ariadne_TM_SR_NX<T>
Hence, the result from a factory for the child:
- Ariadne_TM_SR_ND_Array<T> x make(){...}
+ Ariadne_TM_SR_NX_Array<T> x make(){...}
Cannot be assigned to a variable declared of the parent type,
- Ariadne_TM_SR_ND<T>
+ Ariadne_TM_SR_NX<T>
Yet it will not allow overloading of
- Ariadne_TM_SR_ND<T> make(..){
+ Ariadne_TM_SR_NX<T> make(..){
}
- Ariadne_TM_SR_ND_Array<T> make(..){
+ Ariadne_TM_SR_NX_Array<T> make(..){
}
If the programmer puts a caste on the factory output when assigning
The crux of the issue is Java's type erasure combined with its strict generic type checks:
Java enforces that overloaded methods can't differ only by their return type because, after type erasure, they would have identical signatures.
- At the same time, assigning a subclass instance (Ariadne_TM_SR_ND_Array<T>) to a variable of the parent type (Ariadne_TM_SR_ND<T>) causes type ambiguity with generics.
+ At the same time, assigning a subclass instance (Ariadne_TM_SR_NX_Array<T>) to a variable of the parent type (Ariadne_TM_SR_NX<T>) causes type ambiguity with generics.
+
+2025-01-24T10:54:26Z[]
+ global substitute in this file _ND -> _NX
+
-import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND;
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_NX;
import java.math.BigInteger;
-public class CountingNumber extends Ariadne_TM_SR_ND<BigInteger>{
+public class CountingNumber extends Ariadne_TM_SR_NX<BigInteger>{
// Static
//
-import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND;
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_NX;
import java.math.BigInteger;
public class CountingNumber_0_CLI{
if( !n.can_read() ) return;
- if( n.topology() == Ariadne_TM_SR_ND.Topology.SEGMENT ){
+ if( n.topology() == Ariadne_TM_SR_NX.Topology.SEGMENT ){
do{
System.out.println("Current Number: " + n.read());
if( !n.can_step() ) break;
n.step();
}while( true );
- }else if( n.topology() == Ariadne_TM_SR_ND.Topology.INFINITE ){
+ }else if( n.topology() == Ariadne_TM_SR_NX.Topology.INFINITE ){
int count = 0;
do{
System.out.println("Current Number: " + n.read());
import java.util.ArrayList;
import java.util.List;
-import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND;
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_NX;
import com.ReasoningTechnology.Ariadne.Ariadne_Graph;
import com.ReasoningTechnology.Ariadne.Ariadne_Node;
import com.ReasoningTechnology.Ariadne.Ariadne_Label;
-import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND_Array;
-import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND_List;
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_NX_Array;
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_NX_List;
-class TM_SR_ND_Depth extends Ariadne_TM_SR_ND<Label>{
+class TM_SR_NX_Depth extends Ariadne_TM_SR_NX<Label>{
// ----------------------------------------
// static
//
- TM_SR_ND_Depth make(Ariadne_Graph graph){
+ TM_SR_NX_Depth make(Ariadne_Graph graph){
if(graph == null) return null;
- TM_SR_ND_Depth depth = new TM_SR_ND_Depth();
+ TM_SR_NX_Depth depth = new TM_SR_NX_Depth();
depth.graph = graph;
depth.context_path.add( graph.start() );
- depth.context_path_tm = Ariadne_TM_SR_ND_Array.make(context_path);
+ depth.context_path_tm = Ariadne_TM_SR_NX_Array.make(context_path);
initialize i = initialize.f(depth.context_path_tm ,depth.path_member_set);
if( !i.success() ) return null;
first_in_path_cycle_node_label = i.first_in_path_cycle_node_label;
//
protected Graph graph = null;
- protected List<Ariadne_TM_SR_ND<Label>> context_path = new ArrayList<>();
- protected Ariadne_TM_SR_ND_Array<Ariadne_TM_SR_ND> context_path_tm = null;
+ protected List<Ariadne_TM_SR_NX<Label>> context_path = new ArrayList<>();
+ protected Ariadne_TM_SR_NX_Array<Ariadne_TM_SR_NX> context_path_tm = null;
protected Label first_in_path_cycle_node_label = null;
// Used for cycle detection.
// constructor
//
- protected TM_SR_ND_Depth(){
+ protected TM_SR_NX_Depth(){
set_topology(topo_null);
}
protected void g(context_path_tm ,path_member_set){
if( context_path.isEmpty() ){
- System.out.println("TM_SR_ND_Depth::initialize required context_path is empty.");
+ System.out.println("TM_SR_NX_Depth::initialize required context_path is empty.");
success = false;
return;
}
boolean is_cycle_node = false;
- Ariadne_TM_SR_ND sibling_tm = null;
+ Ariadne_TM_SR_NX sibling_tm = null;
Ariadne_Label path_node_label = null;
do{
sibling_tm = context_path_tm.read();
path_node_label = sibling_tm.read();
if(path_node_label == null){
- System.out.println("TM_SR_ND_Depth::complete_context_path hit null path label on path");
+ System.out.println("TM_SR_NX_Depth::complete_context_path hit null path label on path");
success = false;
return;
}
if( is_cycle_node && context_path_tm.can_step() ){
System.out.println
(
- "TM_SR_ND_Depth::initialize_path_member_set: cycle found in initial context_path."
+ "TM_SR_NX_Depth::initialize_path_member_set: cycle found in initial context_path."
);
first_in_path_cycle_node_label = path_node_label;
success = false;
boolean is_cycle_node = false;
Ariadne_Node path_node = null;
boolean is_leaf_node = false;
- Ariadne_TM_SR_ND sibling_tm = null;
+ Ariadne_TM_SR_NX sibling_tm = null;
Ariadne_Label path_node_label = null;
sibling_tm = context_path_tm.read();
if(path_node == null){
System.out.println
(
- "TM_SR_ND_Depth::complete_context_path internal algorithm error, node on path not found in graph for: label(\""
+ "TM_SR_NX_Depth::complete_context_path internal algorithm error, node on path not found in graph for: label(\""
+ path_node_label
+ "\")"
);
protected Graph(){
}
- @Override public TM_SR_ND_Child start(){
+ @Override public TM_SR_NX_Child start(){
Label root_label = Label.root();
- return TM_SR_ND_Child.make(root_label);
+ return TM_SR_NX_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_TM_SR_ND_List;
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_NX_List;
public class Label implements Ariadne_Label{
StringBuilder formatted = new StringBuilder("Label([");
- // 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));
+ // Use precise loop with TM_SR_NX_List to iterate
+ Ariadne_TM_SR_NX_List<BigInteger> value_srtm = Ariadne_TM_SR_NX_List.make(Arrays.asList(value));
if(value_srtm.can_read()){
do{
formatted.append(value_srtm.read().toString());
first_child_label.inc_down();
}
- @Override public TM_SR_ND_Child neighbor(){
- return TM_SR_ND_Child.make(first_child_label);
+ @Override public TM_SR_NX_Child neighbor(){
+ return TM_SR_NX_Child.make(first_child_label);
}
}
/*
-TM_SR_ND_Child represents in the abstract the infinite child list of an
+TM_SR_NX_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
+TM_SR_NX_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;
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_NX;
-public class TM_SR_ND_Child extends Ariadne_TM_SR_ND<Label>{
+public class TM_SR_NX_Child extends Ariadne_TM_SR_NX<Label>{
// Static
//
- public static TM_SR_ND_Child make(Label leftmost_child_label){
- return new TM_SR_ND_Child(leftmost_child_label);
+ public static TM_SR_NX_Child make(Label leftmost_child_label){
+ return new TM_SR_NX_Child(leftmost_child_label);
}
// Instance data
// Constructor(s)
//
- protected TM_SR_ND_Child(Label leftmost_child_label){
+ protected TM_SR_NX_Child(Label leftmost_child_label){
this.label = leftmost_child_label != null ? leftmost_child_label.copy() : null;
if(label == null){
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_List;
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_NX;
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_NX_List;
-public class TM_SR_ND_Diagonal extends Ariadne_TM_SR_ND<List<Label>> {
+public class TM_SR_NX_Diagonal extends Ariadne_TM_SR_NX<List<Label>> {
// Static
//
- public static TM_SR_ND_Diagonal make(Label start_node) {
- return new TM_SR_ND_Diagonal(start_node);
+ public static TM_SR_NX_Diagonal make(Label start_node) {
+ return new TM_SR_NX_Diagonal(start_node);
}
// Instance data
//
private List<Label> diagonal = new ArrayList<>();
- private final List<TM_SR_ND_Child> child_srtm_list = new ArrayList<>();
+ private final List<TM_SR_NX_Child> child_srtm_list = new ArrayList<>();
// Constructor(s)
//
- protected TM_SR_ND_Diagonal(Label start_node) {
+ protected TM_SR_NX_Diagonal(Label start_node) {
if (start_node == null) {
set_topology(topo_null);
return;
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);
+ Ariadne_TM_SR_NX_List<Label> diagonal_srtm = Ariadne_TM_SR_NX_List.make(diagonal);
if( diagonal_srtm.can_read() ){
do{
Node node = Node.make(diagonal_srtm.read());
}
// add to diagonal_1 from each on entry on the child_srtm list
- Ariadne_TM_SR_ND_List<TM_SR_ND_Child> child_srtm_srtm = Ariadne_TM_SR_ND_List.make(child_srtm_list);
+ Ariadne_TM_SR_NX_List<TM_SR_NX_Child> child_srtm_srtm = Ariadne_TM_SR_NX_List.make(child_srtm_list);
if( child_srtm_srtm.can_read() ){
do{
- TM_SR_ND_Child child_srtm = child_srtm_srtm.read();
+ TM_SR_NX_Child child_srtm = child_srtm_srtm.read();
Label label = child_srtm.read();
diagonal_1.add(label.copy());
child_srtm.step();
//
@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);
+ StringBuilder formatted = new StringBuilder("TM_SR_NX_Diagonal(");
+ Ariadne_TM_SR_NX_List<Label> diagonal_srtm = Ariadne_TM_SR_NX_List.make(diagonal);
if (diagonal_srtm.can_read()) {
do {
import java.util.List;
-public class TM_SR_ND_Diagonal_CLI{
+public class TM_SR_NX_Diagonal_CLI{
public static void main(String[] args){
- System.out.println("Starting IndexTree TM_SR_ND Example");
+ System.out.println("Starting IndexTree TM_SR_NX Example");
- // Instantiate the IndexTree Diagonal TM_SR_ND
+ // Instantiate the IndexTree Diagonal TM_SR_NX
Graph g = Graph.make();
- TM_SR_ND_Child start_srtm = g.start();
+ TM_SR_NX_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);
+ TM_SR_NX_Diagonal srtm = TM_SR_NX_Diagonal.make(start_label);
int step_count = 0;
if( srtm.can_read() ){
do{
-import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND;
-import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND_List;
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_NX;
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_NX_List;
public class four_down_four_across_CLI{
// Initialize graph and start at root
Graph graph = Graph.make();
- TM_SR_ND_Child start = graph.start();
+ TM_SR_NX_Child start = graph.start();
Label label = start.read();
Node node;
- TM_SR_ND_Child child_srm;
+ TM_SR_NX_Child child_srm;
System.out.println("starting at: " + start.read());
-import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND;
-import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND_Array;
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_NX;
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_NX_Array;
import java.util.Arrays;
import java.util.List;
-public class TM_SR_ND_Array_CLI {
+public class TM_SR_NX_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);
+ // Attach TM_SR_NX to the array
+ Ariadne_TM_SR_NX_Array<String> srm = Ariadne_TM_SR_NX_Array.make(label_array);
if( srm.can_read() ){
do{
System.out.println( "Reading: " + srm.read() );
import java.util.LinkedList;
-import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND;
-import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND_List;
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_NX;
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_NX_List;
-public class TM_SR_ND_List_CLI {
+public class TM_SR_NX_List_CLI {
public static void main( String[] args ){
// Create a linked list
LinkedList<String> label_list = new LinkedList<>();
label_list.add( "B" );
label_list.add( "C" );
- // Attach TM_SR_ND to the linked list and traverse
- Ariadne_TM_SR_ND_List<String> srm = Ariadne_TM_SR_ND_List.make(label_list);
+ // Attach TM_SR_NX to the linked list and traverse
+ Ariadne_TM_SR_NX_List<String> srm = Ariadne_TM_SR_NX_List.make(label_list);
if( srm.can_read() ){
do{
System.out.println( "Reading: " + srm.read() );
/*
-Example of the TM_SR_ND's toString function.
+Example of the TM_SR_NX's toString function.
*/
import java.util.Arrays;
import java.util.List;
-import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND;
-import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND_List;
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_NX;
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_NX_List;
-public class TM_SR_ND_Print_CLI{
+public class TM_SR_NX_Print_CLI{
public static void main(String[] args){
List<Object> data = Arrays.asList(42 ,null ,"" ,"World" ,1000);
- Ariadne_TM_SR_ND tm = Ariadne_TM_SR_ND_List.make(data);
+ Ariadne_TM_SR_NX tm = Ariadne_TM_SR_NX_List.make(data);
System.out.println( tm.toString() );
tm.step();
System.out.println( tm.to_string_annotated() );
-import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_ND_Set;
+import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_NX_Set;
import java.util.HashSet;
import java.util.Set;
-public class TM_SR_ND_Set_CLI {
+public class TM_SR_NX_Set_CLI {
public static void main( String[] args ){
// Create a Set
Set<String> label_set = new HashSet<>();
label_set.add("B");
label_set.add("C");
- // Attach TM_SR_ND to the set and traverse
- Ariadne_TM_SR_ND_Set<String> srm = Ariadne_TM_SR_ND_Set.make(label_set);
+ // Attach TM_SR_NX to the set and traverse
+ Ariadne_TM_SR_NX_Set<String> srm = Ariadne_TM_SR_NX_Set.make(label_set);
if( srm.can_read() ){
do{
System.out.println( "Reading: " + srm.read() );
+++ /dev/null
-package com.ReasoningTechnology.Ariadne;
-
-import java.math.BigInteger;
-
-// LT == Label Type
-public abstract class
- Ariadne_SiblingContext<LT extends Ariadne_Label>
- extends Ariadne_TM_SR_ND<LT>
-{
-
- // Static
- //
-
- public static <T extends Ariadne_Label> Ariadne_SiblingContext<T> make(){
- throw new UnsupportedOperationException("Ariadne_SiblingContext::make not implemented.");
- }
-
- // Instance Data
- //
-
- // Constructors
- //
-
- protected Ariadne_SiblingContext(){
- super();
- }
-
- // Instance Interface
- //
-
-
- @Override public boolean can_rewind(){
- return false;
- }
-
- @Override public void rewind(){
- throw new UnsupportedOperationException("Ariadne_SiblingContext::rewind not implemented.");
- }
-
- @Override public void append_rightmost(LT x){
- throw new UnsupportedOperationException("Ariadne_SiblingContext::append_rightmost not implemented.");
- }
-
- // Topology for sibling context
- //
-
- @Override public Topology topology(){
- return current_topology.topology();
- }
-}
import java.util.List;
// LT == Label Type
-public class Ariadne_ContextPath_FD< Ariadne_TM_SR_ND<LT> >{
+public class Ariadne_ContextPath_FD< Ariadne_TM_SR_NX<LT> >{
//----------------------------------------
// static
//----------------------------------------
// Instance data
- private final List< Ariadne_TM_SR_ND<LT> > context_path_list;
+ private final List< Ariadne_TM_SR_NX<LT> > context_path_list;
private final HashSet<LT> path_member_set;
private Ariand_Label cycle_node_label;;
* @param tm The traversal state to add.
* @return true if successfully added, false if it introduces a cycle.
*/
- public boolean push(Ariadne_TM_SR_ND<LT> tm){
+ public boolean push(Ariadne_TM_SR_NX<LT> tm){
if( tm == null || !tm.can_read() ){
return false;
}
*
* @return The removed traversal state, or null if the path is empty.
*/
- public Ariadne_TM_SR_ND<LT> pop(){
+ public Ariadne_TM_SR_NX<LT> pop(){
if( context_path_list.isEmpty() ){
return null;
}
- Ariadne_TM_SR_ND<LT> last = context_path_list.remove( context_path_list.size() - 1 );
+ Ariadne_TM_SR_NX<LT> last = context_path_list.remove( context_path_list.size() - 1 );
path_member_set.remove( last.read() );
return last;
}
public String toString(){
StringBuilder output = new StringBuilder("Ariadne_ContextPath(");
@SuppressWarnings("unchecked")
- Ariadne_TM_SR_ND<Ariadne_TM_SR_ND<LT>> tm = Ariadne_TM_SR_ND_Array.make(context_path_list);
+ Ariadne_TM_SR_NX<Ariadne_TM_SR_NX<LT>> tm = Ariadne_TM_SR_NX_Array.make(context_path_list);
if( tm.can_read() ){
do{
throw new UnsupportedOperationException("Ariadne_Graph::is_wellformed.");
}
- public Ariadne_TM_SR_ND<LT> start() {
+ public Ariadne_TM_SR_NX<LT> start() {
throw new UnsupportedOperationException("Ariadne_Graph::start.");
}
// Nodes are distinct due to the use of the HashMap
// Check that start nodes are in the graph
- Ariadne_TM_SR_ND_Array<LT> tm = Ariadne_TM_SR_ND_Array.make(start_list);
+ Ariadne_TM_SR_NX_Array<LT> tm = Ariadne_TM_SR_NX_Array.make(start_list);
if( tm.can_read() ){
do{
start_flag = this.node( tm.read() ) != null;
return distinct_flag && start_flag;
}
- @Override public Ariadne_TM_SR_ND<LT> start(){
- return Ariadne_TM_SR_ND_Array.make(start_list);
+ @Override public Ariadne_TM_SR_NX<LT> start(){
+ return Ariadne_TM_SR_NX_Array.make(start_list);
}
// Lookup a node on the graph by label
}
// A tm of all nodes
- public Ariadne_TM_SR_ND<NT> node(){
- return Ariadne_TM_SR_ND_Array.make( new ArrayList<>(node_db.values()) );
+ public Ariadne_TM_SR_NX<NT> node(){
+ return Ariadne_TM_SR_NX_Array.make( new ArrayList<>(node_db.values()) );
}
// Lookup an edge by two labels. For a directed graph, label0 is the origin node label.
}
// A tm of all edges
- public Ariadne_TM_SR_ND<Ariadne_Edge<LT>> edge(){
- return Ariadne_TM_SR_ND_Array.make( new ArrayList<>(edge_db.values()) );
+ public Ariadne_TM_SR_NX<Ariadne_Edge<LT>> edge(){
+ return Ariadne_TM_SR_NX_Array.make( new ArrayList<>(edge_db.values()) );
}
// Object interface
output.append("Graph_FD( ");
{
- Ariadne_TM_SR_ND<NT> tm = this.node();
+ Ariadne_TM_SR_NX<NT> tm = this.node();
if( !tm.can_read() ){
output.append( "Node_list()" );
}else{
}
{
- Ariadne_TM_SR_ND<Ariadne_Edge<LT>> tm = this.edge();
+ Ariadne_TM_SR_NX<Ariadne_Edge<LT>> tm = this.edge();
if( !tm.can_read() ){
output.append( "Edge_list()" );
}else{
return this.label;
}
- public Ariadne_TM_SR_ND<LT> neighbor(){
+ public Ariadne_TM_SR_NX<LT> neighbor(){
throw new UnsupportedOperationException("Ariadne_Node::neighbor not implemented in the base class.");
}
// Marks representation
if( !mark_set.isEmpty() ){
- Ariadne_TM_SR_ND_Set srm = Ariadne_TM_SR_ND_Set.make(mark_set);
+ Ariadne_TM_SR_NX_Set srm = Ariadne_TM_SR_NX_Set.make(mark_set);
output.append( " Mark(" );
do{
// Instance interface
//
- @Override public Ariadne_TM_SR_ND<LT> neighbor(){
- return Ariadne_TM_SR_ND_Set.make(neighbor_set);
+ @Override public Ariadne_TM_SR_NX<LT> neighbor(){
+ return Ariadne_TM_SR_NX_Set.make(neighbor_set);
}
// Good citizen
//
@Override public String toString(){
- Ariadne_TM_SR_ND_Set<LT> tm = Ariadne_TM_SR_ND_Set.make(neighbor_set);
+ Ariadne_TM_SR_NX_Set<LT> tm = Ariadne_TM_SR_NX_Set.make(neighbor_set);
boolean has_label = label() != null;
boolean has_neighbor = tm.can_read();
+/*
+Currently SiblingContext is an alias for Ariadne_TM_SR_NX<LT>.
+
+*/
package com.ReasoningTechnology.Ariadne;
import java.math.BigInteger;
// LT == Label Type
public abstract class
Ariadne_SiblingContext<LT extends Ariadne_Label>
- extends Ariadne_TM_SR_ND<LT>
+ extends Ariadne_TM_SR_NX<LT>
{
- // Static
+ // static
//
public static <T extends Ariadne_Label> Ariadne_SiblingContext<T> make(){
throw new UnsupportedOperationException("Ariadne_SiblingContext::make not implemented.");
}
- // Instance Data
+ // instance data
//
- // Constructors
+ // constructor(s)
//
protected Ariadne_SiblingContext(){
super();
}
- // Instance Interface
- //
-
- @Override public boolean can_read(){
- return current_topology.can_read();
- }
-
- @Override public LT read(){
- return current_topology.read();
- }
-
- @Override public boolean can_step(){
- return current_topology.can_step();
- }
-
- @Override public void step(){
- increment();
- current_topology.step();
- }
-
- @Override public boolean can_rewind(){
- return false;
- }
-
- @Override public void rewind(){
- throw new UnsupportedOperationException("Ariadne_SiblingContext::rewind not implemented.");
- }
-
- @Override public void append_rightmost(LT x){
- throw new UnsupportedOperationException("Ariadne_SiblingContext::append_rightmost not implemented.");
- }
-
- // Topology for sibling context
- //
-
- @Override public Topology topology(){
- return current_topology.topology();
- }
}
--- /dev/null
+/*
+Currently SiblingContext is an alias for Ariadne_TM_SR_NX<LT>.
+
+*/
+package com.ReasoningTechnology.Ariadne;
+
+import java.math.BigInteger;
+
+// LT == Label Type
+public abstract class
+ Ariadne_SiblingContext<LT extends Ariadne_Label>
+ extends Ariadne_TM_SR_NX_Array<LT>
+{
+
+ // static
+ //
+
+ public static <T extends Ariadne_Label> Ariadne_SiblingContext<T> make(){
+ throw new UnsupportedOperationException("Ariadne_SiblingContext::make not implemented.");
+ }
+
+ // instance data
+ //
+
+ // constructor(s)
+ //
+
+ protected Ariadne_SiblingContext(){
+ super();
+ }
+
+}
+++ /dev/null
-/*
-A step right only, non-destructive tape operations, tape machine, TM_SR_ND. This
-machine has explicit tracking of the head address.
-
-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;
-
-// RT == read type
-public class Ariadne_TM_SR_ND<RT>{
-
- // static
- //
-
- protected static int id_well = 100;
-
- public enum Topology{
- NULL
- ,CYCLIC
- ,SEGMENT
- ,RIGHTMOST
- ,INFINITE
- }
-
- public static Ariadne_TM_SR_ND make(){
- return new Ariadne_TM_SR_ND();
- }
-
- // instance data
- //
-
- private int id;
- Ariadne_Test test = null;
- protected TopoIface<RT> current_topology;
- protected BigInteger index;
-
- // constructor(s)
- //
-
- public Ariadne_TM_SR_ND(){
- id = id_well++;
- test = Ariadne_Test.make("Ariadne_TM_SR_ND::" + id + "::");
- test.switch_test(false);
- set_topology( not_mounted );
- this.index = BigInteger.ZERO;
- }
-
- // Implementation of instance interface.
- //
-
- public int id(){
- return this.id;
- }
-
- public BigInteger head_address(){
- return index;
- }
-
- protected void increment(){
- index = index.add(BigInteger.ONE);
- }
-
- public boolean head_on_same_cell(Ariadne_TM_SR_ND<RT> tm){
- boolean p = this.index.equals(tm.index);
- if( test.is_on() ){
- test.print("head_on_same_cell this id/index: " + this.id() + "/" + this.index );
- test.print("head_on_same_cell tm id/index: " + tm.id() + "/" + tm.index );
- test.print("head_on_same_cell returning: " + p );
- }
- return p;
- }
-
- protected void entangle(Ariadne_TM_SR_ND<RT> copy){
- copy.current_topology = this.current_topology;
- // Nuance here, BigInteger is immutable, so operation on the original
- // index, and the copy index, will be independent, which is what we want.
- copy.index = this.index;
- }
- public Ariadne_TM_SR_ND<RT> entangle(){
- throw new UnsupportedOperationException("Ariadne_TM_SR_ND::entangle not implemented.");
- }
-
- public boolean is_mounted(){
- return
- current_topology != null
- && current_topology != not_mounted
- ;
- }
-
- public boolean can_rewind(){
- return false;
- }
-
- public void rewind(){
- index = BigInteger.ZERO;
- }
-
- // Append to rightmost is not considered 'destructive' because the system, including
- // any entangled machines, remains sound after the operation. I.e. no
- // machine is broken or has its current read value changed.
- // However, an entangled machine can detect the end of tape, so a machine
- // can detect that an append happened. Hence append can affect an algorithm
- // that is running on an entangled machine, but this can also happen when
- // any of the entangled machine writes the tape. Hence, append has a similar
- // affect as other writes.
- public void append_rightmost(RT x){
- throw new UnsupportedOperationException("Ariadne_TM_SR_ND::entangle not implemented.");
- }
-
- // stateful interface
- //
-
- public boolean can_read(){
- boolean p = current_topology.can_read();
- if( test.is_on() ) test.print("can_read " + p);
- return p;
- }
-
- public RT read(){
- RT o = current_topology.read();
- if( test.is_on() ) test.print("read: " + o);
- return o;
- }
-
- public boolean can_step(){
- boolean p = current_topology.can_step();
- if( test.is_on() ) test.print("can_step " + p);
- return p;
- }
-
- public void step(){
- increment();
- if( test.is_on() ) test.print("step: " + index);
- current_topology.step();
- }
-
- public Topology topology(){
- return current_topology.topology();
- }
-
- // Sets the tape access methods to be used.
- protected void set_topology(TopoIface<RT> new_topology){
- current_topology = new_topology;
- if( test.is_on() ){
- test.print("set_topology i: " + index);
- if(is_mounted()){
- test.print("set_topology to: " + new_topology.topology());
- }else{
- test.print("set_topology to: Unmounted");
- }
- }
- }
-
- protected interface TopoIface<T>{
- boolean can_read();
- T read();
- boolean can_step();
- void step();
- Topology topology();
- }
-
- // yes officially this works, but it introduces subtle problems at compile time:
- // protected final TopoIface<RT> not_mounted = new TopoIface<RT>(){
-
- protected class NotMountedTopo implements TopoIface<RT>{
- @Override public boolean can_read(){
- return false;
- }
- @Override public RT 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.");
- }
- }
- protected final TopoIface<RT> not_mounted = new NotMountedTopo();
-
-
- protected class NullTopo implements TopoIface<RT>{
- @Override public boolean can_read(){
- return false;
- }
-
- @Override public RT read(){
- throw new UnsupportedOperationException("Cannot read from null topology.");
- }
-
- @Override public boolean can_step(){
- return false;
- }
-
- @Override public void step(){
- throw new UnsupportedOperationException("Cannot step over null topology.");
- }
-
- @Override public Topology topology(){
- return Topology.NULL;
- }
- }
- protected final TopoIface<RT> topo_null = new NullTopo();
-
- // good citizen
- //
-
- public String to_string_annotated(){
-
- test.print("::to_string_annotated");
-
- if(!is_mounted()) return "TM_SR_ND(NotMounted)";
- if(!can_read()) return "TM_SR_ND(Null)";
-
- // output takes two lines, starting from the left column on each
- StringBuilder data_channel = new StringBuilder("\n");
- StringBuilder control_channel = new StringBuilder("");
-
- data_channel.append( "TM_SR_ND(" ).append( topology().name()).append("(" );
- control_channel.append( " ".repeat(data_channel.length()-1) );
-
- String element = null;
- Ariadne_TM_SR_ND<RT> copy = this.entangle();
- if( copy.can_rewind() ) copy.rewind();
-
- Object o = null;
- do{
-
- o = copy.read();
-
- if(o == null){
- data_channel.append( " ".repeat(3) );
- if( head_on_same_cell(copy) ){
- control_channel.append("<->");
- }else{
- control_channel.append("|-|");
- }
- }else if(o.toString().isEmpty()){
- data_channel.append( " ".repeat(3) );
- if( head_on_same_cell(copy) ){
- control_channel.append("<e>");
- }else{
- control_channel.append("|e|");
- }
- }else{
- element = o.toString();
- data_channel.append(" ").append(element).append(" ");
- if(head_on_same_cell(copy)){
- control_channel
- .append("<")
- .append("d".repeat(element.length()))
- .append(">");
- }else{
- control_channel
- .append("|")
- .append("d".repeat(element.length()))
- .append("|");
- }
- }
-
- if( !copy.can_step() ) break;
- copy.step();
-
- }while(true);
-
- data_channel.append(" )");
- control_channel.append(" ");
-
- return
- data_channel
- .append("\n")
- .append(control_channel)
- .toString();
- }
-
- // RT code format style comma separated list
- @Override public String toString(){
-
- Ariadne_TM_SR_ND<RT> tm = this.entangle();
- if( tm.can_rewind() ) tm.rewind();
-
- if( !tm.can_read() ) return "";
-
- StringBuilder output = new StringBuilder();
- do{
-
- if( tm.head_on_same_cell(this) ) output.append("[");
- RT x = tm.read();
- if( x != null ) output.append(x);
- if( tm.head_on_same_cell(this) ) output.append("]");
-
- if( !tm.can_step() ) break;
-
- tm.step();
- if( x == null )
- output.append(",");
- else
- output.append(" ,");
-
- }while(true);
-
- return output.toString();
- }
-
-
-}
+++ /dev/null
-package com.ReasoningTechnology.Ariadne;
-
-import java.math.BigInteger;
-import java.util.List;
-
-// RT == read type
-public class Ariadne_TM_SR_ND_Array<RT> extends Ariadne_TM_SR_ND<RT>{
-
- // 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<RT> array;
-
- // Constructor(s)
- //
-
- protected Ariadne_TM_SR_ND_Array(List<RT> 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 );
- }
-
- // instance interface implementation
- //
-
- // Children of this can call super.entangle(copy) to perform the parent part of the entanglement.
- // This calls super to perform its parent portion of the entanglement.
- protected void entangle(Ariadne_TM_SR_ND_Array<RT> copy){
- super.entangle(copy);
- }
- @Override public Ariadne_TM_SR_ND_Array<RT> entangle(){
- Ariadne_TM_SR_ND_Array<RT> copy = Ariadne_TM_SR_ND_Array.make(this.array);
- entangle(copy);
-
- switch (this.current_topology.topology()) {
- case NULL:
- copy.current_topology = copy.topo_null;
- break;
- case SEGMENT:
- copy.current_topology = copy.topo_segment;
- break;
- case RIGHTMOST:
- copy.current_topology = copy.topo_rightmost;
- break;
- default:
- throw new IllegalStateException("Unexpected topology: " + this.current_topology.topology());
- }
-
- return copy;
- }
-
- @Override public boolean can_rewind(){
- return true;
- }
-
- @Override public void rewind() {
- super.rewind();
- if (array == null || array.isEmpty()) {
- set_topology(topo_null); // Null topology for empty or null arrays
- return;
- }
- set_topology(array.size() == 1 ? topo_rightmost : topo_segment); // Adjust topology
- }
-
- protected class SegmentTopo implements TopoIface<RT>{
- @Override public boolean can_read(){return true;}
- @Override public RT read(){
- return array.get(head_address().intValueExact());
- }
- @Override public boolean can_step(){return true;}
- @Override public void step(){
- if(head_address().compareTo(BigInteger.valueOf(array.size() - 1)) == 0)
- set_topology(topo_rightmost);
- }
- @Override public Topology topology(){return Topology.SEGMENT;}
- }
- protected final TopoIface<RT> topo_segment = new SegmentTopo();
-
- protected class RightmostTopo implements TopoIface<RT>{
- @Override public boolean can_read(){return true;}
- @Override public RT 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;}
- }
- protected final TopoIface<RT> topo_rightmost = new RightmostTopo();
-
-}
+++ /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<RT> extends Ariadne_TM_SR_ND<RT>{
-
- // 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<RT> list; // The attached linked list
- private ListIterator<RT> iterator; // Iterator for traversal
- private RT read_value; // Stores the current cell value
-
- // constructor(s)
- //
-
- protected Ariadne_TM_SR_ND_List(List<RT> 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
- //
-
- // Children of this can call entangle(copy) to perform the parent part of the entanglement.
- // This calls super to perform its parent portion of the entanglement.
- protected void entangle(Ariadne_TM_SR_ND_List<RT> copy){
- super.entangle(copy);
- copy.read_value = this.read_value;
- copy.iterator = this.list.listIterator(this.iterator.nextIndex());
- }
-
- @Override public Ariadne_TM_SR_ND_List<RT> entangle(){
- Ariadne_TM_SR_ND_List<RT> copy = Ariadne_TM_SR_ND_List.make(this.list);
- entangle(copy);
-
- // Set the appropriate topology in the copy based on the current topology
- switch (this.current_topology.topology()) {
- case NULL:
- copy.current_topology = copy.topo_null;
- break;
- case SEGMENT:
- copy.current_topology = copy.topo_segment;
- break;
- case RIGHTMOST:
- copy.current_topology = copy.topo_rightmost;
- break;
- default:
- throw new IllegalStateException("Unexpected topology: " + this.current_topology.topology());
- }
-
- return copy;
- }
-
- @Override public boolean can_rewind(){
- return true;
- }
-
- @Override public void rewind(){
- super.rewind();
- if(list == null || list.isEmpty()){
- set_topology(topo_null);
- return;
- }
- iterator = list.listIterator(); // Reset the iterator
- read_value = iterator.next(); // Sync the read value
- set_topology(list.size() == 1 ? topo_rightmost : topo_segment); // Adjust topology
- }
-
- protected class SegmentTopo implements TopoIface<RT>{
- @Override public boolean can_read(){ return true; }
- @Override public RT read(){ return (RT) 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; }
- }
- protected final TopoIface<RT> topo_segment = new SegmentTopo();
-
- protected class RightmostTopo implements TopoIface<RT>{
- @Override public boolean can_read(){ return true; }
- @Override public RT 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; }
- }
- protected final TopoIface<RT> topo_rightmost = new RightmostTopo();
-
-}
-
-
+++ /dev/null
-package com.ReasoningTechnology.Ariadne;
-
-import java.util.Set;
-import java.util.Iterator;
-
-public class Ariadne_TM_SR_ND_Set<RT> extends Ariadne_TM_SR_ND<RT>{
-
- // Static methods
- public static <RT> Ariadne_TM_SR_ND_Set<RT> make(Set<RT> set){
- return new Ariadne_TM_SR_ND_Set<>(set);
- }
-
- // Instance data
- private Set<RT> set;
- private Iterator<RT> iterator;
- private RT read_value;
-
- protected final TopoIface<RT> topo_segment = new SegmentTopo();
- protected final TopoIface<RT> topo_rightmost = new RightmostTopo();
-
- // Constructor
- protected Ariadne_TM_SR_ND_Set(Set<RT> set){
- this.set = set;
- if (set == null || set.isEmpty()){
- this.iterator = null;
- set_topology(topo_null);
- return;
- }
- this.iterator = set.iterator();
- this.read_value = iterator.hasNext() ? iterator.next() : null;
- set_topology(set.size() == 1 ? topo_rightmost : topo_segment);
- }
-
- // Instance interface implementation
- @Override public void rewind(){
- super.rewind();
- if (set == null || set.isEmpty()){
- set_topology(topo_null);
- return;
- }
- this.iterator = set.iterator();
- this.read_value = iterator.hasNext() ? iterator.next() : null;
- set_topology(set.size() == 1 ? topo_rightmost : topo_segment);
- }
-
- protected void entangle(Ariadne_TM_SR_ND_Set<RT> copy){
- super.entangle(copy);
- copy.iterator = this.set.iterator();
- copy.read_value = this.read_value;
- }
-
- @Override public Ariadne_TM_SR_ND_Set<RT> entangle(){
- Ariadne_TM_SR_ND_Set<RT> copy = Ariadne_TM_SR_ND_Set.make(this.set);
- entangle(copy);
- switch (this.current_topology.topology()){
- case NULL:
- copy.current_topology = copy.topo_null;
- break;
- case SEGMENT:
- copy.current_topology = copy.topo_segment;
- break;
- case RIGHTMOST:
- copy.current_topology = copy.topo_rightmost;
- break;
- default:
- throw new IllegalStateException("Unexpected topology: " + this.current_topology.topology());
- }
- return copy;
- }
-
- protected class SegmentTopo implements TopoIface<RT>{
- @Override public boolean can_read(){ return true; }
- @Override public RT read(){ return read_value; }
- @Override public boolean can_step(){ return iterator.hasNext(); }
- @Override public void step(){
- read_value = iterator.next();
- if (!iterator.hasNext()) set_topology(topo_rightmost);
- }
- @Override public Topology topology(){ return Topology.SEGMENT; }
- }
-
- protected class RightmostTopo implements TopoIface<RT>{
- @Override public boolean can_read(){ return true; }
- @Override public RT 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
+/*
+A step right only, non-destructive tape operations, tape machine, TM_SR_NX. This
+machine has explicit tracking of the head address.
+
+BigInteger is used so that it will be possible to bind TM_SR_NX machine extensions
+to file system objects.
+
+*/
+
+package com.ReasoningTechnology.Ariadne;
+import java.math.BigInteger;
+
+// RT == read type
+public class Ariadne_TM_SR_NX<RT>{
+
+ // static
+ //
+
+ protected static int id_well = 100;
+
+ public enum Topology{
+ NULL
+ ,CYCLIC
+ ,SEGMENT
+ ,RIGHTMOST
+ ,INFINITE
+ }
+
+ public static Ariadne_TM_SR_NX make(){
+ return new Ariadne_TM_SR_NX();
+ }
+
+ // instance data
+ //
+
+ private int id;
+ Ariadne_Test test = null;
+ protected TopoIface<RT> current_topology;
+ protected BigInteger index;
+
+ // constructor(s)
+ //
+
+ public Ariadne_TM_SR_NX(){
+ id = id_well++;
+ test = Ariadne_Test.make("Ariadne_TM_SR_NX::" + id + "::");
+ test.switch_test(false);
+ set_topology( not_mounted );
+ this.index = BigInteger.ZERO;
+ }
+
+ // Implementation of instance interface.
+ //
+
+ public int id(){
+ return this.id;
+ }
+
+ public BigInteger head_address(){
+ return index;
+ }
+
+ protected void increment(){
+ index = index.add(BigInteger.ONE);
+ }
+
+ public boolean head_on_same_cell(Ariadne_TM_SR_NX<RT> tm){
+ boolean p = this.index.equals(tm.index);
+ if( test.is_on() ){
+ test.print("head_on_same_cell this id/index: " + this.id() + "/" + this.index );
+ test.print("head_on_same_cell tm id/index: " + tm.id() + "/" + tm.index );
+ test.print("head_on_same_cell returning: " + p );
+ }
+ return p;
+ }
+
+ protected void entangle(Ariadne_TM_SR_NX<RT> copy){
+ copy.current_topology = this.current_topology;
+ // Nuance here, BigInteger is immutable, so operation on the original
+ // index, and the copy index, will be independent, which is what we want.
+ copy.index = this.index;
+ }
+ public Ariadne_TM_SR_NX<RT> entangle(){
+ throw new UnsupportedOperationException("Ariadne_TM_SR_NX::entangle not implemented.");
+ }
+
+ public boolean is_mounted(){
+ return
+ current_topology != null
+ && current_topology != not_mounted
+ ;
+ }
+
+ public boolean can_rewind(){
+ return false;
+ }
+
+ public void rewind(){
+ index = BigInteger.ZERO;
+ }
+
+ // Append to rightmost is not considered 'destructive' because the system, including
+ // any entangled machines, remains sound after the operation. I.e. no
+ // machine is broken or has its current read value changed.
+ // However, an entangled machine can detect the end of tape, so a machine
+ // can detect that an append happened. Hence append can affect an algorithm
+ // that is running on an entangled machine, but this can also happen when
+ // any of the entangled machine writes the tape. Hence, append has a similar
+ // affect as other writes.
+ public void append_rightmost(RT x){
+ throw new UnsupportedOperationException("Ariadne_TM_SR_NX::entangle not implemented.");
+ }
+
+ // stateful interface
+ //
+
+ public boolean can_read(){
+ boolean p = current_topology.can_read();
+ if( test.is_on() ) test.print("can_read " + p);
+ return p;
+ }
+
+ public RT read(){
+ RT o = current_topology.read();
+ if( test.is_on() ) test.print("read: " + o);
+ return o;
+ }
+
+ public boolean can_step(){
+ boolean p = current_topology.can_step();
+ if( test.is_on() ) test.print("can_step " + p);
+ return p;
+ }
+
+ public void step(){
+ increment();
+ if( test.is_on() ) test.print("step: " + index);
+ current_topology.step();
+ }
+
+ public Topology topology(){
+ return current_topology.topology();
+ }
+
+ // Sets the tape access methods to be used.
+ protected void set_topology(TopoIface<RT> new_topology){
+ current_topology = new_topology;
+ if( test.is_on() ){
+ test.print("set_topology i: " + index);
+ if(is_mounted()){
+ test.print("set_topology to: " + new_topology.topology());
+ }else{
+ test.print("set_topology to: Unmounted");
+ }
+ }
+ }
+
+ protected interface TopoIface<T>{
+ boolean can_read();
+ T read();
+ boolean can_step();
+ void step();
+ Topology topology();
+ }
+
+ // yes officially this works, but it introduces subtle problems at compile time:
+ // protected final TopoIface<RT> not_mounted = new TopoIface<RT>(){
+
+ protected class NotMountedTopo implements TopoIface<RT>{
+ @Override public boolean can_read(){
+ return false;
+ }
+ @Override public RT read(){
+ throw new UnsupportedOperationException("Ariadne_TM_SR_NX::NotMounted::read.");
+ }
+ @Override public boolean can_step(){
+ return false;
+ }
+ @Override public void step(){
+ throw new UnsupportedOperationException("Ariadne_TM_SR_NX::NotMounted::step.");
+ }
+ @Override public Topology topology(){
+ throw new UnsupportedOperationException("Ariadne_TM_SR_NX::NotMounted::topology.");
+ }
+ }
+ protected final TopoIface<RT> not_mounted = new NotMountedTopo();
+
+
+ protected class NullTopo implements TopoIface<RT>{
+ @Override public boolean can_read(){
+ return false;
+ }
+
+ @Override public RT read(){
+ throw new UnsupportedOperationException("Cannot read from null topology.");
+ }
+
+ @Override public boolean can_step(){
+ return false;
+ }
+
+ @Override public void step(){
+ throw new UnsupportedOperationException("Cannot step over null topology.");
+ }
+
+ @Override public Topology topology(){
+ return Topology.NULL;
+ }
+ }
+ protected final TopoIface<RT> topo_null = new NullTopo();
+
+ // good citizen
+ //
+
+ public String to_string_annotated(){
+
+ test.print("::to_string_annotated");
+
+ if(!is_mounted()) return "TM_SR_NX(NotMounted)";
+ if(!can_read()) return "TM_SR_NX(Null)";
+
+ // output takes two lines, starting from the left column on each
+ StringBuilder data_channel = new StringBuilder("\n");
+ StringBuilder control_channel = new StringBuilder("");
+
+ data_channel.append( "TM_SR_NX(" ).append( topology().name()).append("(" );
+ control_channel.append( " ".repeat(data_channel.length()-1) );
+
+ String element = null;
+ Ariadne_TM_SR_NX<RT> copy = this.entangle();
+ if( copy.can_rewind() ) copy.rewind();
+
+ Object o = null;
+ do{
+
+ o = copy.read();
+
+ if(o == null){
+ data_channel.append( " ".repeat(3) );
+ if( head_on_same_cell(copy) ){
+ control_channel.append("<->");
+ }else{
+ control_channel.append("|-|");
+ }
+ }else if(o.toString().isEmpty()){
+ data_channel.append( " ".repeat(3) );
+ if( head_on_same_cell(copy) ){
+ control_channel.append("<e>");
+ }else{
+ control_channel.append("|e|");
+ }
+ }else{
+ element = o.toString();
+ data_channel.append(" ").append(element).append(" ");
+ if(head_on_same_cell(copy)){
+ control_channel
+ .append("<")
+ .append("d".repeat(element.length()))
+ .append(">");
+ }else{
+ control_channel
+ .append("|")
+ .append("d".repeat(element.length()))
+ .append("|");
+ }
+ }
+
+ if( !copy.can_step() ) break;
+ copy.step();
+
+ }while(true);
+
+ data_channel.append(" )");
+ control_channel.append(" ");
+
+ return
+ data_channel
+ .append("\n")
+ .append(control_channel)
+ .toString();
+ }
+
+ // RT code format style comma separated list
+ @Override public String toString(){
+
+ Ariadne_TM_SR_NX<RT> tm = this.entangle();
+ if( tm.can_rewind() ) tm.rewind();
+
+ if( !tm.can_read() ) return "";
+
+ StringBuilder output = new StringBuilder();
+ do{
+
+ if( tm.head_on_same_cell(this) ) output.append("[");
+ RT x = tm.read();
+ if( x != null ) output.append(x);
+ if( tm.head_on_same_cell(this) ) output.append("]");
+
+ if( !tm.can_step() ) break;
+
+ tm.step();
+ if( x == null )
+ output.append(",");
+ else
+ output.append(" ,");
+
+ }while(true);
+
+ return output.toString();
+ }
+
+
+}
--- /dev/null
+package com.ReasoningTechnology.Ariadne;
+
+import java.math.BigInteger;
+import java.util.List;
+
+// RT == read type
+public class Ariadne_TM_SR_NX_Array<RT> extends Ariadne_TM_SR_NX<RT>{
+
+ // Static methods
+ //
+
+ public static <T> Ariadne_TM_SR_NX_Array<T> make(List<T> array){
+ return new Ariadne_TM_SR_NX_Array<>(array);
+ }
+
+ // Instance data
+ //
+
+ private final List<RT> array;
+
+ // Constructor(s)
+ //
+
+ protected Ariadne_TM_SR_NX_Array(List<RT> 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 );
+ }
+
+ // instance interface implementation
+ //
+
+ // Children of this can call super.entangle(copy) to perform the parent part of the entanglement.
+ // This calls super to perform its parent portion of the entanglement.
+ protected void entangle(Ariadne_TM_SR_NX_Array<RT> copy){
+ super.entangle(copy);
+ }
+ @Override public Ariadne_TM_SR_NX_Array<RT> entangle(){
+ Ariadne_TM_SR_NX_Array<RT> copy = Ariadne_TM_SR_NX_Array.make(this.array);
+ entangle(copy);
+
+ switch (this.current_topology.topology()) {
+ case NULL:
+ copy.current_topology = copy.topo_null;
+ break;
+ case SEGMENT:
+ copy.current_topology = copy.topo_segment;
+ break;
+ case RIGHTMOST:
+ copy.current_topology = copy.topo_rightmost;
+ break;
+ default:
+ throw new IllegalStateException("Unexpected topology: " + this.current_topology.topology());
+ }
+
+ return copy;
+ }
+
+ @Override public boolean can_rewind(){
+ return true;
+ }
+
+ @Override public void rewind() {
+ super.rewind();
+ if (array == null || array.isEmpty()) {
+ set_topology(topo_null); // Null topology for empty or null arrays
+ return;
+ }
+ set_topology(array.size() == 1 ? topo_rightmost : topo_segment); // Adjust topology
+ }
+
+ protected class SegmentTopo implements TopoIface<RT>{
+ @Override public boolean can_read(){return true;}
+ @Override public RT read(){
+ return array.get(head_address().intValueExact());
+ }
+ @Override public boolean can_step(){return true;}
+ @Override public void step(){
+ if(head_address().compareTo(BigInteger.valueOf(array.size() - 1)) == 0)
+ set_topology(topo_rightmost);
+ }
+ @Override public Topology topology(){return Topology.SEGMENT;}
+ }
+ protected final TopoIface<RT> topo_segment = new SegmentTopo();
+
+ protected class RightmostTopo implements TopoIface<RT>{
+ @Override public boolean can_read(){return true;}
+ @Override public RT 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;}
+ }
+ protected final TopoIface<RT> topo_rightmost = new RightmostTopo();
+
+}
--- /dev/null
+/*
+ By convention an TM_SR_NX 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_NX is made from.
+ The type of values found in the TM_SR_NX 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_NX_List<RT> extends Ariadne_TM_SR_NX<RT>{
+
+ // Static methods
+ //
+
+ public static <T> Ariadne_TM_SR_NX_List<T> make(List<T> list) {
+ return new Ariadne_TM_SR_NX_List<>(list);
+ }
+
+ // instance data
+ //
+
+ private List<RT> list; // The attached linked list
+ private ListIterator<RT> iterator; // Iterator for traversal
+ private RT read_value; // Stores the current cell value
+
+ // constructor(s)
+ //
+
+ protected Ariadne_TM_SR_NX_List(List<RT> 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
+ //
+
+ // Children of this can call entangle(copy) to perform the parent part of the entanglement.
+ // This calls super to perform its parent portion of the entanglement.
+ protected void entangle(Ariadne_TM_SR_NX_List<RT> copy){
+ super.entangle(copy);
+ copy.read_value = this.read_value;
+ copy.iterator = this.list.listIterator(this.iterator.nextIndex());
+ }
+
+ @Override public Ariadne_TM_SR_NX_List<RT> entangle(){
+ Ariadne_TM_SR_NX_List<RT> copy = Ariadne_TM_SR_NX_List.make(this.list);
+ entangle(copy);
+
+ // Set the appropriate topology in the copy based on the current topology
+ switch (this.current_topology.topology()) {
+ case NULL:
+ copy.current_topology = copy.topo_null;
+ break;
+ case SEGMENT:
+ copy.current_topology = copy.topo_segment;
+ break;
+ case RIGHTMOST:
+ copy.current_topology = copy.topo_rightmost;
+ break;
+ default:
+ throw new IllegalStateException("Unexpected topology: " + this.current_topology.topology());
+ }
+
+ return copy;
+ }
+
+ @Override public boolean can_rewind(){
+ return true;
+ }
+
+ @Override public void rewind(){
+ super.rewind();
+ if(list == null || list.isEmpty()){
+ set_topology(topo_null);
+ return;
+ }
+ iterator = list.listIterator(); // Reset the iterator
+ read_value = iterator.next(); // Sync the read value
+ set_topology(list.size() == 1 ? topo_rightmost : topo_segment); // Adjust topology
+ }
+
+ protected class SegmentTopo implements TopoIface<RT>{
+ @Override public boolean can_read(){ return true; }
+ @Override public RT read(){ return (RT) 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; }
+ }
+ protected final TopoIface<RT> topo_segment = new SegmentTopo();
+
+ protected class RightmostTopo implements TopoIface<RT>{
+ @Override public boolean can_read(){ return true; }
+ @Override public RT 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; }
+ }
+ protected final TopoIface<RT> topo_rightmost = new RightmostTopo();
+
+}
+
+
--- /dev/null
+package com.ReasoningTechnology.Ariadne;
+
+import java.util.Set;
+import java.util.Iterator;
+
+public class Ariadne_TM_SR_NX_Set<RT> extends Ariadne_TM_SR_NX<RT>{
+
+ // Static methods
+ public static <RT> Ariadne_TM_SR_NX_Set<RT> make(Set<RT> set){
+ return new Ariadne_TM_SR_NX_Set<>(set);
+ }
+
+ // Instance data
+ private Set<RT> set;
+ private Iterator<RT> iterator;
+ private RT read_value;
+
+ protected final TopoIface<RT> topo_segment = new SegmentTopo();
+ protected final TopoIface<RT> topo_rightmost = new RightmostTopo();
+
+ // Constructor
+ protected Ariadne_TM_SR_NX_Set(Set<RT> set){
+ this.set = set;
+ if (set == null || set.isEmpty()){
+ this.iterator = null;
+ set_topology(topo_null);
+ return;
+ }
+ this.iterator = set.iterator();
+ this.read_value = iterator.hasNext() ? iterator.next() : null;
+ set_topology(set.size() == 1 ? topo_rightmost : topo_segment);
+ }
+
+ // Instance interface implementation
+ @Override public void rewind(){
+ super.rewind();
+ if (set == null || set.isEmpty()){
+ set_topology(topo_null);
+ return;
+ }
+ this.iterator = set.iterator();
+ this.read_value = iterator.hasNext() ? iterator.next() : null;
+ set_topology(set.size() == 1 ? topo_rightmost : topo_segment);
+ }
+
+ protected void entangle(Ariadne_TM_SR_NX_Set<RT> copy){
+ super.entangle(copy);
+ copy.iterator = this.set.iterator();
+ copy.read_value = this.read_value;
+ }
+
+ @Override public Ariadne_TM_SR_NX_Set<RT> entangle(){
+ Ariadne_TM_SR_NX_Set<RT> copy = Ariadne_TM_SR_NX_Set.make(this.set);
+ entangle(copy);
+ switch (this.current_topology.topology()){
+ case NULL:
+ copy.current_topology = copy.topo_null;
+ break;
+ case SEGMENT:
+ copy.current_topology = copy.topo_segment;
+ break;
+ case RIGHTMOST:
+ copy.current_topology = copy.topo_rightmost;
+ break;
+ default:
+ throw new IllegalStateException("Unexpected topology: " + this.current_topology.topology());
+ }
+ return copy;
+ }
+
+ protected class SegmentTopo implements TopoIface<RT>{
+ @Override public boolean can_read(){ return true; }
+ @Override public RT read(){ return read_value; }
+ @Override public boolean can_step(){ return iterator.hasNext(); }
+ @Override public void step(){
+ read_value = iterator.next();
+ if (!iterator.hasNext()) set_topology(topo_rightmost);
+ }
+ @Override public Topology topology(){ return Topology.SEGMENT; }
+ }
+
+ protected class RightmostTopo implements TopoIface<RT>{
+ @Override public boolean can_read(){ return true; }
+ @Override public RT 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; }
+ }
+}