## Question:

Good day.

I need to write a program in prologue that would change parts of an expression to equivalent ones according to the de Morgan rule.

The difficulty is that the program receives as an argument a temr consisting of functors, which in turn contain more functors.

Those. an expression like ~ (A v B) & (~ (A & C) v D & B) is fed into the program as

& (~ (v (A, B)), v (~ (& (A, C)), & (D, B))).

However, I can't get the result.

```
transform( ~ (XX & YY), ~XX v ~YY).
transform( ~ (XX v YY), ~XX & ~YY).
exp_transform(Term, Result_Term):-
var(Term), var(Result_Term).
exp_transform(Term, Result_Term):-
arg(_, Term, Value_Basic),
arg(_, Result_Term, Value_of_ResTerm),
exp_transform(Value_Basic, Value_of_ResTerm).
exp_transform(Term, Result_Term):-
transform(Term, Result_Term),
exp_transform(Term, Result_Term).
```

I went through various options. Can you tell me what the problem is? How do I serve and process an expression?

## Answer:

How do I serve and process an expression?

I would probably simplify the syntax by replacing the operators with regular functors

~ -> not,

& -> and,

v -> or.

```
% Упростить булеву функцию
reduce( X, Y ) :-
transform( X, Y ), !.
% Не упрощается, остаётся сама собой
reduce( X, X ).
% Двойное отрицание
transform( not( not( X )), X ).
% De Morgan
transform( not( and( X, Y )), or( not( X ), not( Y ))).
% De Morgan
transform( not( or( X, Y )), and( not( X ), not( Y ))).
% ......
Я использую SWI-Prolog.
```