Quick Start¶
Provides a guide and a toy example of how to create a repository and generate some results. The toy example shows the computation of Fibonacci numbers by means of result of components fib_zero, fib_one, and fib_next.
1. Define Component Specifications¶
Using domain-specific language provided by the SpecificationBuilder class define a triple of named components and respective specifications (name, interpretation, specification).
- The component
fib_zerois specified byConstructor("fib") & Constructor("at", Literal(0, "int")), which combines two properties. Constructor("fib")means thatfib_zeroit is a Fibonacci number.Constructor("at", Literal(0))means thatfib_zerois associated with index0.- The component
fib_one, similarly tofib_zero, is a Fibonacci number and is associated with index1. - The component
fib_nexthas three parameters associated with the DataGroupint. In the toy example, indices less than20are considered. zindex of the constructed Fibonacci numberyindex of the previous Fibonacci number, which isz - 1xindex of the Fibonacci number two indices prior, which isz - 2
and two arguments + f1 previous Fibonacci number + f2 Fibonacci number two indices prior
Given the above parameters and arguments the component fib_next computes a Fibonacci number and is associated with index z, specified by Constructor("fib") & Constructor("at", Var("z"))).
def fib_zero() -> int:
return 0
def fib_one() -> int:
return 1
def fib_next(_z: int, _y: int, _x: int, f1 : int, f2: int) -> int:
return f1 + f2
named_components_with_specifications = [
(
"fib_zero",
fib_zero,
SpecificationBuilder()
.suffix(Constructor("fib") & Constructor("at", Literal(0))),
),
(
"fib_one",
fib_one,
SpecificationBuilder()
.suffix(Constructor("fib") & Constructor("at", Literal(1))),
),
(
"fib_next",
fib_next,
SpecificationBuilder()
.parameter("z", DataGroup("int", range(bound)))
.parameter("y", DataGroup("int", range(bound)), lambda vs: [vs["z"] - 1])
.parameter("x", DataGroup("int", range(bound)), lambda vs: [vs["z"] - 2])
.argument("f1", Constructor("fib") & Constructor("at", Var("y")))
.argument("f2", Constructor("fib") & Constructor("at", Var("x")))
.suffix(Constructor("fib") & Constructor("at", Var("z"))),
),
]
2. Instantiate CoSy¶
Let the Maestro know what he is working with; by providing the named components with their specifications.
3. Specify a Target and Construct Results¶
Specify the target for which results should be found. Results are found by means of instantiation and result of the given components in the given parameter space ().
Arbitrary Fibonacci numbers¶
The following target Constructor("fib") describes arbitrary Fibonacci numbers at indices in the given parameter space.
Using the design method, iterate over and display results for the given target.
Fibonacci numbers at Specific Indices¶
The specification allows us to target Fibonacci numbers at specific indices. For an index i the target Constructor("fib") & Constructor("at", Literal(i)) describes the Fibonacci number at index i. Using the design method, construct and display this Fibonacci number.