From ad2d812cf2ff7e529a290d59b3ee91713542925c Mon Sep 17 00:00:00 2001 From: Thomas Walker Lynch Date: Mon, 6 Jan 2025 10:22:07 +0000 Subject: [PATCH] More true to the C implementation SRM running on CountingNumber example --- .../Step_Right_Machine.txt" | 99 ++++++++++------ .../example/CountingNumber$BaseState.class | Bin 0 -> 635 bytes .../CountingNumber$State_Infinite.class | Bin 0 -> 1113 bytes .../example/CountingNumber$State_Null.class | Bin 0 -> 998 bytes .../CountingNumber$State_Rightmost.class | Bin 789 -> 1017 bytes .../CountingNumber$State_Segment.class | Bin 0 -> 1375 bytes developer/example/CountingNumber.class | Bin 1670 -> 1896 bytes developer/example/CountingNumber.java | 111 +++++++++--------- developer/example/Example_CountingNumber_0 | 2 + .../example/Example_CountingNumber_0.class | Bin 0 -> 2042 bytes .../example/Example_CountingNumber_0.java | 55 +++++---- .../example/Example_IndexTree_Diagonal_SRM | 2 + .../Example_IndexTree_Diagonal_SRM.class | Bin 0 -> 1852 bytes developer/example/Example_SRMI_Array | 2 + developer/example/Example_SRMI_Array.class | Bin 0 -> 2389 bytes developer/example/Example_SRM_List | 2 + developer/example/Example_SRM_List.class | Bin 0 -> 2515 bytes .../example/IndexTree_Diagonal_SRM.class | Bin 0 -> 4313 bytes .../javac\360\237\226\211/Ariadne_SRM.java" | 92 ++++----------- 19 files changed, 175 insertions(+), 190 deletions(-) create mode 100644 developer/example/CountingNumber$BaseState.class create mode 100644 developer/example/CountingNumber$State_Infinite.class create mode 100644 developer/example/CountingNumber$State_Null.class create mode 100644 developer/example/CountingNumber$State_Segment.class create mode 100755 developer/example/Example_CountingNumber_0 create mode 100644 developer/example/Example_CountingNumber_0.class create mode 100755 developer/example/Example_IndexTree_Diagonal_SRM create mode 100644 developer/example/Example_IndexTree_Diagonal_SRM.class create mode 100755 developer/example/Example_SRMI_Array create mode 100644 developer/example/Example_SRMI_Array.class create mode 100755 developer/example/Example_SRM_List create mode 100644 developer/example/Example_SRM_List.class create mode 100644 developer/example/IndexTree_Diagonal_SRM.class diff --git "a/developer/document\360\237\226\211/Step_Right_Machine.txt" "b/developer/document\360\237\226\211/Step_Right_Machine.txt" index d602f9b..df98f3a 100644 --- "a/developer/document\360\237\226\211/Step_Right_Machine.txt" +++ "b/developer/document\360\237\226\211/Step_Right_Machine.txt" @@ -1,56 +1,83 @@ - A 'tape' as a model for computation is a sequence of cells, where something can be written or read from each cell. We talk about the sequence as though written on paper, running from left to right. The elements in the sequence have neighbors, so the sequence of cells can be said to be mutually connected. This is to say that if cell B is to the right of cell A in the sequence, then cell A is to the left of cell B; Also if cell A is to the left of cell B, then cell B is to the right of cell A. +Tape - One of the cells on the tape is specially marked as being the 'mounted cell'. This is the cell that can be written or read after the tape is mounted on a 'tape machine', and before any steps have been taken. + A 'tape' is a one dimensional discrete space. Being a discrete space, rather than having points, it has 'cells'. - Information from the `topology` method will remain valid for as long as the topology of - the tape is not modified. + Rather than a function definition assigning a value to a point, and evaluating a function resulting in reading that value back, in a discrete space, a machine writes a value to a cell, and then upon revisiting the cell it can read the value back. The cell that the machine is reading or writing, is the 'cell the head is on'. The machine domain is then the 'tape'. - A finite tape will have a leftmost cell, which has no left neighbor, and a rightmost cell, which has no right neighbor. All other cells will have two neighbors. + A 'tape' is any manifold where each cell has two neighbors, there are two possible such manifolds, either a finite number of cells linked in a cycle, or an unbounded number of cells. A third candidate, the null manifold, does not violate the two neighbor requirements, nor does it fulfill them.. - A tape can have an infinite number of cells to the left of the mount point, to the right of the mount point, or in both directions. Hence it is possible that two, one, or zero cells on a tape have only one neighbor, where the zero neighbor case is for finite tapes, and the latter cases are for infinite tapes. + Experience with physical memory tapes guides our abstraction of a tape as a mathematical entity. Note that physicals tapes can have no cells. Two examples include unformated tapes and short tapes that have leaders for mounting on the machine, but after being mounted, do not have sufficient length to be written to. This can happen physically, or logically if more than one volume shares a given tape. Hence, our analogy supports the idea of having a null tape, one with no cells, as an entity. - An algorithm running on a tape machine that has a left going tape can be translated into an algorithm for a right going tape simply by swapping `step_right` for `step_left`. Hence there is no utility to be had by keeping both models. + Given a tape we can prove it to be either a cycle or unbounded by analyzing the situation of mounting the tape on a tape machine and stepping. If by analysis we can proves that when starting at the mount point cell, that stepping in one direction eventually leads back to the mount point cell, then the tape is a cycle. On the other hand if we can prove that will not happen, the tape is unbounded. Note, we must use analysis rather than running the machine, because when stepping the machine in the unbounded case, it will never halt. This is a form of hmotropy analysis of our manifold, with the stepping machine representing a limit. - Another isomorphism can be setup between a single ended tape and a double direction tape by replacing each step by two steps, and then placing odd cell into correspondence with the right going tape, and even cells with left going tape. Hence an algorithm implemented over the top of either can be mechanically transformed to an algorithm for the other. + Suppose we have an unbounded tape. We can create a new manifold by cutting the tape, thus producing to two half tapes, each singly ended though still countably infinite in length. Such a manifold is equivalent to a 'sequence' in mathematics. Both of these manifolds are equivalent to the original uncut manifold. We can see this by taking a sequence and placing every other cell in correspondence to cells on the original tape, alternately mapping to the next consecutive cell on the right going side, then on the left going side. - However, what we can not do without affecting the power of our computation machine is to - eliminate 'step-left', yet this is a common simplification in data structures. The Lisp language is based on single linked lists for example. + We can take the right going tape and cut it again, to create a finite tape segment, and another right going infinite tape which we let drop to the cutting floor. The finite segment is not equivalent to the original tape of course, as any at mapping all the cells from each tape, will exhaust all the cells on the finite tape with cells left over on the unbounded one. It is interesting to note that the right going tape we left on the floor is in fact equivalent to the tape it was cut from. - This 'Step Right Machine' (SRM) defined here can only be stepped to the right. Thus whether cells are mutually connected, or not, becomes irrelevant. Also, saying 'leftmost' is a feature of the tape, becomes muddled, as the mount point cell will be the leftmost cell that is ever visited. + The finite tape of at least two cells will have two cells that have only one neighbor, the leftmost and the rightmost cell. This manifold is equivalent to a vector variable in mathematics. If merely one cell is shaved off, this singleton tape will have no neighbors. This is equivalent to a variable in mathematics. - A SRM can be defined using functions, or it can be used as an iterator for traversing through a container. + Hence, a half tape manifold can be null, singleton, cyclic, or infinite. - The property methods defined here are kept general so that they can be used with other tape machines. +--- +Singly Linked Tape ------ + Consider a tape where each cell has one right neighbor instead of two mutual neighbors. -public void lenient_mount() { - if(status() != Status.TAPE_NOT_MOUNTED) { - dismount(); // Ensure the current tape is dismounted first - } - mount(); // Proceed to mount the new tape -} + When mounted on a tape machine, the mount point cell is the leftmost cell, because the machine can not step left because there is no left neighbor. -public void lenient_dismount() { - if(status() != Status.TAPE_NOT_MOUNTED) { - dismount(); // Only dismount if a tape is currently mounted - } -} -Why This Works Without synchronized: -Thread Safety via LockManagerDelegate: + When cut, we do not get two infinite singly linked tapes, instead we jump ahead to + the case of the two parts being an a finite segment, and an infinite right going tail. -LockManagerDelegate manages locks and ensures that only one thread can operate on the tape at a time. -When relinquish or request is called, the delegate ensures proper locking/unlocking. -No Shared State Changes in SRM Methods: + In the case of the doubly linked tape, the only way a tape could be cyclic while each cell has two local mutually connected neighbors, is if all the cells are connected in one big cycle. For the singly linked tape, there are no mutual connections, so a cycle can be created by a cell assigning a right neighbor to any other cell already on the tape, including itself. Hence, the Singly Linked Tape has three possible cycle cases. However, for the + state machine methods behave the same for all three. -The SRM methods (mount, dismount, lenient_mount, lenient_dismount) simply delegate to LockManagerDelegate and update internal state like Status. There’s no risk of race conditions if the delegate properly handles concurrent access. -Relinquishing Locks Last: + Also for the single linked machine, the Singleton manifold and the Rightmost manifold + become identical. -By ensuring that relinquish is the last step in dismount and other relevant methods, we prevent premature lock release before operations are complete. + Hence these are the possible manifolds for a singly linked tape: + null, cyclic, segment, or infinite. ----- -a SRM with a function implementation represents an evolving system, it is common that information is lost for reversing a forward step in an evolving system, so it is natural in function based programming to have a tape machine that only steps right. + + A machine with a singly linked tape mounted, can not compute some things that a Turing Machine can, yet, it is a common data structure used in computing. It can be used with forward, irreversible, advance of a program. This is the most common kind actually. If local reversibility is needed, a cache or window can be used for recent values. The depth of this local memory is an interesting metric. For macro level reversibility, a system can use checkpoints. -Still a Turing Machine can step left, and there are computation complexity implications. Some of these can be mitigated by having a context window, and thus tentative forward evolution of the system. +--- + +The Step Right Machine + + This is a conventional iterator for traversing through containers. The items visited + during the traversal are as though values in cells on a single linked tape. + + +--------------------------------------- + +Tape Topology + +A tape is a one-dimensional discrete space consisting of "cells." These cells represent the fundamental units of memory that a machine can read from or write to. The set of all cells defines the tape topology, which determines the connectivity and traversal characteristics of the tape. + +Key Characteristics of Tape Topologies +1. Stepping Determines Topology: + - A machine begins at the leftmost cell when the tape is mounted. Stepping right from this cell reveals the connectivity of the tape. This process is analogous to "shrinking the circle" in topology, where stepping serves as an operation to explore and classify the tape's structure. + +2. Single-ended Constraint: + - A tape is always single-ended because there is no cell to the left of the leftmost cell. This rules out two-way infinite tapes, as there is no way to step left. + +3. Unbroken Connectivity: + - The tape is either unbounded (infinite), cyclic (all cells connect into a single cycle), or finite (with distinct leftmost and rightmost boundaries). If stepping reaches a cell that is not connected to any other cell, that cell is the rightmost cell of a finite tape segment. + +Defined Topologies + +State can_read() can_step() Notes +Null false false No cells exist; the machine cannot perform any operation. +Cyclic true true The machine loops indefinitely, can always read and step. +Segment true true (until rightmost) Represents a bounded tape; steps until reaching the rightmost cell. +Infinite Right true true Unbounded cells extend infinitely; can always read and step. +Rightmost true false At the last cell of a finite segment (or singleton tape). + +--- +🥳 Cheers to: + +A precise loop that doesn’t compromise readability or efficiency. +An elegant state pattern that aligns with the real-world model. +The beauty of RT code format guiding clarity and consistency! diff --git a/developer/example/CountingNumber$BaseState.class b/developer/example/CountingNumber$BaseState.class new file mode 100644 index 0000000000000000000000000000000000000000..9f5177a70541e6bbb69fa088498bc6bd5a132b89 GIT binary patch literal 635 zcmZ8e+fKqj5IqY^D;K${Al@+H0W<;MAw(rHniONi_-Yo|z#7;l?c#s=Wa5J#;71vU zf?90TnVy|FGiPQ$zurFpba9+O1W_A2g%~V`+=ZvaNXw`GeXrU#!bk?It+X;7hHT9V zgGAD+HjrNRQuuPkEYzI!AaNLY*Bw#WjH9$%avsEBN+)^89g69r zAPIz5huln*&rtqX>90+Tg!QDExT8DaiJ3Igqx_h^6u)1qhecO=VmP6`fk0x$`)aI( znS0d!G@RIWp2dr3&V-pXFV*-)8#$IJi!Af6;^fsw5vMK%@uTi8UJP=>x31+!UB204Npd9o1{uod`i>;%4u YUGil_DOScl=Om(t10KO4;mY~$H_xt@@Bjb+ literal 0 HcmV?d00001 diff --git a/developer/example/CountingNumber$State_Infinite.class b/developer/example/CountingNumber$State_Infinite.class new file mode 100644 index 0000000000000000000000000000000000000000..e9433cd847630f05515a466eaff29d640c8e79f0 GIT binary patch literal 1113 zcma)5TW=CU6#iyex?HvtOQ|ik)(a{Zg?g!)V2qZuaT7oz4G+GMDU7fNcAMS7_@jK# zrq#p;e}F&AcxHE%7XcVyJW*gz8B)1f zkbEnO1eOdWO~qiNT}QN=uj|=5@APfwcd-$x zv2Qi3gFS{!?Qdok2EFQbslQ7#ay{$)0Y4m&X1V5e_@Kop0?A{guExNyHPgSDaS?2? zE@a>BzTzGq3Mo8tigdWs_5`P@L%IB$vBH<)h_X0iq;D~VeKmZBja>d;na7&$$m@uG zTVxiDfFd-6FJHL6WH2qq5ngq`eP2*AiP;5jYf?Hs_8 zNwvIm3zLSnkLWd$c8F`llVX!=J*CqM=hAleuNDEx=#(Ol1B5KG0ZA{4|-7fz@EIwx2>M(PXJPO zmRL}xq@^BB0H)7Vxr5TU2*p(q`Y|>>&6M$B!dD;rhENWywsAM$3EU%|p|mvmr}v3Q Ph(FLZ`VTvJ^lbeXm&V{> literal 0 HcmV?d00001 diff --git a/developer/example/CountingNumber$State_Null.class b/developer/example/CountingNumber$State_Null.class new file mode 100644 index 0000000000000000000000000000000000000000..fdba8e46851da25e92b38769c25b171f44cdd4fd GIT binary patch literal 998 zcma)5-*3`T6#i~06gu1xoDMb>6&Y-k?O_ilEJh_7O$r)uB>F<`;5ur`Eom>tKgtL7 zWr-&G?jL15x8PP5m)NBD{OCE~`OcTyU%$Wo0MJ6ihJl0yGm9ir3~McaDwQjbJJa!z z2r7?xD7uO(!H_y|rK=t=6l%_5RkPl+kY?C?&p+^8kIUoTLm5sd6F*R5_+lagu3TR} z`8W_0?WAEdY_zzPzAA@GOv>*9e_ZYyIu3<2j96L7YD$+FR%^}~ZdV0Fjs|A1f}DlR zS>#b5-j4#852fgLU$rZ3J{Y<3FK<)hGL)Q)N}3i{8H$TLRidr?ovG(Bm@R)u3amJU zIuqtKKk_J(cl-hOdYpz+JWrZxU?Tz`vmL@ zc?PcO7>v$)Sfeu=`6(1pqG+AoBz?@~$l1Vk`lx|+$m$j&@kyUCki8g)F$V!|{72{h zKRa*IGP9ZcNJKO3@37wFGbdR3d2aUo7=nE|`xb7`5gKGQYx66XKcDM8i1nKD-URMM gRTbQgY!x-KCE{VAin?jgFR_K4heeXRO7a zG|@!g{iBStfC#6(2Hw_1s~ue*EI7SvzesiIjzeW^{#N&9451Z77epQNI|HNLjd= zKpGjM{ls&4SBiF{Udz{br|-x=v}1EvhHUk+yt0KghVA9K@{`Hib*I-?L)TXfX2tE& zDw0*gpKhqh&j%DqSKSUDv^dcqe-<=V-|-o8fprC8%M7WSP<^-il6!n8l<=r3+TpV8 z3EpK0*~QnhfZi6-m@1057{dPae75Z3<>N8L8}8Wai06)`n^_*Tq&G|*PK2+HXiy8g z46DmI42feYg;yDH-xowMHoqGd_8C?dR!h0dhmZ_x5;i>IG3X}WqOuakG5w2nvi z_AkIblV#wB_Q6QDuud{Du_M?(mb^`R!}KwgB4Z0T>7xcZAgxOb^P`pvAZH68#ta15 z{R>@kf5SMAVncXVgZ+ehI|8Z;45gTB7p=w zze7cXn6q4%h?8z+_jYIYwBO;Q-u(P|eFxCQMg#>fgkM4cEvPkY)eqi`23{PzOvoq)?yt~v~|ZP)0kLcwoi8N zdTVZhhuvl^OIn1-@q8+jf7%2bQVZp@~TvYA?Ec}%^ zjW@2m`&YS$rF`fCyzFn$8^W{d#ON54A7jJs3l>p6+{1F#wSv`*4c7zqxm6g{eZ^%N G#8AJfk|=oq diff --git a/developer/example/CountingNumber$State_Segment.class b/developer/example/CountingNumber$State_Segment.class new file mode 100644 index 0000000000000000000000000000000000000000..971226676562b751e465b4c15d3d48151f145914 GIT binary patch literal 1375 zcma)5ZBr6a6n-u&E-$O1sHvHmQ2`qCZiSUfh$dhojvxHuT;UF^!D73M(_iU7^r0NJ znLhLb`cX~iE?X@Q)AZqw#&u`xWxz^-aSTbzx>h7{j=V2@O}I=~zD{ z2LEbz!9*>_6a22gc}kkF7s ziXmhP`@pfHQY88)%PKD7u8OpV45(R?UceHsHgw~6Gt^4HP|BBg8K!%XyjocXCD*PA z3bsg=-O1SHhfR`<7TZ^fx7_3{VGEONf>mxD zn1WMJ{E6hgE3j;FOhI%R$@drrX_~6kK2_GCQg&HW(rvF+;%lV9>l3#vE;7 zkQS0fqjC@F79a_264CqgdQ99$Jd#>C2TLt{h5Ch_K0F{g07i5L4~c5dJ%UGM0z9D; zpie>tmhhB5CE6l!Y2s5pN$LT~c|d$F2=MGbEDL=tpCjw~Jb~Zwxs*Di1n8V$@D#BN zOrB%VeRtW+1+IU@$X~si7q}y{^*e!%LZSN>ZCeoulqkn-kLx8j=w(Nr$pXBqUDN;+l*7DvOv{B_ytNXIjf zgrV}xn|MYgNd%Z~u&v{QKzb~|j@>%)I$f6#3jxHUi6sRw9YFL>9CSP@urwB=;(Vp( zk_OTN#&af~_iGI>>~KGh6FxVxAYgV3wd(Dx;D(7;6@<2T zduQ9A;dK*l;7!IiyPXGCPwsZv0NL>;%2iavnu)i-eu>Gi`&Qc(m_=xq@x@x!* zvCG{<22EFOM+R-ZYaO&{Nmjc}tKG0T64XPZ<{jBAZ02-_v)c&RyuW2VIPvUQ_lc7I zH^$B)Bw5~QYw>uglbVM)6j=E`H8R|&cl*7jyko11W=GLiRdaFZYtr?$q#9^f$H%03 z)NOgwa;49ffLU=I*(9??0KLwb}*Y(-k$1w;&* zpXXuzSBU%*=yxf^2QVoom7E%2j`D(%FAi{ta$3ok2gu|fV|jplzA(T`g+DNr&;NqV zF<$-&Hwuq&{TQ$P7#L08c$voKW0ZafjF)`lqzam&_=xpPpu*=mruj_pWan6G9E&h` zcTD0srcmPEP1bXZb#G%9cag#&=HOr+-|;s49vAT*qvwOF@II>4fQLSN0$Y@m(Ees{ zL`OpB6eE?=nWaXP&k3&a9D;uFCrGGL-~O3O#6Mch-&pcfn1NIHS`@$sAwY%z>gNN9 z5I_t8Wa!9258aDgRlX>h$e+%2WhhrPC}(Da!5^LpKE~$h;EA)rWHsoV9n_gKf?a&X wRb5YM@|Wayt$|Nyxys%nLu5FDJ^nw_H0~zwIpqbeUvN!x-RIii`lS~62X=;-MF0Q* literal 1670 zcmZ`(T~8BH5IwgoU0N1IKrAWa50lxU4 zMl_McR}+7fc<$XTX>sjC=g#cRnVECv&hI}zegY`tiGhSbPr2T31KX`FHJo+nWg(C< z(Sfu;`j+k5!K}bgq4LstW0f2$*ecE0wFNhjHR;Vvu4d7RjDf6*=o0AFZrheyD=n|T zl+{2WS(seSpc_2~4w>l1VS#}-FnTU8JrEd-PnBU^{U!!fys(uvXyT~S499wBI}OLc zkie<-ZYEX&E0Ajo?xyNQKDBFGK^8e2SM{DCVxiI=z?KY*2n@HIBbixIYQyuS8?5;%pK2m5ekO}NP8&F5qJT;A5a%S&S+(3XPg)zAyca5H%EVa} zp+EV7e65VrCQ6F*lrm5_)+?qi{O_&~lr+PLa(#mlhbp!!!`pvmt#8xPSE*O6?N!UO zmEJTKCSxFiE!*e4|NEtz)K_0ETCbzn}bHC1R@Ri{fx=n}HpnqwhDEosyHY15b?&D=Zc*+y6wwNC1bUorX(6Ca5iqJSfBuNc;tNzd~C8 diff --git a/developer/example/CountingNumber.java b/developer/example/CountingNumber.java index adedfc5..c9717ee 100644 --- a/developer/example/CountingNumber.java +++ b/developer/example/CountingNumber.java @@ -1,129 +1,124 @@ import java.math.BigInteger; -public class CountingNumber { +public class CountingNumber extends Ariadne_SRM{ private BigInteger i; private BigInteger maximum; - private State current_state; - public static CountingNumber make( BigInteger maximum ){ - return new CountingNumber( maximum ); - } + private final State state_null = new State_Null(); + private final State state_segment = new State_Segment(); + private final State state_rightmost = new State_Rightmost(); + private final State state_infinite = new State_Infinite(); - public static CountingNumber make(){ - return new CountingNumber( null ); - } - - private CountingNumber( BigInteger maximum ){ + private CountingNumber(BigInteger maximum){ this.i = BigInteger.ONE; this.maximum = maximum; - this.current_state = ( maximum == null ) ? new State_InfiniteRight() : new State_Leftmost(); - } - private void set_state( State new_state ){ - this.current_state = new_state; - } - - public boolean can_read(){ - return current_state.can_read(); + if( maximum == null ){ + set_state(state_infinite); + }else if( maximum.compareTo(BigInteger.ZERO) <= 0 ){ + set_state(state_null); + }else if( maximum.equals(BigInteger.ONE) ){ + set_state(state_rightmost); + }else{ + set_state(state_segment); + } } - public boolean can_step(){ - return current_state.can_step(); + public static CountingNumber make(BigInteger maximum){ + return new CountingNumber(maximum); } - public void step(){ - current_state.step(); + public static CountingNumber make(){ + return new CountingNumber(null); } + @Override public BigInteger read(){ return i; } - // --- State Interface --- - private abstract class State { - abstract boolean can_read(); - abstract boolean can_step(); - abstract void step(); + private abstract class BaseState extends State{ + abstract MachineState state(); } - // --- State_Leftmost --- - private class State_Leftmost extends State { + private class State_Null extends BaseState{ @Override boolean can_read(){ - return true; + return false; } - @Override boolean can_step(){ - return true; + return false; } - @Override void step(){ - i = i.add( BigInteger.ONE ); - if( i.equals( maximum ) ){ - set_state( new State_Rightmost() ); - }else{ - set_state( new State_InterimSegment() ); - } + throw new UnsupportedOperationException("Cannot step from NULL state."); + } + @Override + MachineState state(){ + return MachineState.NULL; } } - // --- State_InterimSegment --- - private class State_InterimSegment extends State { + private class State_Segment extends BaseState{ @Override boolean can_read(){ return true; } - @Override boolean can_step(){ return true; } - @Override void step(){ - i = i.add( BigInteger.ONE ); - if( i.equals( maximum ) ){ - set_state( new State_Rightmost() ); + i = i.add(BigInteger.ONE); + if( i.equals(maximum) ){ + set_state(state_rightmost); } } + @Override + MachineState state(){ + return MachineState.SEGMENT; + } } - // --- State_InfiniteRight --- - private class State_InfiniteRight extends State { + private class State_Rightmost extends BaseState{ @Override boolean can_read(){ return true; } - @Override boolean can_step(){ - return true; + return false; } - @Override void step(){ - i = i.add( BigInteger.ONE ); + throw new UnsupportedOperationException("Cannot step from RIGHTMOST."); + } + @Override + MachineState state(){ + return MachineState.RIGHTMOST; } } - // --- State_Rightmost --- - private class State_Rightmost extends State { + private class State_Infinite extends BaseState{ @Override boolean can_read(){ return true; } - @Override boolean can_step(){ - return false; + return true; } - @Override void step(){ - throw new UnsupportedOperationException( "Cannot step from RIGHTMOST." ); + i = i.add(BigInteger.ONE); + } + @Override + MachineState state(){ + return MachineState.INFINITE; } } + } diff --git a/developer/example/Example_CountingNumber_0 b/developer/example/Example_CountingNumber_0 new file mode 100755 index 0000000..03434e8 --- /dev/null +++ b/developer/example/Example_CountingNumber_0 @@ -0,0 +1,2 @@ +#!/bin/bash +java Example_CountingNumber_0 diff --git a/developer/example/Example_CountingNumber_0.class b/developer/example/Example_CountingNumber_0.class new file mode 100644 index 0000000000000000000000000000000000000000..44b2030f98d571488a2a16ead3ba60991256cac8 GIT binary patch literal 2042 zcmaJ?T~``c6x~;l0UQUg5Cu$?6st55Xx%POOshA zkYUB|+lDC%(iXgt@MDDGaz+Z9OT(;2WX-nP)mkKJwM}Os-)?LRyR{lb2xA(;I>s@< zFy1E^gVt1`>n3H3y6GI=l#5~~Vp~B>VOqnCj#RmBI^IW=!RykRq4ZAa4K8c(b)%XwrKk!!5yUb+&~Qb^RjhQk!Kt27KIiqe z*nG;c)G3bJ)WmVvPQAk9hif`M#77L%4ZbUqmRaWVks)jJM0%LAbt>42(!JuVT0YV7 zsnXq%nY__di=XNET=~qa7L6a9pu&K6U7hN-h;oI*-R8XLq&)yxn*R_nClv23?} zs0A5(so^UfS>&kush@bGSr?^lSm_!=!0~BG3Ucar^mH88r<;n!eTFb~ygNdIs3olm zQ5(&Y^<487`F5RF!da`#>sy>0O7r7IudEr=sk!V~j40w@S$%N~EJGL33iT!(CX<(U zbG&&Hw!sZTPDP*ewmY^(B)MIswBvoY8G;3?ZI?ybP^{0NMQla2kjSiCmTXCzH*-SP ztV+v|GQ(K1ZQH_>5m$lL2pjc51o0GA4K-z4gJHojfn#fOjI}G`u18%jr+Hag_8!A8 zou9-p(9Ly^o0Ym~Eo3cgx7|$imfEq>^9fwHrdc9!Kk;0&7OjFp& zI&ZZ^OGBMusN-Cr{mvsugT=7eQ**ykG(2Ot@c&Rc>)pC>k<2|n2Lj*$xdlENzouE7 z?u_n(%fErWqK5%IpiylrXn{uE1)zwB&WyeeTA`Pjm(VKc{vovR@N0}NzsBSXcwfiL0KqUif?{@T)=(EA-Ed9lZPV z07EL_8U<5~Jr3hE#^~8ce=|S*YJ!*}-d8Y;>lnc*Msb7oHxMQnCh!E4sL7B39_y#tzNG Rv>qYOjoY)tx(OSz{{r0+2XX)a literal 0 HcmV?d00001 diff --git a/developer/example/Example_CountingNumber_0.java b/developer/example/Example_CountingNumber_0.java index 95a1fd7..1bc1ee9 100644 --- a/developer/example/Example_CountingNumber_0.java +++ b/developer/example/Example_CountingNumber_0.java @@ -1,37 +1,36 @@ -import com.ReasoningTechnology.Ariadne.Ariadne_SRM; import java.math.BigInteger; -public class Example_CountingNumber_0 { +public class Example_CountingNumber_0{ - protected static void print_ten(CountingNumber n) { + protected static void print_ten(CountingNumber n){ System.out.println("Iterating through Counting Numbers:"); - if (!n.can_read()) return; - - if (n.topology() == Ariadne_SRM.Topology.SEGMENT) { - if (n.can_read()) { - do { - System.out.println("Current Number: " + n.read()); - if (!n.can_step()) break; - n.step(); - } while (true); - } - } else if (n.topology() == Ariadne_SRM.Topology.INFINITE_RIGHT) { - int i = 1; - if (n.can_read()) { - do { - System.out.println("Current Number: " + n.read()); - if (i == 10) break; - n.step(); - i++; - } while (true); - } - } else { - System.out.println("Unrecognized tape topology."); + + if( !n.can_read() ) return; + + if( n.state() == Ariadne_SRM.MachineState.SEGMENT ){ + do{ + System.out.println("Current Number: " + n.read()); + if( !n.can_step() ) break; + n.step(); + }while( true ); + + }else if( n.state() == Ariadne_SRM.MachineState.INFINITE ){ + int count = 0; + do{ + System.out.println("Current Number: " + n.read()); + if( count == 9 ) break; + n.step(); + count++; + }while( true ); + + }else{ + System.out.println("Unrecognized or invalid tape state."); } } - public static void main(String[] args) { - print_ten(CountingNumber.make(BigInteger.TEN)); - print_ten(CountingNumber.make()); + public static void main(String[] args){ + print_ten( CountingNumber.make(BigInteger.TEN) ); // Finite segment up to 10 + print_ten( CountingNumber.make() ); // Infinite tape, stopping after 10 steps } + } diff --git a/developer/example/Example_IndexTree_Diagonal_SRM b/developer/example/Example_IndexTree_Diagonal_SRM new file mode 100755 index 0000000..5b45c16 --- /dev/null +++ b/developer/example/Example_IndexTree_Diagonal_SRM @@ -0,0 +1,2 @@ +#!/bin/bash +java Example_IndexTree_Diagonal_SRM diff --git a/developer/example/Example_IndexTree_Diagonal_SRM.class b/developer/example/Example_IndexTree_Diagonal_SRM.class new file mode 100644 index 0000000000000000000000000000000000000000..7f9b08e0649ece48dbe8210813346b0f3c1b17b4 GIT binary patch literal 1852 zcmaJ?T~kv>7=D(7oDdFR1M+1GkuQO$X|4StYAYx;ZBT0{)KVIkWE+m0oRc{@apb-~ zqSK2`#~W|8)4`6N;Rp0T^s4`&GuA$v6BS5GGTGht-FKh&c|UgZ=fBVQ0W3kr(1DPF zu!&AY1Ww$S4`kYwPC0#R>%J=b0+CCWWBFGELbG#gU5KK~K+Hrp%tPk+-I}i|v~ue_ zbTZcfvfT7-&vN{{?Z56`_yk#J6 zq8|eS{cUgrjH*Vp9Xgr~JT)lO4RJGbYcULB$iT3P5sV59zV=kOX34VaNV`Cn0^y3> zQ39j0bGh~=nK;vwF!46V1ctQrlIs+uzi#>4T-AK(_%+QUJJ-rXvq+jatrHt&cB)ZK z3Uq928ki>9n^Xt97weW?QeG5i1jI%RQ<&3L8Hgc;vj)zYIFGczK;v9R`rGM6tDJRw zRaTxr)OQ0IS}>fW;2Dkgu89kHk0q7Ws&YyK=h|hjLYiH`ed(2n)Zb>Com%tQufzXWd4ZU&S)u6G9d@+H3iPmbi#sc_+9Yaz?|Ljm z!IoRf7D&CKailnzHsv6oCD7SCIn*S0^q@dj;KEm|)<{c`uPQ^XdAIHr)v~3tI(dBJ z&g6VzUN7rA8nAnP4H#>0e>Qd-l-xJ0IE5 zWlD+gz2`UuP?w1Og2-d^{Lmp%dl-NG@^9@X)NnIHIKbco9-|u*z5FIH#7jJkGkhmg z8071Axo_>9DFP~VNv3-lTo6eqg~n#Jc$uD><8F3<1( zgh+hi$sd@y8=rZGSu#${??1w1YCdsc5A%C?XPt_0=@DY7_(d&}`{S2?rQ#oGfl++) z8cC7nf0e*iQ1qCpj;oWlzBaa!KQEwa?~dl8Pl mK(~P@G5!zB6vAz4JMbm$aE{XIEB^A>pcLckTYQIm82JwtRn6c4 literal 0 HcmV?d00001 diff --git a/developer/example/Example_SRMI_Array b/developer/example/Example_SRMI_Array new file mode 100755 index 0000000..80c5dbd --- /dev/null +++ b/developer/example/Example_SRMI_Array @@ -0,0 +1,2 @@ +#!/bin/bash +java Example_SRMI_Array diff --git a/developer/example/Example_SRMI_Array.class b/developer/example/Example_SRMI_Array.class new file mode 100644 index 0000000000000000000000000000000000000000..b66274fa8b64c3165e0efa70b69627bc274f5d5c GIT binary patch literal 2389 zcmbVNT~`}b6x|mB6Vjp3@Kq|Uw9*kS`<1D9a z9Q~Z`C6L5`f;afo?)gJ97i6wJV3fR!{td=Q;%~e&(BPTqQJu6mPz0|MipF8 z@fyYiZWQfGdR>>UZ84I9Ufi*4(=H#-y&+4M9?e_YdVX~)I8z{2k$bwpa_Xe>$z1#H zGCjD2*AsDZXJHGR<}87?@s5HUD&EDcz(7#j=Ij|_)yKlL2v1{(k=G5s+_zM` zhueh5v>A+Hb91}!p8NT*S#IP)>U@cbVfyT%|b+&RtW#K>Qr2Kj!GG!An2KQ4KdBj|W`!U=0r`p|QA#7&h8XRa)f)4Zt17Les5K@y77~U!B1ie362Sjp_lph^TjxaB@8lwAxI3f zlP};~zWCp9ho9(pm<&F_I#*+O3JnFOdKo4@#RidkMENl1Q1{ufZj-XlsZ-JM2bL5( xR&f3by?sep2fo4<=RvNY(BkW0+z!SPJ%dqnq5>OF?~d{fvEgubQNuSF{Tt;6li>gW literal 0 HcmV?d00001 diff --git a/developer/example/Example_SRM_List b/developer/example/Example_SRM_List new file mode 100755 index 0000000..e0d48dd --- /dev/null +++ b/developer/example/Example_SRM_List @@ -0,0 +1,2 @@ +#!/bin/bash +java Example_SRM_List diff --git a/developer/example/Example_SRM_List.class b/developer/example/Example_SRM_List.class new file mode 100644 index 0000000000000000000000000000000000000000..1b3e05c3ab35e9686aed43dbe36843e1ec31f3d9 GIT binary patch literal 2515 zcmb7GOII6Z7=AuTnGmK@0|cqGrU(e6Hnn1{4Pt>d1r4Q=2)0%6BbkOFlbJX(pR{#t6GJ+0tDhR1K zfi8hl+j2)H4QUpWE1TO|-WBMY(M{c*73iFpTvHGh==X)Hu5KhVx>?c+8QpOsP|z7h zkARr-&L>qogJwk`{%R^KR%T>Ym2VCNf$3KAwym3P*0nWRPIkzNT@iE7X=1A;1(=1FWq(B z-Qvk{rRh3N#%h|At;Qlq;-Z3=R9wQ#0)2k6k77a>D;`3I*;Ed7t7{%;uc)|;R|%S7 z(HY&MaJ!&oYMP8tAkmGhNGX_6@j6(<(`^*OXx)-P_v+Hk#oY2rHYaeoonkt);g`fU z6?2$pPsw~GUj`X*QJd z8%$?LViWfoygtky`O+>@x9=FXK*W%nnz3Q{tr`mqGz}3x(dpRitxN4->~}v^V@Jc; ztJFi9I`*-d));1KCEfPZ|6%B4)|L6vvaHmAjbyE=o!8R32mL@Zx);1MVEX1Q%XM5^ zR+cq)%PKfwaD4XE2f@|22!lP|x5SyOOCw${QJ=9zkU236Y;XU*P0e^C!C+qFY29pA zWKMhM?z@^D56X$!yPG*qRNdUMN?I~VeK0uEGVfaUp1`+_^QR^l z1hXj3f}uI=39D4Cq+0QBpd3-mF_*`PH_c5oL{9}<)Zd<&FpBgr^?F7~vV7Mi9j``Z!->lpDk* z|8(dW#zS(yMjYP|#P2EPVG(BCSACFfc-EAClGq$yb4KB5zS6@2{G_7X4NC*OI@MQKjr@>h53{A72~dXKfb` MxqpJs@CAnc0U@xf@Bjb+ literal 0 HcmV?d00001 diff --git a/developer/example/IndexTree_Diagonal_SRM.class b/developer/example/IndexTree_Diagonal_SRM.class new file mode 100644 index 0000000000000000000000000000000000000000..c6d1d1ac2791397afa22adb3ac387286598f616d GIT binary patch literal 4313 zcmb_fYj+dZ72PArj4Z~0g)t_?;FgDNNk%P(1Z>xUO_Br?Z zpZ|ULJpkiaRuNFpIc4U>E3>u`nX`souuQ#_nYoaTKtV`D3$`fOGGds9GpZoi*FP6Q z7$Fs{3gS6yF?m7g70Wct!mP*@O{-)TmXc>|L(iL{_Lb&TY*n!Hx_(1XRvn|nEn8no z85Jjj2tutqY@3Gd*g=0vT+LY5GMTDrm4zwt8Pm!O1v^p=b*VWlwW1n!O07e6Enmkl z>0P-b9FfTtjZ!`%1*FC<4V_Y>)fT$98b+6buE)bL)Dyu|*sJ1c4c*wMAhFS)XGO&! zgp2wDeIM)doGsrSi)ClYCBPY#R=LeS=K_e ztl)g#I?@|Qu#wzpa>+erNW(Bj$e?S&$rWoP(X*mdQE;wr!@#aF?MLjA+-0eRW>mu| zoF-IyJ}+^36qWwVGW0QxWqFplxn|jfCR38`u+Y{Az)e&$tD-FJ2@RjbBvF>+8@J4y z?#vrbk)w*En-1eU-0VV~kB=CW+&`z`Q%I2lWwMrxUgdpFbxy^!f)3Zfnw&-%*F*&8 zaY4n5EFz}%nT;}kHMr8sr!~xBUP0ItMxmIsSOll~J`54Y-LAmaL^gzRNyBAH>u^pt zGpwz$T>OlN7jczEEL#P`<2en8d^$_Hmo(_IY(i2|MUKcfb}UbL?NL6;QfpCz35&&{m)RTX)WC)^=^sBF#>+fE5e7M+yeJJC zl6N;Wd={@rtGS%0a4%X5wZUU{%o(F#>Q2>W3~OmVvQCMP4l5Y;P^+67Svy}>S86{+ zR~j^EzM{Ap8h5XT?J2_))78bSuxIsbiT*`XR!%R?>AZ(O__0>)VSz68Dn= zYw_zd%>}jgiRW-=)E^aEkP0=+nV^!^( zm@p&@_dcGuM`U;4gJz7$t2nk^P79}KcD48%5eV`9uKo%Mag|Gk+&5$2H~NRNP;l zjMvr%)0F5)c)A?!mzK}Gi|2q9Ov%ad>DT}dYdWgU7hisOOTrj(VVov}U`AVUkRTqy z0ra6CaRQXU2|jhlIhx?Z_5wkD34<_j3=WPHp=a?!4B_W|MZSp<{FyJjJ2>qkH_6l- zASb>?SzeV)&8zr25l%8y-yj!)v@qoE2B_cV?gnXn+TE3DdCN!rn;du6HE&YWle$T} z-{M{?T3SyA{)0k*LVVVHiNP`jgWNtH{2S6Ki4+l(D7#286GZBH52;34nvwFwB}~C4 zwvCg-XBof*i(r!P+9?Kjj)AA#uzS2Seb-wE%(q { - - public static Ariadne_SRM make(){ - return new Ariadne_SRM<>(); - } - protected Ariadne_SRM(){ - } - - // machine and tape status/properties - // +public abstract class Ariadne_SRM{ - public enum Topology{ - UNDEFINED - ,NO_CELLS - ,SINGLETON + public enum MachineState{ + NULL + ,CYCLIC ,SEGMENT - ,SEGMENT_OR_CIRCLE - ,CIRCLE - ,CIRCLE_OR_INFINITE_RIGHT - ,INFINITE_RIGHT - ; - } - public enum Location{ - OTHER - ,LEFTMOST - ,INTERIM ,RIGHTMOST + ,INFINITE ; } - public Topology topology(){ - return Topology.UNDEFINED; - } - public Location location(){ - throw new UnsupportedOperationException("Ariadne_SRM::location not implemented."); - } - public boolean can_step() { - return topology().ordinal() >= Topology.SEGMENT.ordinal() - && location().ordinal() <= Location.INTERIM.ordinal(); - } - public boolean can_read() { - return topology().ordinal() >= Topology.SINGLETON.ordinal(); - } - - // moving the head - // - - public void step(){ - throw new UnsupportedOperationException("Ariadne_SRM::step not implemented."); + protected abstract class State{ + abstract boolean can_read(); + abstract boolean can_step(); + abstract void step(); + abstract MachineState state(); } - public void rewind(){ - throw new UnsupportedOperationException("Ariadne_SRM::rewind not implemented."); - } + private State current_state; - public void fast_forward(){ - throw new UnsupportedOperationException("Ariadne_SRM::fast_forward not implemented."); + protected void set_state(State new_state){ + this.current_state = new_state; } - // access - // - - public TElement access(){ - // returns a reference, cell can then be read or written - throw new UnsupportedOperationException("Ariadne_SRM::read not implemented."); + public boolean can_read(){ + return current_state.can_read(); } - - public TElement read(){ - TElement accessed_cell = access(); - return deep_copy( accessed_cell ); + public boolean can_step(){ + return current_state.can_step(); } - private TElement deep_copy( TElement original ){ - throw new UnsupportedOperationException("Ariadne_SRM::deep_copy not implemented."); + public void step(){ + current_state.step(); } - - // writes value - public void write(TElement e){ - throw new UnsupportedOperationException("Ariadne_SRM::read not implemented."); + public MachineState state(){ + return current_state.state(); } + public abstract T read(); } + -- 2.20.1