Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,6 @@
def assert($e; $msg): if $e then . else "assertion violation @ \($msg)" | error end;
def is_integer: type=="number" and floor == .;
# To take advantage of gojq's arbitrary-precision integer arithmetic:
def power($b): . as $in | reduce range(0;$b) as $i (1; . * $in);

View file

@ -0,0 +1,38 @@
# "ModularArithmetic" objects are represented by JSON objects of the form: {value, mod}.
# The function modint::assert/0 checks the input is of this form with integer values.
def is_modint: type=="object" and has("value") and has("mod");
def modint::assert:
assert(type=="object"; "object expected")
| assert(has("value"); "object should have a value")
| assert(has("mod"); "object should have a mod")
| assert(.value | is_integer; "value should be an integer")
| assert(.mod | is_integer; "mod should be an integer");
def modint::make($value; $mod):
assert($value|is_integer; "value should be an integer")
| assert($mod|is_integer; "mod should be an integer")
| { value: ($value % $mod), mod: $mod};
def modint::add($A; $B):
if ($B|type) == "object"
then assert($A.mod == $B.mod ; "modint::add")
| modint::make( $A.value + $B.value; $A.mod )
else modint::make( $A.value + $B; $A.mod )
end;
def modint::mul($A; $B):
if ($B|type) == "object"
then assert($A.mod == $B.mod ; "mul")
| modint::make( $A.value * $B.value; $A.mod )
else modint::make( $A.value * $B; $A.mod )
end;
def modint::pow($A; $pow):
assert($pow | is_integer; "pow")
| reduce range(0; $pow) as $i ( modint::make(1; $A.mod);
modint::mul( .; $A) );
# pretty print
def modint::pp: "«\(.value) % \(.mod)»";

View file

@ -0,0 +1,26 @@
def ring::add($A; $B):
if $A|is_modint then modint::add($A; $B)
elif $A|is_integer then $A + $B
else "ring::add" | error
end;
def ring::mul($A; $B):
if $A|is_modint then modint::mul($A; $B)
elif $A|is_integer then $A * $B
else "ring::mul" | error
end;
def ring::pow($A; $B):
if $A|is_modint then modint::pow($A; $B)
elif $A|is_integer then $A|power($B)
else "ring::pow" | error
end;
def ring::pp:
if is_modint then modint::pp
elif is_integer then .
else "ring::pp" | error
end;
def ring::f($x):
ring::add( ring::add( ring::pow($x; 100); $x); 1);

View file

@ -0,0 +1,5 @@
def main:
(ring::f(1) | "f(\(1)) => \(.)"),
(modint::make(10;13)
| ring::f(.) as $out
| "f(\(ring::pp)) => \($out|ring::pp)");