New answers tagged

1

J, 114102 bytes [:*/([:;e.&' ()'({.;(<./@i.~&'rapt'{ ::''+`*`<:,'1-';'&{',~&":1-~#)@}.);.1]),/&.":"#.2#:@i.@^1#.e.&'P' Try it online! How it works 2|:@#:@i.@^1#.e.&'P' Count the P's in the string, 2^y, range, and base 2 it. This is a matrix with all boolean combinations for P variables. Now transforming the ...


2

05AB1E (legacy), 45 bytes „€Ÿ(ì'''_:'Ø¢„<=:D'P¢ƒ1Ý'_Nד €‡ Pÿ€†ÿ“}')J.Eb Port of @KirillL.'s Python answer, so make sure to upvote him! Outputs 1/0 respectively. If outputting True/False is allowed (even though these are both falsey in 05AB1E), the trailing b could be omitted. Uses the legacy version of 05AB1E, where list [0,1] will be input as string ...


4

Python 3, 128 bytes lambda s:eval("all("+s.replace("implies","<=").replace(*"'_")+"".join(f" for P{'_'*i} in[0,1]"for i in range(s.count("P")))+")") Try it online! The operator names in the task definition are the same as in Python (except implies, which is replaceable by &...


1

SageMath, 140 134 132 bytes lambda p:propcalc.formula(r(*"'0",r("implies","->",r("or","|",r("and","&",r("not","~",p)))))).is_tautology() from re import sub as r Try it online!


0

Wolfram Language (Mathematica), 10 bytes TautologyQ Yep, there's a builtin.... Now, the OP will have to decide if the input format is acceptable (I feel that it is well within the spirit of this site's guidelines). In terms of the variables themselves, we need to use strings of letters in place of P, P', P'', and so on: we can use P, Pp, Ppp, and so on (as ...


7

Retina 0.8.2, 136 124 121 bytes {T`()`<> .*P.* <$& ¶ $&> (?=(P'*))(?=.*\1[^P']*(¶|$))\1 $.2 ¶ a <not 1>|<0 or 0>|<1 [ai]\w* 0>|<0 a\w* .>|(<[^P<>]*>) $#1 Try it online! Link includes test cases. Explanation: Works by considering each variable in turn, replacing the string f(p) with the string <f(1) ...


3

JavaScript (ES6),  129 ... 122  115 bytes Saved 1 byte thanks to @Neil Returns 0 or 1. f=(s,n)=>eval(s.replace(m=/\w+'*/g,s=>(m|=l=s.length,{a:"&",i:"<=",n:"!",o:"|"})[s[0]]||n>>l-1&1))?n>>m||f(s,-~n):0 Try it online! How? We use /\w+'*/g to match all variables and operator names. The ...


6

Haskell, 482 ... 408 402 bytes -5 thanks to @ovs -18 by inlining functions that are used just once -12 by introducing short names of constants and removing parentheses -11 by making a function local so it can take less arguments -29 thanks to @Laikoni and @Trebor -6 bytes by preferring list comprehension to filter, and turn F Int[A] into Q[A]Int for 1 ...


4

Python 3, 393 382 bytes -11 bytes thanks to @ovs from itertools import* T=tuple P=product def C(A,e,n): G=range(n);t=0;c=[] for m in P(*[[dict(zip(P(*[G]*a),o))for o in P(*[G]*n**a)]for a in A]): E=lambda x,f:f[x]if x*0==0else m[x[0]][T(E(s,f)for s in x[1:])] if m not in c: c+=[T({T(r[a]for a in k):r[f[k]]for k in f}for f in m)for r in permutations(G)...


Top 50 recent answers are included