git @ Cat's Eye Technologies Burro / f3b2cb9
Dark clouds gather. Chris Pressey 4 months ago
1 changed file(s) with 55 addition(s) and 29 deletion(s). Raw diff Collapse all Expand all
280280 * If value is 5 then _a_ then _a_′ _b_ then _b_′ _c_ is executed.
281281 * _a_ _a_′ _b_ _b_′ _c_ = _c_, so in effect, only _c_ is executed.
282282
283 We must also remember that each successive happens one cell to the
283 We must also remember that each successive test happens one cell to the
284284 right of the previous test (the cell being tested is the work cell of
285285 the previous test). So we may have to wrap the contents of the
286286 conditional with `<` and `>` one or more times, if we want all the
391391 Using and Re-using the Idiom
392392 ----------------------------
393393
394 In the context of using this condition idiom in a Turing machine simulator:
394 In the context of using this conditional idiom in a Turing machine simulator:
395395
396396 The construction above can be used to rewrite the value on the tape at one spot.
397397 But to do so, it needs several "scratch cells" adjacent to the tape cell - one for
547547 We can treat this sequence like a data record, and call it a _CellStruct_.
548548 A CellStruct needs to consist of at least:
549549
550 - `state`, the TM state stored locally, represented as an even integer
551 - `scratch0`, scratch cell for executing the conditional
552 - `cell`, the symbol written at position on the TM tape, also represented as an even integer
553 - `scratch1`, another scratch cell for executing the conditional
554
555 Therefore, 4 Burro tape cells are needed to store each CellStruct,
556 and the TM instruction "Move Right" is the Burro program `>>>>`, while
557 the TM instruction "Move Left" is the Burro program `<<<<`.
550 - `state`, the TM state stored locally, represented as an odd integer
551 - `tmps_1`..`tmps_n`, _n_ scratch cells for executing the conditional
552 - `cell`, the symbol written at position on the TM tape, also represented as an odd integer
553 - `tmpc_1`..`tmpc_m`, another _m_ scratch cells for executing the inner conditional
554
555 _n_ in the above is the number of states of the TM, while _m_
556 is the number of possible symbols in a tape cell.
557
558 Therefore, _k_ = _n_ + _m_ + 2 Burro tape cells are needed to store each CellStruct,
559 and the TM instruction "Move Right" is a string of _k_ `>` instructions, while
560 the TM instruction "Move Left" is a string _k_ `<` instructions.
561
562 Within a CellStruct, to move from the `state` cell to the `cell` cell,
563 uses _n_ + 1 `>` instructions - and suchlike for other internal moves.
558564
559565 For convenience we will also refer to the `start` of a CellStruct, which
560566 is the Burro cell containing the first field, which also happens to be
562568
563569 The set of TM states is finite, as is the set of symbols that can appear
564570 on cells of the TM tape. This will allow us to work with these values
565 with finite program structures without loops.
571 with finite program structures which do not contain loops.
566572
567573 At any point there is a current CellStruct. This is indicated by where
568574 the current Burro tape cell is. Whichever CellStruct it is inside, is
595601 We need to do this adjustment for both the tape contents and the state
596602 kept locally in the CellStruct.
597603
604 A (_possibly serious_) problem is that we do want to be able
605 to, in a conditional, leave the tape in a different place than we started;
606 we want to move left or right on the simulated tape. I don't know the
607 implications of that, for the conditional idiom.
608
609 For now we can think of switching the state as happening last, in a
610 conditional which is not part of the conditional idiom. And hope this
611 can be made to work...
612
598613 ### Pseudocode
599614
600615 while (not halted) {
601 move to state offset (of new CellStruct): (no moves needed)
616 (the tape head should be over the state part of the CellStruct)
602617 bump up the state id by 1, to make it odd
603618 if state == 1 {
604 zero out this state keeper (using -'s for this state)
605 move to start offset (of new CellStruct): (no moves needed)
606 move to cell offset (of current CellStruct): >>
619 move to cell part of current CellStruct
607620 bump up the cell value by 1, to make it odd
608621 if cell == 1 {
609 write new value of cell (adjust 0 using +'s) -- NOTE: the basis is zero!
610 bump down the cell value by 1, to make it even again
611 move to start offset (of current CellStruct): <<
612 move to CellStruct to the left (<<<<) or to the right (>>>>)
613 move to state offset (of new CellStruct): (no moves needed)
614 write new state (using +'s to increase 0 to the state id)
615 move to start offset (of new CellStruct): (no moves needed)
622 move to "new cell" part of the CellStruct
623 write new value of cell (adjust 0 using +'s)
624 move to "new state" part of the CellStruct
625 write new value of cell (adjust 0 using +'s)
616626 }
617627 elseif cell == 3 {
618 write new value of cell (adjust 0 using +'s) -- NOTE: the basis is zero!
619 bump down the cell value by 1, to make it even again
620 move to start offset (of current CellStruct): <<
621 move to CellStruct to the left (<<<<) or to the right (>>>>)
622 move to state offset (of new CellStruct): (no moves needed)
623 write new state (using +'s to increase 0 to the state id)
624 move to start offset (of new CellStruct): (no moves needed)
628 move to "new cell" part of the CellStruct
629 write new value of cell (adjust 0 using +'s)
630 move to "new state" part of the CellStruct
631 write new value of cell (adjust 0 using +'s)
632 }
633 elseif cell == 5 {
634 ....
635 }
636 move to the "cell" part of the CellStruct
637 bump down the cell value by 1, to make it even again
638 move to the "new cell" part of current CellStruct
639 if new cell == 1 {
640 move to "cell" part of the CellStruct
641 write new value of cell (adjust cell using +'s and -'s)
642 }
643 elseif cell == 3 {
644 move to "cell" part of the CellStruct
645 write new value of cell (adjust cell using +'s and -'s)
625646 }
626647 elseif cell == 5 {
627648 ....
634655 ...
635656 }
636657 bump down the state id by 1, to make it even again
658 move to "new state" part of the CellStruct
659 ...this might need to encode both the new state and the direction.
660 ...move to the new CellStruct indicated by the direction,
661 ...and write the state indicated by the new state,
662 ...and toggle the halt flag if the new state is "halt".
637663 }
638664
639665 In conclusion, this is the method by which we propose that arbitrary