3.27 iif : Select by comparison of items

Format

$obj$.iif(zdd1,zdd2) $\rightarrow $ $zdd3$

Description

Select terms in itemset included in $obj$ from $zdd1$, select terms in itemset not included in $obj$ from $zdd2$, and return the selected term which created the ZDD object as $zdd3$.

The weight of the itemset in $obj$ does not affect the operation.

Examples

Example 1: Basic Example

> require 'zdd'
> a=ZDD::itemset("a")
> b=ZDD::itemset("b")
> c=ZDD::itemset("c")
> d=ZDD::itemset("d")

# From all terms in the first argument of iif, select terms 2a, 3b which contains
# (a+b) with items a,b, and from all terms in the second argument of iif,
# select terms 8c, 9d which contains (a+b) with items a,b.
> f=(a+b).iif(2*a+3*b+4*c+5*d,6*a+7*b+8*c+9*d)
> f.show
 2 a + 3 b + 8 c + 9 d

# Used in conjunction with typical comparison operators as follows.
> x=3*a+2*b+2*c
> y=2*a+2*b+4*c
> x.show
 3 a + 2 b + 2 c
> y.show
 2 a + 2 b + 4 c

# Compare x and y, select term(s) where the weight of x is great than y, otherwise select y.
# If the result of x>y includes a, select 3a from the first argument x,
# Select the other itemsets 2b and 4c from the second argument y.
> r1=(x>y).iif(x,y)
> r1.show
 3 a + 2 b + 4 c

# Compare x and y, select term(s) where the weight of x is greater than y.
# Similar to the above example, since the second term is 0,
# itemset other than a is not selected.
> r2=(x>y).iif(x,0)
> r2.show
 3 a

# Compare x and y, select term(s) where the weight of x is the same weight as y.
> r3=(x==y).iif(x,0)
> r3.show
 2 b

See Also

==, $<$, $<=$, $>$, $>=$, ne? : Various comparison operations