diff --git a/documentation/bookmark/biological_programming.md b/documentation/bookmark/biological_programming.md index 056d49498..84476effc 100644 --- a/documentation/bookmark/biological_programming.md +++ b/documentation/bookmark/biological_programming.md @@ -1,5 +1,6 @@ # Reference +0. [A motor for cell-free metabolism: Researchers have developed the first cell-free system in which genetic information and metabolism work together](https://www.mpg.de/22163540/0703-terr-a-motor-for-cell-free-metabolism-153410-x) 0. [New tools for programming biology](https://centuryofbio.com/p/new-tools-for-programming-biology) 0. [Open Genes: Structured data on human genes associated with aging: functions, evolution, the influence of gene activity on lifespan, age-related changes in gene expression, associations of allelic variants of genes with longevity and age-related phenotype.](https://open-genes.com/genes) 0. [Axial Discovery - Cell reprogramming](https://discoverybio.substack.com/p/axial-discovery-cell-reprogramming) diff --git a/stdlib/source/library/lux.lux b/stdlib/source/library/lux.lux index f9cdaa2e7..fe2b8eb46 100644 --- a/stdlib/source/library/lux.lux +++ b/stdlib/source/library/lux.lux @@ -1729,6 +1729,7 @@ _ (failure ..wrong_syntax)))) +(the' .public per Macro ..left_associative) (the' .public all Macro ..right_associative) ... (every (Monad m) diff --git a/stdlib/source/library/lux/abstract/functor/pro.lux b/stdlib/source/library/lux/abstract/functor/pro.lux index 5946e58fd..7bdc4f695 100644 --- a/stdlib/source/library/lux/abstract/functor/pro.lux +++ b/stdlib/source/library/lux/abstract/functor/pro.lux @@ -5,33 +5,44 @@ [library [lux (.except)]]) -(every .public (Functor it) +(every .public (Functor =>) (Interface (is (for_any (_ cause effect cause' effect') (-> (<- cause cause') (-> effect effect') - (-> (it cause effect) - (it cause' effect')))) + (-> (=> cause effect) + (=> cause' effect')))) each))) -(every .public (Cartesian it) +(every .public (Cartesian =>) (Interface - (is (for_any (_ cause effect extra) - (-> (it cause effect) - (it (And cause extra) (And effect extra)))) + (is (for_any (_ head head' tail) + (-> (=> head head') + (=> (And head tail) (And head' tail)))) in_left) - (is (for_any (_ cause effect extra) - (-> (it cause effect) - (it (And extra cause) (And extra effect)))) + (is (for_any (_ tail tail' head) + (-> (=> tail tail') + (=> (And head tail) (And head tail')))) in_right))) -(every .public (Co_Cartesian it) +(every .public (Co_Cartesian =>) (Interface - (is (for_any (_ cause effect extra) - (-> (it cause effect) - (it (Or cause extra) (Or effect extra)))) + (is (for_any (_ head head' tail) + (-> (=> head head') + (=> (Or head tail) (Or head' tail)))) when_left) - (is (for_any (_ cause effect extra) - (-> (it cause effect) - (it (Or extra cause) (Or extra effect)))) + (is (for_any (_ tail tail' head) + (-> (=> tail tail') + (=> (Or head tail) (Or head tail')))) when_right))) + +(every .public (Monoidal =>) + (Interface + (is (for_any (_ head head' + tail tail') + (-> (=> head head') + (=> tail tail') + (=> [head tail] [head' tail']))) + in_parallel) + (is (=> Any Any) + empty))) diff --git a/stdlib/source/library/lux/aspect.lux b/stdlib/source/library/lux/aspect.lux index cb46a0fa6..da0f8d8ae 100644 --- a/stdlib/source/library/lux/aspect.lux +++ b/stdlib/source/library/lux/aspect.lux @@ -1,105 +1,11 @@ ... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. ... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. +... [Profunctor Optics: Modular Data Accessors](https://arxiv.org/abs/1703.10857) (.using [library - [lux (.except all with) - [abstract - [functor (.only Functor) - ["[0]" pro]]] - [type - ["[0]" nominal]] - ["[0]" function] - [data - ["[0]" product]]]]) + [lux (.except)]]) -(every .public (Aspect it context context' aspect aspect') - (-> (it aspect aspect') - (it context context'))) - -... TODO: Make this nominal type unnecessary. -(nominal.every .public (Membership one all) - (Variant - {#All all} - {#One one (Membership one (-> one all))}) - - (the outer - (for_any (_ one all) - (-> (Membership one all) - (Or all (And one (Membership one (-> one all)))))) - (|>> nominal.as)) - - (the inner - (for_any (_ one all) - (-> (Or all (And one (Membership one (-> one all)))) - (Membership one all))) - (|>> nominal.of)) - - (the .public membership_functor - (for_any (_ one) - (Functor (Membership one))) - (implementation - (the (each value it) - (nominal.of - (.when (nominal.as it) - {#All all} - {#All (value all)} - - {#One one next} - {#One one (each (function (_ before) - (|>> before - value)) - next)})) - ))) - - (every .public (Apply context) - (Interface - (is (Functor context) - functor) - (is (for_any (_ it) - (-> it - (context it))) - pure) - (is (for_any (_ it it') - (-> (context (-> it it')) - (-> (context it) - (context it')))) - with))) - - (the .public membership_apply - (for_any (_ one) - (Apply (Membership one))) - (implementation - (the functor ..membership_functor) - (the pure (|>> {#All} nominal.of)) - (the (with internal_effect internal_cause) - (.when (nominal.as internal_effect) - {#All internal_effect} - (by ..membership_functor each internal_effect internal_cause) - - {#One one internal_effect} - (nominal.of - {#One one (with (by ..membership_functor each function.flipped internal_effect) - internal_cause)}))))) - - (the .public (one it) - (for_any (_ it) - (-> it - (Membership it it))) - (nominal.of {#One it (nominal.of {#All (|>>)})})) - - (the .public (all it) - (for_any (_ one all) - (-> (Membership one all) - all)) - (.when (nominal.as it) - {#All it} - it - - {#One one next} - ((all next) one))) - - (every .public (Member all one) - (-> all - (Membership one all))) - ) +(every .public (Aspect => context context' aspect aspect') + (-> (=> aspect aspect') + (=> context context'))) diff --git a/stdlib/source/library/lux/aspect/case.lux b/stdlib/source/library/lux/aspect/case.lux index e4395cafd..e25c4aefa 100644 --- a/stdlib/source/library/lux/aspect/case.lux +++ b/stdlib/source/library/lux/aspect/case.lux @@ -1,6 +1,7 @@ ... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. ... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. +... [Profunctor Optics: Modular Data Accessors](https://arxiv.org/abs/1703.10857) (.using [library [lux (.except macro @@ -78,9 +79,9 @@ ) (every .public (Aspect context context' case case') - (for_any (_ it) - (-> [(pro.Functor it) (pro.Co_Cartesian it)] - (//.Aspect it context context' case case')))) + (for_any (_ =>) + (-> [(pro.Functor =>) (pro.Co_Cartesian =>)] + (//.Aspect => context context' case case')))) (the functor (for_any (_ case case') @@ -117,12 +118,12 @@ (|>> when_right (each /#when (sum.either function.identity /#some))))) -(the .public (of_aspect it) +(the .public (of_aspect =>) (for_any (_ context context' case case') (-> (Aspect context context' case case' (for_any (_ context context') (Case' context context' case case'))) (Case' context context' case case'))) - (it [..functor ..co_cartesian] + (=> [..functor ..co_cartesian] [#when sum.right #some function.identity])) diff --git a/stdlib/source/library/lux/aspect/member.lux b/stdlib/source/library/lux/aspect/member.lux new file mode 100644 index 000000000..df4814e1a --- /dev/null +++ b/stdlib/source/library/lux/aspect/member.lux @@ -0,0 +1,237 @@ +... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. +... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. + +... [Profunctor Optics: Modular Data Accessors](https://arxiv.org/abs/1703.10857) +(.using + [library + [lux (.except all with macro) + [abstract + [functor (.only Functor) + ["[0]" pro]]] + [type + ["[0]" nominal]] + ["[0]" function] + [data + ["[0]" sum] + ["[0]" product]]]] + ["[0]" //]) + +(the macro (.in_module# .prelude .template#macro)) + +(the Head + (macro (_ ,Membership ,one ,one' ,all) + [,one])) + +(the Tail + (macro (_ ,Membership ,one ,one' ,all) + [(,Membership ,one ,one' (-> ,one' ,all))])) + +(the Cons + (macro (_ ,Membership ,one ,one' ,all) + [(And (Head ,Membership ,one ,one' ,all) + (Tail ,Membership ,one ,one' ,all))])) + +(the Null + (macro (_ ,Membership ,one ,one' ,all) + [,all])) + +(the Reification + (macro (_ ,Membership ,one ,one' ,all) + [(Or (Null ,Membership ,one ,one' ,all) + (Cons ,Membership ,one ,one' ,all))])) + +... TODO: Make this nominal type unnecessary. +(nominal.every .public (Membership one one' all) + (Variant + {#All (Null Membership one one' all)} + {#One (Cons Membership one one' all)}) + + (the outer + (for_any (_ one one' all) + (-> (Membership one one' all) + (Reification Membership one one' all))) + (|>> nominal.as)) + + (the inner + (for_any (_ one one' all) + (-> (Reification Membership one one' all) + (Membership one one' all))) + (|>> nominal.of)) + + (the functor_of_membership + (for_any (_ one one') + (Functor (Membership one one'))) + (implementation + (the (each value it) + (nominal.of + (.when (nominal.as it) + {#All all} + {#All (value all)} + + {#One one next} + {#One one (each (function (_ before) + (|>> before + value)) + next)}))))) + + (every .public (Application context) + (Interface + (is (Functor context) + functor) + (is (for_any (_ it) + (-> it + (context it))) + pure) + (is (for_any (_ it it') + (-> (context (-> it it')) + (-> (context it) + (context it')))) + with))) + + (the (pair application on_left on_right [left right]) + (for_any (_ ! + cause cause' + effect effect') + (-> (Application !) + (-> cause (! effect)) + (-> cause' (! effect')) + (-> [cause cause'] (! [effect effect'])))) + (.with application + (per with + (pure (function (_ left right) + [left right])) + (on_left left) + (on_right right)))) + + (the .public application + (for_any (_ one one') + (Application (Membership one one'))) + (implementation + (the functor ..functor_of_membership) + (the pure (|>> {#All} nominal.of)) + (the (with internal_effect internal_cause) + (.when (nominal.as internal_effect) + {#All internal_effect} + (by ..functor_of_membership each internal_effect internal_cause) + + {#One one internal_effect} + (nominal.of + {#One one (with (by ..functor_of_membership each function.flipped internal_effect) + internal_cause)}))))) + + (the .public (one it) + (for_any (_ it it') + (-> it + (Membership it it' it'))) + (nominal.of {#One it (nominal.of {#All (|>>)})})) + + (the .public (all it) + (for_any (_ one all) + (-> (Membership one one all) + all)) + (.when (nominal.as it) + {#All it} + it + + {#One one next} + ((all next) one))) + + (every .public (Member' all all' + one one') + (-> all + (Membership one one' all'))) + + (every .public (Member all one) + (Member' all all + one one)) + + (the pro_functor + (for_any (_ one one') + (pro.Functor (for_any (_ all all') + (Member' all all' + one one')))) + (implementation + (the (each before after it) + (|>> before + it + (by functor_of_membership each after))))) + + (the cartesian + (for_any (_ one one') + (pro.Cartesian (for_any (_ all all') + (Member' all all' + one one')))) + (implementation + (the (in_left it) + (function (_ [all extra]) + (by functor_of_membership each + (function (_ all) + [all extra]) + (it all)))) + (the (in_right it) + (function (_ [extra all]) + (by functor_of_membership each + (function (_ all) + [extra all]) + (it all)))))) + + (the co_cartesian + (for_any (_ one one') + (pro.Co_Cartesian (for_any (_ all all') + (Member' all all' + one one')))) + (implementation + (the (when_left it) + (sum.either (|>> it (by functor_of_membership each (|>> {.#Left}))) + (|>> {.#Right} {#All} nominal.of))) + (the (when_right it) + (sum.either (|>> {.#Left} {#All} nominal.of) + (|>> it (by functor_of_membership each (|>> {.#Right}))))))) + + (the monoidal + (for_any (_ one one') + (pro.Monoidal (for_any (_ all all') + (Member' all all' + one one')))) + (implementation + (the in_parallel + (pair ..application)) + (the empty + (by application pure)))) + + (every .public (Aspect all all' one one') + (for_any (_ =>) + (-> [(pro.Functor =>) (pro.Co_Cartesian =>) (pro.Cartesian =>) (pro.Monoidal =>)] + (//.Aspect => all all' one one')))) + + (the .public (of_aspect =>) + (for_any (_ all all' one one') + (-> (Aspect all all' one one' + (for_any (_ all all') + (Member' all all' one one'))) + (Member' all all' one one'))) + (=> [..pro_functor ..co_cartesian ..cartesian ..monoidal] ..one)) + + (the (traversal pro_functor co_cartesian monoidal) + (for_any (_ =>) + (-> (pro.Functor =>) (pro.Co_Cartesian =>) (pro.Monoidal =>) + (for_any (_ cause effect one all) + (-> (=> cause + effect) + (=> (Membership cause one all) + (Membership effect one all)))))) + (function (traversal =>) + (<| (by pro_functor each ..outer ..inner) + (by co_cartesian when_right) + ... TODO: Handle this stack overflow. + (by monoidal in_parallel => (traversal =>))))) + + (the .public (as_aspect it + [pro_functor co_cartesian cartesian monoidal] + =>) + (for_any (_ all all' one one') + (-> (Member' all all' one one') + (Aspect all all' one one'))) + (<| (by pro_functor each it ..all) + (traversal pro_functor co_cartesian monoidal =>))) + ) diff --git a/stdlib/source/library/lux/aspect/property.lux b/stdlib/source/library/lux/aspect/property.lux index 2b910ea0e..ca712a1e5 100644 --- a/stdlib/source/library/lux/aspect/property.lux +++ b/stdlib/source/library/lux/aspect/property.lux @@ -1,6 +1,7 @@ ... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. ... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. +... [Profunctor Optics: Modular Data Accessors](https://arxiv.org/abs/1703.10857) (.using [library [lux (.except macro @@ -93,9 +94,9 @@ (revised outer (has inner focus) context))]) (every .public (Aspect context context' focus focus') - (for_any (_ it) - (-> [(pro.Functor it) (pro.Cartesian it)] - (//.Aspect it context context' focus focus')))) + (for_any (_ =>) + (-> [(pro.Functor =>) (pro.Cartesian =>)] + (//.Aspect => context context' focus focus')))) (the functor (for_any (_ focus focus') @@ -141,11 +142,11 @@ (|>> in_left (each (product.forked /#its function.identity) /#has)))) -(the .public (of_aspect it) +(the .public (of_aspect =>) (for_any (_ context context' focus focus') (-> (Aspect context context' focus focus' (for_any (_ context context') (Property' context context' focus focus'))) (Property' context context' focus focus'))) - (it [..functor ..cartesian] + (=> [..functor ..cartesian] [#its function.identity #has product.left])) diff --git a/stdlib/source/library/lux/aspect/view.lux b/stdlib/source/library/lux/aspect/view.lux index 55568f0f6..815d765de 100644 --- a/stdlib/source/library/lux/aspect/view.lux +++ b/stdlib/source/library/lux/aspect/view.lux @@ -1,6 +1,7 @@ ... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. ... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. +... [Profunctor Optics: Modular Data Accessors](https://arxiv.org/abs/1703.10857) (.using [library [lux (.except macro @@ -77,9 +78,9 @@ (..view function.identity function.identity)) (every .public (Aspect context context' analogy analogy') - (for_any (_ it) - (-> (pro.Functor it) - (//.Aspect it context context' analogy analogy')))) + (for_any (_ =>) + (-> (pro.Functor =>) + (//.Aspect => context context' analogy analogy')))) (the functor (for_any (_ analogy analogy') @@ -99,11 +100,11 @@ (<| (with pro_functor) (each /#as /#of))) -(the .public (of_aspect it) +(the .public (of_aspect =>) (for_any (_ context context' analogy analogy') (-> (Aspect context context' analogy analogy' (for_any (_ context context') (View' context context' analogy analogy'))) (View' context context' analogy analogy'))) - (it [..functor] + (=> [..functor] [#as function.identity #of function.identity])) diff --git a/stdlib/source/library/lux/function.lux b/stdlib/source/library/lux/function.lux index 893e8fa29..6a0f6b275 100644 --- a/stdlib/source/library/lux/function.lux +++ b/stdlib/source/library/lux/function.lux @@ -73,3 +73,12 @@ (when left|right {0b left} {0b left} {1b right} {1b (it right)})))) + +(the .public monoidal + (pro.Monoidal Function) + (implementation + (the (in_parallel on_left on_right [left right]) + [(on_left left) + (on_right right)]) + (the empty + ..identity))) diff --git a/stdlib/source/test/lux/aspect.lux b/stdlib/source/test/lux/aspect.lux index 6977fe7f7..501c3d5c9 100644 --- a/stdlib/source/test/lux/aspect.lux +++ b/stdlib/source/test/lux/aspect.lux @@ -30,6 +30,8 @@ ["[0]" property (.only) ["[2][1]" \\test]] ["[0]" case (.only) + ["[2][1]" \\test]] + ["[0]" member (.only) ["[2][1]" \\test]]]]) (the sign @@ -57,27 +59,6 @@ {.#Left it}))) integer.decimal)) -(every (Tree it) - (Variant - {#Leaf} - {#Branch (Tree it) it (Tree it)})) - -(the (in_order it) - (for_any (_ it) - (/.Member (Tree it) it)) - (<| (with /.membership_apply) - (when it - {#Leaf} - (pure {#Leaf}) - - {#Branch left it right} - (left_associative with - (pure (function (_ left it right) - {#Branch left it right})) - (in_order left) - (/.one it) - (in_order right))))) - (the .public test Test (<| (_.covering /._) @@ -103,4 +84,5 @@ /view.test /property.test + /member.test ))) diff --git a/stdlib/source/test/lux/aspect/member.lux b/stdlib/source/test/lux/aspect/member.lux new file mode 100644 index 000000000..7cb2ab3db --- /dev/null +++ b/stdlib/source/test/lux/aspect/member.lux @@ -0,0 +1,46 @@ +... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. +... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. + +(.using + [library + [lux (.except) + [abstract + [monad (.only do)]] + [math + ["[0]" random]] + [test + ["_" property (.only Test)]]]] + [\\library + ["[0]" /]]) + +(every (Tree it) + (Variant + {#Leaf} + {#Branch (Tree it) it (Tree it)})) + +(the (in_order it) + (for_any (_ it) + (/.Member (Tree it) it)) + (<| (with /.application) + (when it + {#Leaf} + (pure {#Leaf}) + + {#Branch left it right} + (per with + (pure (function (_ left it right) + {#Branch left it right})) + (in_order left) + (/.one it) + (in_order right))))) + +(the .public test + Test + (<| (_.covering /._) + (do [! random.monad] + []) + (_.for [/.Member]) + (all _.and + (_.coverage [/.one] + false) + )))