Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add mul, dbl to negabinary-scott-test #108

Merged
merged 1 commit into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/negabinary-scott/solution.lc
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,13 @@ pred = snd Enum
add = \ m n . m n
( \ zm . n m ( \ zn . nega-dbl (add zm zn) ) ( \ zn . Bit1 (add zm zn) ) )
( \ zm . n m ( \ zn . Bit1 (add zm zn) ) ( \ zn . nega-dbl (pred (add zm zn)) ) )
mul = \ m n . m 0
( \ zm . n 0 ( \ zn . Bit0 (Bit0 (mul zm zn)) ) ( \ _z . Bit0 (mul zm n) ) )
( \ zm . n 0 ( \ zn . Bit0 (mul m zn) ) ( \ zn . Bit1 (add (nega-dbl (mul zm zn)) (add zm zn)) ) )

negate = \ n . add n (nega-dbl n)
sub = \ m n . add m (negate n)
dbl = \ m . m 0 ( \ n . Bit0 (dbl n) ) ( \ n . nega-dbl (pred (dbl n)) )
zero = \ n . n True (K False) (K False)

Ord = Y4 (Quad (T \ lt0 le0 ge0 gt0 . \ n . n False gt0 gt0) # lt0
Expand Down
11 changes: 10 additions & 1 deletion tests/negabinary-scott/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ LC.configure({ purity: "LetRec", numEncoding: { fromInt, toInt } });

const solutionText = readFileSync(new URL("./solution.lc", import.meta.url), {encoding: "utf8"});
const solution = LC.compile(solutionText);
const { succ,pred, add,negate,sub, zero, lt0,le0,ge0,gt0,compare } = solution;
const { succ,pred, add,mul,negate,sub,dbl, zero, lt0,le0,ge0,gt0,compare } = solution;

const toBoolean = p => p (true) (false) ;
const toOrdering = cmp => cmp ("LT") ("EQ") ("GT") ;
Expand All @@ -43,6 +43,11 @@ describe("NegaBinaryScott", () => {
for ( let n=-10; n<=10; n++ )
assert.strictEqual( toInt(add(m)(n)), m+n, `add ${ m } ${ n }` );
});
it("mul", () => {
for ( let m=-10; m<=10; m++ )
for ( let n=-10; n<=10; n++ )
assert.strictEqual( toInt(mul(m)(n)), m*n, `mul ${ m } ${ n }` );
});
it("negate", () => {
for ( let n=-10; n<=10; n++ )
assert.strictEqual( toInt(negate(n)), -n, `negate ${ n }` );
Expand All @@ -56,6 +61,10 @@ describe("NegaBinaryScott", () => {
for ( let n=-10; n<=10; n++ )
assert.strictEqual( toInt(sub(m)(n)), m-n, `sub ${ m } ${ n }` );
});
it("dbl", () => {
for ( let n=-10; n<=10; n++ )
assert.strictEqual( toInt(dbl(n)), 2*n, `dbl ${ n }` );
});
it("eq, uneq", () => {
for ( let n=-10; n<=10; n++ )
assert.strictEqual(toBoolean(zero(n)),n===0,`zero ${ n }`),
Expand Down
Loading