On this page:
define-forward-instance-construction
define-forward-certificate-construction
define-backward-certificate-construction
target-inst
define
check-reduction
get-counterexample
union-in
3.1 Additional Operations
if
for/  set
corr
find-one
argmax
argmin
all-pairs-in
all-triplets-in
el
_  1s
_  2s
_  3s
_  ks
index-in
element-of-index
ints-from-to
8.12

3 Reduction🔗

 #lang karp/reduction package: Karp

syntax

(define-forward-instance-construction
  #:from from-name #:to to-name
  id inst-arg
  body ...+)
Define a forward instance construction function from decision problem from-name to decision problem to-name with name id. The function takes one from-name-instance as its arugment and produces one to-name-instance as its output.

The final expression of the body is expected to evaluate to an to-name-instance.

syntax

(define-forward-certificate-construction
  #:from from-name #:to to-name
  id f->t-construction-arg inst-arg cert-arg
  body ...+)
Define a forward certificate construction function from decision problem from-name to decision problem to-name with name id. The function takes one from-name-instance and a from-name-certificate of the instance as its arugments and produces one to-name-certificate as its output.

The final expression of the body is expected to evaluate to an to-name-certificate.

syntax

(define-backward-certificate-construction
  #:from from-name #:to to-name
  id f->t-construction-arg inst-arg cert-arg
  body ...+)
Define a forward certificate construction function from decision problem from-name to decision problem to-name with name id. The function takes one from-name-instance and a to-name-certificate of the instance as its arugments and produces one from-name-certificate as its output.

The final expression of the body is expected to evaluate to an from-name-certificate.

value

target-inst : instance?

Use target-inst to access the to-problem instance constructed from the current from-problem instance through the supplied forward instance construction.

syntax

(define id expr)

Define id as the result of expr.

syntax

(check-reduction #:from from-name #:to to-name
                 maybe-from-generator maybe-n-test maybe-random-seed
                 f->t-instance-construction
                 f->t-certificiate-construction
                 t->f-certificate-construction)
 
maybe-from-generator = 
  | #:from-generator generator
     
maybe-n-test = 
  | #:n-test n-test
     
maybe-random-seed = 
  | #:random-seed random-seed
 
  from-name : decision-problem
  to-name : decision-problem
  n-test : natural?
  random-seed : natural?
Run random testing on the given reduction.

The f->t-instance-construction, f->t-certificiate-construction and t->f-certificate-construction arguments should be construction functions defined with define-forward-instance-construction, define-forward-certificate-construction and define-backward-certificate-construction respectively.

syntax

(get-counterexample)

Access counterexample instance of the from-problem found by the last run of check-reduction.

syntax

(union-in file-1 file-2)

Import the decision problem definitions from file-1 and file-2. union-in takes care of the fields that share the same name across the two decision problems.

3.1 Additional Operations🔗

The additional operations described in this section are NOT available in verifier definitions.

syntax

(if cond-expr then-expr else-expr)

\begin{cases} a & p \\ b & o.w. \end{cases} where a is then-expr, b is else-expr, and p is cond-expr

syntax

(for/set { el-expr element-in-set ...+ maybe-cond})

 
element-in-set = for [var  X]
     
var = x
  | (x #:index i)
     
maybe-cond = if cond-expr
  | 
 
  X : set?
  cond-expr : boolean-expression?
Create a set with representative element el-expr going over all element x in X ... satisfying the cond-expr, i.e., \{ f(x,y,\dots) \mid x \in X(y,\dots), y \in Y(\dots),P(x,y,\dots) \} where f(x,y,\dots) is the value produced by el-expr.

In this example, the elements of the set are sums of a and b, where a and b are drawn from the sets \{1,2,3\} and \{4,5,6\}, respectively.
> (for/set {(+ a b)
    for [a  (set 1 2 3)]
    for [b  (set 4 5 6)]})

{5ₚ, 6ₚ, 7ₚ, 8ₚ, 9ₚ}

When the form [(e #:index j) X] is used, j is bound to the index of x in set X.

Example
> (define set-of-abc (set "a" "b" "c"))
> (for/set {(set e1 e2 j)
    for [(e1 #:index j)  set-of-abc]
    for [(e2 #:index k)  set-of-abc]
    if (not (equal? j k))})

{{3ₚ, "b", "a"}, {1ₚ, "b", "c"}, {2ₚ, "c", "a"}, {1ₚ, "b", "a"}, {3ₚ, "c", "a"}, {2ₚ, "b", "c"}}

procedure

(corr x)  any

  x : any
If x is an element of a set created with for/set, (corr x) produces one element that x is created from.

syntax

(find-one [var  X] maybe-cond)

 
var = x
  | (x #:index i)
     
maybe-cond = s.t. cond-expr
 
  X : set?
  cond-expr : boolean-expression?
Get an (arbitary) element from set X that satisfies the condition. An error will be triggered if no such elemenet exists.

When the form [(x #:index i) X] is used, i is bound to the index of x in set X.

syntax

(argmax x-expr [x  X] maybe-cond)

 
maybe-cond = s.t. cond-expr
 
  X : set?
  x-expr : number-expression?
  cond-expr : boolean-expression?

syntax

(argmin x-expr [x  X] maybe-cond)

 
maybe-cond = s.t. cond-expr
 
  X : set?
  x-expr : number-expression?
  cond-expr : boolean-expression?

syntax

(all-pairs-in X maybe-ordered)

 
maybe-ordered = 
  | #:ordered
Produce a set containing all pairs (2-tuple) of elements in set X.

syntax

(all-triplets-in X maybe-ordered)

 
maybe-ordered = 
  | #:ordered
Produce a set containing all triplets (3-tuple) of elements in set X.

procedure

(el subscript ...)  abstract-element

  subscript : any
An abstract element with subscripts subscript ... .

procedure

(_1s e)  any

  e : el?
Get the first subscript of e ... .

procedure

(_2s e)  any

  e : el?
Get the second subscript of e ... .

procedure

(_3s e)  any

  e : el?
Get the third subscript of e ... .

procedure

(_ks e k)  any

  e : el?
  k : positive-integer?
Get the k-th subscript of e ... .

procedure

(index-in e S)  natural?

  e : any
  S : set?
Get the index of the e in set S.

procedure

(element-of-index i S)  any

  i : natural?
  S : set?
Get the element in set S of index i.

procedure

(ints-from-to from to)  (setof natural?)

  from : natural? polynomial-size?
  to : natural? polynomial-size?
Produce the set of integers from from to to inclusive of the endpoints. The endpoints must be within polynomial of the input size.