Skip to main content

fherma-lang

FHERMA Kernel Language: lexer, parser and emitters. A standalone package — text in, structure out. It knows nothing about any platform, has no dependencies, and is what everything else builds on: the fherma command line tool, a server, a build script, an editor.

pip install fherma-lang

Most people arrive through the command line tool, which is built on this package and brings it along: pipx install fherma. Install this one directly when you want the language and nothing else — a server validating a signature, an editor, a build step — and then it belongs in the environment that imports it.

The language in one example

A kernel states a computational problem as generally as it is true. A specification refines it: it settles the types, names the dimensions and adds whatever the representation needs.

kernel poly_mult<T: Numeric, N: uint>(
    %a: tensor<N x T>,
    %b: tensor<N x T>,
) -> %c: tensor<N x T>
spec rlwe 1.0.0 "Cyclotomic, at RLWE parameters" {
    kernel poly_mult<T: i64, N: uint, L: uint, q: uint>(
        %a: tensor<N x L x T>,
        %b: tensor<N x L x T>,
    ) -> %c: tensor<N x L x T>
}

Both are the same production: a specification is a header wrapping a kernel declaration. What tells them apart is not syntax but how much they leave open.

Reading a declaration

$ fherma-lang parse sig.fhk
specification  rlwe 1.0.0
               Cyclotomic, at RLWE parameters
refines kernel poly_mult
parameters
    T          i64
    N          uint
    L          uint
    q          uint
arguments
    %a         tensor<N x L x T>
    %b         tensor<N x L x T>
results
    %c         tensor<N x L x T>

--json prints the parse result for another tool to consume, and it can be fed straight back in — see below.

Failures carry a code from the specification of the language, the place, and something to do about it:

$ fherma-lang parse bad.fhk
E-TYPE-1: Field is neither a class nor a type of this language
  line 1, column 13
  kernel f<T: Field>(%x: T) -> %y: T
              ^
  Classes are Numeric, Integer, Real. Types are i8…i64, f8…f64, index, uint, int, real.

Emitting a scaffold

A scaffold is a pure function of a declaration: the same signature always gives the same tree, which is what lets a command line tool and a web button hand out identical bundles without coordinating.

$ fherma-lang emit --testing sig.fhk
testing scaffold in poly_mult-rlwe-1.0.0
    fherma.py        3729  generated
    generate.py       558  yours
    oracle.py         504  yours
    verify.py         625  yours
    README.md         889  generated

fherma.py holds the types derived from the signature — Point, Inputs, Outputs — along with the deterministic Stream and the codec. The three stubs are where an author writes the generator, the oracle and the verifier.

Name the parts to scaffold one or two of them:

fherma-lang emit --testing sig.fhk --oracle --verifier

Either a declaration or a stored parse result will do; the tool tells them apart by looking at the first character, and does the rest:

fherma-lang parse --json sig.fhk > parsed.json
fherma-lang emit --testing parsed.json --out ./bundle

As a library

from fherma_lang import emit, parse

declaration = parse(open("sig.fhk").read())
for file in emit(declaration, kind="testing", parts=["oracle"]):
    print(file.path, file.generated)
from fherma_lang import reference                    # "poly_mult/rlwe@1.0.0"
from fherma_lang.serde import from_plain, to_plain   # a declaration to JSON and back

reference is what a declaration calls itself, and there is one definition of it because more than one thing depends on the exact string: it keys the deterministic stream, and a bundle records it as its own origin.

What is refused, and why

A scaffold needs every parameter settled, because there is no honest Python type for an open one. This is about abstraction, not about the shape of the declaration: a kernel that pins all of its parameters scaffolds fine.

E-SPEC-3: parameter T is constrained to Numeric rather than settled
  A class admits many types; pick one, as in <T: i64>.

Secrecy is a different matter. Where a signature hides a value, the scaffold sees through it: the generator and the oracle always work in cleartext, since encryption — where there is any — happens between them and the run.

Exit codes

0  done          1  the declaration was rejected          2  called wrongly

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fherma_lang-0.4.0.tar.gz (38.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fherma_lang-0.4.0-py3-none-any.whl (37.9 kB view details)

Uploaded Python 3

File details

Details for the file fherma_lang-0.4.0.tar.gz.

File metadata

  • Download URL: fherma_lang-0.4.0.tar.gz
  • Upload date:
  • Size: 38.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for fherma_lang-0.4.0.tar.gz
Algorithm Hash digest
SHA256 2d51382760b56a07f5dfde5825eef60ac149ab6c16b462b59be03779aaa88f88
MD5 33c34b395b8870c40f73d83be2326eed
BLAKE2b-256 090d0041152ebd4197cd8a343d4876b8b7894375fb07d185ff56424e5966b4f2

See more details on using hashes here.

Provenance

The following attestation bundles were made for fherma_lang-0.4.0.tar.gz:

Publisher: publish.yml on fairmath/fherma2

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fherma_lang-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: fherma_lang-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 37.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for fherma_lang-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3f4066591dd37e74a77f934703f2f7503abb454465981b142afc5c2e6a656bc1
MD5 fdd7003edc4971f4964cac9a98184bc1
BLAKE2b-256 fcc6a060b0a154523fe9166cfefdd43a4b8e9dd2b217cc55b9b5134dc2bad3c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for fherma_lang-0.4.0-py3-none-any.whl:

Publisher: publish.yml on fairmath/fherma2

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.8.0

2 files

0.7.0

2 files

0.6.0

2 files

0.5.0

2 files

This release

0.4.0 This release

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page