# Package or method to determine truth table or is a statement is a Tautology?

Hi all,

I was wondering is there anything close to or similar function/method that can be used to determine if a combination of 2 values are tautology (a statement that is always true).

It is a basic logic statements in mathematics if p then q (p β q), p or q ( p v q), p and q (p ^ q), p happens if and only if q happens ( p <-> q).

With possible outcomes for p and q are only 2(True or False / 1 or 0).

Otherwise if no package available on this subject, I think it will be a code writing with a lot of if then statements.

I suppose you mean a combination of two propositional variables (not values). In the case of only two variables, you can just check the whole truth table, i.e., check all four possible valuations of your formula:

``````function is_tautology(formula)
for (p, q) in Iterators.product([true, false], [true, false])
formula(p, q) || return false
end
return true
end

my_formula(p::Bool, q::Bool) = !p || (p && q)
is_tautology(my_formula)

is_tautology((p, q) -> !p || p)

is_tautology() do p, q
return !(p && ! p)
end
``````

Do you think it is possible to create table like below:

With dataframe package or other suggestion?

How to create a function like yours if I want to have 4 propositional variables?
2^4 rows.
Is there a general formula / function for n propositional variables?

something like that, would it be okay?

``````all((p,q,r,s)-> !p || (p && q) && (r || (s && !r)), Iterators.product(repeat([[true, false]],4)...))
``````

If you are looking for formatted output, to get something that comes close, you could try DatFrames and PrettyTables

``````using DataFrames, PrettyTables
df=DataFrame(p=repeat([true, false],outer=2), q=repeat([true, false],inner=2))

df[!,"p β» q"] .=df.p .β» df.q

βββββββββ¬ββββββββ¬ββββββββ¬ββββββββ¬ββββββββ
β     p β     q β p β© q β p β© q β p β» q β
βββββββββΌββββββββΌββββββββΌββββββββΌββββββββ€
β  true β  true β  true β  true β false β
β false β  true β false β  true β  true β
β  true β false β false β  true β  true β
β false β false β false β false β false β
βββββββββ΄ββββββββ΄ββββββββ΄ββββββββ΄ββββββββ
``````
``````julia> df=DataFrame(p=repeat([true, false],outer=4),
q=repeat([true, false],inner=2, outer=2),
r=repeat([true, false],inner=4))

βββββββββ¬ββββββββ¬ββββββββ¬βββββββββββββββββββββββ
βββββββββΌββββββββΌββββββββΌβββββββββββββββββββββββ€
β  true β  true β  true β                 true β
β false β  true β  true β                 true β
β  true β false β  true β                 true β
β false β false β  true β                 true β
β  true β  true β false β                 true β
β false β  true β false β                 true β
β  true β false β false β                 true β
β false β false β false β                 true β
βββββββββ΄ββββββββ΄ββββββββ΄βββββββββββββββββββββββ
``````
1 Like

Here are my problems:

1. I am trying to create the negation, but do not have an idea what to write, tried to put `!` and `~` not working. Then read your text above and needs to add `.` before `!` and put `()` as well. Thanksβ¦
2. How about implication ( β) and biimplication
``````using DataFrames, PrettyTables
df=DataFrame(p=repeat([true, false],inner=4), q=repeat([true, false],inner=2,outer=2), r=repeat([true, false],outer=4))

df[!,"~p"].=.!(df.p)
df[!,"~q"].=.!(df.q)
df[!,"~r"].=.!(df.r)