Skip to content

fix: pow and daysBetween are not commutative - #232

Merged
mchav merged 1 commit into
DataHaskell:mainfrom
skymanbp:fix/noncommutative-ops
Sep 25, 2026
Merged

mchav merged 1 commit into
DataHaskell:mainfrom
skymanbp:fix/noncommutative-ops

Conversation

@skymanbp

Copy link
Copy Markdown
Contributor

normalize reorders the operands of commutative operations by expression key. pow and daysBetween were flagged commutative, so pow (x + 1) 2 could run as 2 ^ (x + 1), and the sign of daysBetween followed the column names. Both are now flagged not commutative. The daysBetween example in the docs relied on the swap and now passes the deadline first.

Before, with x = [2, 4]:

ghci> D.columnAsList @Int (F.col "sq") (D.derive "sq" (F.pow (F.col @Int "x" + F.lit 1) 2) df)
[8,32]

After:

[9,25]

With start = 2024-03-01 and end = 2024-03-10, daysBetween start end gave 9 and now gives -9. daysBetween end start gives 9 in both.

@mchav

mchav commented Sep 25, 2026

Copy link
Copy Markdown
Member

This is a really sad kind of Boolean blindness. Maybe we should make a small type that encodes this and makes it easier to reason locally about each of these definitions.

@mchav

mchav commented Sep 25, 2026

Copy link
Copy Markdown
Member

Can you file that as a follow up issue?

@mchav
mchav merged commit 96ec374 into DataHaskell:main Sep 25, 2026
15 checks passed
@skymanbp

Copy link
Copy Markdown
Contributor Author

Can you file that as a follow up issue?

sure, no problem.

@skymanbp

Copy link
Copy Markdown
Contributor Author

Filed as #234.

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