Skip to content

Commit

Permalink
fix: #3172 simplify "true and true"
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed Mar 13, 2024
1 parent e3f8de8 commit a41def8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

- Docs: implement an interactive version of the Lorenz example, and show the
chart full screen (#3151). Thanks @dvd101x.
- Fix #3172: simplify `"true and true"`.
- Fix #3163: `toTex` wrongly returning `Infinity` for large BigNumbers.
- Fix #3162: add license information about CSParse (#3164).
- Fix: expose `math.Unit.ALIASES` (see #3175).
Expand Down
3 changes: 3 additions & 0 deletions src/function/algebra/simplifyCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ export const createSimplifyCore = /* #__PURE__ */ factory(name, dependencies, ({
if (isConstantNode(a0)) {
if (a0.value) {
if (isAlwaysBoolean(a1)) return a1
if (isConstantNode(a1)) {
return a1.value ? nodeT : nodeF
}
} else {
return nodeF
}
Expand Down
9 changes: 9 additions & 0 deletions test/unit-tests/function/algebra/simplifyCore.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,21 @@ describe('simplifyCore', function () {
testSimplifyCore('not (not (p and q))', 'p and q')
testSimplifyCore('1 and not done', 'not done')
testSimplifyCore('false and you(know, it)', 'false')
testSimplifyCore('you(know, it) and false', 'false')
testSimplifyCore('(p or q) and "you"', 'p or q')
testSimplifyCore('something and ""', 'false')
testSimplifyCore('false or not(way)', 'not way')
testSimplifyCore('6 or dozen/2', 'true')
testSimplifyCore('(a and b) or 0', 'a and b')
testSimplifyCore('consequences or true', 'true')
testSimplifyCore('true or true', 'true')
testSimplifyCore('1 or 2', 'true')
testSimplifyCore('0 or 2', 'true')
testSimplifyCore('2 or 0', 'true')
testSimplifyCore('true and true', 'true')
testSimplifyCore('2 and 2', 'true')
testSimplifyCore('0 and 2', 'false')
testSimplifyCore('2 and 0', 'false')
testSimplifyCore('(1*x + y*0)*1+0', 'x')
testSimplifyCore('sin(x+0)*1', 'sin(x)')
testSimplifyCore('((x+0)*1)', 'x')
Expand Down

0 comments on commit a41def8

Please sign in to comment.