Skip to content

Commit

Permalink
add more molecules
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfitz committed Oct 27, 2019
1 parent 1f30068 commit 267767e
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 24 deletions.
157 changes: 148 additions & 9 deletions msg/COS_Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,151 @@

const cos = require('./cosmic');

cos.intro("proton:electron:mass:ratio");
cos.intro("proton:mass");
cos.intro("neutron:mass");
cos.intro("electron:mass");

cos.add("define float:= | ? x | ? y | within (frac (+ $x $y) 200000) $x $y");
cos.add("float:= $proton:mass | * $electron:mass | decimal 1836 | vector 1 5 2 6 7 3");
cos.add("float:= $electron:mass | * $proton:mass | decimal 0 | vector 0 0 0 5 4 4 6 1 7");
cos.add("float:= $neutron:mass | * $proton:mass | decimal 1 | vector 0 0 1 3 7 8 4 2");
cos.add("intro power:10");
cos.add(`define power:10 | ? n |
if (= $n 0) 1 |
assign part (if (>= $n 0) 10 (frac 1 10)) |
reduce $* | map (? x $part) | range 0 (abs $n)`);

cos.add(`define float:= | ? x | ? y |
if (= $x $y) $true |
within (frac (+ $x $y) 200000) $x $y`);
cos.add(`float:= 10 | power:10 1`);
cos.add(`float:= 100 | power:10 2`);
cos.add(`float:= 1000 | power:10 3`);
cos.add(`float:= (frac 1 10) | power:10 | minus 1`);
cos.add(`float:= (frac 1 100) | power:10 | minus 2`);
cos.add(`float:= 1 | power:10 0`);

cos.add(`define decimal:power | ? x:power | ? x:int | ? x:list |
* (power:10 $x:power) (decimal $x:int $x:list)`);

cos.add(`float:= 1530 | decimal:power 3 1 | vector 5 3`);
cos.add(`float:= 15300 | decimal:power 4 1 | vector 5 3`);
cos.add(`float:= (decimal 1 | vector 5 3) | decimal:power 0 1 | vector 5 3`);
cos.add(`float:= (decimal 0 | vector 0 0 1 5 3) | decimal:power (minus 3) 1 | vector 5 3`);

cos.intro("proton");
cos.intro("electron");
cos.intro("neutron");
cos.intro("mass");

cos.doc(`The following definitions are not included in the message, since they are
unit-specific. The message will only present ratios.`);

cos.add(`assume | define proton | make-hash | vector
(pair mass | decimal:power (minus 27) 1 | vector 6 7 2 6 1 9 2 3 6 9)
(pair charge 1)`);

cos.add(`assume | define electron | make-hash | vector
(pair mass | decimal:power (minus 31) 9 | vector 1 0 9 3 8 3 5 6)
(pair charge | minus 1)`);

cos.add(`assume | define neutron | make-hash | vector
(pair mass | decimal:power (minus 27) 1 | vector 6 7 4 9 2 7 4 7 1)
(pair charge 0)`);

cos.add("float:= (proton mass) | * (electron mass) | decimal 1836 | vector 1 5 2 6 7 3");
cos.add("float:= (electron mass) | * (proton mass) | decimal 0 | vector 0 0 0 5 4 4 6 1 7");
cos.add("float:= (neutron mass) | * (proton mass) | decimal 1 | vector 0 0 1 3 7 8 4 2");

cos.add("float:= (proton charge) | * (electron charge) (minus 1)");
cos.add("float:= (neutron charge) 0");

cos.add(`define atom | ? x:proton | ? x:proton:neutron | make-hash | vector
(pair proton $x:proton)
(pair neutron | - $x:proton:neutron $x:proton)
(pair electron $x:proton)`);

cos.add(`= ((atom 1 1) proton) 1`);
cos.add(`= ((atom 1 1) electron) 1`);
cos.add(`= ((atom 1 1) neutron) 0`);
cos.add(`= ((atom 1 2) proton) 1`);
cos.add(`= ((atom 1 2) electron) 1`);
cos.add(`= ((atom 1 2) neutron) 1`);

cos.add(`class elemental (proton isotope:list)
(method proton $proton)
(method isotope:list $isotope:list)
(method electron $proton)
(method neutron:list | map (? x | - $x $proton) $isotope:list)`);

cos.intro(`hydrogen`);
cos.intro(`helium`);
cos.intro(`carbon`);
cos.intro(`nitrogen`);
cos.intro(`oxygen`);
cos.add(`define hydrogen | elemental new 1 | vector 1 2`);
cos.add(`define helium | elemental new 2 | vector 2 4`);
cos.add(`define carbon | elemental new 6 | vector 12 13`); // ignoring 14
cos.add(`define nitrogen | elemental new 7 | vector 14 15`);
cos.add(`define oxygen | elemental new 16 | vector 16 17 18`);

cos.add(`= (hydrogen proton) 1`);
cos.add(`= (hydrogen electron) 1`);
cos.add(`list= (hydrogen isotope:list) | vector 1 2`);
cos.add(`list= (hydrogen neutron:list) | vector 0 1`);

cos.add(`= (carbon proton) 6`);
cos.add(`= (carbon electron) 6`);
cos.add(`list= (carbon isotope:list) | vector 12 13`);
cos.add(`list= (carbon neutron:list) | vector 6 7`);

cos.add(`class molecule (elemental:list)
(method elemental:list $elemental:list)
(method count | lambda ((e elemental)) |
list-length | select-match (? x | = (x proton) (e proton)) $elemental:list)`);

cos.intro('hydrogen:2');
cos.add(`define hydrogen:2 | molecule new | vector $hydrogen $hydrogen`);
cos.add(`= (hydrogen:2 count $hydrogen) 2`);
cos.add(`= (hydrogen:2 count $carbon) 0`);
cos.add(`= (hydrogen:2 count $nitrogen) 0`);
cos.add(`= (hydrogen:2 count $oxygen) 0`);
cos.intro('oxygen:2');
cos.add(`define oxygen:2 | molecule new | vector $oxygen $oxygen`);
cos.add(`= (oxygen:2 count $hydrogen) 0`);
cos.add(`= (oxygen:2 count $carbon) 0`);
cos.add(`= (oxygen:2 count $nitrogen) 0`);
cos.add(`= (oxygen:2 count $oxygen) 2`);
cos.intro('oxygen:3');
cos.add(`define oxygen:3 | molecule new | vector $oxygen $oxygen $oxygen`);
cos.add(`= (oxygen:3 count $hydrogen) 0`);
cos.add(`= (oxygen:3 count $carbon) 0`);
cos.add(`= (oxygen:3 count $nitrogen) 0`);
cos.add(`= (oxygen:3 count $oxygen) 3`);
cos.intro(`water`);
cos.add(`define water | molecule new | vector $hydrogen $hydrogen $oxygen`);
cos.add(`= (water count $hydrogen) 2`);
cos.add(`= (water count $carbon) 0`);
cos.add(`= (water count $nitrogen) 0`);
cos.add(`= (water count $oxygen) 1`);
cos.intro(`nitrogen:2`);
cos.add(`define nitrogen:2 | molecule new | vector $nitrogen $nitrogen`);
cos.add(`= (nitrogen:2 count $hydrogen) 0`);
cos.add(`= (nitrogen:2 count $carbon) 0`);
cos.add(`= (nitrogen:2 count $nitrogen) 2`);
cos.add(`= (nitrogen:2 count $oxygen) 0`);
cos.intro(`ammonia`);
cos.add(`define ammonia | molecule new | vector
$nitrogen $hydrogen $hydrogen $hydrogen`);
cos.add(`= (ammonia count $hydrogen) 3`);
cos.add(`= (ammonia count $carbon) 0`);
cos.add(`= (ammonia count $nitrogen) 1`);
cos.add(`= (ammonia count $oxygen) 0`);
cos.intro(`methane`);
cos.add(`define methane | molecule new | vector
$carbon $hydrogen $hydrogen $hydrogen $hydrogen`);
cos.add(`= (methane count $hydrogen) 4`);
cos.add(`= (methane count $carbon) 1`);
cos.add(`= (methane count $nitrogen) 0`);
cos.add(`= (methane count $oxygen) 0`);
cos.intro(`ethane`);
cos.add(`define ethane | molecule new | vector
$hydrogen $hydrogen $hydrogen
$carbon $carbon
$hydrogen $hydrogen $hydrogen`);
cos.add(`= (ethane count $hydrogen) 6`);
cos.add(`= (ethane count $carbon) 2`);
cos.add(`= (ethane count $nitrogen) 0`);
cos.add(`= (ethane count $oxygen) 0`);
6 changes: 6 additions & 0 deletions msg/COS_Element.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
# PHYSICS introduce the elements

Introducing the elements is done well in the [DearET message](https://web.archive.org/web/20161017192136/http:https://www.dearet.org/testing-a-message) by [Michael Busch](https://seti.org/our-scientists/michael-busch). We draw inspiration from that work.

The general idea here is that there are some physical ratios that should be known by
anybody with a handle on what is going on at the atomic level, and may be recognizable.
The pattern of how elementary particles are combined into atoms, and atoms into
molecules, may also ring a bell.
9 changes: 9 additions & 0 deletions msg/COS_List.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,12 @@ cos.add(`define append | ? x | ? lst |
prepend (head | $lst) | append $x | tail $lst`);

cos.add(`list= (vector 1 2 5) | append 5 | vector 1 2`);

cos.intro("select-match");
cos.add(`define select-match | ? test | ? lst |
if (= 0 | list-length $lst) $lst |
if (not | test | head $lst) (select-match $test | tail $lst) |
prepend (head $lst) (select-match $test | tail $lst)`);

cos.add(`list= (vector 14 19 13) | select-match (? x | > $x 10) | vector 1 14 19 3 13 0 4`);

7 changes: 0 additions & 7 deletions msg/COS_NewType.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,6 @@ cos.add(`define list-append | lambda (lst1 lst2) |

cos.add(`list= (vector 1 2 3 4 5 6) | list-append (vector 1 2 3) (vector 4 5 6)`);

cos.add(`define select-match | lambda (test lst) |
if (= 0 | list-length $lst) $lst |
if (not | test | head $lst) (select-match $test | tail $lst) |
prepend (head $lst) (select-match $test | tail $lst)`);

cos.add(`list= (vector 14 19 13) | select-match (? x | > $x 10) | vector 1 14 19 3 13 0 4`);

cos.add(`define unique | assign store (make-cell 0) | ? x |
assign id (get! $store) |
begin (set! $store (+ $id 1)) $id`);
Expand Down
1 change: 1 addition & 0 deletions msg/COS_Series.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ define range | ? x:- | ? x:+ |
prepend $x:- | range (+ 1 $x:-) $x:+`);
cos.add("= 6 | reduce $+ | range 0 4");
cos.add("= 12 | reduce $+ | map (? x | * $x 2) | range 0 4");
cos.add("= 3 | reduce $+ | range 3 4");

cos.add("intro even");
cos.add("not | even 1");
Expand Down
2 changes: 1 addition & 1 deletion msg/DEPEND.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set(req_COS_Series COS_Map COS_OrLogic COS_If)
set(req_COS_Translate COS_ListPre)
set(req_COS_List COS_ListPre COS_Translate COS_OrLogic)
set(req_COS_Dot COS_List)
set(req_COS_Element COS_List COS_Series)
set(req_COS_Element COS_List COS_Series COS_Hash COS_NewType)
set(req_COS_Let COS_List)
set(req_COS_MultipleParameter COS_Let)
set(req_COS_Implication COS_TrueFalse)
Expand Down
1 change: 1 addition & 0 deletions msg/README.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ set(COSMIC_DEPENDS
COS_Turing
COS_Quote
COS_NewType
COS_Element
COS_CommentBase2
COS_Unless
COS_NOT
Expand Down
7 changes: 6 additions & 1 deletion src/assemble/CosmicDrive.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,21 @@ CosmicDrive.prototype.complete_stanza_core = function(op, stanza, can_run) {
norm.encode(encoded);
symbol.encode(encoded);
var code = encoded.content[0];
var assume = false;
if (part!=null) {
part["preprocessed"] = preprocessed;
part["code"] = code;
part["parse"] = parsed.content;
part["spider"] = this.spider.addString(code);
part["dt"] = this.cosmicos.Parse.looksLikeMutation(parsed.content);
if (op.indexOf("assume ")==0) {
part["assume"] = true;
assume = true;
}
}
var cline = 999;
console.log(cline + ": " + op + " --> " + code);
if (this.txt != null) {
if (this.txt != null && !assume) {
this.txt += code;
this.txt += "\n";
}
Expand Down
6 changes: 0 additions & 6 deletions src/cosmicos/Evaluate.hx
Original file line number Diff line number Diff line change
Expand Up @@ -398,12 +398,6 @@ class Evaluate {
evaluateLine("@ is:square | ? x | has-square-divisor-within $x $x");
evaluateLine("@ undefined 999"); // this should be a special value, not 999 :-)
evaluateLine("@ even | ? x | = 0 | - $x | * 2 | div $x 2");
// evaluateLine("@ proton:electron:mass:ratio 1836.15267343f");
mem.add(vocab.get("proton:electron:mass:ratio"), 1836.15267343);
mem.add(vocab.get("proton:mass"), 1.6726192369e-27); // number should never be revealed
// since arbitrary units (kg)
mem.add(vocab.get("neutron:mass"), 1.674927471e-27); // ditto
mem.add(vocab.get("electron:mass"), 9.10938356e-31); // ditto

// meta-lambda-function
id_lambda0 = vocab.get("??");
Expand Down

0 comments on commit 267767e

Please sign in to comment.