From a41def836077f09b4ba0ccf953e600527ef4720f Mon Sep 17 00:00:00 2001 From: Jos de Jong Date: Wed, 13 Mar 2024 14:25:56 +0100 Subject: [PATCH] fix: #3172 simplify `"true and true"` --- HISTORY.md | 1 + src/function/algebra/simplifyCore.js | 3 +++ test/unit-tests/function/algebra/simplifyCore.test.js | 9 +++++++++ 3 files changed, 13 insertions(+) diff --git a/HISTORY.md b/HISTORY.md index 8f391883e0..7dac6a8d2f 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -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). diff --git a/src/function/algebra/simplifyCore.js b/src/function/algebra/simplifyCore.js index 86ebe850da..f8b09209f2 100644 --- a/src/function/algebra/simplifyCore.js +++ b/src/function/algebra/simplifyCore.js @@ -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 } diff --git a/test/unit-tests/function/algebra/simplifyCore.test.js b/test/unit-tests/function/algebra/simplifyCore.test.js index e4e5f4d371..18f04758cb 100644 --- a/test/unit-tests/function/algebra/simplifyCore.test.js +++ b/test/unit-tests/function/algebra/simplifyCore.test.js @@ -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')