Skip to content

Version 4.0.1 - Rational numbers support#1

Merged
PHRaposo merged 14 commits intomasterfrom
rational
Aug 2, 2025
Merged

Version 4.0.1 - Rational numbers support#1
PHRaposo merged 14 commits intomasterfrom
rational

Conversation

@PHRaposo
Copy link
Owner

@PHRaposo PHRaposo commented Aug 2, 2025

Rational numbers are now supported in Screamer. The
following functions have been added:

A-RANDOM-MEMBER-OF
A-RATIONAL
A-RATIONAL-ABOVE
A-RATIONAL-BELOW
A-RATIONAL-BETWEEN
A-RATIO
A-RATIO-ABOVE
A-RATIO-BELOW
A-RATIO-BETWEEN
RATIONALPV

A-RATIONALV
A-RATIONAL-BETWEENV
A-RATIONAL-ABOVEV
A-RATIONAL-BELOWV

RATIOPV

A-RATIOV
A-RATIO-BETWEENV
A-RATIO-ABOVEV
A-RATIO-BELOWV
FLOATPV
A-FLOATV
A-FLOAT-ABOVEV
A-FLOAT-BELOWV
A-FLOAT-BETWEENV

The following functions have been modified to support rational numbers:
LINEAR-FORCE
DIVIDE-AND-CONQUER-FORCE

The following functions have been added to support Farey sequences (unexported):
RATIOP
FAREY-NEXT-VALUE
FAREY-PREV-VALUE
MAKE-FAREY-GENERATOR-START
CLOSEST-RATIONAL-LOWER
CLOSEST-RATIONAL-UPPER
CLOSEST-RATIO-LOWER
CLOSEST-RATIO-UPPER
RATIONALS-BETWEEN
RATIOS-BETWEEN
VARIABLE POSSIBLY-NONINTEGER-RATIONAL? SLOT
VARIABLE MAX-DENOM SLOT

Additions and fixes from swapneils update (see nikodemus#34)
SEQUENCEP (FROM ALEXANDRIA, SEE https://alexandria.common-lisp.dev/)
MAPPEND (FROM ALEXANDRIA, IBID.)
APPLY-NONDETERMINISTIC FIX
MAPCAR-NONDETERMINISTIC
ASSERT!-NOTV-EQUALV FIX
VARIABLE DEPENDENCIES SLOT

Constraint package functions modified to use the new variable generators (see initial commit ):

  • ALL VARIABLES PREDICATES (VARIABLE-INTEGER?, VARIABLE-NONINTEGER?, etc.)
  • ALL RESTRICTION FUNCTIONS (RESTRICT-INTEGER!, RESTRICT-NONINTEGER!, etc.)
  • ALL VARIABLE LOWER/UPPER BOUNDS AND DOMAINS PRUNING (RESTRICT-BOUNDS!, RESTRICT-ENUMERATED-DOMAIN!, etc.)
  • ALL ARITHMETIC FUNCTIONS AND RULES (+V, +-RULE-UP, +-RULE-DOWN, etc.)
  • NEW RULES FOR MAXIMUM-RATIO-DENOMINATOR
  • KNOWN?- AND ASSERT!- FUNCTIONS (KNOWN?-RATIOPV, ASSERT!-RARTIOPV, etc.)
  • TRANSFORM-KNOWN?, TRANSFORM-ASSERT!- AND TRANSFORM-DECIDE

New tests files and tests.lisp modifications

  • rational-tests.lisp
  • variable-types.lisp
  • tests.lisp (runs same tests as screamer::rational-ordeal and screamer::run-variable-type-tests under Stefil)

Examples (third argument of rational/ratio generators are the maximum ratio denominator):

(all-values (a-rational-between 0 1 4))
(0 1/4 1/3 1/2 2/3 3/4 1)

(all-values (a-ratio-between 0 1 4))
(1/4 1/3 1/2 2/3 3/4)

(let ((x (a-rational-betweenv 0 1 4))) (all-values (solution x (static-ordering #'linear-force))))
(0 1/4 1/3 1/2 2/3 3/4 1)

(let ((x (a-ratio-betweenv 0 1 4))) (all-values (solution x (static-ordering #'linear-force))))
(1/4 1/3 1/2 2/3 3/4)

SEE ADDITIONAL EXAMPLES IN RATIONAL-TESTS.LISP

PHRaposo added 14 commits July 31, 2025 15:48
Attempt to add support for rational numbers and different variable types:  
boolean, number, integer, ratio, rational, float and real.
- rational-ordeal in rational-tests.lisp
- variable-type-tests in variable-types.lisp
Changed rational-ordeal to use cl:defun.
New versions of:

 - assert!-notv-equalv (number optimization) fro swapneils version

 - print-variable
- Minor fix.
- New tests.
- Removed nickname (moved to om-compat only).
- Changes in screamer-version and formatting.
- Version 4.0.1 - rational support
- new information about rational numbers support and version 4.0.1
- fixed typo in README
 - divide-and-conquer-force: set-enumerated-domain! for rationals;
- restrict-bounds! - fixed bug in integers enumerated domains.
- restored screamer-version
@PHRaposo PHRaposo merged commit 8500468 into master Aug 2, 2025
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.

1 participant