Skip to content

Commit

Permalink
Merge pull request #16 from Azumabashi/feat/export-generateAtomicProp…
Browse files Browse the repository at this point in the history
…WithGivenId

export `generateAtomicPropWithGivenId`
  • Loading branch information
Azumabashi authored Aug 23, 2023
2 parents 097b13f + c0598b5 commit be386ad
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/propositionalLogic.nim
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import
# List of types/procs/iterators to be exported
export
TruthValue, TOP, BOTTOM, `==`, `and`, `or`, `not`,
PropLogicFormula, generateAtomicProp, `&`, `|`, `=>`, `!`, `$`, recByStructure,
PropLogicFormula, generateAtomicProp, generateAtomicPropWithGivenId, `&`, `|`, `=>`, `!`, `$`, recByStructure,
isSat, getModels, isTautology, isContradiction,
Interpretation, interpretations, getModels,
simplification
15 changes: 15 additions & 0 deletions src/propositionalLogic/formulae.nim
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ proc generateAtomicProp*(): PropLogicFormula =
existingAtomicProps += 1

proc generateAtomicPropWithGivenId*(id: int): PropLogicFormula =
## Returns atomic propositions with given id.
## If the atomic propositions which id is given `id` does not exist, this proc raises `AssertionDefect`.
##
## This procedure is defined to generate new `PropLogicFormula` objects correspond to an existing atomic proposition.
## **Use proc `generateAtomicProp` to generate new atomic propositions**.
runnableExamples:
import propositionalLogic

let
P = generateAtomicProp()
Q = generateAtomicPropWithGivenId(P.id)
echo P == Q
## Output:
## true
doAssert 0 <= id and id < existingAtomicProps
result = PropLogicFormula(
formulaType: PropFormulaType.atomicProp,
id: id
Expand Down
6 changes: 5 additions & 1 deletion tests/testEquivalance.nim
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ suite "check formula equivalance":
check (P => Q) == (P => Q)

test "logical equivalence but different formula":
check not ((P => Q) == ((!P) | Q))
check not ((P => Q) == ((!P) | Q))

test "an atomic propositions generated by generateAtomicProp and generateAtomicPropWithGivenId is considered as same":
let R = generateAtomicPropWithGivenId(P.id)
check P == R

0 comments on commit be386ad

Please sign in to comment.