// casep.txt 1.5.0 UTF-8 2024-06-16 //--|----1----|----2----|----3----|----4----|----5----|----6----|----7----|--* // // OFRUGAL UTILITY FUNCTIONS // ========================= // // // // HAND-COMPILED casep(v, L) // ------------------------- // // Note: the file at // has been tombstoned for continuation here under the oFrugal topic. // // The casep(v, L) function is introduced in Miser Project Discussion // Note #76. This file demonstrates the manual compilation of the // casep(v, L) Frugalese description to an oFrugal implementation. // // This file is meant to be processable by oFrugal. // // 1. The Original Definition // 2. The Approach // 3. The Conditional Evaluation Idiom // 4. The is-singleton(L) Default-Result Conditional // 5. The Current Case-Condition Checking Part // 6. Putting It All Together // 7. Abstracting to an Applicative-Function Script // 7.1 Abstracting operand L // 7.2 Abstracting the recursion // 7.3 Abstracting operand v // 8. Musings // // // 1. THE ORIGINAL DEFINITION // // From // // casep(v) L = if is-singleton(L) // then L // else if (.b .a L) v // then .a L // else casep(v) .b L; // // Operand L is a list structure [r1:p1, r2:p2, ..., ` rdefault:]. // // casep(v) is a procedure that, given an L, finds the first ri:pi for // which pi(v) is satisfied, returning the ri:pi pair. If no pi(v) // is satisfied, `rdefault is returned. In this manner, .a casep(v) L // is always the result for the v property case. // // In Frugalese pseudo-notation, this can be reformed into a form in // which the lambda-abstractions are explicitly applied. // // casep = λ.v ρ.casepv λ.L // (1) // ( if is-singleton(L) // then L // else if (.b .a L) v // then .a L // else casepv .b L // ); // // Note that the left hand side occurrences of parameters have been slid // to the right-hand side, with introduction of ρ.casepv to account for // the recursion on L, but with fixed operand v. The renaming to lindy // casepv is to emphasize that arrangement. // // 2. THE APPROACH // // Assume that the abstractions procedures λ and ρ are already // available. Then what remains is transforming the body, "( ... )", // into the Canonical Form (CFob) operand to be abstracted into an // applicative script. In the CFob, lindies v, casepv, and L will // appear where they are to be abstracted in forming the applicative- // operation script, ^casep. // // 3. THE CONDITIONAL EVALUATION IDIOM // // The oFrugal idiomatic handling of the conditional form // // if condition-form // then satisfied-part // else not-satisfied-part // // is with a script on the pattern // // .ev :: (condition-form) // ::`( satisfied-part // :: // not-satified-part // ) // // Evaluation of the condition-form will result in either an .A (for // satisfied) or a .B (for not-satified) that will select between one of // the not-yet-evaluated parts of the encapsulated pair. Then .EV // evaluates the selected part for continuation of the procedure. // // The layout on multiple indented lines is a convention for // emphasizing the conditional structure. // // 4. THE is-singleton(L) DEFAULT-RESULT CONDITIONAL // // The is-singleton(x) condition is defined to be // // x = .b x // // so the first condition-form in casep (1, above) translates to the // oFrugal form // // .ev :: (.d :: L :: .b :: L) // (4) // :: `( L // :: // not-satisfied-part // ) // // // 5. THE CURRENT CASE-CONDITION CHECKING PART // // The not-satisfied-part of (4) is another conditional form of (1), // thus // // .ev :: ((.b :: .a :: L) :: ` v) // (5) // :: `( (.a :: L) // :: // casepv :: .b :: L // ) // // We are slowly boiling the Frugalese pseudo-code down to a canonical // oFrugal form in which the only remaining lindies are those which are // to be abstracted away. // // Note that v is enclosed, ensuring that at the level where (5) is // evaluated, the previously-substituted operand value for v is simply // used, not evaluated further. // // // // 6. PUTTING IT ALL TOGETHER // // casep = λ.v ρ.casepv λ.L // (6a) // (.ev :: (.d :: L :: .b :: L) // :: `( L // :: // .ev :: ((.b :: .a :: L) :: ` v) // :: `( (.a :: L) // :: // casepv :: .b :: L // ) // ) // ); // // This is the complete substitution of the derived oFrugal form of // the script. All of the detals are there, but we've lost the clarity // of the original Frugalese form. // // The following is offered as illustration of an annotated script that // can be sight-checked for agreement between the comments and the // oFrugal. With availability of an operating oFrugal implementation, // a dependable confirmation can also be established. !def ob ^casep // (6b) = ^λ.v ^ρ.casepv ^λ.L ( // if is-singleton(L) .ev :: (.d :: L :: .b :: L) :: `( // then L L :: // else if (.b .a L) v .ev :: ((.b :: .a :: L) :: ` v) :: `( // then .a L (.a :: L) :: // else casepv .b L casepv :: .b :: L ) ) ); // assuming already-defined ^λ and ^ρ. // // Note: Before oFrugal 1.0 the abstraction operations will be written // // ^lambda, ^rec, and ^sigma // // because of character-set limitations. With oFrugal 1.0, both forms // will be defined in a standard library file. // // // 7. ABSTRACTING TO AN APPLICATIVE-FUNCTION SCRIPT // // When a script-form is not yet for an applicative function taking any // operands, the λ.L heuristic will simply rewrite that script so that // every occurrence of L is replaced by the primitive .arg. // // 7.1 Abstracting Operand L !def ob ^casep // (7.1) = ^λ.v ^ρ.casepv // ^λ.L ( // if is-singleton(L) .ev :: (.d :: L :: .b :: .arg) :: `( // then L .arg :: // else if (.b .a L) v .ev :: ((.b :: .a :: .arg) :: ` v) :: `( // then .a L (.a :: .arg) :: // else casepv .b L casepv :: .b :: .arg ) ) ); // // 7.2 Abstracting the Recursion // // The ρ.casepv heuristic operation is based on the assumption that the // operand is (now) that of an applicative function which is desired to // make recursive at all occurrences of lindy casepv. Every occurrence // of lindy casepv will be replaced by the primitive .SELF. // // That reaches // !def ob ^casep = ^λ.v // ^ρ.casepv ^λ.L // (7.2) ( // if is-singleton(L) .ev :: (.d :: L :: .b :: .arg) :: `( // then L .arg :: // else if (.b .a L) v .ev :: ((.b :: .a :: .arg) :: ` v) :: `( // then .a L (.a :: .arg) :: // else casepv .b L .self :: .b :: .arg ) ) ); // // 7.3 Abstracting Operand v // // When the λ.v heuristic determines that the operand script-form is // likely an applicative-function script, the simple replacement of // all occurrences of v by .ARG is incorrect. // // The required behavior in this case is to create a script that when // applied to an operand, V, yields the above script but with V in // place of v. // // This version is obtained by manually applying the algorithm in // oSigma.txt . !def ob ^casep = // ^λ.v ^ρ.casepv ^λ.L ( // if is-singleton(L) .c :: `.ev :: .c :: `(.d :: .arg :: .b :: .arg) // then L :: .e :: c :: `.arg :: // else if (.b .a L) v .c :: `.ev :: .c :: (.c :: `(.b :: .a :: .arg) :: .e :: .arg) :: ` `( // then .a L (.a :: .arg) :: // else casepv .b L .self :: .b :: .arg ) ); // demonstrating why it is important to have the abstraction functions // up-and-running, with easier confirmation and simpler expresssion. // // // 8. MUSINGS // // There are no variables in oFrugal in the sense that variables occur // in mathematical-logic expressions such as those in formulation of // structure ‹ob› = 〈Ob,Of,Ot〉definitions, theorems, and introduction // of the universal-computation functions obap.ap and obap.eval. // // There are also no variables in the sense they are introduced and // spoken about in the usage of programming languages for software // development. // // There are a flavor of pseudo-variables in oFrugalese where lindies // (such as v, casepv, and L) are employed for abstraction in the guise // of free variables. The abstraction procedures replace such lindies // with primitive forms lacking all evidence of the replaced lindies. // In hand-compiled scripts, compensation for that lack is in the // comments (which may or may not be accurate). The undecorated oFrugal // scripts are inscrutible. // // Comprehension of raw oFrugal scripts without even pseudo-variables // and narrative commentary is just as frustrating as are the binary // machine-language binary program code for modern digital computers. // It is small consolation that comprehension of any significant Turing // Machine definitions is even more difficult. // // An interesting exercise for the future would be to create a script // that can be used to "de-abstract" an ob to an oFrugalese form that // gives rise to it, substituting lindies in some understandable manner. // This would provide a form of symbolic confirmation of what a script // is abstracted from. // // Generally, however, the best way to confirm the operation of scripts // is to compose them from understandable parts, ideally parts that can // be confirmed individually, exploiting the applicative techniques for // composition of procedures to achieve the overall objective. Some // indications of this can be seen in the formulation of oSigma.txt at // . It will take // practice. // //--|----1----|----2----|----3----|----4----|----5----|----6----|----7----|--* // // Copyright 2024 Dennis E. Hamilton // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // //--|----1----|----2----|----3----|----4----|----5----|----6----|----7----|--* // // ATTRIBUTION // // Hamilton, Dennis E. Hand-Compiled casep(v, L). Miser Theory // Conception text file casep.txt version 1.5.0 dated 2024-06-16, // available on the Internet as a version of // // //--|----1----|----2----|----3----|----4----|----5----|----6----|----7----|--* // // TODO // // * Test this with oFrugal when implementation is available. // // //--|----1----|----2----|----3----|----4----|----5----|----6----|----7----|--* // // 1.5.0 2024-06-16T16:35Z Add Musings section 8 // 1.4.1 2024-06-15T18:32Z Touch-ups with layout improvements // 1.4.0 2024-06-98T16:06Z More clarifications, better layout, tying in oSigma // 1.3.0 2024-05-12T20:41Z Cleanit it all up // 1.2.4 2024-05-11T21:36Z Completed polishing ^casep for now. // 1.2.3 2024-05-11T16:46Z Use intermediates to make conditionals more // explicit and perhaps understandable // 1.2.2 2024-05-03T20:35Z Touched-up to reflect new location // 1.2.1 2024-05-03T19:35Z Moved here and tombstoned at previous location. // 1.2.0 2024-05-03T19:35Z Introduce possibility for subst(val, x) usage. // 1.1.0 2024-04-29T18:42Z Complete with demonstration oFrugal code // 1.0.0 2024-04-29T00:14Z Completed explanation // 0.0.1 2024-04-26T22:22Z Create the initial draft (placeholder). // // *** end of casep.txt ***