Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
49
Task/Truth-table/Maxima/truth-table-1.maxima
Normal file
49
Task/Truth-table/Maxima/truth-table-1.maxima
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/* Maxima already has the following logical operators
|
||||
=, # (not equal), not, and, or
|
||||
define some more and set 'binding power' (operator
|
||||
precedence) for them
|
||||
*/
|
||||
infix("xor", 60)$
|
||||
"xor"(A,B):= (A or B) and not(A and B)$
|
||||
|
||||
infix("=>", 59)$
|
||||
"=>"(A,B):= not A or B$
|
||||
|
||||
/*
|
||||
Substitute variables `r' in `e' with values taken from list `l' where
|
||||
`e' is expression, `r' is a list of independent variables, `l' is a
|
||||
list of the values
|
||||
lsubst( '(A + B), ['A, 'B], [1, 2]);
|
||||
1 + 2;
|
||||
*/
|
||||
lsubst(e, r, l):= ev(e, maplist( lambda([x, y], x=y), r, l), 'simp)$
|
||||
|
||||
/*
|
||||
"Cartesian power" `n' of list `b'. Returns a list of lists of the form
|
||||
[<x_1>, ..., <x_n>], were <x_1>, .. <x_n> are elements of list `b'
|
||||
cartesian_power([true, false], 2);
|
||||
[[true, true], [true, false], [false, true], [false, false]];
|
||||
cartesian_power([true, false], 3);
|
||||
[[true, true, true], [true, true, false], [true, false, true],
|
||||
[true, false, false], [false, true, true], [false, true, false],
|
||||
[false, false, true], [false, false, false]];
|
||||
*/
|
||||
cartesian_power(b, n) := block(
|
||||
[aux_lst: makelist(setify(b), n)],
|
||||
listify(apply(cartesian_product, aux_lst))
|
||||
)$
|
||||
|
||||
gen_table(expr):= block(
|
||||
[var_lst: listofvars(expr), st_lst, res_lst, m],
|
||||
st_lst: cartesian_power([true, false], length(var_lst)),
|
||||
res_lst: create_list(lsubst(expr, var_lst, val_lst), val_lst, st_lst),
|
||||
m : apply('matrix, cons(var_lst, st_lst)),
|
||||
addcol(m, cons(expr, res_lst))
|
||||
);
|
||||
|
||||
/* examples */
|
||||
gen_table('(not A));
|
||||
gen_table('(A xor B));
|
||||
gen_table('(Jim and (Spock xor Bones) or Scotty));
|
||||
gen_table('(A => (B and A)));
|
||||
gen_table('(V xor (B xor (K xor D ) )));
|
||||
33
Task/Truth-table/Maxima/truth-table-2.maxima
Normal file
33
Task/Truth-table/Maxima/truth-table-2.maxima
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
[ V B K D V xor (B xor (K xor D)) ]
|
||||
[ ]
|
||||
[ true true true true false ]
|
||||
[ ]
|
||||
[ true true true false true ]
|
||||
[ ]
|
||||
[ true true false true true ]
|
||||
[ ]
|
||||
[ true true false false false ]
|
||||
[ ]
|
||||
[ true false true true true ]
|
||||
[ ]
|
||||
[ true false true false false ]
|
||||
[ ]
|
||||
[ true false false true false ]
|
||||
[ ]
|
||||
[ true false false false true ]
|
||||
[ ]
|
||||
[ false true true true true ]
|
||||
[ ]
|
||||
[ false true true false false ]
|
||||
[ ]
|
||||
[ false true false true false ]
|
||||
[ ]
|
||||
[ false true false false true ]
|
||||
[ ]
|
||||
[ false false true true false ]
|
||||
[ ]
|
||||
[ false false true false true ]
|
||||
[ ]
|
||||
[ false false false true true ]
|
||||
[ ]
|
||||
[ false false false false false ]
|
||||
Loading…
Add table
Add a link
Reference in a new issue