Skip to content

Conversation

@jechol
Copy link

@jechol jechol commented Oct 20, 2025

Update De Morgan's Law to use basic operators (not, and, or) instead of nand/nor:

  • NOT (A AND B) = (NOT A) OR (NOT B)
  • NOT (A OR B) = (NOT A) AND (NOT B)

This matches the moduledoc and other rewrite rules which only use basic operators.

Contributor checklist

Leave anything that you believe does not apply unchecked.

  • I accept the AI Policy, or AI was not used in the creation of this PR.
  • Bug fixes include regression tests
  • Chores
  • Documentation changes
  • Features include unit/acceptance tests
  • Refactoring
  • Update dependencies

- NOT (A AND B) = (NOT A) OR (NOT B)
- NOT (A OR B) = (NOT A) AND (NOT B)
@maennchen
Copy link
Collaborator

@jechol Those compile to exactly the same code:

crux/lib/crux/expression.ex

Lines 160 to 191 in 0fb4a4f

{:nand, _, [left, right]} ->
quote do
{:not, {:and, unquote(left), unquote(right)}}
end
{:nor, _, [left, right]} ->
quote do
{:not, {:or, unquote(left), unquote(right)}}
end
{:xor, _, [left, right]} ->
quote do
{:and, {:or, unquote(left), unquote(right)},
{:not, {:and, unquote(left), unquote(right)}}}
end
{:xnor, _, [left, right]} ->
quote do
{:not,
{:and, {:or, unquote(left), unquote(right)},
{:not, {:and, unquote(left), unquote(right)}}}}
end
{:implies, _, [left, right]} ->
quote do
{:not, {:and, unquote(left), {:not, unquote(right)}}}
end
{:implied_by, _, [left, right]} ->
quote do
{:not, {:and, unquote(right), {:not, unquote(left)}}}
end

I thought that the higher level nand / nor might be easier to understand when reading the code. Not sure though if that is correct.

@jechol jechol closed this Oct 31, 2025
@jechol
Copy link
Author

jechol commented Oct 31, 2025

I get that they compile to the same code. I wanted to match the moduledoc though – it uses basic operators, so I figured the implementation should be consistent with that. Fair point though, nand/nor works fine. Let's just close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants