functional programming - Is there an efficient algorithm to find which composition of boolean functions will match the output of a given boolean function? -
suppose have next boolean functions.
def bottom(): homecoming false def implies(var1, var2): if var1 == true , var2 == false: homecoming false homecoming true def land(var1, var2): homecoming var1 == true , var2 == true. is there efficient algorithm take these 3 functions input, , determine (possibly multiple-application) functional composition of first 2 functions match output of 3rd function every boolean (t,f) input 3rd function?
i using python write illustration in, not restricting solutions python or programming language matter. in fact not looking code, more of description of algorithm or explanation why 1 not exist.
as side note, motivation trying find algorithm because asked show functional completeness of particular set of logical connectives, , showing 1 logical connective can emulated set of others. logic, have utilize little bit of guess , check, not figure out way capture in programme without linear search on big space of possibilities.
if you're looking @ boolean functions of 2 arguments, simple brute-force technique work. extended ternary logic, or ternary functions, or both, exponential can't force far. here's boolean version; hope it's obvious how extend it.
1) binary boolean function relation {false, true} x {false, true} -> {false, true}. there 16 of these. note these include various functions independent of 1 or both of inputs. let's create set 𝓕 consisting of these 16 functions, , note every boolean function has corresponding higher-order function 𝓕 x 𝓕 -> 𝓕.
2) now, start boolean functions take first , take second, , build closure using hofs corresponding "given functions". if target function in closure, it's achievable combination of given functions. more generally, if every element in 𝓕 in closure, given function(s) universal.
so, let's apply example. i'm going write elements of 𝓕 four-tuple corresponding inputs (f,f) (f,t) (t,f) (t,t) in order, , i'm going write hofs in bold. bottom ffff , implies ttft. bottom(a, b) ffff (a,b).
take first fftt , take second ftft, that's our starting set. can utilize bottom add together ffff, no farther applications of bottom going add together anything.
so have 9 possible pairs of functions can apply implies. here go:
implies(fftt, fftt) == tttt (new)
implies(fftt, ftft) == ttft (new)
implies(fftt, ffff) == ttff (new)
implies(ftft, fftt) == tftt (new)
implies(ftft, ftft) == tttt
implies(ftft, ffff) == tftf (new)
implies(ffff, fftt) == tttt
implies(ffff, ftft) == tttt
implies(ffff, ffff) == tttt
now we're 8 of 16 functions, , have bunch more pairs check. since finish set, tedious, i'll leave next step reader (or perhaps computer program).
algorithm functional-programming boolean boolean-logic
No comments:
Post a Comment