+++ /dev/null
-#!/bin/bash
-java com.ReasoningTechnology."Ariadne".Build
+import com.ReasoningTechnology.Ariadne.Ariadne_SRM;
import java.math.BigInteger;
public class CountingNumber extends Ariadne_SRM<BigInteger>{
return i;
}
- private abstract class BaseState extends State{
- abstract MachineState state();
- }
-
- private class State_Null extends BaseState{
+ private class State_Null extends State{
@Override
boolean can_read(){
return false;
}
}
- private class State_Segment extends BaseState{
+ private class State_Segment extends State{
@Override
boolean can_read(){
return true;
}
}
- private class State_Rightmost extends BaseState{
+ private class State_Rightmost extends State{
@Override
boolean can_read(){
return true;
}
}
- private class State_Infinite extends BaseState{
+ private class State_Infinite extends State{
@Override
boolean can_read(){
return true;
+++ /dev/null
-#!/bin/bash
-java Example_*
--- /dev/null
+
+import com.ReasoningTechnology.Ariadne.Ariadne_SRM;
+import com.ReasoningTechnology.Ariadne.Ariadne_SRM_List;
+
+import java.math.BigInteger;
+
+public class Example_IndexTree_4x4{
+
+ public static void main(String[] args){
+
+ Ariadne_IndexTree_Graph graph = new Ariadne_IndexTree_Graph();
+ Ariadne_SRM<BigInteger[]> root = graph.start();
+
+ Ariadne_IndexTree_Node label;
+ Ariadne_IndexTree_Node node;
+ Ariadne_SRM<BigInteger[]> child_srm;
+
+ // descend 3 more levels
+ label = root.read();
+ System.out.println(label);
+ int i = 1;
+ do{
+ node = graph.lookup(label);
+ child_srm = node.neighbor();
+ label = child_srm.read();
+ System.out.println(label);
+ 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(label);
+ if(i == 3) break;
+ i++;
+ }while(true);
+
+ }
+}
+
import java.util.LinkedList;
-public class Example_SRM_List {
+public class Example_SRM_List{
public static void main(String[] args){
// Create a linked list
LinkedList<String> label_list = new LinkedList<>();
import java.math.BigInteger;
-public class Ariadne_IndexTree_Child_SRM extends Ariadne_SRM<BigInteger[]> {
+public class Ariadne_IndexTree_Child_SRM extends Ariadne_SRMI<BigInteger[]>{
private BigInteger[] label;
}
protected Ariadne_IndexTree_Child_SRM(BigInteger[] initial_label){
- super();
- if (initial_label == null || initial_label.length == 0) {
+ super(BigInteger.ZERO ,null);
+ if(initial_label == null || initial_label.length == 0){
throw new IllegalArgumentException("Initial label must not be null or empty.");
}
this.label = initial_label;
+ set_state(state_infinite_right);
}
- @Override
- public Topology topology(){
- return Topology.INFINITE_RIGHT;
- }
+ private final Ariadne_SRM.State state_infinite_right = new Ariadne_SRM.State(){
+ @Override boolean can_read(){
+ return true;
+ }
+ @Override boolean can_step(){
+ return true;
+ }
+ @Override void step(){
+ increment_label();
+ }
+ @Override Ariadne_SRM.MachineState state(){
+ return Ariadne_SRM.MachineState.INFINITE;
+ }
+ };
- @Override
- public BigInteger[] access(){
- // Return a reference to the current label
- return label;
+ private void increment_label(){
+ label[label.length - 1] = super.index();
}
- @Override
- public void step(){
- int max_index = label.length - 1;
- label[max_index] = label[max_index].add(BigInteger.ONE);
+ @Override public void step(){
+ super.step();
+ label[label.length - 1] = super.index();
}
+ @Override public BigInteger[] read(){
+ return label;
+ }
}
import java.math.BigInteger;
import java.util.Arrays;
-public class Ariadne_IndexTree_Node extends Ariadne_Node<BigInteger[]> {
+public class Ariadne_IndexTree_Node extends Ariadne_Node<BigInteger[]>{
public static Ariadne_IndexTree_Node make(BigInteger[] label){
return new Ariadne_IndexTree_Node(label);
}
+ private final BigInteger[] first_child_label;
+
public Ariadne_IndexTree_Node(BigInteger[] label){
super(label);
+ this.first_child_label = new BigInteger[label.length + 1];
+ System.arraycopy(label, 0, this.first_child_label, 0, label.length);
+ this.first_child_label[label.length] = BigInteger.ZERO;
}
@Override
public Ariadne_IndexTree_Child_SRM neighbor(){
- // Copy the current label
- BigInteger[] parentLabel = this.label();
- BigInteger[] childLabel = new BigInteger[parentLabel.length + 1];
- System.arraycopy(parentLabel, 0, childLabel, 0, parentLabel.length);
-
- childLabel[parentLabel.length] = BigInteger.ZERO;
-
- return Ariadne_IndexTree_Child_SRM.make(childLabel);
+ return Ariadne_IndexTree_Child_SRM.make(first_child_label);
}
@Override
return this.label;
}
- public Ariadne_SRM<TLabel> neighbor() {
- return Ariadne_SRM.make();
+ public Ariadne_SRM<TLabel> neighbor(){
+ throw new UnsupportedOperationException("Neighbor is not implemented in the base class.");
}
public void mark(Ariadne_Token token) {
This is for single-threaded execution. The multi-threaded model
uses `mount` and `dismount` to lock the resources being iterated on.
*/
+package com.ReasoningTechnology.Ariadne;
public abstract class Ariadne_SRM<T>{
abstract MachineState state();
}
- private State current_state;
+ protected State current_state;
protected void set_state(State new_state){
this.current_state = new_state;
*/
package com.ReasoningTechnology.Ariadne;
-
-public class Ariadne_SRMI<TElement> extends Ariadne_SRM<TElement>{
-
- public static <TElement> Ariadne_SRMI<TElement> make(){
- return new Ariadne_SRMI<TElement>();
- }
- protected Ariadne_SRMI(){
+import java.math.BigInteger;
+
+public abstract class Ariadne_SRMI<T> extends Ariadne_SRM<T>{
+
+ private BigInteger current_index;
+ private final BigInteger leftmost_index;
+ private final BigInteger rightmost_index;
+
+ public Ariadne_SRMI(BigInteger leftmost_index, BigInteger rightmost_index){
+ if(leftmost_index == null
+ || rightmost_index == null
+ || leftmost_index.compareTo(rightmost_index) > 0
+ ){
+ throw new IllegalArgumentException("Invalid tape bounds.");
+ }
+ this.leftmost_index = leftmost_index;
+ this.rightmost_index = rightmost_index;
+ this.current_index = leftmost_index;
}
- public int index(){
- throw new UnsupportedOperationException("Ariadne_SRMI::index not implemented.");
+ public BigInteger index(){
+ return current_index;
}
- public int leftmost_index(){
- throw new UnsupportedOperationException("Ariadne_SRMI::leftmost_index not implemented.");
+ public BigInteger leftmost_index(){
+ return leftmost_index;
}
- public int rightmost_index(){
- throw new UnsupportedOperationException("Ariadne_SRMI::rightmost_index not implemented.");
+
+ public BigInteger rightmost_index(){
+ return rightmost_index;
}
- void seek(int i){
- throw new UnsupportedOperationException("Ariadne_SRMI::seek not implemented.");
+ public void seek(BigInteger new_index){
+ if(new_index.compareTo(leftmost_index) < 0 || new_index.compareTo(rightmost_index) > 0){
+ throw new IndexOutOfBoundsException("Index out of bounds.");
+ }
+ this.current_index = new_index;
}
+ @Override
+ public void step(){
+ current_state.step();
+ current_index = current_index.add(BigInteger.ONE);
+ }
}
package com.ReasoningTechnology.Ariadne;
-import java.util.List;
-
-public class Ariadne_SRMI_Array<TElement> extends Ariadne_SRMI<TElement>{
-
- public static <T> Ariadne_SRMI_Array<T> make(List<T> array){
- return new Ariadne_SRMI_Array<>(array);
- }
- private List<TElement> _array;
- private int _index;
- private Topology _topology;
- private Location _location;
-
- protected Ariadne_SRMI_Array(List<TElement> array) {
- _array = array;
+import java.math.BigInteger;
+import java.util.List;
- if( _array == null || _array.isEmpty() )
- _topology = Topology.NO_CELLS;
- else if( _array.size() == 1 )
- _topology = Topology.SINGLETON;
- else
- _topology = Topology.SEGMENT;
+public class Ariadne_SRMI_Array<TElement> extends Ariadne_SRMI<TElement> {
- if(_topology == Topology.SEGMENT)
- _location = Location.LEFTMOST;
- else
- _location = Location.OTHER;
+ private final List<TElement> array;
- _index = 0;
- }
+ public Ariadne_SRMI_Array(List<TElement> array) {
+ super(BigInteger.ZERO, array == null || array.isEmpty() ? BigInteger.ZERO : BigInteger.valueOf(array.size() - 1));
- @Override
- public Topology topology(){
- return _topology;
- }
-
- @Override
- public Location location(){
- return _location;
- }
+ if (array == null || array.isEmpty()) {
+ set_state(state_null);
+ } else if (array.size() == 1) {
+ set_state(state_rightmost);
+ } else {
+ set_state(state_segment);
+ }
- @Override
- public TElement access(){
- if( can_read() ) return _array.get( _index );
- throw new UnsupportedOperationException("Ariadne_SRMI_Array::read can not read tape.");
+ this.array = array;
}
@Override
- public void step(){
- if( can_step() ){
- _index++;
- if( _index == _array.size() - 1 ) _location = Location.RIGHTMOST;
- return;
+ public TElement read() {
+ if (!can_read()) {
+ throw new UnsupportedOperationException("Cannot read from the current state.");
}
- throw new UnsupportedOperationException("Ariadne_SRMI_Array::step can not step.");
+ return array.get(index().intValueExact());
}
- @Override
- public int leftmost_index(){
- return 0;
- }
+ private final State state_null = new State() {
+ @Override
+ boolean can_read() {
+ return false;
+ }
+ @Override
+ boolean can_step() {
+ return false;
+ }
+ @Override
+ void step() {
+ throw new UnsupportedOperationException("Cannot step from NULL state.");
+ }
+ @Override
+ MachineState state() {
+ return MachineState.NULL;
+ }
+ };
- @Override
- public int rightmost_index(){
- if( can_read() ) return _array.size() - 1;
- throw new UnsupportedOperationException("Ariadne_SRMI_Array::rightmost_index can not read array.");
- }
+ private final State state_segment = new State() {
+ @Override
+ boolean can_read() {
+ return true;
+ }
+ @Override
+ boolean can_step() {
+ return index().compareTo(rightmost_index().subtract(BigInteger.ONE)) < 0;
+ }
+ @Override
+ void step() {
+ if (can_step()) {
+ seek(index().add(BigInteger.ONE));
+ } else {
+ set_state(state_rightmost);
+ }
+ }
+ @Override
+ MachineState state() {
+ return MachineState.SEGMENT;
+ }
+ };
+ private final State state_rightmost = new State() {
+ @Override
+ boolean can_read() {
+ return true;
+ }
+ @Override
+ boolean can_step() {
+ return false;
+ }
+ @Override
+ void step() {
+ throw new UnsupportedOperationException("Cannot step from RIGHTMOST state.");
+ }
+ @Override
+ MachineState state() {
+ return MachineState.RIGHTMOST;
+ }
+ };
}
to read the current element without advancing the iterator.
*/
-
package com.ReasoningTechnology.Ariadne;
-
import java.util.List;
-import java.util.ListIterator;
-
-public class Ariadne_SRM_List<TElement> extends Ariadne_SRM<TElement> {
-
- public static <TElement> Ariadne_SRM_List<TElement> make(List<TElement> list){
- return new Ariadne_SRM_List<>(list);
- }
-
- private List<TElement> _list; // The attached linked list
- private ListIterator<TElement> iterator; // Iterator for traversal
- private TElement read_value; // Stores the current cell value
- private Topology _topology;
- private Location _location;
-
- // Protected constructor for controlled instantiation
- protected Ariadne_SRM_List(List<TElement> list){
- init(list);
- }
- private void init(List<TElement> list){
- _list = list;
-
- if( _list == null || _list.isEmpty() )
- _topology = Topology.NO_CELLS;
- else if( _list.size() == 1 )
- _topology = Topology.SINGLETON;
- else
- _topology = Topology.SEGMENT;
+public class Ariadne_SRM_List<T> extends Ariadne_SRM<T>{
- if(_topology == Topology.SEGMENT)
- _location = Location.LEFTMOST;
- else
- _location = Location.OTHER;
+ private final List<T> list;
+ private int current_index;
- if(_topology.ordinal() >= Topology.SINGLETON.ordinal()){
- iterator = _list.listIterator();
- read_value = iterator.next();
+ public Ariadne_SRM_List(List<T> list){
+ if(list == null || list.isEmpty()){
+ this.list = null; // not used, but what Java says, goes, if you want you code.
+ set_state(state_null);
+ }else{
+ this.list = list;
+ this.current_index = 0;
+ set_state(state_segment);
}
}
- @Override
- public Topology topology(){
- return _topology;
- }
-
- @Override
- public Location location(){
- return _location;
- }
+ private final State state_null = new State(){
+ @Override
+ boolean can_read(){
+ return false;
+ }
+ @Override
+ boolean can_step(){
+ return false;
+ }
+ @Override
+ void step(){
+ throw new UnsupportedOperationException("Cannot step from NULL state.");
+ }
+ @Override
+ MachineState state(){
+ return MachineState.NULL;
+ }
+ };
- @Override
- public TElement access(){
- if( can_read() ) return read_value;
- throw new UnsupportedOperationException("Ariadne_SRM_List::access can not read tape.");
- }
+ private final State state_segment = new State(){
+ @Override
+ boolean can_read(){
+ return true;
+ }
+ @Override
+ boolean can_step(){
+ return current_index < list.size() - 1;
+ }
+ @Override
+ void step(){
+ if(can_step()){
+ current_index++;
+ }else{
+ set_state(state_rightmost);
+ }
+ }
+ @Override
+ MachineState state(){
+ return MachineState.SEGMENT;
+ }
+ };
- @Override
- public void step(){
- if( can_step() ){
- read_value = iterator.next(); // Move to the next cell and update current value
- if( !iterator.hasNext() ) _location = Location.RIGHTMOST;
- return;
+ private final State state_rightmost = new State(){
+ @Override
+ boolean can_read(){
+ return true;
}
- throw new UnsupportedOperationException("Ariadne_SRM_List::step can not step.");
- }
+ @Override
+ boolean can_step(){
+ return false;
+ }
+ @Override
+ void step(){
+ throw new UnsupportedOperationException("Cannot step from RIGHTMOST state.");
+ }
+ @Override
+ MachineState state(){
+ return MachineState.RIGHTMOST;
+ }
+ };
@Override
- public void rewind(){
- init(_list);
+ public T read(){
+ if(!can_read()){
+ throw new UnsupportedOperationException("Cannot read from NULL state.");
+ }
+ return list.get(current_index);
}
-
}