diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..3bfd1681ac9775df50596503b80a315d1493bd8f --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +mathematics_dataset/mathematics_dataset/*/__pycache__/ +mathematics_dataset/mathematics_dataset/__pycache__/ +mathematics_dataset/mathematics_dataset/.venv/ \ No newline at end of file diff --git a/README.md b/README.md index 32897cd3e640101ba184f8c4ccd896981de3804a..9bc60a20eb26e6a868dcbe9712abfef898f36735 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,20 @@ --- license: mit --- + + +To run generation code within 'mathematics_dataset\mathematics_dataset\': +- Activate python venv ``` .\.venv\Scripts\activate ``` + - Requirements defined in requires.txt +- Run ```python generate_to_file.py --output_dir ds``` to generate dataset to directory \ds + +Had to change enconding when opening files to utf-8 so that some characters are allowed (ã õ é) + +To obtain dataset with the correct amount of rows: +- python ```generate_to_file.py --output_dir ds --per_train_module 1999998 --per_test_module 10000``` + +This dataset creates train set (train-easy,train-medium,train-hard) and the creates extrapolation ("measure generalization along various axes of difficulty to beyond that seen during training") and interpolation ("test questions are distinct +from the train questions") tests. +On HugginFace only interpolate tests are used as test set. + +Some tests will not work, since they rely on english terms. \ No newline at end of file diff --git a/Translation_rules.xlsx b/Translation_rules.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..d1555389ca827e7eb365b1a6efc834eb9e3f1166 Binary files /dev/null and b/Translation_rules.xlsx differ diff --git a/mathematics_dataset/CONTRIBUTING.md b/mathematics_dataset/CONTRIBUTING.md new file mode 100644 index 0000000000000000000000000000000000000000..db177d4ac70f76c2172ce65ca33c830d6cbd3ac5 --- /dev/null +++ b/mathematics_dataset/CONTRIBUTING.md @@ -0,0 +1,28 @@ +# How to Contribute + +We'd love to accept your patches and contributions to this project. There are +just a few small guidelines you need to follow. + +## Contributor License Agreement + +Contributions to this project must be accompanied by a Contributor License +Agreement. You (or your employer) retain the copyright to your contribution; +this simply gives us permission to use and redistribute your contributions as +part of the project. Head over to to see +your current agreements on file or to sign a new one. + +You generally only need to submit a CLA once, so if you've already submitted one +(even if it was for a different project), you probably don't need to do it +again. + +## Code reviews + +All submissions, including submissions by project members, require review. We +use GitHub pull requests for this purpose. Consult +[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more +information on using pull requests. + +## Community Guidelines + +This project follows +[Google's Open Source Community Guidelines](https://opensource.google.com/conduct/). diff --git a/mathematics_dataset/LICENSE b/mathematics_dataset/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..d645695673349e3947e8e5ae42332d0ac3164cd7 --- /dev/null +++ b/mathematics_dataset/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/mathematics_dataset/README.md b/mathematics_dataset/README.md new file mode 100644 index 0000000000000000000000000000000000000000..d12161e88da78b17985457f1ff92da02c52a822e --- /dev/null +++ b/mathematics_dataset/README.md @@ -0,0 +1,177 @@ +# Mathematics Dataset + +This dataset code generates mathematical question and answer pairs, from a range +of question types at roughly school-level difficulty. This is designed to test +the mathematical learning and algebraic reasoning skills of learning models. + +Original paper: [Analysing Mathematical +Reasoning Abilities of Neural Models](https://openreview.net/pdf?id=H1gR5iR5FX) +(Saxton, Grefenstette, Hill, Kohli). + +## Example questions + +``` +Question: Solve -42*r + 27*c = -1167 and 130*r + 4*c = 372 for r. +Answer: 4 + +Question: Calculate -841880142.544 + 411127. +Answer: -841469015.544 + +Question: Let x(g) = 9*g + 1. Let q(c) = 2*c + 1. Let f(i) = 3*i - 39. Let w(j) = q(x(j)). Calculate f(w(a)). +Answer: 54*a - 30 + +Question: Let e(l) = l - 6. Is 2 a factor of both e(9) and 2? +Answer: False + +Question: Let u(n) = -n**3 - n**2. Let e(c) = -2*c**3 + c. Let l(j) = -118*e(j) + 54*u(j). What is the derivative of l(a)? +Answer: 546*a**2 - 108*a - 118 + +Question: Three letters picked without replacement from qqqkkklkqkkk. Give prob of sequence qql. +Answer: 1/110 +``` + +## Pre-generated data + +[Pre-generated files](https://console.cloud.google.com/storage/browser/mathematics-dataset) + +### Version 1.0 + +This is the version released with the original paper. It contains 2 million +(question, answer) pairs per module, with questions limited to 160 characters in +length, and answers to 30 characters in length. Note the training data for each +question type is split into "train-easy", "train-medium", and "train-hard". This +allows training models via a curriculum. The data can also be mixed together +uniformly from these training datasets to obtain the results reported in the +paper. Categories: + +* **algebra** (linear equations, polynomial roots, sequences) +* **arithmetic** (pairwise operations and mixed expressions, surds) +* **calculus** (differentiation) +* **comparison** (closest numbers, pairwise comparisons, sorting) +* **measurement** (conversion, working with time) +* **numbers** (base conversion, remainders, common divisors and multiples, + primality, place value, rounding numbers) +* **polynomials** (addition, simplification, composition, evaluating, expansion) +* **probability** (sampling without replacement) + +## Getting the source + +### PyPI + +The easiest way to get the source is to use pip: + +```shell +$ pip install mathematics_dataset +``` + +### From GitHub + +Alternately you can get the source by cloning the mathematics_dataset +repository: + +```shell +$ git clone https://github.com/deepmind/mathematics_dataset +$ pip install --upgrade mathematics_dataset/ +``` + +## Generating examples + +Generated examples can be printed to stdout via the `generate` script. For +example: + +```shell +python -m mathematics_dataset.generate --filter=linear_1d +``` + +will generate example (question, answer) pairs for solving linear equations in +one variable. + +We've also included `generate_to_file.py` as an example of how to write the +generated examples to text files. You can use this directly, or adapt it for +your generation and training needs. + +## Dataset Metadata +The following table is necessary for this dataset to be indexed by search +engines such as Google Dataset Search. +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
propertyvalue
nameMathematics Dataset
url
sameAshttps://github.com/deepmind/mathematics_dataset
descriptionThis dataset consists of mathematical question and answer pairs, from a range +of question types at roughly school-level difficulty. This is designed to test +the mathematical learning and algebraic reasoning skills of learning models.\n +\n +## Example questions\n +\n +```\n +Question: Solve -42*r + 27*c = -1167 and 130*r + 4*c = 372 for r.\n +Answer: 4\n +\n +Question: Calculate -841880142.544 + 411127.\n +Answer: -841469015.544\n +\n +Question: Let x(g) = 9*g + 1. Let q(c) = 2*c + 1. Let f(i) = 3*i - 39. Let w(j) = q(x(j)). Calculate f(w(a)).\n +Answer: 54*a - 30\n +```\n +\n +It contains 2 million +(question, answer) pairs per module, with questions limited to 160 characters in +length, and answers to 30 characters in length. Note the training data for each +question type is split into "train-easy", "train-medium", and "train-hard". This +allows training models via a curriculum. The data can also be mixed together +uniformly from these training datasets to obtain the results reported in the +paper. Categories:\n +\n +* **algebra** (linear equations, polynomial roots, sequences)\n +* **arithmetic** (pairwise operations and mixed expressions, surds)\n +* **calculus** (differentiation)\n +* **comparison** (closest numbers, pairwise comparisons, sorting)\n +* **measurement** (conversion, working with time)\n +* **numbers** (base conversion, remainders, common divisors and multiples,\n + primality, place value, rounding numbers)\n +* **polynomials** (addition, simplification, composition, evaluating, expansion)\n +* **probability** (sampling without replacement)
provider +
+ + + + + + + + + + + + + +
propertyvalue
nameDeepMind
sameAshttps://en.wikipedia.org/wiki/DeepMind
+
+
citationhttps://identifiers.org/arxiv:1904.01557
+
diff --git a/mathematics_dataset/mathematics_dataset/__init__.py b/mathematics_dataset/mathematics_dataset/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..d780829a1f5101333577a1ca9adcb960529213f1 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/mathematics_dataset/mathematics_dataset/ds/extrapolate/algebra__polynomial_roots_big.txt b/mathematics_dataset/mathematics_dataset/ds/extrapolate/algebra__polynomial_roots_big.txt new file mode 100644 index 0000000000000000000000000000000000000000..350d9690f4c25f759b9007db7e0604f9e36153c2 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/extrapolate/algebra__polynomial_roots_big.txt @@ -0,0 +1,20 @@ +Seja 3*i**2/2 - 474313521*i/2 + 2134410723 = 0. Qual é i? +9, 158104498 +Factoriza 3*g**2 - 169065244338*g + 2381921403588970088187. +3*(g - 28177540723)**2 +Factoriza 3*x**3 + 33899714526*x**2 + 95765887044791569188*x - 191531774225181996504. +3*(x - 2)*(x + 5649952422)**2 +Seja 3*v**4/4 + 9028809*v**3/2 + 1914074427*v**2/4 + 943494003*v + 469489800 = 0. Qual é v? +-6019100, -104, -1 +Encontra i tal que -2*i**3/13 - 281030*i**2/13 - 434648094*i/13 - 1301415066/13 = 0. +-138951, -1561, -3 +Resolve z**3/2 + 664681*z**2 + 221744124000*z + 560260252092672 = 0. +-663408, -2546 +Supõe -t**3/5 - 1058377*t**2/5 + 234356101*t - 8150602719/5 = 0. Qual é t? +-1059483, 7, 1099 +Supõe -2*i**2/9 + 100399784548*i/9 - 1260014592160602445538/9 = 0. Qual é i? +25099946137 +Seja -o**4/3 - 296*o**3 + 149338560*o**2 - 1173502213632*o = 0. Calcula o. +-24744, 0, 11928 +Supõe 3*a**2/4 - 19005912951*a/2 = 0. Calcula a? +0, 12670608634 diff --git a/mathematics_dataset/mathematics_dataset/ds/extrapolate/arithmetic__add_or_sub_big.txt b/mathematics_dataset/mathematics_dataset/ds/extrapolate/arithmetic__add_or_sub_big.txt new file mode 100644 index 0000000000000000000000000000000000000000..5a2cb8c5cf22509b9ed2c8525dcb5cef0cd832aa --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/extrapolate/arithmetic__add_or_sub_big.txt @@ -0,0 +1,20 @@ +Quanto é -41.924 retirado de -33604115882? +-33604115840.076 +-22757918145374.91 + 0.5 +-22757918145374.41 +Determina 1.19 + -278715.37375089. +-278714.18375089 +Quanto é -2.497416 retirado de -69846.3671? +-69843.869684 +Quanto é 233.1458582 + -92.150525? +140.9953332 +Quanto é 2 mais 1383039726125.669? +1383039726127.669 +Quanto é -434368 mais -80.387315806? +-434448.387315806 +Calcula 153631.982 - 2784044885. +-2783891253.018 +Quanto é 92326064.2 - 1586? +92324478.2 +Qual é a distância entre 4 e -263788773099.330361? +263788773103.330361 diff --git a/mathematics_dataset/mathematics_dataset/ds/extrapolate/arithmetic__add_sub_multiple_longer.txt b/mathematics_dataset/mathematics_dataset/ds/extrapolate/arithmetic__add_sub_multiple_longer.txt new file mode 100644 index 0000000000000000000000000000000000000000..a93ca039f93886a8fe2c70b975f329c254f08232 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/extrapolate/arithmetic__add_sub_multiple_longer.txt @@ -0,0 +1,20 @@ +Avalia (-17 - -34 - (-10 + (-3 - -10) - -9)) + 253 - ((17 - 9) + -5). +261 +5 + 11 - (-67 - -98) - -10 - (0 + (2 - 0) + -3 - (36 + -93)) +-61 +Calcula (-1 + -186 - -2) + (-11756 - -11792) + -24 + 2 + -2 - (6 + (-2 - 1)). +-176 +Quanto é (2 + -18 + 13 - 4) + 16 + 352 + (0 - (0 - -3)) + -4 + -10? +344 +Avalia ((-54 - -140) + -133 - 48) + -11 + 2 + (2 + (-2 - -1) - 1). +-104 +Calcula (8 - -1) + -27 + (25 - (-3 - (-16 - -3))) + 15 + 236 + 6 + 0. +254 +Quanto é 9 - (3 - (-15 + (-260 - (-81 - -12)) + 1 + (-4 - -2 - 10)))? +-211 +-8 + (284 - (-20 + (17 - 7))) - (-4 + (-5 - -5)) - (0 + 9) +281 +Calcula 0 - (-301 + 3) - (1 + (-30 - (8 + -34)) + (3 - -15) + -6 + -1). +290 +Quanto é -3 - -4 - -269 - ((-16 - -5) + (22 - (8 - -3 - 8 - -14)))? +276 diff --git a/mathematics_dataset/mathematics_dataset/ds/extrapolate/arithmetic__div_big.txt b/mathematics_dataset/mathematics_dataset/ds/extrapolate/arithmetic__div_big.txt new file mode 100644 index 0000000000000000000000000000000000000000..7095387ba5f607409a4739d080013254dc1159b9 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/extrapolate/arithmetic__div_big.txt @@ -0,0 +1,20 @@ +Divide 34754707062 por -3. +-11584902354 +Divide -1340813140 por -6. +670406570/3 +4734892572 dividido por -4 +-1183723143 +-12017267 dividido por 41 +-12017267/41 +Calcula 29187636984 dividido por -3. +-9729212328 +1987921 dividido por 87284 +1987921/87284 +Quanto é -31551042840 dividido por -788776071? +40 +Divide -29643821060 por 595. +-49821548 +Calcula 21 dividido por 1598856574. +3/228408082 +Calcula 1133 dividido por 81117873. +1133/81117873 diff --git a/mathematics_dataset/mathematics_dataset/ds/extrapolate/arithmetic__mixed_longer.txt b/mathematics_dataset/mathematics_dataset/ds/extrapolate/arithmetic__mixed_longer.txt new file mode 100644 index 0000000000000000000000000000000000000000..8a3a472ad7a005deb9a48e2c74858838c1443f7d --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/extrapolate/arithmetic__mixed_longer.txt @@ -0,0 +1,20 @@ +Avalia (3 + 7 + (-6)/1 - (3 + 4 + -4))*((-2)/(-5))/(105/84525). +322 +Avalia ((-16)/4)/((-32)/56) + -165 - ((-11 - -4)/(-1) - 56/8). +-158 +Qual é o valor de (105/(-315))/((-23)/32904)*(((-600)/9)/(-10) - 6) + 4/46? +318 +11/(-2) - (-90)/(-24420)*-1507 - (1 + (-23306)/74) - 40/10 +310 +Quanto é ((-4 - (-63)/15)/(828/(-855) - -1) - 5) + (1449472/(-6258) - (-4)/14)? +-230 +Qual é o valor de 3 + (414/27 + 8)*(1 + (-8)/(-16)) + (1 - 3 - (2 - 2))? +36 +Avalia 72*1*((-14)/(-8) + -4) + (-28 - (-5 - -1))*((-108)/(-864))/((-2)/(-4)). +-168 +(12/(-56)*7*(-8)/(-6))/((176/81400)/((-2)/(-10))*(-65)/(-117)) +-333 +Avalia (-86 - ((2/(-9) - 2) + 6/27)) + (38 - -17 - 39) + -12. +-80 +Qual é o valor de ((42/(-10))/((-4)/(-10) + (9 - 9)))/(((-87)/330 - 24/(-60))/((-2532)/4642))? +42 diff --git a/mathematics_dataset/mathematics_dataset/ds/extrapolate/arithmetic__mul_big.txt b/mathematics_dataset/mathematics_dataset/ds/extrapolate/arithmetic__mul_big.txt new file mode 100644 index 0000000000000000000000000000000000000000..600e363e820ead7dc0cdf808639b5e7c2c239e1a --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/extrapolate/arithmetic__mul_big.txt @@ -0,0 +1,20 @@ +Qual é o produto de -0.06188 e -340289? +21057.08332 +Multiplica -0.426 e -102234198. +43551768.348 +Quanto é -3.0124 vezes 1258.96? +-3792.491104 +Calcula -8 * 25.0413541. +-200.3308328 +8.245289 * -51.1 +-421.3342679 +-5286 * 2152074 +-11375863164 +Multiplica -16084916214 e 0.5. +-8042458107 +Determina -418254101 * -3. +1254762303 +Determina -298556610 * -4.3. +1283793423 +-0.313*40144699 +-12565290.787 diff --git a/mathematics_dataset/mathematics_dataset/ds/extrapolate/arithmetic__mul_div_multiple_longer.txt b/mathematics_dataset/mathematics_dataset/ds/extrapolate/arithmetic__mul_div_multiple_longer.txt new file mode 100644 index 0000000000000000000000000000000000000000..30a030dd20ee4833cabb8cd8dcbab9389fedf86d --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/extrapolate/arithmetic__mul_div_multiple_longer.txt @@ -0,0 +1,20 @@ +117561/(-1052)*((-3)/(-12))/((30/(-4))/(-15))*(-16)/6*1 +149 +((130/(-39))/(4/(-54)))/(((834/1946*(-28)/(-18))/((-4)/3))/((-10)/(-4))) +-225 +(65/(-26)*(7/(140/512)*20)/((-250)/(-10)))/(4/(-180)*18) +128 +Avalia 325/(((-9)/(117/(-13)))/((-1)/(-1)))*2/(-5)*-2*7/49*7. +260 +Qual é o valor de (2/(-4)*-3*(-1260)/(-2835))/((4/159)/(2*11*(-4)/(-44)))? +53 +Qual é o valor de ((((-6)/10)/((135/(-1390))/(-9)))/(9/15))/((-62944)/(-20232)*(-6)/(-28))? +-139 +Qual é o valor de (((1/75)/(32/192))/(((-68)/1560)/(-17)))/((-369)/(-2460))*1? +208 +Calcula 3/(-4)*-2*(-2)/5*1*10/(-5)*1*28*(-125)/(-600). +7 +Qual é o valor de (9*10/(-30))/(1/(-90)*6*(-4)/4*4/(-4)*(-19)/38)? +-90 +Quanto é ((((-5)/(30/(-8)))/(-3*(-20)/90))/(97/5723))/((-42)/(-21))? +59 diff --git a/mathematics_dataset/mathematics_dataset/ds/extrapolate/comparison__closest_more.txt b/mathematics_dataset/mathematics_dataset/ds/extrapolate/comparison__closest_more.txt new file mode 100644 index 0000000000000000000000000000000000000000..9af2586af6a559134d338ef3867a76f7eb827b0b --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/extrapolate/comparison__closest_more.txt @@ -0,0 +1,20 @@ +Qual está mais perto de -5? (a) 5 (b) -190 (c) -1/2 (d) -1/3 (e) 3 (f) -1 (g) 15 (h) -3/5 +f +Qual está mais próximo de -1/2? (a) -3 (b) -0.4 (c) -362 (d) -1907 (e) -4 (f) 0.2 (g) 4 +b +Qual valor está mais próximo de 2/3 em -0.8, -1, -91, -14, 1652, -1/8, 2/5, 5? +2/5 +Qual valor está mais perto de 0.1 em -3, -3/2, -1466, 5, -5.2, -2/17, 598? +-2/17 +Qual está mais perto de 1? (a) -26/7 (b) 98 (c) -0.1 (d) -5 (e) -4/77 (f) -80.1 (g) -3 +e +Qual valor está mais perto de -0.1 em -0.1, 0.1473, 3/7, -0.5, -39/2, 4, 3? +-0.1 +Qual valor está mais próximo de 1/3 em -4, -0.5, 4/7, 0.41, -0.1765, 0.05, 5? +0.41 +Qual está mais próximo de -1? (a) 2 (b) 4 (c) -1.14 (d) -22/9 (e) -0.4 (f) -24 (g) -1.23 +c +Qual valor está mais perto de -4 em -17/5, -25, 3/37, 3/4, 4, -13, -5? +-17/5 +Qual está mais próximo de 1/5? (a) -33 (b) 6/7 (c) -0.4 (d) -1.2 (e) -0.24 (f) -32 (g) 1/6 (h) 0.5 +g diff --git a/mathematics_dataset/mathematics_dataset/ds/extrapolate/comparison__kth_biggest_more.txt b/mathematics_dataset/mathematics_dataset/ds/extrapolate/comparison__kth_biggest_more.txt new file mode 100644 index 0000000000000000000000000000000000000000..4e849734c2ce54f4805bbee45003f8fff6efa87c --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/extrapolate/comparison__kth_biggest_more.txt @@ -0,0 +1,20 @@ +Qual valor é terceiro maior? (a) 3/7 (b) 15/142361 (c) 0.2 (d) 0 (e) -0.3 (f) 0.3 (g) 2 (h) -0.5 (i) -14 +f +Qual valor é nono menor? (a) 6.2 (b) -5 (c) 7 (d) 0.1 (e) -1/9 (f) -1 (g) -66 (h) 0.07 (i) -2 +c +Qual valor é nono maior? (a) -4 (b) -5 (c) -3 (d) 4/55 (e) 1/5 (f) -29 (g) -1 (h) -0.4 (i) 2/393 +f +Qual valor é décimo maior? (a) -0.1 (b) -0.2 (c) 0.3 (d) -5 (e) -3/4 (f) 0.09 (g) -55/3 (h) -0.082 (i) 1/2 (j) 3 +g +Qual é o sexto maior valor em -5, 35, -21, -0.07, 63, 0.5, 1/7, 53, 2/9? +1/7 +Qual é o sétimo menor valor em -3.1, -1/7, 4/3, -0.1, 2/3, -5, -9, -2, 2/15, 4/7? +2/15 +Qual é o sétimo maior valor em -10, 0.4, 1/3, 261, -59.86, -0.1, -2/3, 2/15, 12? +-2/3 +Qual valor é sexto menor? (a) -2203 (b) 71 (c) 1/2 (d) -4 (e) -3/7 (f) 3 (g) 11 (h) 0.2 (i) -2 +c +Qual é o terceiro maior valor em -5, 5, 2, -9, 51, 3/4, -3/4, -2/7, -3.2? +2 +Qual é o segundo menor valor em 18, 0.5, 8, 33, 0.3, 9, 1, -4, 2, 26? +0.3 diff --git a/mathematics_dataset/mathematics_dataset/ds/extrapolate/comparison__sort_more.txt b/mathematics_dataset/mathematics_dataset/ds/extrapolate/comparison__sort_more.txt new file mode 100644 index 0000000000000000000000000000000000000000..a9f70ab0ca9f7365613c630d543c412303ed24a7 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/extrapolate/comparison__sort_more.txt @@ -0,0 +1,20 @@ +Ordena 2, 11, 29, 8, 3, 450, -4, 0, 4 por ordem decrescente. +450, 29, 11, 8, 4, 3, 2, 0, -4 +Coloca 27, 7, 5, 13, 1, 3, -1, 57, 2 em ordem decrescente. +57, 27, 13, 7, 5, 3, 2, 1, -1 +Ordena 8, 2, 5, -8, 26, -4, 0, 4, 1 por ordem ascendente. +-8, -4, 0, 1, 2, 4, 5, 8, 26 +Ordena 46, 0, 4, 3, 23, 6, -1, -7, -3 por ordem decrescente. +46, 23, 6, 4, 3, 0, -1, -3, -7 +Ordena 3, -1, 57, -3, 16, 9, 11, 4, 7 por ordem ascendente. +-3, -1, 3, 4, 7, 9, 11, 16, 57 +Ordena 2, -56, 24, 1, 13, 4, 0, 3, -3. +-56, -3, 0, 1, 2, 3, 4, 13, 24 +Ordena -432, 5, -1, 3, 8, 17, 0, 9, 2 por ordem descendente. +17, 9, 8, 5, 3, 2, 0, -1, -432 +Coloca 3, -1, 9, 1, 5, -2, -6, 4, -12 em ordem crescente. +-12, -6, -2, -1, 1, 3, 4, 5, 9 +Ordena -4, 7, -1, 1, 2, 4, 857, 6, 12 por ordem decrescente. +857, 12, 7, 6, 4, 2, 1, -1, -4 +Coloca 2, -4, 5, -18, 3, -57, 4, 8, 7 em ordem decrescente. +8, 7, 5, 4, 3, 2, -4, -18, -57 diff --git a/mathematics_dataset/mathematics_dataset/ds/extrapolate/measurement__conversion.txt b/mathematics_dataset/mathematics_dataset/ds/extrapolate/measurement__conversion.txt new file mode 100644 index 0000000000000000000000000000000000000000..5afca82f74e3c476963c4932a423eea46078e233 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/extrapolate/measurement__conversion.txt @@ -0,0 +1,20 @@ +Quantos(as) minutos estão em 209891875.2 nanosegundos? +0.00349819792 +Quanto é 24278998.5nm em quilómetros? +0.0000242789985 +Quanto é 0.744057522 meses em milénios? +0.0000620047935 +Quantos(as) litros estão em 26506726.8 mililitros? +26506.7268 +Converte 44.9700523 millímetros para metros. +0.0449700523 +Converte 0.425743507 centímetros para micrómetros. +4257.43507 +Converte 3.24533491 anos para milénios. +0.00324533491 +Quanto é 2763.8671 quilogramas em nanogramas? +2763867100000000 +Quantos(as) centímetros estão em 37.5474328 quilómetros? +3754743.28 +Quantos(as) milénios estão em 219414.232 anos? +219.414232 diff --git a/mathematics_dataset/mathematics_dataset/ds/extrapolate/numbers__place_value_big.txt b/mathematics_dataset/mathematics_dataset/ds/extrapolate/numbers__place_value_big.txt new file mode 100644 index 0000000000000000000000000000000000000000..25ac9387a9b34d2359b5c335d345e87ed11346c5 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/extrapolate/numbers__place_value_big.txt @@ -0,0 +1,20 @@ +Qual é o dígito das dezena milhões de 585104582785? +0 +Qual é o dígito das unidades de 890994362752? +2 +Qual é o dígito das centenas de 389726456276? +2 +Qual é o dígito das centena milhões de 669628353376? +6 +Qual é o dígito das centenas de 847868848670? +6 +Qual é o dígito das dezenas de 906525410143? +4 +Qual é o dígito das dezena mil milhões de 116778722434? +1 +Qual é o dígito das dezena milhões de 816535057076? +3 +Qual é o dígito das dezena milhões de 294769585676? +6 +Qual é o dígito das dezenas de 429731328864? +6 diff --git a/mathematics_dataset/mathematics_dataset/ds/extrapolate/numbers__round_number_big.txt b/mathematics_dataset/mathematics_dataset/ds/extrapolate/numbers__round_number_big.txt new file mode 100644 index 0000000000000000000000000000000000000000..8611e00e9ed971341717b4e2f1ce8724694a6950 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/extrapolate/numbers__round_number_big.txt @@ -0,0 +1,20 @@ +Quanto é 14091589.69193 arredondado para as 1000 mais próxima? +14092000 +Arredonda 258672564.983 para as 100000 mais próxima. +258700000 +Quanto é 8.30586137387 arredondado para as inteiro mais próximo? +8 +Arredonda -383.62758343 para as casa decimal das doiss. +-383.63 +Arredonda 21306920.88228 para as dez milhar mais próxima. +21310000 +Arredonda -5458120.1311 para as dez milhar mais próxima. +-5460000 +Arredonda 165358640.0843 para as um centena mais próxima. +165358600 +Arredonda 19628.6240013 para as dez mais próxima. +19630 +Arredonda 0.00024028921527 para as casa decimal das 5s. +0.00024 +Arredonda 0.00222836314178 para as casa decimal das quatros. +0.0022 diff --git a/mathematics_dataset/mathematics_dataset/ds/extrapolate/probability__swr_p_level_set_more_samples.txt b/mathematics_dataset/mathematics_dataset/ds/extrapolate/probability__swr_p_level_set_more_samples.txt new file mode 100644 index 0000000000000000000000000000000000000000..2afa810d54056ae4219eb9b30c7b49d3be0dde3e --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/extrapolate/probability__swr_p_level_set_more_samples.txt @@ -0,0 +1,20 @@ +Cinco caractéres são escolhidos sem reposição de ofnfnfofffnffnnfknn. Qual é a probabilidade de(a) escolher 3 n, 1 o e 1 k? +35/5814 +Qual é a probabilidade de(a) escolher 4 x e 1 j quando cinco caractéres são escolhidos sem reposição de {j: 7, x: 4, s: 2}? +7/1287 +Cinco caractéres são escolhidos sem reposição de qcqqcccccccccqc. Dá a probabilidade de(a) escolher 5 c. +2/13 +Qual é a probabilidade de(a) escolher 1 v, 2 c, 1 n e 1 s quando cinco caractéres são escolhidos sem reposição de cvsnsvc? +4/21 +Cinco caractéres são escolhidos sem reposição de {x: 2, l: 5, s: 5}. Dá a probabilidade de(a) escolher 1 s e 4 l. +25/792 +Cinco caractéres são escolhidos sem reposição de denqqjeqqejjq. Dá a probabilidade de(a) escolher 2 e, 1 n e 2 j. +1/143 +Cinco caractéres são escolhidos sem reposição de fzezzz. Dá a probabilidade de(a) escolher 4 z e 1 f. +1/6 +Cinco caractéres são escolhidos sem reposição de {a: 2, d: 2, j: 1, b: 1, u: 1, k: 3}. Qual é a probabilidade de(a) escolher 1 j, 2 d, 1 b e 1 k? +1/84 +Cinco caractéres são escolhidos sem reposição de bfhkfgyyfffff. Dá a probabilidade de(a) escolher 2 k, 1 g, 1 y e 1 f. +0 +Qual é a probabilidade de(a) escolher 3 x e 2 v quando cinco caractéres são escolhidos sem reposição de {v: 4, x: 8}? +14/33 diff --git a/mathematics_dataset/mathematics_dataset/ds/extrapolate/probability__swr_p_sequence_more_samples.txt b/mathematics_dataset/mathematics_dataset/ds/extrapolate/probability__swr_p_sequence_more_samples.txt new file mode 100644 index 0000000000000000000000000000000000000000..9af8041ec2fc1fc26c5da6cd21f873f1362a0ac2 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/extrapolate/probability__swr_p_sequence_more_samples.txt @@ -0,0 +1,20 @@ +Cinco caractéres são escolhidos sem reposição de {y: 1, k: 5, d: 2}. Qual é a probabilidade de(a) sequência kkkdy? +1/56 +Qual é a probabilidade de(a) sequência famft quando cinco caractéres são escolhidos sem reposição de maaftammtaf? +1/1155 +Calcula da probabilidade de(a) sequência wbwrr quando cinco caractéres são escolhidos sem reposição de wwwwwwbwrwwwwr. +1/1092 +Calcula da probabilidade de(a) sequência jxjxy quando cinco caractéres são escolhidos sem reposição de bjjjbyxbbjxj. +1/2376 +Calcula da probabilidade de(a) sequência vqvqv quando cinco caractéres são escolhidos sem reposição de {v: 6, q: 7}. +14/429 +Cinco caractéres são escolhidos sem reposição de kdktddktqttfddtkdrr. Dá a probabilidade de(a) sequência ftrkt. +1/8721 +Calcula da probabilidade de(a) sequência dovoe quando cinco caractéres são escolhidos sem reposição de oiveioooozodeo. +1/2860 +Cinco caractéres são escolhidos sem reposição de {x: 11, y: 2}. Dá a probabilidade de(a) sequência xxxyx. +4/39 +Cinco caractéres são escolhidos sem reposição de {q: 2, n: 8, u: 3, h: 6}. Qual é a probabilidade de(a) sequência nnunu? +7/4845 +Cinco caractéres são escolhidos sem reposição de {q: 6, i: 4, b: 7}. Dá a probabilidade de(a) sequência iiqbi. +3/2210 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/algebra__linear_1d.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/algebra__linear_1d.txt new file mode 100644 index 0000000000000000000000000000000000000000..9bc185ff571f57ba838912fd4d82901be43b0839 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/algebra__linear_1d.txt @@ -0,0 +1,20 @@ +Resolve -31*b = 42*b - 2 + 3360 para b. +-46 +Resolve 0 = 79*w - 174 - 225 - 75 para w. +6 +Resolve 0 = -2363*b + 2158*b - 1845 para b. +-9 +Resolve 27271 - 11807 + 29840 = 1618*o para o. +28 +Resolve -178*x - 14124 = -104*x - 502*x para x. +33 +Resolve 2069 - 965 = -109*r - 145*r - 11088 para r. +-48 +Resolve 1168*j - 14076 + 5317 = -3311 + 14408 para j. +17 +Resolve 201*n + 432*n - 11137 = 148*n + 13113 para n. +50 +Resolve 13405*q - 13462*q = 1710 para q. +-30 +Resolve 0 = -4827*o + 3861*o + 2898 para o. +3 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/algebra__linear_1d_composed.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/algebra__linear_1d_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..3bb8732b77036262738fa6aa4c8a5429b0c89370 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/algebra__linear_1d_composed.txt @@ -0,0 +1,20 @@ +Seja k = 901 - 894. Supõe v - 4 - 4 = 0. Resolve k*b = v + 6 para b. +2 +Assume que z é ((-483)/(-1288))/(6/112). Resolve -163 = z*u - 177 para u. +2 +Supõe -11 = -2*z + 29. Assume que t é 14/4 - (z/8 - 1). Resolve -8 = 2*o + t para o. +-5 +Supõe -2*y - 12 = -i - 13, -4*y + 11 = i. Seja z(m) = m**3 + 3*m**2 - 4*m. Seja o, z(-4). Supõe 3*j - 69 = -o*j. Resolve -4*g = i - j para g. +5 +Assume que a é 2474*(-1)/(-26) - (1236/(-78) - -16). Resolve 3*g + 16*g + a = 0 para g. +-5 +Supõe 13*f + 13*f + 287 = 33*f. Resolve 46 = -29*a - f para a. +-3 +Seja f = 1 - -17. Seja l(h) = -h**3 + 8*h**2 - 9*h - 12. Seja s(t) = t + 1. Seja d(b) = -l(b) - 3*s(b). Seja x, d(7). Resolve -4*i - f = -x para i. +-4 +Supõe -1 = 3*r + 3*s + 8, -3*r + 6 = -2*s. Seja g(f) = 2*f**2 + 7*f + 3. Seja n, g(-5). Assume que y é (r - 2)/((-9)/n). Resolve y*c - 7 - 9 = 0 para c. +4 +Seja t = 11 + -17. Assume que l é t/(-6) + (-4)/(-1). Seja f(u) = 2*u**2 - 2*u - 1. Seja q, f(-1). Resolve -q = 4*r + l para r. +-2 +Seja u = -43 + 33. Seja s = u + 11. Assume que v é ((-3)/(-2) - s)/((-39)/(-702)). Resolve 5*w + 1 = -v para w. +-2 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/algebra__linear_2d.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/algebra__linear_2d.txt new file mode 100644 index 0000000000000000000000000000000000000000..74ad6f6f5c8efc7d0d928043d07d92c6d6fbec87 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/algebra__linear_2d.txt @@ -0,0 +1,20 @@ +Resolve -h - 1 = -9526*b + 9527*b, -b = -10*h - 10 para h. +-1 +Resolve 4*x = -14*z - 590, 88 = -2*z + 2 para x. +3 +Resolve 0 = -6*c - 9*o + 12*o - 3, 32*o + 167 = -4*c + o para c. +-3 +Resolve -5*s = 5*v + 135, -2*s + s - 58*v + 55*v = 27 para s. +-27 +Resolve -1539*c + 1543*c - 60 = -4*w, -108*c = -4*w - 388 para w. +11 +Resolve -3*v = 3*p + 631 - 619, 23 = -5*p - 4*v - 0*v para p. +-7 +Resolve 0 = 50*u + 2*v - 698 - 44, 3*u = 5*v + 65 para u. +15 +Resolve 3*j = -4*s + 11, 0 = j + 1957 - 1962 para s. +-1 +Resolve -4*d - 3798*t + 52 = -3776*t, -3*d - 4*t + 14 = 0 para d. +2 +Resolve -4*l + 7*c = -392 + 416, -3*c - 19 = -31*l para l. +1 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/algebra__linear_2d_composed.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/algebra__linear_2d_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..bc0c668f98869f30257df51fb6eff1fc6e83fa92 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/algebra__linear_2d_composed.txt @@ -0,0 +1,20 @@ +Supõe -a - 5*j + 99 = 0, 2*a + 5*j - 56 = 167. Seja d = -115 + a. Resolve -2*v - d = -5*v, 3*i - v = 0 para i. +1 +Supõe -10 = -j + 6. Supõe -3*o + 8*o + j = h, 5*o = -3*h + 8. Seja s = -4 + h. Resolve -d + 4*f + 16 = 0, -s*f - 6 = -0 para d. +4 +Assume que w é 3/15 - 0 - (-2247)/15. Assume que a é 127/6 + (-25)/w. Resolve -3*z + a = 2*d, 0*d - 5*z = 3*d - 34 para d. +3 +Seja r = -2599 - -2604. Resolve -10 = 5*t, 18 = -r*z + 8*t - 12*t para z. +-2 +Supõe 64*b + 60 - 368 = -13*b. Resolve -b*r - 4*u = 20, -5*r - 2*u + 9 = 31 para r. +-4 +Seja w(a) = -a**3 + 5*a**2 + 27*a - 17. Seja b, w(8). Resolve -g - b = 12*y - 9*y, y - 11 = 3*g para y. +-1 +Seja w(h) = -49*h**3 + 2*h**2 - h - 1. Seja t, w(1). Assume que j é 4/14 - (-760)/(-14). Seja q = t - j. Resolve -4*m + z + q = -8, 16 = 5*m - z para m. +3 +Supõe -15*l + 6*l - 3 = -3. Resolve 16 = u + 3*p, l = -4*u + 3*p + 4 para u. +4 +Seja i(f) = 63 - f. Seja m, i(16). Seja z = m - 34. Resolve 5*u + 0*r = -3*r - 5, -u - z = 3*r para u. +2 +Seja n(g) = 1390 - 33*g. Seja l, n(42). Resolve 12*f + l*d + 3 = 11*f, -3*f = 3*d para f. +1 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/algebra__polynomial_roots.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/algebra__polynomial_roots.txt new file mode 100644 index 0000000000000000000000000000000000000000..c4733009cbef057675e30f3ab1a12adde3372455 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/algebra__polynomial_roots.txt @@ -0,0 +1,20 @@ +Resolve 243*f**5/7 + 314823*f**4 + 4988715660*f**3/7 - 35139394944*f**2/7 + 30889839264*f/7 - 741363984/7 = 0 em relação a f. +-4538, 2/81, 1, 6 +Factoriza -n**3 - 15936*n**2 - 984125*n + 1000062. +-(n - 1)*(n + 63)*(n + 15874) +Factoriza -5*g**2 + 13885*g - 8809380. +-5*(g - 1796)*(g - 981) +Resolve -2*t**4/9 - 1970*t**3/9 + 9982*t**2/9 + 9010*t - 9900 = 0 em relação a t. +-990, -5, 1, 9 +Seja 2436*g**2 - 187564*g - 616 = 0. Calcula g. +-2/609, 77 +Factoriza 5*a**2 + 52935*a - 2819600. +5*(a - 53)*(a + 10640) +Encontra d tal que -4*d**2/7 + 6104*d - 340032 = 0. +56, 10626 +Seja 11*o**3 - 5661*o**2 + 28030*o = 0. Calcula o. +0, 5, 5606/11 +Supõe -4*k**3/7 - 37752*k**2/7 - 37740*k/7 + 75496/7 = 0. Qual é k? +-9437, -2, 1 +Supõe 4*y**3 - 507180*y**2 + 16075704000*y + 80391200000 = 0. Calcula y? +-5, 63400 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/algebra__polynomial_roots_composed.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/algebra__polynomial_roots_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..fd701d2a178991a5da7c43d3d5e5bb37aa35c353 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/algebra__polynomial_roots_composed.txt @@ -0,0 +1,20 @@ +Seja l(q) = 30*q + 336. Seja a, l(-11). Seja u(v) a segunda derivada de 0*v**3 + 0 + 1/3*v**a + 0*v**2 + 5*v - 7/10*v**5 + 1/3*v**4. Factoriza u(c). +2*c**2*(c - 1)*(5*c - 2) +Supõe -43*i = -65*i. Seja s(q) a terceira derivada de -1/140*q**5 + 0*q - 25/14*q**3 + 18*q**2 + i + 5/28*q**4. Resolve s(d) = 0. +5 +Seja y(z) a terceira derivada de -2*z**7/105 + 181*z**6/60 + 139*z**5/15 - 46*z**4/3 - 70*z**2 - 2*z. Seja y(t) = 0. Calcula t. +-2, 0, 1/2, 92 +Seja x(f) a segunda derivada de -f**4/12 + 13*f**3/36 + 5*f**2/4 + 1050*f. Factoriza x(a). +-(a - 3)*(6*a + 5)/6 +Seja y(q) = -153*q**3 - 255*q**2 - 222*q - 25. Seja w(p) = 31*p**3 + 51*p**2 + 45*p + 5. Seja f(r) = 19*w(r) + 4*y(r). Qual é o valor de c em f(c) = 0? +-1, -5/23 +Assume que a é ((-20)/(-3))/((-25)/(-30)). Assume que c é ((2/a)/1)/((-1110)/(-4736)). Determina y, dado que c*y + 0 - 4/15*y**3 - 2/15*y**4 + 8/15*y**2 = 0. +-2, 0, 2 +Seja v(s) a terceira derivada de s**6/60 + 13*s**5/18 + 149*s**4/36 - 19*s**3/3 - 1637*s**2. Factoriza v(z). +2*(z + 3)*(z + 19)*(3*z - 1)/3 +Seja o(m) a primeira derivada de 1/2*m**2 + 0*m**3 + 15*m - 1/12*m**4 + 8. Seja h(f) a primeira derivada de o(f). Encontra x, dado que h(x) = 0. +-1, 1 +Seja s(a) a segunda derivada de a**5/30 + 25*a**4/9 + 97*a**3/9 + 16*a**2 + 2*a - 344. Factoriza s(r). +2*(r + 1)**2*(r + 48)/3 +Assume que b é (-8 + 2)*(-1)/(-3) + 40/18. Supõe 8 = -w + 5*w. Factoriza b*r**w - 8/9 + 0*r. +2*(r - 2)*(r + 2)/9 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/algebra__sequence_next_term.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/algebra__sequence_next_term.txt new file mode 100644 index 0000000000000000000000000000000000000000..3fae20bd7a7da61636b8caf89244479c422fa668 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/algebra__sequence_next_term.txt @@ -0,0 +1,20 @@ +Qual é o termo seguinte em -1506717, -1506716, -1506713, -1506708, -1506701? +-1506692 +Qual é o termo seguinte em 361606, 723207, 1084808, 1446409, 1808010? +2169611 +Qual é o termo seguinte em 330, 2680, 9066, 21504, 42010, 72600? +115290 +Qual é o termo seguinte em 25159, 50326, 75463, 100564, 125623, 150634, 175591? +200488 +O que vem a seguir: 3061, 1652, 243? +-1166 +Qual é o termo seguinte em 251, 542, 903, 1334? +1835 +Qual é o termo seguinte em -60084, -60079, -60074, -60069, -60064? +-60059 +Qual é o termo seguinte em -4282026, -8564064, -12846110, -17128170, -21410250, -25692356, -29974494? +-34256670 +O que se segue em 4900, 9789, 14636, 19441? +24204 +O que se segue em -514769, -1029532, -1544293, -2059052, -2573809, -3088564, -3603317? +-4118068 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/algebra__sequence_nth_term.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/algebra__sequence_nth_term.txt new file mode 100644 index 0000000000000000000000000000000000000000..f3240b05e976165aa30cee5bd207e077fe2a65ce --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/algebra__sequence_nth_term.txt @@ -0,0 +1,20 @@ +Qual é termo nº h na sequência -1330810, -2661626, -3992442? +6 - 1330816*h +Qual é termo nº n na sequência -341601, -341586, -341563, -341532, -341493? +4*n**2 + 3*n - 341608 +Qual é termo nº y na sequência 1022123, 4088490, 9199103, 16353962, 25553067, 36796418? +1022123*y**2 - 2*y + 2 +Qual é termo nº a na sequência -1570, -3187, -4786, -6361, -7906? +a**3 + 3*a**2 - 1633*a + 59 +Qual é termo nº y na sequência 20043, 80589, 181491, 322743, 504339, 726273, 988539? +-y**3 + 20184*y**2 + y - 141 +Qual é termo nº q na sequência -3820, -6819, -9832, -12865, -15924, -19015? +-q**3 - q**2 - 2989*q - 829 +Qual é termo nº l na sequência 253463, 506920, 760373, 1013822, 1267267, 1520708? +-2*l**2 + 253463*l + 2 +Qual é termo nº d na sequência -9077440, -18154880, -27232320, -36309760? +-9077440*d +Qual é termo nº x na sequência 20953, 83859, 188699, 335467, 524157, 754763? +-x**3 + 20973*x**2 - 6*x - 13 +Qual é termo nº z na sequência -742187, -742231, -742305, -742409, -742543? +-15*z**2 + z - 742173 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/arithmetic__add_or_sub.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/arithmetic__add_or_sub.txt new file mode 100644 index 0000000000000000000000000000000000000000..06b5d6336043d963b8ce582b733e03e5637aa069 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/arithmetic__add_or_sub.txt @@ -0,0 +1,20 @@ +Determina 19283.956636 + -0.05. +19283.906636 +Determina 63.7789 - -20052. +20115.7789 +Determina -0.04 + -37488652513. +-37488652513.04 +Calcula 71143946 - 12.31. +71143933.69 +Quanto é 49430807153 menos 0.2? +49430807152.8 +Quanto é -53.497735 - -11.6? +-41.897735 +Determina 0.126321789662 + -0.4. +-0.273678210338 +O total de -0.1 mais -1237.9494883. +-1238.0494883 +Determina -0.4 - 15293176390. +-15293176390.4 +Quanto é -718.82 menos -843323? +842604.18 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/arithmetic__add_or_sub_in_base.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/arithmetic__add_or_sub_in_base.txt new file mode 100644 index 0000000000000000000000000000000000000000..2f96b9d721f969e1cb71283bd6074d456e4927ca --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/arithmetic__add_or_sub_in_base.txt @@ -0,0 +1,20 @@ +Em base 8, quanto é 463 + -46277? +-45614 +Em base 15, quanto é 19da490 + 5? +19da495 +Em base 9, quanto é 83241 + -56? +83174 +Em base 8, quanto é 11576 + 454? +12252 +Em base 13, quanto é 59 + 5587c? +55908 +Em base 5, quanto é 1 - 2211334240? +-2211334234 +Em base 12, quanto é -4 - -168b5a6? +168b5a2 +Em base 9, quanto é 55683680 + -2? +55683677 +Em base 14, quanto é -c + -194955? +-194963 +Em base 3, quanto é 2121 - 11010011? +-11000120 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/arithmetic__add_sub_multiple.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/arithmetic__add_sub_multiple.txt new file mode 100644 index 0000000000000000000000000000000000000000..afb6fa6520228a025ca4b3e1ebd0378cdb92481f --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/arithmetic__add_sub_multiple.txt @@ -0,0 +1,20 @@ +Quanto é -21 - (-7 + 1 + (40 - 104))? +49 +5 + 0 - (16 - 28 - -27 - (-11 + 22)) +1 +Calcula -17 + (0 - (19 - 72)). +36 +-15 + (-8 - -15) + 6 + -23 + 1 + 1 +-23 +Quanto é 11 + (12 - 1 - -1 - (5 - 1))? +19 +Avalia 40 + (-2 + 1 - 5) + (0 - -6) + 5. +45 +Calcula (1 - 29 - (-130 - -137)) + -4. +-39 +Quanto é 3 - (1 + 34 + (-35 - -21))? +-18 +(0 - -9) + (-4 - (-40 - (-15 - 2))) +28 +Avalia (-119 - (44 + -72)) + 42. +-49 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/arithmetic__div.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/arithmetic__div.txt new file mode 100644 index 0000000000000000000000000000000000000000..1c1436be477a5d97b95fbbf22b400b23f2e834c6 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/arithmetic__div.txt @@ -0,0 +1,20 @@ +Calcula 298 dividido por -12183. +-298/12183 +Quanto é 9739216 dividido por 4869608? +2 +8600496 dividido por -2866832 +-3 +Divide 0 por -2900681. +0 +875120 dividido por -16 +-54695 +-7010715 dividido por 4845 +-1447 +Quanto é 15299204 dividido por 24716? +619 +Divide 0 por -3245315. +0 +35861 dividido por -444 +-35861/444 +Calcula 115125165 dividido por 5. +23025033 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/arithmetic__mixed.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/arithmetic__mixed.txt new file mode 100644 index 0000000000000000000000000000000000000000..856b8a0108b4f2b936d8124257c2178907bdc442 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/arithmetic__mixed.txt @@ -0,0 +1,20 @@ +Calcula (((-5)/6 + (-114)/684)*-1)/((-201)/(-6)). +2/67 +Calcula (75/10 - 10) + 668/(-56) - (-8)/(-14). +-15 +1736/(-98) + 18 - ((-8)/4 - 342/(-21)) +-14 +Quanto é (32*(-22 + 10489/476))/((-2)/(-7))? +4 +101 + -97 + -11 + -38 +-45 +Avalia 1158/32 - (1 + 39/(-48)). +36 +-3 + 1202/208 + 3/78*(-16 + 12) +21/8 +Qual é o valor de ((-14)/8)/(-5 - (202/25)/(16/(-10)))? +-35 +Quanto é (-7496)/(-243620) - (2 - 583/65)? +7 +Quanto é (-3)/((-39)/(-2)) + ((-187368)/1950 - -96)? +-6/25 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/arithmetic__mul.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/arithmetic__mul.txt new file mode 100644 index 0000000000000000000000000000000000000000..fca42a5011a7d811284df22af42e2a46483b5388 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/arithmetic__mul.txt @@ -0,0 +1,20 @@ +15836.2*-0.48 +-7601.376 +-0.18 vezes 10345.65 +-1862.217 +Produto de -541134 e 1.5. +-811701 +Produto de -9.1 e 0.111539. +-1.0150049 +-0.5*-0.3542049 +0.17710245 +Calcula -1.79239 * -0.11. +0.1971629 +Multiplica -0.1 e -237.9431. +23.79431 +71418*-17 +-1214106 +Produto de 0.4 e -3459159. +-1383663.6 +Multiplica -69782 e 176. +-12281632 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/arithmetic__mul_div_multiple.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/arithmetic__mul_div_multiple.txt new file mode 100644 index 0000000000000000000000000000000000000000..35938891756fd6a5a60f0d6742c668bd31273ded --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/arithmetic__mul_div_multiple.txt @@ -0,0 +1,20 @@ +406/(-377)*(-5187)/(-114) +-49 +Calcula (108/14)/((6/(-168))/(136/(-1088))). +27 +Quanto é (-20*(-258)/(-4300))/(6/40*1/1)? +-8 +Quanto é ((-1296)/(-378))/(2/(-28))? +-48 +Quanto é (-6)/((-576)/60)*(48/(-8))/(-3)? +5/4 +Quanto é (-3)/(-6)*(60/700*-10)/((-3)/189)? +27 +Qual é o valor de ((-9084)/39364)/((-6)/(-104))? +-4 +Quanto é (-15)/(-21)*48/(-40)*-1*4/16? +3/14 +-44*(-56)/(-53900)*35 +-8/5 +Qual é o valor de (-50)/(-825)*-11*(-2)/120*-4? +-2/45 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/arithmetic__nearest_integer_root.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/arithmetic__nearest_integer_root.txt new file mode 100644 index 0000000000000000000000000000000000000000..e9e3c3e70da9299425db7d7bd42b5b16615a4cbc --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/arithmetic__nearest_integer_root.txt @@ -0,0 +1,20 @@ +Quanto é 79421780 elevado a 1/2, arredondado para o inteiro mais próximo? +8912 +Quanto é 50308105 elevado a 1/2, arredondado para o inteiro mais próximo? +7093 +Qual é a raíz cúbica de 65957304 arredondada para o inteiro mais próximo? +404 +Quanto é 47181849 elevado a 1/2, arredondado para o inteiro mais próximo? +6869 +Qual é a décima raíz de 5923664 arredondada para o inteiro mais próximo? +5 +Qual é a terceira raíz de 42316370 arredondada para o inteiro mais próximo? +348 +Qual é a sexta raíz de 70908946 arredondada para o inteiro mais próximo? +20 +Quanto é 55976877 elevado a 1/9, arredondado para o inteiro mais próximo? +7 +Quanto é 41901349 elevado a 1/8, arredondado para o inteiro mais próximo? +9 +Qual é a raíz cúbica de 72976644 arredondada para o inteiro mais próximo? +418 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/arithmetic__simplify_surd.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/arithmetic__simplify_surd.txt new file mode 100644 index 0000000000000000000000000000000000000000..5ffae6b52e0f5a3ea90e103ec22a464e9700d2fe --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/arithmetic__simplify_surd.txt @@ -0,0 +1,20 @@ +Simplificar ((1*-5*(-1*(2*sqrt(891) + sqrt(891)) + 5 + sqrt(891)*-1) + 1)*3)**2. +3212784 - 77760*sqrt(11) +Simplificar (-3*(sqrt(270) + sqrt(270)*-1*4))/((sqrt(540)/sqrt(2))/(sqrt(12)/sqrt(4)*6)). +54*sqrt(3) +Simplificar -5*-1*(-3 + (-5 + (-1 + sqrt(704) - sqrt(704)))**2)*-5 + 2. +-823 +Simplificar (((0 + sqrt(125))*-2)**2*6 - (sqrt(180)*2)**2*-5)*-4. +-26400 +Simplificar (-5*(5 + sqrt(275)*1 + -5))**2 + -2*sqrt(275) + 4 + (0 + sqrt(275) + 2)**2. +10*sqrt(11) + 7158 +Simplificar -5*((sqrt(32) - (sqrt(32) + -3*sqrt(512)))**2 + -3 - (sqrt(800)*-1*4)**2). +40975 +Simplificar 3 + ((2*sqrt(243) + sqrt(243) - sqrt(243))**2*4 - ((sqrt(243) + 1)*1)**2) - -5*(-2*(sqrt(243) + 0) - (sqrt(243) + 5*(sqrt(243) + 0))**2). +-40093 - 108*sqrt(3) +Simplificar 4*((-2 + sqrt(112)*-2)*6 + -4 + (sqrt(112) - (1 + sqrt(112))) + -4) + 0. +-192*sqrt(7) - 84 +Simplificar -5 + -2 + (0 + -3 + sqrt(80) + 0 - ((sqrt(80) - (-1*sqrt(80))**2) + -5 + 0 + (sqrt(80)*-1)**2)). +-5 +Simplificar -3 + (3*(sqrt(153)/(-2*sqrt(9)) + sqrt(17)) - (-1*sqrt(85)*-4)/sqrt(5))**2 + 2. +421/4 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/calculus__differentiate.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/calculus__differentiate.txt new file mode 100644 index 0000000000000000000000000000000000000000..2753899a27e05ffb41364936302f5c7a4b2f4a00 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/calculus__differentiate.txt @@ -0,0 +1,20 @@ +Encontra a terceira derivada de 2564804*a**4 - 518*a**2 + 12756*a em relação a a. +61555296*a +Encontra a segunda derivada de s**3 - 30529*s**2 + 6926614*s em relação a s. +6*s - 61058 +Encontra a segunda derivada de 333833*s**2*z**2 + 3*s**2*z - 21663*s*z - 8*z**4 + 31*z + 2 em relação a z. +667666*s**2 - 96*z**2 +Qual é a segunda derivada de 7957*a**2*v**2*y + 4*a**2*y + 4*a*v*y**3 + 719*v**2*y**3 + 4142*v*y em relação a v? +15914*a**2*y + 1438*y**3 +Qual é a terceira derivada de 4555153*n**3 + 3*n**2 - 3387*n + 2? +27330918 +Encontra a segunda derivada de -2819*s**3 + 241*s**2 + 2237*s + 2745 em relação a s. +482 - 16914*s +Encontra a terceira derivada de 27473*j**6 - 100*j**5 + 77504*j**2 - 8*j - 2. +3296760*j**3 - 6000*j**2 +Encontra a segunda derivada de -11974623*r**2 + 811338*r. +-23949246 +Qual é a terceira derivada de -8306400*z**3 - 339460*z**2 + 13*z? +-49838400 +Qual é a segunda derivada de -18*b**3 - 243738*b**2 + 340*b - 2983? +-108*b - 487476 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/calculus__differentiate_composed.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/calculus__differentiate_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..1478af77a5fd0c4cb72cbc69a4765f1883f17463 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/calculus__differentiate_composed.txt @@ -0,0 +1,20 @@ +Assume que s é ((-31)/2)/(4/(-8)). Qual é a segunda derivada de 20*t**3 - 7 + 98*t - 95*t + s*t**3 - 6*t**3 em relação a t? +270*t +Supõe -78 = r + 2*r. Seja q = -22 - r. Encontra a terceira derivada de 0*k**4 - 6*k**2 - 4*k**q - 6*k**2 + 0*k**2 em relação a k. +-96*k +Qual é a segunda derivada de -312*o**4 - 354*o**4 + 18431*o**3 + 18420*o**3 + 838*o + 2*o**2 - 36851*o**3 em relação a o? +4 - 7992*o**2 +Seja t(o) a terceira derivada de -16/3*o**3 + 0*o**5 + 5/24*o**4 - 37*o**2 - 1 + 0*o - 7/120*o**6. Diferencia t(l) em relação a l. +5 - 21*l**2 +Seja k(o) a segunda derivada de -71/2*o**2 - 1/10*o**5 + 11/6*o**3 - 52*o + 0 + 0*o**4. Deriva k(x) em relação a x. +11 - 6*x**2 +Assume que v é (152/(-10))/((-8)/20). Assume que h é (-72)/(-20) + 2/5. Qual é a primeira derivada de -j + 48*j**h - v*j**4 + j - 16 em relação a j? +40*j**3 +Seja l(o) a terceira derivada de 52*o**5/15 - 119*o**4/8 - o**3/3 - 887*o**2. Qual é a segunda derivada de l(w) em relação a w? +416 +Supõe 446*p - 444*p = 4. Encontra a primeira derivada de p*a + 326 - 2*a - 291 - 41*a**4 em relação a a. +-164*a**3 +Seja x(c) a primeira derivada de c**7/120 + c**5/24 + 38*c**3/3 + 70. Seja n(f) a terceira derivada de x(f). Encontra a segunda derivada de n(s) em relação a s. +42*s +Seja b(c) a segunda derivada de -532*c**6/15 + c**4/6 - 135*c**2 - 1142*c. Encontra a terceira derivada de b(y) em relação a y. +-25536*y diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/comparison__closest.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/comparison__closest.txt new file mode 100644 index 0000000000000000000000000000000000000000..1ab5404a3f072979dddc1077104bdf1e042dca82 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/comparison__closest.txt @@ -0,0 +1,20 @@ +Qual valor está mais perto de 5/19 em 4, 2/3, 6989? +2/3 +Qual valor está mais perto de -11/12 em 3, -3/2449, -13? +-3/2449 +Qual valor está mais perto de -136 em 0.4, 0, -5/2, -1/245, -2/7? +-5/2 +Qual está mais próximo de -12/47? (a) 0.01 (b) -16 (c) 4 (d) -5/8 +a +Qual valor está mais próximo de 1/3 em -2/23, -13120, 3? +-2/23 +Qual valor está mais próximo de 0 em 4765, 0.29, 23, 2/3? +0.29 +Qual está mais próximo de -16? (a) -2 (b) -4.4 (c) 4/9 (d) -89 (e) -4 +b +Qual está mais perto de 2/3? (a) 19671 (b) -1.1 (c) 0.7 +c +Qual está mais próximo de -2? (a) 11 (b) -3.8 (c) 0.4 (d) 99 (e) 0 +b +Qual valor está mais perto de 0 em 9, -4, 0.02, 1515, -1? +0.02 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/comparison__closest_composed.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/comparison__closest_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..8e47d819affa95e0b34509ac04c6e2fd1d8cb3c1 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/comparison__closest_composed.txt @@ -0,0 +1,20 @@ +Assume que s é (9 - 10) + -8 - (-102)/12. Supõe 2*m + 1 - 7 = 0. Seja a = m + -3. Qual valor está mais perto de 0.1 em s, -3, a? +a +Assume que g é (-178)/(-356)*-3*(-2)/9. Qual valor está mais próximo de g em -2, -14, 1/3, 2? +1/3 +Seja z = -1.617 + 2.617. Qual está mais próximo de 8? (a) -1/4 (b) z (c) 0.4 +b +Seja y = 4228323/169330 + -7222/295. Seja g = 5/82 - y. Qual está mais perto de -0.1? (a) 0 (b) g (c) -3 +a +Seja m = 48855 + -341983/7. Assume que z é 1 + (-10)/12 + 0. Qual está mais perto de 0? (a) z (b) -1 (c) m +a +Seja y = -2595 + 2600. Qual está mais perto de -1? (a) -1/5 (b) 1/4 (c) 3/2 (d) y +a +Seja k = 19609 + -19610. Supõe 4*j = 4*m + 16, -4*m - 3*j = -j - 14. Qual está mais perto de 2/9? (a) -3 (b) m (c) k +b +Seja p(z) = 3*z + 3. Seja h, p(-4). Assume que m é h/(-12)*2*2. Seja f = -83/3 + 412/15. Qual está mais perto de 2? (a) -1 (b) f (c) m +c +Seja k = 1 - 1.3. Assume que x é 4/7 - ((-3750)/(-315) + -11). Qual está mais perto de k? (a) -1/2 (b) -8/7 (c) x +c +Seja f = 239/7 - 34. Supõe 4*x + 40 = -2*i, -5*x = -4*i + 9 + 15. Qual está mais perto de 0? (a) 1 (b) x (c) f +c diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/comparison__kth_biggest.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/comparison__kth_biggest.txt new file mode 100644 index 0000000000000000000000000000000000000000..c17819363a42b14cfa04fa3fd608116bcabe16bc --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/comparison__kth_biggest.txt @@ -0,0 +1,20 @@ +Qual valor é quarto maior? (a) -318/7 (b) 98 (c) 0.4 (d) 5 (e) -0.1 (f) -3 +e +Qual é o terceiro menor valor em 0.3, 132, 40113? +40113 +Qual valor é sexto maior? (a) 3/4 (b) 315 (c) 61 (d) 4/7 (e) 1/11 (f) -1 (g) 2 +e +Qual valor é segundo menor? (a) 23 (b) -9 (c) 957 +a +Qual valor é terceiro menor? (a) -0.2 (b) -4/31 (c) 0.5 (d) -1 (e) -5 (f) 13 (g) -2 +d +Qual é o menor valor em 10/11, 11/6, 2, -8, -1? +-8 +Qual é o segundo menor valor em 2.3, -3, -2/9, -0.2, -4/445, -4? +-3 +Qual valor é quarto menor? (a) 0.08 (b) -3/5 (c) -3133 (d) 4 (e) 0 (f) 0.4 +a +Qual é o menor valor em -756, -4, 7.489? +-756 +Qual valor é sexto menor? (a) 3/2 (b) -1 (c) 2.1 (d) 0.4 (e) 0.15 (f) 5 (g) -0.219 +c diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/comparison__kth_biggest_composed.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/comparison__kth_biggest_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..1e0e2994e8847844c61e1e2a89cd479ce8d7f240 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/comparison__kth_biggest_composed.txt @@ -0,0 +1,20 @@ +Assume que h é (4/(-24) - -1) + (-1)/(18/(-12)). Seja x = -0.3 + 3.3. Qual é o terceiro menor valor em x, 4, h, 0? +x +Supõe 17 - 19 = -i, -4*f + 3*i + 14 = 0. Seja d = 0.07 + -0.16. Qual valor é terceiro maior? (a) f (b) d (c) -1/2 +c +Seja k = -106.979 - -107. Seja r = k - -1.079. Qual valor é segundo maior? (a) -1 (b) r (c) -0.4 +c +Supõe -n + w = -3*w - 12, 0 = 4*n - 4*w - 24. Seja b = n + -1. Assume que r é (-3 - (-9)/b)/(-2). Qual é o terceiro maior valor em -10, r, 2? +-10 +Assume que f é 2/(3/(-6)*2). Seja v = 323410/41 - 7888. Qual valor é terceiro maior? (a) -1 (b) f (c) v (d) 1 +a +Seja m = 199 - 202. Seja n = 1 - m. Qual é o quarto menor valor em 5/3, 0, 2, n? +n +Seja f = -1651 + 1648.842. Seja h = f + 0.158. Seja j = 0 + -0.1. Qual é o terceiro maior valor em h, 10, j? +h +Seja m = 0 + 0. Seja q = 10.87 + -155.96. Seja t = 145 + q. Qual é o menor valor em t, -1, -2, m? +-2 +Seja s = 2228.1 + -2228. Qual é o segundo menor valor em s, 0, -83.2? +0 +Supõe -2*f = -2*w + 2, -4*f + 0 = 2*w - 32. Supõe 0 = -w*s - 0. Supõe n + 1 - 2 = s. Qual valor é menor? (a) -3 (b) 4 (c) n +a diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/comparison__pair.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/comparison__pair.txt new file mode 100644 index 0000000000000000000000000000000000000000..5ed51a34dd0553a6f985fd81628ca44cad9e5267 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/comparison__pair.txt @@ -0,0 +1,20 @@ +Será que 0.1 e 14906487 possuem valores diferentes? +True +Será 23715, no máximo, 23703? +False +Qual é menor: -229647 ou -229623? +-229647 +Qual é maior: -0.3 ou 8664526? +8664526 +Qual é menor: -1 ou -458/29429? +-1 +Qual é menor: 728 ou -3436? +-3436 +Será que 277047 != 277079? +True +Qual é maior: -114258 ou -114299? +-114258 +Será 4351/53 menor que 81? +False +Será que 988 e 206318/209 não são equivalentes? +True diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/comparison__pair_composed.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/comparison__pair_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..d56f9f8015e4e347e98d6714295f45ff1b467145 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/comparison__pair_composed.txt @@ -0,0 +1,20 @@ +Assume que i é (199/(-2) + -1)/((-33)/88). Será que 268 e i não são equivalentes? +False +Assume que z é (-196)/(-12) + (-2)/6. Seja h = z + -16. Supõe h = 4*r - 2 - 2. Qual é maior: r ou 7/4? +7/4 +Assume que b é (3/(-6))/((-2)/(-12)). Assume que k é (-177)/(-585) - b/(-9). Supõe 5*y + 10 = -15*h + 16*h, -5*y - 15 = -2*h. Será y <= k? +True +Seja h = 3120541437374/5565 - 560744221. Seja m = h + 2/1113. Qual é superior: -28 ou m? +m +Seja i(v) = -3*v**2 - 100*v - 115. Seja c, i(-32). Qual é menor: 96/7 ou c? +c +Seja h = -4842 + 4801. Será que 8 = h? +False +Supõe -3*p + 2*p + 2*m = -25, m + 134 = 5*p. Seja c(f) = 9 + 20*f - 21*f + 37. Seja g, c(19). Será g maior do que p? +False +Supõe l = 7*h - 2*h + 27, -4*l - 3*h - 7 = 0. Assume que a é 2*1646/6600 - l/4. Seja k = -10729/3300 - a. Qual é superior: -3 ou k? +-3 +Seja u(k) = k**2 + k - 4. Assume que q é 0/(1/((-4)/8)). Seja t(g) = 2*g**3 + g**2 - g - 5. Seja b, t(q). Seja r, u(b). Qual é superior: r ou 17? +17 +Seja r = 5142 - 5144. Supõe -2*j + 3*w = 5*w + 18, j = -2*w - 6. Será j >= r? +False diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/comparison__sort.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/comparison__sort.txt new file mode 100644 index 0000000000000000000000000000000000000000..7ee27d42b3a36f4228e2f29e257c82e080714c81 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/comparison__sort.txt @@ -0,0 +1,20 @@ +Coloca -350, -57, -3, 2 em ordem ascendente. +-350, -57, -3, 2 +Coloca -2, 4, -0.3, 0, -1078, 1/4 em ordem ascendente. +-1078, -2, -0.3, 0, 1/4, 4 +Coloca 2/75, -1, 1188, 2/19 em ordem decrescente. +1188, 2/19, 2/75, -1 +Ordena 1, -3, -4, 3062, -1, -2, -5. +-5, -4, -3, -2, -1, 1, 3062 +Ordena -11, -2, 1020, 3, 4, 8 por ordem decrescente. +1020, 8, 4, 3, -2, -11 +Ordena -4, -0.05, 4, -0.3, -3, -783 por ordem decrescente. +4, -0.05, -0.3, -3, -4, -783 +Ordena -22, -1, 10890, 3, -2 por ordem crescente. +-22, -2, -1, 3, 10890 +Ordena 10/11, -0.1806, 1, -0.05 por ordem ascendente. +-0.1806, -0.05, 10/11, 1 +Coloca -4, 13, 5, -5, 2, 3, -42 em ordem descendente. +13, 5, 3, 2, -4, -5, -42 +Ordena -23, -1/9, -4, -5, -15, -6. +-23, -15, -6, -5, -4, -1/9 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/comparison__sort_composed.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/comparison__sort_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..546937c8da53f5c7dbd4d9585a7012230030fa0b --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/comparison__sort_composed.txt @@ -0,0 +1,20 @@ +Seja l = -6.7 + 19.2. Seja u = -17.5 + l. Ordena 3, -5/4, 0.3, u por ordem crescente. +u, -5/4, 0.3, 3 +Supõe -25*z = -11 + 11. Coloca z, 5, -536 em ordem decrescente. +5, z, -536 +Supõe 95 = -42*u + 179. Seja p(y) = y**2 + 3*y - 1. Seja t, p(-4). Ordena -5, t, u, 4. +-5, u, t, 4 +Seja q = 122/27 - 158/27. Coloca -68, q, -1 em ordem crescente. +-68, q, -1 +Seja c = 23756.5 - 23756. Seja k = -0.1 - -0.1. Seja b = k + -0.3. Coloca b, 0.08, c em ordem decrescente. +c, 0.08, b +Seja g = 11316/5 + -2263. Coloca g, 0.1, -0.2, -0.18 em ordem crescente. +-0.2, -0.18, 0.1, g +Supõe -2*n + 12*o - 8*o = 6, 0 = 4*n - 2*o - 12. Coloca n, -54, 0, 2, -3 em ordem crescente. +-54, -3, 0, 2, n +Seja b = 621 + -564. Ordena 1, b, 2 por ordem descendente. +b, 2, 1 +Seja l = -3813 - -3812. Coloca 1, l, -1/11 em ordem decrescente. +1, -1/11, l +Supõe -32*k + 22 = -34 - 40. Ordena -5, 5, 4, -24, k. +-24, -5, k, 4, 5 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/measurement__conversion.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/measurement__conversion.txt new file mode 100644 index 0000000000000000000000000000000000000000..90f45404d094d242761f1140a3c433a3284ac69a --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/measurement__conversion.txt @@ -0,0 +1,20 @@ +Quantos(as) segundos estão em 5/3 de um(a) hora? +6000 +Quantos(as) gramas estão em 1/40 de um(a) tonelada? +25000 +Quantos(as) meses estão em 0.4160668 anos? +4.9928016 +Quanto é 2/25 de um(a) milligrama em um(a) microgramas? +80 +Converte 4102.461l para mililitros. +4102461 +Quantos(as) meses estão em 4.924495 décadas? +590.9394 +Quanto é 24/5 de um(a) dia em um(a) minutos? +6912 +Converte 7392.307 anos para décadas. +739.2307 +Converte 783.3969 centímetros para metros. +7.833969 +Quanto é 619964.7t em nanogramas? +619964700000000000000 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/measurement__time.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/measurement__time.txt new file mode 100644 index 0000000000000000000000000000000000000000..4639c3d0d2344961562e1ecc6e0d9602708feb05 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/measurement__time.txt @@ -0,0 +1,20 @@ +O que é 1 minutos despois de 1:20 AM? +1:21 AM +O que é 86 minutos despois de 4:41 AM? +6:07 AM +Quantos minutos existem entre 6:26 PM e 12:45 AM? +379 +O que é 208 minutos despois de 5:09 PM? +8:37 PM +O que é 55 minutos despois de 6:43 AM? +7:38 AM +O que é 267 minutos despois de 10:26 AM? +2:53 PM +O que é 65 minutos antes de 8:50 PM? +7:45 PM +O que é 242 minutos despois de 7:05 AM? +11:07 AM +O que é 632 minutos antes de 4:14 PM? +5:42 AM +Quantos minutos existem entre 5:52 AM e 11:44 AM? +352 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__base_conversion.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__base_conversion.txt new file mode 100644 index 0000000000000000000000000000000000000000..209c3ba27f765d143a84f78abceef952777c2e1c --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__base_conversion.txt @@ -0,0 +1,20 @@ +Converte -113211032 (em base 4) para base 14. +-272b4 +Quanto é 37996 (base 13) em base 5? +11241311 +-7661 (em base 15) para base 12 +-1260a +-143847 (em base 10) para base 9 +-238280 +Converte -13039 (em base 14) para base 8. +-133153 +Quanto é -35164 (base 15) em base 13? +-5bc54 +Quanto é -58487 (base 9) em base 16? +-9880 +155245 (em base 7) para base 2 +111011111000010 +Converte 20173 (em base 14) para base 10. +77129 +Quanto é 3dac0 (base 14) em base 13? +5487c diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__div_remainder.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__div_remainder.txt new file mode 100644 index 0000000000000000000000000000000000000000..bbbb7ad9c74915102bd3872b52000154e4834cc3 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__div_remainder.txt @@ -0,0 +1,20 @@ +Calcula o resto da divisão entre 83784 e 105. +99 +Calcula o resto da divisão entre 45012 e 565. +377 +Calcula o resto da divisão entre 378383 e 54050. +33 +Qual é o resto da divisão entre 367745 e 133? +0 +Qual é o resto da divisão entre 30461 e 5065? +71 +Calcula o resto da divisão entre 534282 e 7973. +91 +Calcula o resto da divisão entre 483553 e 4605. +28 +Qual é o resto da divisão entre 5579 e 1031? +424 +Calcula o resto da divisão entre 32695 e 321. +274 +Qual é o resto da divisão entre 331609 e 36845? +4 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__div_remainder_composed.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__div_remainder_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..6178490bdb44584ae4f213c4553233fa8fd9ba39 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__div_remainder_composed.txt @@ -0,0 +1,20 @@ +Seja i = 4124 - 3945. Qual é o resto da divisão entre 549 e i? +12 +Seja o = -4976 + 5185. Calcula o resto da divisão entre o e 6. +5 +Seja g(y) = 19*y + 15*y - 42*y - 51. Qual é o resto da divisão entre g(-10) e -7*(40/(-14) - -2)? +5 +Seja w(b) = -3*b - 27. Seja q, w(-9). Qual é o resto da divisão entre (q - 636/(-18))*9/6 e 27? +26 +Supõe -32*r = -1840 - 4784. Qual é o resto da divisão entre r e 97? +13 +Supõe p = 5*q - 1202 + 197, -3*p = 0. Qual é o resto da divisão entre q e 26 + (-1 - -2) - (41 - 43)? +27 +Assume que s é ((-6)/4)/((-6)/16). Supõe -10*c + 5512 = 5472. Supõe -3*z + 3 = -s*z, -5*z = -c*d + 91. Qual é o resto da divisão entre d e 6? +1 +Supõe -2*h = -2*m - 3*m + 46, 5*h - 60 = -5*m. Supõe -135 = -5*p - 5*x, 85 = m*p - 7*p + 5*x. Qual é o resto da divisão entre 34 e p? +9 +Supõe 4*j + f - 226 = 11, 4*j - 235 = f. Calcula o resto da divisão entre 170 e j. +52 +Seja j(u) = 4 - 11*u**2 - u + u**3 + 6*u + 8*u - 21. Seja r(a) = -a**3 + 4*a**2 + 6*a + 5. Seja b, r(5). Calcula o resto da divisão entre 46 e j(b). +7 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__gcd.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__gcd.txt new file mode 100644 index 0000000000000000000000000000000000000000..fae4df0a54168bfd27868e4185e9378299a46b99 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__gcd.txt @@ -0,0 +1,20 @@ +Qual é o maior fator comum de 69921 e 2839? +17 +Calcula o maior divisor comum de 36180 e 460. +20 +Calcula o maior divisor comum de 5258 e 36586. +22 +Calcula o maior divisor comum de 8298 e 5835338. +922 +Qual é o maior fator comum de 125218 e 269630? +914 +Qual é o maior divisor comum de 10608472 e 336? +56 +Calcula o maior divisor comum de 1441 e 1975873. +131 +Qual é o maior divisor comum de 162325 e 72025? +1075 +Calcula o maior fator comum de 54 e 270810. +54 +Calcula o maior divisor comum de 501 e 45249. +3 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__gcd_composed.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__gcd_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..8184cd2061bdb28ab08257a6993f640aac5feefc --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__gcd_composed.txt @@ -0,0 +1,20 @@ +Assume que a é (-2)/(-4) - 49/2. Assume que d é 1/((-27)/a - 1). Seja l(z) = z**3 + 31*z**2 + 7*z + 233. Seja t, l(-31). Qual é o maior fator comum de d e t? +8 +Seja n(p) = 2*p**3 - p**2 - 1. Seja t, n(2). Supõe -4*i = -t*i + 455. Qual é o maior fator comum de i e 13? +13 +Supõe 300 = 15*k - 600. Calcula o maior fator comum de k e 2240. +20 +Seja h(n) = n**3 - n**2 - 3*n + 3. Seja d = -232 + 235. Seja j, h(d). Qual é o maior divisor comum de 44 e j? +4 +Assume que l é -6*(2 - 5)/6. Supõe f - 2 = l. Supõe -5*c - 680 = -f*m, 272 = 2*m + 3*c - 0*c. Calcula o maior divisor comum de 34 e m. +34 +Supõe 0 = -13*v - 169*v + 3673 + 474077. Calcula o maior fator comum de 30 e v. +15 +Seja d(c) = 17*c**3 + c**2 - 4*c + 2. Seja r, d(1). Seja p = -134 - -218. Assume que m é (36/21)/(1/p). Calcula o maior divisor comum de m e r. +16 +Assume que i é 2/3 + (-2)/(-6). Assume que z é 6/i + 2/(-2). Assume que f é (2345/(-134))/(1*2/(-4)). Qual é o maior divisor comum de f e z? +5 +Seja p(r) = -5*r**2 + 187*r - 54. Seja l, p(37). Supõe i - 83 = -g, 2*i = 3*g + 4*i - 246. Qual é o maior divisor comum de l e g? +20 +Assume que i é 0 - 17*(-3)/3. Supõe -p = r - 31 - i, 0 = r + 4*p - 36. Supõe 0 = 105*g - 755 + 135 - 745. Qual é o maior divisor comum de r e g? +13 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__is_factor.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__is_factor.txt new file mode 100644 index 0000000000000000000000000000000000000000..db9a1cb7f97dffb8a93b884a5f1dceb2e39dfd82 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__is_factor.txt @@ -0,0 +1,20 @@ +Será que 21 divide 21297129? +True +Será 32793800 um múltiplo de 101? +False +Será 33543096 um múltiplo de 516? +True +Será que 10 divide 12030600? +True +Será 59 um fator de 6106544? +False +Será 37046561 um múltiplo de 19? +True +Será que 12 divide 1992140? +False +Será 6 um fator de 2613817? +False +Será que 72 divide 4783248? +True +Será 56 um fator de 72369976? +True diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__is_factor_composed.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__is_factor_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..9eadd29b37849ca4e0a455de78490f7bf7a67bb1 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__is_factor_composed.txt @@ -0,0 +1,20 @@ +Supõe 0*o - 39*o + 80109 = 30*o. Será 43 um fator de o? +True +Supõe 0 = 5*k - 2*z - 1665, 2*z = k - 6*k + 1685. Seja d = k - 211. Será 11 um fator de d? +False +Será 60 um fator de 41*126 + (-5 + 12 - 13)? +True +Assume que f é 62 + 4 - (2 + 2). Supõe 0 = 2*c - c - f. Seja t = -24 + c. Será 22 um fator de t? +False +Seja r(b) = 51*b**2 + 2*b + 21. Seja v, r(-5). Supõe 6*o = 3*m + 4*o - 770, -4*o = -5*m + v. Será 21 um fator de m? +False +Seja j = 32 + 3411. Será que 61 divide j? +False +Supõe 4*y + 5*b - 3 = 13, 5*y = 4*b + 20. Seja c(o) = 2*o**2 - 42*o - 21. Seja w, c(25). Supõe 313 = y*v - w. Será 19 um fator de v? +False +Seja j(r) = -154*r**3 + 3*r**2 + 2*r. Seja w, j(-1). Supõe -4*u + w + 41 = 0. Será u um múltiplo de 6? +False +Supõe 556 = -4*z - l, -4*l - 229 = 3*z + 188. Seja j = z - -191. Será j um múltiplo de 52? +True +Supõe 49*o = 2*o + 4576 - 346. Será 18 um fator de o? +True diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__is_prime.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__is_prime.txt new file mode 100644 index 0000000000000000000000000000000000000000..4ff4a288de59ceee823b5acc9b04f51a164f47f5 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__is_prime.txt @@ -0,0 +1,20 @@ +Será 1787261185 primo? +False +Será 3582758659 um número primo? +True +Será 730776089 compósito? +False +Será 461689093 primo? +False +Será 84231019 primo? +True +Será 564826859 primo? +True +Será 727429379 um número compósito? +False +Será 295283971 um número compósito? +False +Será 85278461 um número compósito? +False +Será 1457577139 um número compósito? +False diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__is_prime_composed.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__is_prime_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..f0900cb4f78a4a32eda34f4b09a4cc4436038bd1 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__is_prime_composed.txt @@ -0,0 +1,20 @@ +Seja r(p) a terceira derivada de -657*p**4/8 + 4*p**3/3 + 33*p**2. Será r(-1) primo? +True +Supõe 0 = -5*z + 10 + 5. Assume que d é (3/(-6))/((z/18)/1). Seja j(c) = 71*c**2 + 3*c + 1. Será j(d) compósito? +False +Supõe -3*g - 3*u = -5*g + 20, 4*u = -4*g. Supõe 43 = -0*v + v - g*s, 3*v - 197 = -5*s. Será v um número primo? +True +Assume que a é -4 - (-5 + 45/3). Será 7 + -1 - 71974/a compósito? +False +Supõe 4*s - 13965 = p, -20*s = -19*s + p - 3490. Será s primo? +True +Supõe -h + 3*l = -4*h, 3*l + 21 = 4*h. Supõe h*c - 12 = c - 4*n, 5*n + 7 = 3*c. Supõe 2472 = c*k - 4*a, -4*a - 1858 = -0*k - 3*k. Será k compósito? +True +Supõe -2*v + 677 = 667. Seja z(u) = 3*u + 3*u**3 + 4 + 9*u**3 + 4 - 2*u**2. Será z(v) compósito? +True +Seja l = -29 + 32. Supõe -2*u + l = 3. Será ((3 - -1) + 19)*(17 + u) um número primo? +False +Seja c = -194 + 197. Supõe -1240 + 19791 = w + 2*d, 18550 = w + c*d. Será w um número compósito? +False +Seja m(n) a primeira derivada de 127*n**4/2 - n**3/3 + n**2 - 2*n + 11. Seja f, m(1). Supõe 0 = 5*i - f - 3202. Será i um número compósito? +False diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__lcm.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__lcm.txt new file mode 100644 index 0000000000000000000000000000000000000000..ee21614ad7fc72529ecd774c3a297f12c3184994 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__lcm.txt @@ -0,0 +1,20 @@ +Calcula o menor múltiplo comum de 598 e 30753. +18390294 +Calcula o denominador comum de -62/585005 e -13/86479. +9945085 +Qual é o denominador comum de 83/29565 e -133/78300? +17147700 +Calcula o denominador comum de -31/3180 e -115/666. +352980 +Qual é o menor múltiplo comum de 2121350 e 798? +6364050 +Calcula o denominador comum de 73/199556 e -49/3363944. +23547608 +Calcula o menor múltiplo comum de 18 e 5250378. +15751134 +Encontra o denominador comum de -16/33 e -41/595341. +6548751 +Qual é o menor múltiplo comum de 343665 e 420035? +3780315 +Calcula o menor múltiplo comum de 4396 e 83524. +83524 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__lcm_composed.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__lcm_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..aac7c2275bf20a907687f8ed82e91becbb26e7c4 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__lcm_composed.txt @@ -0,0 +1,20 @@ +Encontra o denominador comum de 9/(-15) + 3562/520 e -55/5096. +5096 +Supõe 3*b - 1 = 122. Seja w = -29 + b. Supõe 147*d - 48 = 144*d. Qual é o menor múltiplo comum de w e d? +48 +Calcula o denominador comum de -31/1113 e (-44)/3 - 22/88*24. +1113 +Calcula o denominador comum de (3776/(-5760))/(2 + 0 - -1) e -37/891. +8910 +Seja x(s) = -142*s - 1958. Calcula o menor múltiplo comum de 195 e x(-14). +390 +Qual é o denominador comum de -173/60 e ((4 - 2)/512)/((-43)/(-430))? +1920 +Seja o(s) = 2*s + 21. Seja d, o(-9). Assume que v é d*(-2 + 3) - -30. Qual é o menor múltiplo comum de 3 e 1/(135/v - 3 - 1)? +33 +Supõe -9*l = 535 - 1491 - 2482. Calcula o menor múltiplo comum de 4 e l. +764 +Assume que v é (-12)/18 - (-16)/6. Assume que h é (-6)/12 + 21/v. Supõe -m - h = -2*y + 1, m = -5*y + 45. Calcula o menor múltiplo comum de 2 e y. +8 +Encontra o denominador comum de 65/38 e 153150/(-10300) + 13 + 2. +3914 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__list_prime_factors.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__list_prime_factors.txt new file mode 100644 index 0000000000000000000000000000000000000000..368c6edb3f810aeedc2a69f25cca050ae5607d08 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__list_prime_factors.txt @@ -0,0 +1,20 @@ +Enumera os fatores primos de 75356763. +3, 23, 1092127 +Quais são os fatores primos 4553559? +3, 19, 31, 859 +Enumera os fatores primos de 21867297. +3, 7289099 +Enumera os fatores primos de 87629182. +2, 43814591 +Enumera os fatores primos de 23015739. +3, 17, 37, 12197 +Enumera os fatores primos de 29521083. +3, 31, 317431 +Enumera os fatores primos de 25843322. +2, 97, 133213 +Quais são os fatores primos 50800505? +5, 7, 17, 12197 +Quais são os fatores primos 46101815? +5, 37, 249199 +Quais são os fatores primos 21609521? +43, 197, 2551 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__list_prime_factors_composed.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__list_prime_factors_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..ee214d3942affd02cc14e2fa1c8c5efda3c536e4 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__list_prime_factors_composed.txt @@ -0,0 +1,20 @@ +Quais são os fatores primos (-912)/(-114) - (-15700)/2? +2, 3929 +Seja d = 9705 + -2895. Enumera os fatores primos de d. +2, 3, 5, 227 +Supõe 11809 = 24*j - 6359. Supõe -5*x + j = -1058. Quais são os fatores primos x? +3, 11 +Seja m(i) = -i - 5. Seja r, m(-7). Supõe -4*z + 512 = 3*n, -r*z - n + 92 + 166 = 0. Enumera os fatores primos de z. +131 +Seja t(u) = -191*u - 58 + 46 - 120 + 182*u. Quais são os fatores primos t(-23)? +3, 5 +Quais são os fatores primos 144/(-264) - 63570/(-22)? +3, 107 +Seja a(x) = 30*x**2 - 48*x + 877. Quais são os fatores primos a(18)? +9733 +Supõe 24*q + 4 = 23*q + 3*r, 0 = 2*q + r - 6. Supõe 5 = -3*l - 7, 3*p = 3*l + 51. Supõe -w + p = c, -q*c + 4 = w - 6. Enumera os fatores primos de w. +2 +Assume que z é 3/(-15) + (-5272)/(-10). Supõe 297 = 5*i - 2*a - 365, 4*i = -a + z. Enumera os fatores primos de i. +2, 3, 11 +Seja p(l) = -l**2 + 9*l + 10. Seja r, p(10). Supõe 2*j = 3*j + 2*n - 402, 4*n + 4 = r. Enumera os fatores primos de j. +2, 101 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__place_value.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__place_value.txt new file mode 100644 index 0000000000000000000000000000000000000000..0a7886978925eff73ae5a2190639762c36189e07 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__place_value.txt @@ -0,0 +1,20 @@ +Qual é o dígito das milhões de 76506059? +6 +Qual é o dígito das centenas de 92525637? +6 +Qual é o dígito das milhares de 86264362? +4 +Qual é o dígito das unidades de 9014123? +3 +Qual é o dígito das dezena milhões de 18850520? +1 +Qual é o dígito das unidades de 48501266? +6 +Qual é o dígito das centena milhares de 15351013? +3 +Qual é o dígito das milhões de 78689710? +8 +Qual é o dígito das milhares de 55764147? +4 +Qual é o dígito das centena milhares de 88759692? +7 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__place_value_composed.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__place_value_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..e4ecace3f3ca996cec60d2e3c71b34ffdf87401c --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__place_value_composed.txt @@ -0,0 +1,20 @@ +Qual é o dígito das centenas de ((-31)/(-5))/(5/7775)? +6 +Seja q(v) = 37*v**3 - 12*v + 4. Seja s, q(4). Supõe 3382 = 18*m - s. Qual é o dígito das unidades de m? +7 +Seja z = -37 + 73. Assume que t é (4/6)/(12/z). Supõe 0 = 2*b + 4*w - 92 - 4, t*b - w = 106. Qual é o dígito das unidades de b? +2 +Supõe -n + 0*w - 4*w - 2 = 0, 0 = 3*n - w - 20. Supõe 0 = 4*r + 12, 3*s - n*r + 4*r = 228. Qual é o dígito das dezenas de s? +7 +Assume que u é (-13)/(-4) - (-2)/((-24)/3). Supõe u*i = 127 - 49. Qual é o dígito das dezenas de i? +2 +Seja j(v) = -5*v**2 - 3*v - 432. Seja a(d) = -2*d**2 - d - 216. Seja g(n) = -9*a(n) + 4*j(n). Qual é o dígito das unidades de g(0)? +6 +Supõe -9*t + 8*t = -238. Seja a = t + -18. Qual é o dígito das dezenas de a? +2 +Seja u(l) = -l**3 - 2*l**2 + 2*l - 1. Seja o, u(0). Qual é o dígito das unidades de 83 - (o + 0)*3? +6 +Supõe -4*g = 2*c - 6, 0 = -3*c - 0*c - 2*g - 11. Qual é o dígito das dezenas de (-3217)/c + 36/(-63)? +5 +Qual é o dígito das centenas de 50307/6 - (-20)/(-8)*(-9)/(-15)? +3 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__round_number.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__round_number.txt new file mode 100644 index 0000000000000000000000000000000000000000..d9c246a4d33154e22ea27fa9c8b4bf5a8306e2b7 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__round_number.txt @@ -0,0 +1,20 @@ +Arredonda 235711 para as 100000 mais próxima. +200000 +Quanto é -38336.966 arredondado para as um milhar mais próxima? +-38000 +Quanto é 8822.777 arredondado para as 10 mais próxima? +8820 +Arredonda -189.731309 para as casa decimal das doiss. +-189.73 +Quanto é 0.5699581 arredondado para as casa decimal das 4s? +0.57 +Arredonda -0.0000188379792 para as casa decimal das 7s. +-0.0000188 +Arredonda -0.0000134900893 para as casa decimal das seiss. +-0.000013 +Quanto é 32.5056379 arredondado para as casa decimal das um? +32.5 +Arredonda 1658337.36 para as 100 mais próxima. +1658300 +Arredonda -2189.05553 para as 10 mais próxima. +-2190 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__round_number_composed.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__round_number_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..b570afbd563c9b7c2fb77fdf57757d1b2de2a52f --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/numbers__round_number_composed.txt @@ -0,0 +1,20 @@ +Seja t = 116942170670204 + -116942177881929.4799841. Seja o = -7211726 - t. Seja d = o - -0.52. Quanto é d arredondado para as casa decimal das 6s? +-0.000016 +Seja s = -79.3252 - 0.0748. Seja w = s - -60. Quanto é w arredondado para as casa decimal das zeros? +-19 +Seja g = -1355511 + -16865083. Seja k = 18220633.999805 + g. Seja y = -40 + k. Quanto é y arredondado para as casa decimal das 5s? +-0.0002 +Seja n = -783 - -799.475. Seja g = n - 3.189. Seja h = g + -13.5. Quanto é h arredondado para as casa decimal das 2s? +-0.21 +Seja i = 6726961 - 2535961. Quanto é i arredondado para as um milhão mais próxima? +4000000 +Seja c = -0.0252 - 45.0748. Seja d = -48 - c. Seja z = d + 7.7. Quanto é z arredondado para as casa decimal das zeros? +5 +Seja t = -0.4613 - -0.0749. Arredonda t para as casa decimal das 1. +-0.4 +Seja r = 1.00231 - 209.99031. Seja i = r + 209. Arredonda i para as casa decimal das doiss. +0.01 +Seja k(i) = -i**3 + 3*i**2 + 24*i + 42. Seja l(f) = f**2 + 8*f + 14. Seja r(w) = 2*k(w) - 7*l(w). Seja u, r(-9). Arredonda u para as 100 mais próxima. +1400 +Seja b = -0.67 + 0.85. Seja c = b + -0.0755. Arredonda c para as casa decimal das 2s. +0.1 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/polynomials__add.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/polynomials__add.txt new file mode 100644 index 0000000000000000000000000000000000000000..b53c4d42510428413ab05b6a0a9bb8401ba229d2 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/polynomials__add.txt @@ -0,0 +1,20 @@ +Seja d(h) = 110*h**2 + 14*h - 14. Seja n(z) = 18*z + 141. Seja x, n(-8). Seja j(w) = 22*w**2 + 3*w - 3. Determina x*d(c) + 14*j(c). +-22*c**2 +Seja z(i) = -i. Seja r(a) a terceira derivada de a**4/6 - a**3 - 108*a**2 - 2. Obtém -r(y) - 5*z(y). +y + 6 +Supõe -9*m + 10*m - 2*o = -9, -4*m = -4*o + 24. Seja f(d) = 7*d**3 - 2*d**2 + 3*d + 1. Seja h(i) = -8*i**3 + 3*i**2 - 4*i - 2. Calcula m*f(n) - 2*h(n). +-5*n**3 - n + 1 +Seja c(j) = 126*j**2 + 21*j + 23. Seja d(l) = 43*l**2 + 6*l + 8. Determina -2*c(a) + 7*d(a). +49*a**2 + 10 +Seja b(n) a segunda derivada de -n**3/6 + 2*n**2 + 2*n. Seja k(l) a segunda derivada de l**3/3 - 3*l**2 - l. Supõe 4*u + 28 - 38 = -42. Obtém u*b(i) - 5*k(i). +-2*i - 2 +Seja d(j) = 32*j**2 + 3*j - 3. Seja g(n) = -2465*n**2 - 232*n + 232. Supõe 268*k + 3 = 269*k - 3*a, 5*k = -3*a + 15. Obtém k*g(f) + 232*d(f). +29*f**2 +Seja g(u) = 1 - 2*u**2. Seja d(j) = -12*j**2 + j + 9. Calcula -d(o) + 5*g(o). +2*o**2 - o - 4 +Seja m(p) a terceira derivada de -p**4/6 + 89*p**2 - 2. Seja g(i) = 1 - 4*i. Determina -3*g(v) + 4*m(v). +-4*v - 3 +Seja k(s) = 5*s**2 - 12*s + 4. Seja c(f) = f**2 - 2*f. Seja z(n) = 4*c(n) - k(n). Seja i(g) = -2*g**2 + 4*g**2 + 27*g + 3 - 30*g. Obtém 4*i(b) + 3*z(b). +5*b**2 +Seja v(u) = 8*u + 3. Seja l(y) = 3*y + 1. Seja n(a) = 11*l(a) - 4*v(a). Seja x(d) = 2. Obtém -3*n(t) - x(t). +1 - 3*t diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/polynomials__coefficient_named.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/polynomials__coefficient_named.txt new file mode 100644 index 0000000000000000000000000000000000000000..77c8fe967e0f5c9620da09eaaf5c498d76c762f9 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/polynomials__coefficient_named.txt @@ -0,0 +1,20 @@ +Expressa 7*b + 23 - 54*b**2 + 218*b**2 - 83*b**2 - 76*b**2 na forma i*b + p + d*b**2 e dá d. +5 +Rearranja (-6 + 4*s**2 + 6)*(-3*s**2 + 3*s**2 - 2*s**2) - 8945*s + 8945*s - 985*s**4 como c*s**2 + p*s**3 + v*s + q + d*s**4 e dá d. +-993 +Expressa 0*x + 13685*x**3 + 2*x - 3*x**2 - 13684*x**3 - 21 - 2*x**4 como g*x**3 + r*x**2 + t*x + b*x**4 + c e dá t. +2 +Expressa 256*n**2 - 127*n**2 - 130*n**2 - 77*n + 1137*n - 1 como m*n + d*n**2 + f e dá m. +1060 +Rearranja (-20 + 71 + 70 + (1 + 3 - 5)*(5 + 2 - 5))*(-24*m**4 + 26*m**4 + 16*m**4) na forma g + q*m**4 + u*m**3 + j*m**2 + z*m e dá q. +2142 +Expressa (-2 + 6 + 2)*(2 + 2 - 5)*(1149*r - 1575*r + 880*r) como w*r + g e dá w. +-2724 +Expressa 33*x**4 + 181 - 181 + (-x**2 - 4*x + 4*x)*(x**2 + 3 - 3) - 898*x**2 + 8*x**4 + 898*x**2 na forma h + j*x + t*x**4 + g*x**2 + c*x**3 e dá t. +40 +Rearranja (-w**2 - 2*w + 2*w)*(3*w - w + 4*w) + (6 - 16 - 4)*(-3*w + 0 + 0)*(-9*w + 4*w**2 + 3*w - 3*w**2) como n*w + s + y*w**2 + z*w**3 e dá z. +36 +Rearranja (-3 + 3 + 3*t)*(1 - 608*t - 8810*t**2 + 4432*t**2 + 4376*t**2) na forma g*t + s*t**2 + r*t**3 + d e dá g. +3 +Expressa (7 - 1 + 0 + (-69 - 86 + 141)*(0 + 2 + 0))*(t**4 + 4 - 4) como u*t**4 + v*t + s + w*t**3 + y*t**2 e dá u. +-22 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/polynomials__collect.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/polynomials__collect.txt new file mode 100644 index 0000000000000000000000000000000000000000..5390d5f85a74849852dcdac421f510a9f6edb1bc --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/polynomials__collect.txt @@ -0,0 +1,20 @@ +Coleta os termos em 3*a + 20*a - 23*a - 28018*a**2. +-28018*a**2 +Coleta os termos em -6 - 15518*x + 15643*x + 19 + 5. +125*x + 18 +Coleta os termos em 300*u + 3 - 1 - 264*u - 2 + 0. +36*u +Coleta os termos em -4*r + r + 18171*r**3 - 301788*r**3. +-283617*r**3 - 3*r +Coleta os termos em -11825*f**2 + 5749*f**2 + 5904*f**2 - 3*f. +-172*f**2 - 3*f +Coleta os termos em -2720*v + 1072*v - 3727*v + 104*v. +-5271*v +Coleta os termos em -44*w**3 + 14*w + 43*w**2 + 17*w - 33*w**2 - 32*w. +-44*w**3 + 10*w**2 - w +Coleta os termos em -26 + 64 - 30 - 24*b**2 + 19*b**2. +8 - 5*b**2 +Coleta os termos em 324*l**2 - 146*l**2 - 148*l**2 - 8*l + 3*l - 20*l**3. +-20*l**3 + 30*l**2 - 5*l +Coleta os termos em -15*w**3 - 11*w**3 - 12*w**3 + 69*w**3 + 2*w**2 - 15*w**3. +16*w**3 + 2*w**2 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/polynomials__compose.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/polynomials__compose.txt new file mode 100644 index 0000000000000000000000000000000000000000..43d1ea9f3578bb6ded648af3be272b8461b7e66b --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/polynomials__compose.txt @@ -0,0 +1,20 @@ +Seja t(z) = z + 32. Seja d(w) = -w**2 - w - 32. Seja i(j) = -4*d(j) - 4*t(j). Seja c(s) = 2 - 42*s. O que é c(i(k))? +2 - 168*k**2 +Seja s(t) = 2666*t - 5337*t + 125*t**2 + 2671*t. Seja m(a) = a**2 + a - 1. Seja x(o) = -10*o**2 - 12*o + 12. Seja w(c) = -12*m(c) - x(c). Obtém s(w(r)). +500*r**4 +Seja i(n) a terceira derivada de -13*n**5/30 + 15652*n**2. Seja v(j) = -j - 2. Seja y(t) = -3*t - 9. Seja h(d) = 9*v(d) - 2*y(d). Obtém i(h(m)). +-234*m**2 +Seja y(i) = 141*i. Seja l(u) = 30442*u. O que é l(y(m))? +4292322*m +Seja l(m) = -25351*m**2. Seja x(y) = -y**2 - 133*y. Determina x(l(n)). +-642673201*n**4 + 3371683*n**2 +Seja y(i) = -4 + 10 + 5 - 35*i - 1 - 7. Seja z(h) = -8*h. Determina z(y(v)). +280*v - 24 +Seja n(h) = 1587*h. Seja k(z) = 28*z - 52. Seja s(t) = 13*t - 24. Seja y(j) = -6*k(j) + 13*s(j). O que é y(n(l))? +1587*l +Seja p(d) = -2*d**2. Seja j(x) a segunda derivada de 8/3*x**3 + 49*x + 0 + 0*x**2. Calcula p(j(k)). +-512*k**2 +Seja v(b) = 2*b + 2253. Seja m(g) = -4*g - 42. Determina m(v(z)). +-8*z - 9054 +Seja h(s) a primeira derivada de 2*s**3 + 10*s - 869. Seja k(g) = 3*g**2. Determina h(k(c)). +54*c**4 + 10 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/polynomials__evaluate.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/polynomials__evaluate.txt new file mode 100644 index 0000000000000000000000000000000000000000..a6b531ae80362eb54ba3b62634f844e2b1ee0223 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/polynomials__evaluate.txt @@ -0,0 +1,20 @@ +Seja i(c) = 481940 - 2802*c. Calcula i(172). +-4 +Seja o(c) = -416*c - 435. Calcula o(-2). +397 +Seja a(u) = 2*u**3 - 62*u**2 - 441*u - 342. Determina a(37). +-231 +Seja n(g) = 257*g - 6195. Determina n(24). +-27 +Seja h(g) = -g**2 - 37*g + 11359. Calcula h(90). +-71 +Seja l(o) = -3*o**2 + 434*o - 2485. Calcula l(6). +11 +Seja v(w) = -7892*w - 31433. Calcula v(-4). +135 +Seja r(c) = -33992*c - 169967. O que é r(-5)? +-7 +Seja t(y) = y**3 + 6*y**2 - 702*y - 415. O que é t(24)? +17 +Seja z(j) = 36*j**2 - 3671*j - 205. O que é z(102)? +-103 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/polynomials__evaluate_composed.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/polynomials__evaluate_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..9169e882ecc48d035eaa0bce4a9ae5c9c0617153 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/polynomials__evaluate_composed.txt @@ -0,0 +1,20 @@ +Seja r(d) a segunda derivada de -d**8/6720 + d**7/630 + d**6/360 + d**5/120 + d**4/3 - d**2/2 - 47*d. Seja k(j) a terceira derivada de r(j). Calcula k(4). +9 +Seja i(d) = d**3 - 6*d**2 + 4*d + 2. Seja p, i(5). Seja o(h) = h + 1. Seja q(c) = -c - 2. Seja x(y) = p*q(y) - 5*o(y). Seja n = 16 + -14. Obtém x(n). +-3 +Seja o(x) a segunda derivada de -1/6*x**3 + x + x**2 - 18. Obtém o(-6). +8 +Seja f = 35 + -38. Assume que n é 1*-7*f/(2 + -5). Seja z(p) = p**2 + 4*p + 1. Seja x(m) = -m - 1. Seja o(s) = -3*x(s) + z(s). Determina o(n). +4 +Seja b(z) = 2*z**2 - 33*z + 16. Seja s(t) = 4*t**2 - 65*t + 32. Seja k(q) = 7*b(q) - 4*s(q). Seja p, k(14). Seja a(u) = -5*u**2 - u + 1. Calcula a(p). +-17 +Seja t(u) = 67*u**3 + 12*u**2 - 5*u - 2. Seja o(i) = -25*i**3 - 4*i**2 + 2*i. Seja m(q) = -8*o(q) - 3*t(q). Determina m(-3). +0 +Seja g(w) a terceira derivada de w**8/6720 - w**7/840 + w**6/720 + w**5/60 + 11*w**4/6 + w**3/6 - 50*w**2. Seja n(y) a segunda derivada de g(y). Obtém n(2). +0 +Seja i(l) = -l**3 + 20*l**2 + 2*l - 39. Seja m(k) = 2*k + 32. Seja z, m(-6). Seja n, i(z). Seja a(v) = -7*v**3 - v**2 + 1. Determina a(n). +-7 +Seja i(t) = t + 4. Seja j = -127 - -130. Assume que q é 1/j - (-351)/(-81). O que é i(q)? +0 +Supõe -47*y = -37*y - 140. Seja m(s) = -y + 14 + s - 4. O que é m(7)? +3 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/polynomials__expand.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/polynomials__expand.txt new file mode 100644 index 0000000000000000000000000000000000000000..97e1494a5599815549532473862945c038323b31 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/polynomials__expand.txt @@ -0,0 +1,20 @@ +Expande -m - m**4 - 52*m**2 + 52*m**2 + (49*m - 49*m - 6*m**4 + (-m**2 + 0*m**2 + 3*m**2)*(2*m**2 - 3*m**2 - m**2))*(-11 + 13 + 10). +-121*m**4 - m +Expande (-3*r**2 - 6*r**2 - 5*r**2)*(-239 - 263 + 188). +4396*r**2 +Expande (u + 4*u - u)*(-43989*u**3 - 1 - 41*u**4 + 43987*u**3 - 294*u**4). +-1340*u**5 - 8*u**4 - 4*u +Expande (-b - 4*b - 2*b)*(441 - 441 + 123*b). +-861*b**2 +Expande (0*h - 3*h - 127*h)*(-7*h - 7*h + 9*h). +650*h**2 +Expande -4*d + d + 5*d + (-10 + 13 + 28)*(-4*d + d + 2*d + (-1 - 2 + 5)*(2 + 2*d - 2)). +95*d +Expande (2*g**3 + 3*g**3 - 3*g**3)*(6 - 3 + 3)*(-89 + 6 + 51). +-384*g**3 +Expande (8*o - o - 2*o)*(314 - 1057 - 678). +-7105*o +Expande (2 + 4 - 5)*(2*d**2 + 2*d - 2*d) + (-226*d - 151*d + 300*d)*(-d + 6 - 6). +79*d**2 +Expande (3 - 1 + 0)*(-4*w**2 + 6*w**2 - w**2) + (18*w - 14*w + 20*w)*(0*w + 3*w - 8*w) + 0*w - 2*w**2 + 0*w. +-120*w**2 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/polynomials__simplify_power.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/polynomials__simplify_power.txt new file mode 100644 index 0000000000000000000000000000000000000000..3deb7dfe4170824b089ba3f58dc57f625e8bf204 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/polynomials__simplify_power.txt @@ -0,0 +1,20 @@ +Simplifica (u**(1/8))**16/(u**(-2/15)/((u**(-1/4)*u*u)/u*u*u))**(-2/59) assumindo que u é positiva. +u**(3367/1770) +Simplifica ((y**(2/5)/y)/(y*y**(-4/7)/y*y))**12*(y**(-2/3)*((y*y**2*y)/y)/y)/((y**(-4)*y)/(y/(y/((y/(y/y**1))/y*y)))) assumindo que y é positiva. +y**(-736/105) +Simplifica ((a/a**(1/3))/a**3)**(-36/7)/(a**(4/9)/(a**1/a))**(17/5) assumindo que a é positiva. +a**(472/45) +Simplifica ((s*s**(5/2)*s**(2/13))/((s*s**(-1)*s)/s**(-1/4)))/(((s*s*s**(3/4))/(s*(s*s/(s/(s**1*s)))/s*s))/s**(-15)) assumindo que s é positiva. +s**(-295/26) +Simplifica i**26/(i*i**(2/3)*i**(-3)*i)*(i**31)**(6/19) assumindo que i é positiva. +i**(2059/57) +Simplifica (((m*m**(4/5)/m*m)/m)/(m**4*m))/m**(2/111)*((m*m**(-4/7)/m*m)/m**4)**(16/7) assumindo que m é positiva. +m**(-336709/27195) +Simplifica ((u/((u*u/(u/((u*u**(-2))/u*u)))/u))**(1/25)/((u/u**(9/7))/u**(-1/2)))**(-2/159) assumindo que u é positiva. +u**(47/27825) +Simplifica (n**4/(n/(n*(n*n/(n**(-3)*n*n))/n*n)))**(-2/49)/((((n*n/(n/n**(1/2))*n)/n)/n*n**0)/n**22) assumindo que n é positiva. +n**(297/14) +Simplifica ((n/n**(1/7))**(2/115)*(n**(3/2))**(19/3))**(-2/39) assumindo que n é positiva. +n**(-15319/31395) +Simplifica ((g**(-5))**(10/11)*(g*g**4*g)/g*g**4)**23 assumindo que g é positiva. +g**(1127/11) diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/probability__swr_p_level_set.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/probability__swr_p_level_set.txt new file mode 100644 index 0000000000000000000000000000000000000000..219816fb80468a6be4cac804b04b8cdedbb95350 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/probability__swr_p_level_set.txt @@ -0,0 +1,20 @@ +Dois caractéres são escolhidos sem reposição de tkytenytekn. Dá a probabilidade de(a) escolher 2 k. +1/55 +Qual é a probabilidade de(a) escolher 1 d e 2 y quando três caractéres são escolhidos sem reposição de yddygyeyygecddyeyyee? +28/285 +Calcula da probabilidade de(a) escolher 1 z e 1 o quando dois caractéres são escolhidos sem reposição de {d: 1, u: 1, k: 1, o: 1, z: 2}. +2/15 +Calcula da probabilidade de(a) escolher 2 v e 1 f quando três caractéres são escolhidos sem reposição de {b: 1, f: 1, a: 2, v: 1, x: 6, k: 3}. +0 +Três caractéres são escolhidos sem reposição de cgatccatr. Dá a probabilidade de(a) escolher 1 a e 2 c. +1/14 +Três caractéres são escolhidos sem reposição de {y: 3, r: 2, c: 1, x: 2, k: 1}. Qual é a probabilidade de(a) escolher 1 c e 2 r? +1/84 +Quatro caractéres são escolhidos sem reposição de wqaaaafa. Qual é a probabilidade de(a) escolher 2 a, 1 f e 1 w? +1/7 +Dois caractéres são escolhidos sem reposição de cfcaofcocobocc. Dá a probabilidade de(a) escolher 1 b e 1 o. +4/91 +Três caractéres são escolhidos sem reposição de {v: 7, h: 3, d: 3, t: 3}. Dá a probabilidade de(a) escolher 1 d e 2 t. +9/560 +Quatro caractéres são escolhidos sem reposição de vvcvvvccvcc. Qual é a probabilidade de(a) escolher 4 v? +1/22 diff --git a/mathematics_dataset/mathematics_dataset/ds/interpolate/probability__swr_p_sequence.txt b/mathematics_dataset/mathematics_dataset/ds/interpolate/probability__swr_p_sequence.txt new file mode 100644 index 0000000000000000000000000000000000000000..0e0c027528597291279fc7c038502caccbcfcb82 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/interpolate/probability__swr_p_sequence.txt @@ -0,0 +1,20 @@ +Dois caractéres são escolhidos sem reposição de lcztclxzpcpcxxzzzc. Dá a probabilidade de(a) sequência lz. +5/153 +Dois caractéres são escolhidos sem reposição de bbtbbb. Qual é a probabilidade de(a) sequência bt? +1/6 +Três caractéres são escolhidos sem reposição de {l: 3, y: 4, k: 3}. Qual é a probabilidade de(a) sequência ykk? +1/30 +Qual é a probabilidade de(a) sequência ege quando três caractéres são escolhidos sem reposição de eeegeeeegegeegggg? +21/136 +Quatro caractéres são escolhidos sem reposição de {m: 7, k: 11}. Qual é a probabilidade de(a) sequência kmkm? +77/1224 +Calcula da probabilidade de(a) sequência bxxa quando quatro caractéres são escolhidos sem reposição de xaamabmmmaaxamam. +1/3120 +Três caractéres são escolhidos sem reposição de aewgeeezege. Qual é a probabilidade de(a) sequência eza? +1/165 +Quatro caractéres são escolhidos sem reposição de {d: 6, q: 14}. Qual é a probabilidade de(a) sequência qqdq? +182/1615 +Três caractéres são escolhidos sem reposição de {m: 1, e: 4, b: 1, q: 1, y: 1, z: 1}. Dá a probabilidade de(a) sequência eyy. +0 +Quatro caractéres são escolhidos sem reposição de xxxmmmxxmmxmmxx. Qual é a probabilidade de(a) sequência xxmx? +14/195 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/algebra__linear_1d.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/algebra__linear_1d.txt new file mode 100644 index 0000000000000000000000000000000000000000..b2f87bcef9a79e81f0424d3ce12aeda85baba485 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/algebra__linear_1d.txt @@ -0,0 +1,6 @@ +Resolve 9*k = 7*k + 4 para k. +2 +Resolve 3*y - 27*y - 96 = 0 para y. +-4 +Resolve -7*x + 3 - 24 = 0 para x. +-3 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/algebra__linear_1d_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/algebra__linear_1d_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..49f8bbf70e76bcb78f5210e96540eb58e08c0ab0 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/algebra__linear_1d_composed.txt @@ -0,0 +1,6 @@ +Supõe 0 = j - 4*j - 21. Seja b(d) = d**3 + 7*d**2 + 5. Seja v, b(j). Supõe 40 + 25 = 5*i. Resolve -i = v*q - 38 para q. +5 +Assume que y é ((-2)/(-1))/((-2)/(-3)). Supõe 3*c - i - 18 + 1 = 0, 0 = 4*c + y*i - 1. Supõe c*f = 3*f + 2. Resolve 0 = 4*p - f*p - 8 para p. +4 +Assume que m é 10*7/((-14)/(-3)). Resolve 2*u + m = 7*u para u. +3 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/algebra__linear_2d.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/algebra__linear_2d.txt new file mode 100644 index 0000000000000000000000000000000000000000..b08a1f7bdf486cc7b8d196211829ae399b67c9cd --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/algebra__linear_2d.txt @@ -0,0 +1,6 @@ +Resolve 0 = r + 2*g - 8, -5*g = -4*r - 16 - 17 para r. +-2 +Resolve 4*q - 26*r + 4 = -30*r, -3*q - 3 = -2*r para q. +-1 +Resolve -x - 25 = -5*q, -q + 19 = -8*x + 5*x para x. +-5 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/algebra__linear_2d_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/algebra__linear_2d_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..52bc281cabe5231de1efc744c893775574303f1c --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/algebra__linear_2d_composed.txt @@ -0,0 +1,6 @@ +Supõe 0 = -14*p + 16*p - 6. Supõe -5*x + 6 = 1. Resolve -q - 5 = -3*v - p*q, -3*v + 2*q = -x para v. +1 +Assume que q é 6*1/(6/4). Supõe -3*t + 8 + q = 0. Resolve n - o = -0*n + 4, 0 = t*n - 2*o - 12 para n. +2 +Seja f(k) = 4 - k. Supõe -4*s + 7 = -5. Assume que v é ((0 - s) + 1)/(-1). Seja i, f(v). Resolve i*c = d + 4, -3*c - c + 28 = 3*d para c. +4 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/algebra__polynomial_roots.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/algebra__polynomial_roots.txt new file mode 100644 index 0000000000000000000000000000000000000000..4977f02f633e4244b2dbc8d60679a7ea002d0740 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/algebra__polynomial_roots.txt @@ -0,0 +1,6 @@ +Determina q para que -q**3/6 + 5*q**2/6 + 3*q/2 - 15/2 = 0. +-3, 3, 5 +Seja -4*a**5 - 20*a**4 + 48*a**3 + 176*a**2 - 320*a = 0. Qual é a? +-5, -4, 0, 2 +Qual é o valor de o em -3*o**4/7 + 15*o**3 - 1287*o**2/7 + 6171*o/7 - 7986/7 = 0? +2, 11 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/algebra__polynomial_roots_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/algebra__polynomial_roots_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..586339590f4cc051af5a656a483d0905f63d0cb0 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/algebra__polynomial_roots_composed.txt @@ -0,0 +1,6 @@ +Seja c(k) = 12 - k. Supõe -4*v = -v - 5*y - 42, -4*y = 2*v - 6. Seja j, c(v). Determina q para que 2*q**5 + 2*q**j - q**4 - 2*q**4 - q**4 = 0. +0, 1 +Seja b(r) = -7*r**2 + 2*r + 5. Seja x(h) a primeira derivada de 0*h**2 - 1/3*h**3 + h + 2. Seja v(j) = b(j) - 5*x(j). Factoriza v(o). +-2*o*(o - 1) +Assume que u é 11/(-4) + 2 - -1. Supõe 4*b - 32 = 5*d, -3*b - 3*d + 5 = -2*d. Seja u*n + 0 + n**2 - 3/4*n**5 - n**4 + 1/2*n**b = 0. Calcula n. +-1, -1/3, 0, 1 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/algebra__sequence_next_term.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/algebra__sequence_next_term.txt new file mode 100644 index 0000000000000000000000000000000000000000..9602469aa0d444a1345df4b563c8156f0f8900b2 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/algebra__sequence_next_term.txt @@ -0,0 +1,6 @@ +O que vem a seguir: 105, 210, 315, 420, 525, 630? +735 +Qual é o termo seguinte em -870, -866, -862, -858, -854, -850? +-846 +Qual é o termo seguinte em -33, -105, -225, -393, -609, -873? +-1185 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/algebra__sequence_nth_term.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/algebra__sequence_nth_term.txt new file mode 100644 index 0000000000000000000000000000000000000000..72a84c28468cae08bd23bd29a7af4f3bbf2ed40f --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/algebra__sequence_nth_term.txt @@ -0,0 +1,6 @@ +Qual é termo nº x na sequência -118, -114, -108, -100, -90, -78, -64? +x**2 + x - 120 +Qual é termo nº z na sequência 2183, 2168, 2151, 2132? +-z**2 - 12*z + 2196 +Qual é termo nº l na sequência -176, -303, -430, -557, -684, -811? +-127*l - 49 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/arithmetic__add_or_sub.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/arithmetic__add_or_sub.txt new file mode 100644 index 0000000000000000000000000000000000000000..5758c4d22041cbe90b84b0ac7de5bb9a6e51575a --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/arithmetic__add_or_sub.txt @@ -0,0 +1,6 @@ +Junta -0.693 e -16. +-16.693 +Quanto é -1.82 menos -0.2456? +-1.5744 +0.01526 + 0.027 +0.04226 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/arithmetic__add_or_sub_in_base.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/arithmetic__add_or_sub_in_base.txt new file mode 100644 index 0000000000000000000000000000000000000000..25e8f607cfdc5213c3686c44bc43ebb125ecfe43 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/arithmetic__add_or_sub_in_base.txt @@ -0,0 +1,6 @@ +Em base 10, quanto é -414 - 11? +-425 +Em base 10, quanto é -4556 + -4? +-4560 +Em base 6, quanto é -5513 - -15? +-5454 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/arithmetic__add_sub_multiple.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/arithmetic__add_sub_multiple.txt new file mode 100644 index 0000000000000000000000000000000000000000..6a57898a4905731f2cbeb6c37b6bfb03d8420a92 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/arithmetic__add_sub_multiple.txt @@ -0,0 +1,6 @@ +Avalia 9 - (6 + 8 + -6). +1 +Calcula (5 - -2) + -4 + -3. +0 +Calcula (10 - 10) + -12 - -5. +-7 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/arithmetic__div.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/arithmetic__div.txt new file mode 100644 index 0000000000000000000000000000000000000000..7da14153fca4e3f8da600f0a7e4a01678bca9b81 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/arithmetic__div.txt @@ -0,0 +1,6 @@ +Quanto é -610 dividido por 5? +-122 +-1 dividido por 8362 +-1/8362 +Quanto é 539 dividido por 11? +49 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/arithmetic__mixed.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/arithmetic__mixed.txt new file mode 100644 index 0000000000000000000000000000000000000000..ff2c591e10dc02d12ba305188c617971fff3feaf --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/arithmetic__mixed.txt @@ -0,0 +1,6 @@ +Avalia 62/84 + (-12)/63*3. +1/6 +Calcula ((-16)/(-30))/(16/(-6) - -2). +-4/5 +((-8)/1 + 4)*(-1)/(-2) +-2 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/arithmetic__mul.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/arithmetic__mul.txt new file mode 100644 index 0000000000000000000000000000000000000000..9e9f4433ef6e5ff5729a66d427c6223ddac79b73 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/arithmetic__mul.txt @@ -0,0 +1,6 @@ +Multiplica -27 e 0.3. +-8.1 +Quanto é -0.35 vezes -2? +0.7 +Quanto é -255 vezes -6? +1530 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/arithmetic__mul_div_multiple.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/arithmetic__mul_div_multiple.txt new file mode 100644 index 0000000000000000000000000000000000000000..09f618ab238b2ffc3583216b172ca4aa677e3109 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/arithmetic__mul_div_multiple.txt @@ -0,0 +1,6 @@ +Calcula ((-6)/10)/((-264)/352). +4/5 +0*20/(-8)*2/10 +0 +Quanto é -12*((-2)/(-5))/((-66)/55)? +4 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/arithmetic__nearest_integer_root.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/arithmetic__nearest_integer_root.txt new file mode 100644 index 0000000000000000000000000000000000000000..7f11b52849458fbf1d5d6f76fa1829b297f0660e --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/arithmetic__nearest_integer_root.txt @@ -0,0 +1,6 @@ +Quanto é 1093 elevado a 1/7, arredondado para o inteiro mais próximo? +3 +Qual é a quarta raíz de 811 arredondada para o inteiro mais próximo? +5 +Quanto é 21605 elevado a 1/2, arredondado para o inteiro mais próximo? +147 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/arithmetic__simplify_surd.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/arithmetic__simplify_surd.txt new file mode 100644 index 0000000000000000000000000000000000000000..d5499b56794d8d6a47ab96eb6a108b8df2486fa5 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/arithmetic__simplify_surd.txt @@ -0,0 +1,6 @@ +Simplificar sqrt(2)*1 + -3 - sqrt(2) - -6*sqrt(32). +-3 + 24*sqrt(2) +Simplificar -3 + (sqrt(2) - (sqrt(6)/sqrt(3) + sqrt(2)))**2 + sqrt(2) + -3. +-4 + sqrt(2) +Simplificar sqrt(27)/(sqrt(576) - sqrt(36)). +sqrt(3)/6 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/calculus__differentiate.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/calculus__differentiate.txt new file mode 100644 index 0000000000000000000000000000000000000000..6ffbca9358104ae33be86f83aeeea6a1206d7e21 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/calculus__differentiate.txt @@ -0,0 +1,6 @@ +Encontra a terceira derivada de 609*s**4 + 2*s**2 + 292 em relação a s. +14616*s +Encontra a terceira derivada de 150*o**4 + 8*o**3 + 1830*o**2 em relação a o. +3600*o + 48 +Encontra a terceira derivada de 650*d**3*h**3 - 2*d**2*h**3 - 102*h**2 em relação a d. +3900*h**3 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/calculus__differentiate_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/calculus__differentiate_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..102452c264059bdcd44070af862dedba464b44c4 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/calculus__differentiate_composed.txt @@ -0,0 +1,6 @@ +Seja n(s) = 2*s - 2. Seja o(q) a primeira derivada de 2*q**2 - 5*q + 3. Seja p(u) = 7*n(u) - 3*o(u). Qual é a derivada de p(r) em relação a r? +2 +Seja d(u) a terceira derivada de -7*u**5/60 - 7*u**3/6 + 40*u**2. Qual é a primeira derivada de d(o) em relação a o? +-14*o +Seja f(l) a segunda derivada de 0*l**3 + 1/4*l**4 - 3/20*l**5 + 0 + 0*l**2 - 3*l. Encontra a terceira derivada de f(q) em relação a q. +-18 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/comparison__closest.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/comparison__closest.txt new file mode 100644 index 0000000000000000000000000000000000000000..fb2d98724cac45b5dee15f6671a72fe04895ab89 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/comparison__closest.txt @@ -0,0 +1,6 @@ +Qual valor está mais perto de -39 em -1/3, -1/8, -3? +-3 +Qual está mais próximo de 2? (a) 2/9 (b) 13 (c) 1/2 +c +Qual está mais próximo de 0.1? (a) -2 (b) 5/6 (c) -4 +b diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/comparison__closest_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/comparison__closest_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..131b92a45b61744849f149bdb1be0ffeb9d4483f --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/comparison__closest_composed.txt @@ -0,0 +1,6 @@ +Seja u = 0 + 2. Assume que q é ((-1)/3)/(66/81). Seja m = 12/11 - q. Qual valor está mais perto de 0.1 em u, m, -4? +m +Seja r = -179 - -109. Assume que u é 15/3*4/r. Qual valor está mais próximo de 0.1 em u, 2, -0.3? +u +Seja v = -5/21 + -2/21. Supõe k - 5*x + 5 = -0*k, k = -3*x + 3. Supõe -8 - 12 = -4*i. Qual valor está mais próximo de k em v, i, 2/5? +v diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/comparison__kth_biggest.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/comparison__kth_biggest.txt new file mode 100644 index 0000000000000000000000000000000000000000..498c08655481e9de9bc82ff4884d454925dc356d --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/comparison__kth_biggest.txt @@ -0,0 +1,6 @@ +Qual é o terceiro maior valor em 0.3, 1/6, -7.19? +-7.19 +Qual valor é maior? (a) -0.3 (b) -332 (c) -3 +a +Qual é o segundo menor valor em 9, 36/5, 4, 0.3? +4 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/comparison__kth_biggest_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/comparison__kth_biggest_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..f83bb111d2ac9108f23fdeccb80ffe60810a7790 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/comparison__kth_biggest_composed.txt @@ -0,0 +1,6 @@ +Seja g = -1.3 - 2.7. Qual valor é terceiro menor? (a) g (b) 2/15 (c) 0.4 +c +Seja t(k) = -3*k - 4. Seja u, t(-3). Seja y(q) = 2*q**2 + 4*q. Seja z, y(u). Assume que i é (-6)/z + 2/7. Qual valor é segundo menor? (a) 1/6 (b) -4 (c) i +a +Seja w = -1.54 + 1.4. Qual valor é maior? (a) w (b) -2/9 (c) -1/3 +a diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/comparison__pair.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/comparison__pair.txt new file mode 100644 index 0000000000000000000000000000000000000000..4e2e3d939953f1b224d26a1281c7e2389caa94ab --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/comparison__pair.txt @@ -0,0 +1,6 @@ +Será -15 menor do que -213/13? +False +Qual é menor: 218/27 ou 7? +7 +Qual é menor: 1885/2 ou -0.1? +-0.1 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/comparison__pair_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/comparison__pair_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..47739452ef78df81925c04d0592929aa95341b7c --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/comparison__pair_composed.txt @@ -0,0 +1,6 @@ +Seja q = 7 + 1. Assume que o é q/6*(-3)/22. Assume que r é (-3 + 15/3)/(-2). Qual é menor: o ou r? +r +Seja m(r) = r**3 + 5*r**2 + 5*r - 10 + 6 - 2*r. Seja c, m(-3). Supõe c*g = 2*z + 4, -3*z - z = 2*g - 16. Será z, no máximo, 2? +False +Supõe 0 = 4*z + 4*v + 4, z = 4*z + v + 1. Será -9/7, no máximo, tão grande quanto z? +True diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/comparison__sort.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/comparison__sort.txt new file mode 100644 index 0000000000000000000000000000000000000000..1c497b6a49731df89f0e5c2c56b5bd2d17afe518 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/comparison__sort.txt @@ -0,0 +1,6 @@ +Ordena -1.5, 2, 4. +-1.5, 2, 4 +Coloca -41/3, 2/9, -0.3, 0.4, 3 em ordem crescente. +-41/3, -0.3, 2/9, 0.4, 3 +Ordena 1/5, -107, 0.5. +-107, 1/5, 0.5 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/comparison__sort_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/comparison__sort_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..8ffadb65a96a18760f1addb11fbbd8fded90e0c3 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/comparison__sort_composed.txt @@ -0,0 +1,6 @@ +Seja m(z) = -z**2 + 4*z + 1. Seja w, m(4). Seja r(o) = -4*o**3 - 2*o - 1. Seja p, r(-1). Supõe 2*v = p*v + 3. Ordena 2, v, w por ordem ascendente. +v, w, 2 +Seja r(c) = c**3 - 6*c**2 + c - 2. Seja d, r(6). Supõe -3*g + d = 1. Coloca g, -2, 4 em ordem decrescente. +4, g, -2 +Seja u = 2.6 + -3.5. Ordena u, 4, 5 por ordem ascendente. +u, 4, 5 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/measurement__conversion.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/measurement__conversion.txt new file mode 100644 index 0000000000000000000000000000000000000000..019d468997439c23aaa5847473f82557429494cf --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/measurement__conversion.txt @@ -0,0 +1,6 @@ +Quantos(as) micrómetros estão em 1/10 de um(a) metro? +100000 +Quantos(as) décadas estão em 479.9781 milénios? +47997.81 +Quanto é 5.716473 litros em mililitros? +5716.473 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/measurement__time.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/measurement__time.txt new file mode 100644 index 0000000000000000000000000000000000000000..39b3b327d796151da05baa20f8ab2de2f3c355e2 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/measurement__time.txt @@ -0,0 +1,6 @@ +O que é 171 minutos despois de 3:12 AM? +6:03 AM +Quantos minutos existem entre 2:28 AM e 9:53 AM? +445 +Quantos minutos existem entre 6:00 AM e 11:24 AM? +324 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__base_conversion.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__base_conversion.txt new file mode 100644 index 0000000000000000000000000000000000000000..e1f9ec722c6e5001784ac18b68c12a1ac54e2154 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__base_conversion.txt @@ -0,0 +1,6 @@ +Quanto é -d (base 15) em base 13? +-10 +-7 (em base 8) para base 12 +-7 +Converte 7 (em base 12) para base 8. +7 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__div_remainder.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__div_remainder.txt new file mode 100644 index 0000000000000000000000000000000000000000..2286b1ea54d3158b6ebdbdeabdf8f3ade3c306f0 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__div_remainder.txt @@ -0,0 +1,6 @@ +Qual é o resto da divisão entre 270 e 50? +20 +Calcula o resto da divisão entre 217 e 14. +7 +Calcula o resto da divisão entre 4229 e 90. +89 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__div_remainder_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__div_remainder_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..7625eeb8a890a1aec90a9db5f17ab61b396ca574 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__div_remainder_composed.txt @@ -0,0 +1,6 @@ +Supõe -10 = -5*m + q + 203, -q - 45 = -m. Calcula o resto da divisão entre 125 e m. +41 +Seja s = 36 - 24. Seja g = s + 8. Seja j = -14 + 21. Qual é o resto da divisão entre g e j? +6 +Seja g = 91 - 64. Seja u = 16 - g. Seja c = u - -26. Calcula o resto da divisão entre c e 8. +7 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__gcd.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__gcd.txt new file mode 100644 index 0000000000000000000000000000000000000000..7835f31d9c1be3886e1ecad768992385c66a08c7 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__gcd.txt @@ -0,0 +1,6 @@ +Qual é o maior fator comum de 1012 e 736? +92 +Calcula o maior divisor comum de 175 e 200. +25 +Calcula o maior divisor comum de 5668 e 52. +52 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__gcd_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__gcd_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..2b9ab4c46e30ed2a7dbe6f643c2e73db8390c582 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__gcd_composed.txt @@ -0,0 +1,6 @@ +Supõe 5*q = -4*u, -2*u - 2*q = 3*u. Supõe u = -5*v - 0*v. Supõe v = -5*b - 3 + 23. Calcula o maior divisor comum de b e 2. +2 +Supõe 0 = 24*s - 62 - 106. Qual é o maior fator comum de s e 2? +1 +Seja j(q) = 54*q + 16. Seja y, j(5). Calcula o maior fator comum de 22 e y. +22 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__is_factor.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__is_factor.txt new file mode 100644 index 0000000000000000000000000000000000000000..626f11f4dd3b012d77b87b18c0bace88d5e32e87 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__is_factor.txt @@ -0,0 +1,6 @@ +Será 518 um múltiplo de 37? +True +Será que 24 divide 8194? +False +Será 18 um fator de 318? +False diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__is_factor_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__is_factor_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..151a3146044d15f63cd95b219c56c8b703bcb10c --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__is_factor_composed.txt @@ -0,0 +1,6 @@ +Seja h = 14 - -8. Supõe h = -3*w + 91. Será 14 um fator de w? +False +Assume que n é 0/(-2)*2/4. Seja i = 9 - n. Seja x = i + 26. Será x um múltiplo de 17? +False +Seja m = 9 + -4. Supõe -m*q + 190 + 40 = 5*d, 0 = -4*d - 2*q + 194. Será d um múltiplo de 24? +False diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__is_prime.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__is_prime.txt new file mode 100644 index 0000000000000000000000000000000000000000..1d4ca1f78dcb51f905e387325ff2c9197c0d8957 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__is_prime.txt @@ -0,0 +1,6 @@ +Será 553 um número primo? +False +Será 139114 um número primo? +False +Será 21251 compósito? +True diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__is_prime_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__is_prime_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..458f9e6ce04c56dae41aa133f6f42b1def77c297 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__is_prime_composed.txt @@ -0,0 +1,6 @@ +Assume que n é 21/(2/4 - 2). Seja g(j) = -j - 9. Seja u, g(-6). Será (n/u)/(-2)*-3 um número primo? +True +Seja t = 9 + -15. Seja x(z) = z**2 - z - z + 9 + z + 6*z. Será x(t) um número compósito? +True +Será (-10820)/(-3) - 26/(-78) primo? +True diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__lcm.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__lcm.txt new file mode 100644 index 0000000000000000000000000000000000000000..92b2d5398ec5d5d2653c1b5c78b1f1d749b8c3f4 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__lcm.txt @@ -0,0 +1,6 @@ +Calcula o denominador comum de 33/224 e 121/1120. +1120 +Calcula o menor múltiplo comum de 1130 e 8. +4520 +Calcula o menor múltiplo comum de 1792 e 512. +3584 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__lcm_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__lcm_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..945eddc0738686ec65f61f758dbfe57b2fc8594f --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__lcm_composed.txt @@ -0,0 +1,6 @@ +Assume que w é 1/3*(9 + 0). Calcula o denominador comum de 77/18 e (-1)/3 - w/2. +18 +Supõe -35 - 5 = -4*t. Supõe 15 = -4*q + j, 0*q = -4*q + 4*j - 12. Calcula o menor múltiplo comum de ((-2)/q)/((-4)/(-176)) e t. +110 +Seja n(r) = 5 - 8*r. Seja q(u) = u - 1. Seja o(c) = -2*n(c) - 18*q(c). Seja t, o(10). Qual é o denominador comum de (17/20)/(t/(-30)) e 29/9? +72 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__list_prime_factors.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__list_prime_factors.txt new file mode 100644 index 0000000000000000000000000000000000000000..9c774be667e4466bccbc806685bef00599ae270c --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__list_prime_factors.txt @@ -0,0 +1,6 @@ +Quais são os fatores primos 235? +5, 47 +Enumera os fatores primos de 675. +3, 5 +Quais são os fatores primos 654? +2, 3, 109 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__list_prime_factors_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__list_prime_factors_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..f39a0df901cdcddb918e437b73cdbf7e0f7f9885 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__list_prime_factors_composed.txt @@ -0,0 +1,6 @@ +Seja j(g) = g + 11. Seja q(d) = -d**2 - 5*d + 1. Supõe -4*r + 1 = -3*r, -2*l + 5*r = 17. Seja n, q(l). Quais são os fatores primos j(n)? +2, 3 +Assume que y é -4 + 1 + 78/2. Supõe -4*i = -0*i - y. Enumera os fatores primos de i. +3 +Assume que w é 7/14*(-4 + 0). Seja i(t) = 3*t**2 + 2*t - 2. Quais são os fatores primos i(w)? +2, 3 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__place_value.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__place_value.txt new file mode 100644 index 0000000000000000000000000000000000000000..d720c42af9c9f56a5fea035704e30e62d7f38f7e --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__place_value.txt @@ -0,0 +1,6 @@ +Qual é o dígito das dezena milhares de 54091? +5 +Qual é o dígito das milhares de 2360? +2 +Qual é o dígito das dezenas de 5670? +7 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__place_value_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__place_value_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..9f3e466e668ad4c24f70c33f0d98975d48b41412 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__place_value_composed.txt @@ -0,0 +1,6 @@ +Qual é o dígito das unidades de 1815/(-66)*-8*(-2)/(-10)? +4 +Seja u = -13 - -32. Qual é o dígito das unidades de u? +9 +Seja b(x) = -x**2 + x + 9. Seja h(j) = 8 - j**2. Seja u(s) = 4*b(s) - 5*h(s). Qual é o dígito das unidades de u(-5)? +1 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__round_number.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__round_number.txt new file mode 100644 index 0000000000000000000000000000000000000000..2e3defa7b806c5efa300edd3b2bdf0ac481cda3e --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__round_number.txt @@ -0,0 +1,6 @@ +Quanto é -0.00716 arredondado para as casa decimal das quatros? +-0.0072 +Quanto é 510600 arredondado para as um centena milhar mais próxima? +500000 +Arredonda -0.00595 para as casa decimal das quatros. +-0.006 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__round_number_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__round_number_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..eeaf083272808d65353a315119fa3fec40caa341 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/numbers__round_number_composed.txt @@ -0,0 +1,6 @@ +Supõe -8654 = -5*x - 4*a + 3*a, 2*x = a + 3456. Arredonda x para as 100 mais próxima. +1700 +Supõe q = 3 + 126. Quanto é q arredondado para as dez mais próxima? +130 +Seja x = 515 - 353. Seja p = -162.0091 + x. Arredonda p para as casa decimal das 3s. +-0.009 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/polynomials__add.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/polynomials__add.txt new file mode 100644 index 0000000000000000000000000000000000000000..e555015086f2a664e728f98500bb25f1f2f0de98 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/polynomials__add.txt @@ -0,0 +1,6 @@ +Seja n(b) = -b**2 + b - 1. Seja u(t) = 2 + 15*t**2 + 0 - 7 + 6*t - 19*t**2. Supõe -w - 4*d - 14 = 0, 6 = -w - 2*d - 2. Determina w*u(q) + 10*n(q). +-2*q**2 - 2*q +Seja a(u) = -4*u - 6. Seja z, a(-3). Seja o(h) = 4*h**2 - 3. Seja y(i) = 7 - 9*i**2. Obtém z*y(g) + 14*o(g). +2*g**2 +Seja f = -17 + 10. Seja o(s) = 5*s**3 + 6. Supõe -5*v + 0*n = -n - 20, v - 4*n = 4. Seja y(b) = -v + 11 + b**3 + 5*b**3. Determina f*o(c) + 6*y(c). +c**3 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/polynomials__coefficient_named.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/polynomials__coefficient_named.txt new file mode 100644 index 0000000000000000000000000000000000000000..df2a6da230fb3a58f09593a9c2c2925764045139 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/polynomials__coefficient_named.txt @@ -0,0 +1,6 @@ +Rearranja -o + 26*o**2 + 17*o**3 + 27*o**2 + 26*o**2 - 78*o**2 - 3 como j + y*o**2 + w*o + g*o**3 e dá y. +1 +Rearranja -6*o**2 - 42*o**2 + 15*o**2 na forma x + p*o**2 + g*o e dá p. +-33 +Expressa -1 + 41*n**2 - 3*n**4 + 0 - 2*n - 43*n**2 como j + y*n**4 + i*n**3 + d*n + t*n**2 e dá y. +-3 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/polynomials__collect.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/polynomials__collect.txt new file mode 100644 index 0000000000000000000000000000000000000000..db737118caa48d237e0265de2ab96f0e4d6eb545 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/polynomials__collect.txt @@ -0,0 +1,6 @@ +Coleta os termos em 57*o - 36*o + 3*o**2 - 21*o. +3*o**2 +Coleta os termos em 3*i + 35*i**3 - 29*i**3 - 9*i**3 - 3*i. +-3*i**3 +Coleta os termos em -14*q**3 + 18*q**3 - 2*q**2 + 2*q**2. +4*q**3 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/polynomials__compose.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/polynomials__compose.txt new file mode 100644 index 0000000000000000000000000000000000000000..d1c7305da642c590c9535a18edd84374dc4d566c --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/polynomials__compose.txt @@ -0,0 +1,6 @@ +Seja n(a) = -7*a. Seja v(d) = -d**3 + 9*d**2 + d - 7. Seja w, v(9). Assume que p é (-4)/5*(-5)/2. Seja q(s) = -s**p + s**w - 2*s**2. O que é q(n(x))? +-98*x**2 +Seja k(c) a segunda derivada de 3*c**4/4 - 4*c. Seja r(i) = -2*i**2 + 2*i + 2. Seja m(u) = u + 1. Seja s(h) = 2*m(h) - r(h). O que é s(k(n))? +162*n**4 +Seja u(i) = i**2. Seja y(v) a terceira derivada de 0 + 1/20*v**5 + 0*v**4 + 7*v**2 + 0*v + 0*v**3. Determina u(y(j)). +9*j**4 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/polynomials__evaluate.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/polynomials__evaluate.txt new file mode 100644 index 0000000000000000000000000000000000000000..fce27889b9bbe36616b56c50ebee074a29a89d48 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/polynomials__evaluate.txt @@ -0,0 +1,6 @@ +Seja r(x) = -x**2 - 18*x - 15. Determina r(-18). +-15 +Seja f(n) = -3*n**2 - 23*n - 1. Obtém f(-7). +13 +Seja v(t) = 8 - 2*t**2. O que é v(6)? +-64 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/polynomials__evaluate_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/polynomials__evaluate_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..ac929730793ad07e365a10052f0ce4412e900b41 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/polynomials__evaluate_composed.txt @@ -0,0 +1,6 @@ +Assume que w é (-2)/7 + (-40)/7. Seja p(l) = -636*l + 159*l + 158*l + 164*l + 9 + 154*l. Determina p(w). +15 +Seja l(h) = h**2 - 5*h + 4. Seja f(v) = 3*v**2 - 14*v + 13. Seja d(a) = 2*f(a) - 7*l(a). O que é d(6)? +4 +Seja m(w) = -w**2 + w + 4. Seja q, m(0). Supõe -5*b = -u - 5, -2*b - 3*u + 3 = b. Seja o(i) = 2 + i - 3 - b. Determina o(q). +2 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/polynomials__expand.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/polynomials__expand.txt new file mode 100644 index 0000000000000000000000000000000000000000..f5e522382735c6538a2533d6468b68707ddd7262 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/polynomials__expand.txt @@ -0,0 +1,6 @@ +Expande (m - 1 + 1)*(-m**2 + 13*m**2 - 2*m**2 + (5*m - 5*m + 2*m)*(m - 2*m + 2*m)). +12*m**3 +Expande ((2*x + 1 - 1)*(3*x - x - x) + 3*x**2 - x**2 - 3*x**2)*(-x - 2*x**2 + 6*x - 2*x). +-2*x**4 + 3*x**3 +Expande (4*g**3 + 0*g**3 - 5*g**3)*(g - g - 2*g**2) + (12*g**3 + 16*g**3 - 6*g**3)*(0*g**2 - g**2 - g**2). +-42*g**5 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/polynomials__simplify_power.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/polynomials__simplify_power.txt new file mode 100644 index 0000000000000000000000000000000000000000..9e774df2b07f43d71e52fb58959006948bed8437 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/polynomials__simplify_power.txt @@ -0,0 +1,6 @@ +Simplifica r*r**(-16)*r**(-1/7)*r assumindo que r é positiva. +r**(-99/7) +Simplifica ((k*k**7*k)/(k**(-1/5)*k))**(-1/4) assumindo que k é positiva. +k**(-41/20) +Simplifica (j/(j/(((j*j**(-2/23))/j)/j)))**(-3/4) assumindo que j é positiva. +j**(75/92) diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/probability__swr_p_level_set.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/probability__swr_p_level_set.txt new file mode 100644 index 0000000000000000000000000000000000000000..5fac816956e67ab7f76b45a9499485e9b6d6905d --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/probability__swr_p_level_set.txt @@ -0,0 +1,6 @@ +Calcula da probabilidade de(a) escolher 2 k quando dois caractéres são escolhidos sem reposição de {k: 2, o: 3}. +1/10 +Calcula da probabilidade de(a) escolher 4 h quando quatro caractéres são escolhidos sem reposição de {t: 7, h: 2}. +0 +Calcula da probabilidade de(a) escolher 2 e e 1 d quando três caractéres são escolhidos sem reposição de eeeccctegccdceeect. +7/272 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-easy/probability__swr_p_sequence.txt b/mathematics_dataset/mathematics_dataset/ds/train-easy/probability__swr_p_sequence.txt new file mode 100644 index 0000000000000000000000000000000000000000..974506f5fcf2f627f92bf3c337b96312623d198c --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-easy/probability__swr_p_sequence.txt @@ -0,0 +1,6 @@ +Qual é a probabilidade de(a) sequência hm quando dois caractéres são escolhidos sem reposição de {q: 1, h: 11, m: 7}? +77/342 +Quatro caractéres são escolhidos sem reposição de alkkkslkkkeaaaahs. Qual é a probabilidade de(a) sequência eksa? +1/952 +Quatro caractéres são escolhidos sem reposição de hnznjzq. Dá a probabilidade de(a) sequência nzhj. +1/210 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/algebra__linear_1d.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/algebra__linear_1d.txt new file mode 100644 index 0000000000000000000000000000000000000000..0281162cdafbb92712aefcb3212c1441956f4d53 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/algebra__linear_1d.txt @@ -0,0 +1,6 @@ +Resolve -2532*x + 68646 - 953 = -8077 - 15382 para x. +36 +Resolve -8075*a + 2436 = -8423*a para a. +-7 +Resolve -2741574*o - 26705 = -2742119*o para o. +49 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/algebra__linear_1d_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/algebra__linear_1d_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..090b210da868cdf5208999f0cd11770b8ad9e36c --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/algebra__linear_1d_composed.txt @@ -0,0 +1,6 @@ +Seja f = -77 + 81. Seja o(z) = -z**3 + 13*z**2 - 22*z + 2. Seja q, o(11). Supõe -4*c + x + 4 = 0, -3*c + 4*x = -q*c - 16. Resolve -h + c*h + f = 0 para h. +4 +Supõe 12*t = -6*t + 486. Seja o = -23 + t. Resolve m + 9 = o*m para m. +3 +Seja o(d) = 543*d + 8. Seja q, o(1). Seja u = q - 543. Resolve 0 = u*v - 41 + 1 para v. +5 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/algebra__linear_2d.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/algebra__linear_2d.txt new file mode 100644 index 0000000000000000000000000000000000000000..88e86f0c3f3e002698f2b54920053e5e884737de --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/algebra__linear_2d.txt @@ -0,0 +1,6 @@ +Resolve 0 = -4*w + 5*j - 12, w + 4*j = 5*w + 626 - 614 para w. +-3 +Resolve -1076392*x + 1076395*x + 44 = -5*b, -3*b = 23*x + 514 para x. +-23 +Resolve -11*n - 64*w + 30*w = -29*w - 165, 3*n + 3*w = 45 para n. +15 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/algebra__linear_2d_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/algebra__linear_2d_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..e809ed5854e9004aac9278a2dae0c2852af610d2 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/algebra__linear_2d_composed.txt @@ -0,0 +1,6 @@ +Supõe 0 = -17*c + 16*c + 16. Supõe v = -2*n + 11, -5*n + c + 8 = -v. Resolve 0 = 5*w - m - m - 3, 4*m = -w + n para w. +1 +Supõe 5 = 5*o, -o = -2*d + 3*o + 6. Supõe -5*r = d*r - 3*r. Resolve r = w + 5*u - 3, 4 = -2*w + 2*u - 2 para w. +-2 +Supõe 27*g - 3*g - 92 - 4 = 0. Resolve 22*z - 25*z + 5*n = 40, z - g*n + 25 = 0 para z. +-5 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/algebra__polynomial_roots.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/algebra__polynomial_roots.txt new file mode 100644 index 0000000000000000000000000000000000000000..071f9f1f561400efbe033c5280d6fc59275b2166 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/algebra__polynomial_roots.txt @@ -0,0 +1,6 @@ +Factoriza w**2/2 - 318351*w - 3183535/2. +(w - 636707)*(w + 5)/2 +Factoriza -32*q**3 - 131363*q**2 - 143643*q - 12312. +-(q + 1)*(q + 4104)*(32*q + 3) +Factoriza c**3 - 5650*c**2 + 9789632*c - 4774711808. +(c - 2416)**2*(c - 818) diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/algebra__polynomial_roots_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/algebra__polynomial_roots_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..dc27c88b8f6875b73805ade88d37c2234bc2b686 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/algebra__polynomial_roots_composed.txt @@ -0,0 +1,6 @@ +Seja n = -920966/7 - -131570. Resolve 6/7*s**4 - 3/7*s**5 - 6/7 + 6/7*s**3 + 3*s - n*s**2 = 0 em relação a s. +-2, 1 +Seja t(a) a segunda derivada de a**4/4 + 26*a**3 + 153*a**2/2 + 15*a - 1. Encontra w tal que t(w) = 0. +-51, -1 +Supõe 0 = -2*q + 7*q + 4*l + 570, -25 = 5*l. Assume que s é (5/q)/(2/(-8)). Factoriza 0*n + 2/11 - s*n**2. +-2*(n - 1)*(n + 1)/11 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/algebra__sequence_next_term.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/algebra__sequence_next_term.txt new file mode 100644 index 0000000000000000000000000000000000000000..fd49848d1d7a417ef085d4431752719d8810fa7e --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/algebra__sequence_next_term.txt @@ -0,0 +1,6 @@ +O que se segue em 96679, 192327, 287975? +383623 +O que se segue em 67384555, 67384570, 67384593, 67384624, 67384663? +67384710 +O que se segue em -854936, -854939, -854942? +-854945 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/algebra__sequence_nth_term.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/algebra__sequence_nth_term.txt new file mode 100644 index 0000000000000000000000000000000000000000..e564632d61976acff24ba4152591cf433df8e29a --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/algebra__sequence_nth_term.txt @@ -0,0 +1,6 @@ +Qual é termo nº w na sequência 15613, 58800, 130777, 231544, 361101, 519448, 706585? +14395*w**2 + 2*w + 1216 +Qual é termo nº q na sequência 92542, 185776, 279010, 372244, 465478, 558712? +93234*q - 692 +Qual é termo nº c na sequência 5031, 20167, 45405, 80745, 126187, 181731, 247377? +5051*c**2 - 17*c - 3 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/arithmetic__add_or_sub.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/arithmetic__add_or_sub.txt new file mode 100644 index 0000000000000000000000000000000000000000..97e10586fe2c71650b26b0aae2fe091cbd799428 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/arithmetic__add_or_sub.txt @@ -0,0 +1,6 @@ +Subtrai 0.14 de -3410.1745224. +-3410.3145224 +Qual é a distância entre -729.9 e 55330904? +55331633.9 +Calcula 1160326990177 - -178. +1160326990355 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/arithmetic__add_or_sub_in_base.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/arithmetic__add_or_sub_in_base.txt new file mode 100644 index 0000000000000000000000000000000000000000..fa17606b91c001651d825783d709db899ed468f7 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/arithmetic__add_or_sub_in_base.txt @@ -0,0 +1,6 @@ +Em base 6, quanto é -10004225 - 4? +-10004233 +Em base 16, quanto é 50eb + 7a4? +588f +Em base 15, quanto é -12c9 - 2045? +-331e diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/arithmetic__add_sub_multiple.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/arithmetic__add_sub_multiple.txt new file mode 100644 index 0000000000000000000000000000000000000000..996d9d617abb03edd0fda5d6ec57f6004427a5d6 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/arithmetic__add_sub_multiple.txt @@ -0,0 +1,6 @@ +2 + 2 - (0 + (-9 - 7) + -5 + 145) +-120 +Quanto é 23 - 0 - (-9 + (26 - -50))? +-44 +Avalia -76 - (45 + -139) - (-22 - -2). +38 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/arithmetic__div.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/arithmetic__div.txt new file mode 100644 index 0000000000000000000000000000000000000000..54fe837b4d4b04986faedaac3869f68dc32d6d87 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/arithmetic__div.txt @@ -0,0 +1,6 @@ +100734 dividido por -1 +-100734 +Divide -4 por 827002. +-2/413501 +Divide -19108613 por 15. +-19108613/15 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/arithmetic__mixed.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/arithmetic__mixed.txt new file mode 100644 index 0000000000000000000000000000000000000000..31112670a60a75bc4d7e8fc641e3673874fcfd0a --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/arithmetic__mixed.txt @@ -0,0 +1,6 @@ +Quanto é 16 + (31005/636)/((-342)/112)? +2/57 +(-135)/(-2)*(45 - 1197/27) +45 +(-355)/(-213)*(-2 + -7) + (-204)/(-4) +36 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/arithmetic__mul.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/arithmetic__mul.txt new file mode 100644 index 0000000000000000000000000000000000000000..d84806ca5d25b95e03ca9bdc6f776e3e1b3036fa --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/arithmetic__mul.txt @@ -0,0 +1,6 @@ +0.006985283*0.1 +0.0006985283 +Quanto é 0.7 vezes 385248? +269673.6 +-264428119*-0.5 +132214059.5 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/arithmetic__mul_div_multiple.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/arithmetic__mul_div_multiple.txt new file mode 100644 index 0000000000000000000000000000000000000000..2ab695779ff45fe66157c26d2d4fe94dce0b90a5 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/arithmetic__mul_div_multiple.txt @@ -0,0 +1,6 @@ +Avalia (((-12627)/(-276))/3)/(2/(-8)). +-61 +Qual é o valor de 10*(-2)/(-570)*((-1)/3)/(21/189)? +-2/19 +Quanto é 1*60/(-11520)*-18? +3/32 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/arithmetic__nearest_integer_root.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/arithmetic__nearest_integer_root.txt new file mode 100644 index 0000000000000000000000000000000000000000..2583a3b16a5810bfa74309428adbd4fa6f6ec603 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/arithmetic__nearest_integer_root.txt @@ -0,0 +1,6 @@ +Quanto é 65443000 elevado a 1/7, arredondado para o inteiro mais próximo? +13 +Qual é a terceira raíz de 146597612 arredondada para o inteiro mais próximo? +527 +Qual é a quarta raíz de 2216814268 arredondada para o inteiro mais próximo? +217 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/arithmetic__simplify_surd.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/arithmetic__simplify_surd.txt new file mode 100644 index 0000000000000000000000000000000000000000..3ec96ad1c5c73e553db5f85187ed6b6190fd829e --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/arithmetic__simplify_surd.txt @@ -0,0 +1,6 @@ +Simplificar ((1*sqrt(3993)*-4 - ((-4*(sqrt(3993) - 1*sqrt(3993)) - sqrt(3993)) + sqrt(3993)))/(sqrt(12)*3 + sqrt(3) - (sqrt(3) + sqrt(108)/sqrt(4))))**2 + 3. +21323/9 +Simplificar 1 + (sqrt(108) + -1)**2 + 5 - 4*sqrt(9)/(sqrt(21)/(sqrt(28)/sqrt(4))). +115 - 16*sqrt(3) +Simplificar (-3 + sqrt(176)*-5)**2 - (2 + sqrt(176) - sqrt(176))*-5 - ((3 + (2 + sqrt(176) - sqrt(176)) + sqrt(176)*-2*-5)**2 + 1). +-13207 - 280*sqrt(11) diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/calculus__differentiate.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/calculus__differentiate.txt new file mode 100644 index 0000000000000000000000000000000000000000..7ed7aa60f4c8a472476ab6e927034786e10b213f --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/calculus__differentiate.txt @@ -0,0 +1,6 @@ +Qual é a terceira derivada de -5*b**2*u*w**3 - 11*b**2*u + 41*b**2*w**2 + 361*b + 117044*u*w**3 em relação a w? +-30*b**2*u + 702264*u +Qual é a terceira derivada de -26992083*c**4 - 340*c**2 + 2979*c - 2? +-647809992*c +Qual é a segunda derivada de -8361282*l**3 + 65031*l - 3? +-50167692*l diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/calculus__differentiate_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/calculus__differentiate_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..697c876bbeb1e3122986fc7b232cd1a26dcb535c --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/calculus__differentiate_composed.txt @@ -0,0 +1,6 @@ +Seja b(u) = 2534*u**2 + 4009*u. Seja a(q) = -2528*q**2 - 4008*q. Seja f(l) = 5*a(l) + 4*b(l). Encontra a segunda derivada de f(k) em relação a k. +-5008 +Supõe 3 - 4 = -4*h + 5*a, 3*h - 2*a = 6. Encontra a primeira derivada de -64 + 313*g**4 - 132*g**h - 120*g**4 em relação a g. +244*g**3 +Supõe 14*d - 910 = -20300. Seja o = -900 - d. Qual é a derivada de 12*l + 15*l + 484 - o em relação a l? +27 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/comparison__closest.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/comparison__closest.txt new file mode 100644 index 0000000000000000000000000000000000000000..7711d50565c2acc063defe0dde6d7105ba90f101 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/comparison__closest.txt @@ -0,0 +1,6 @@ +Qual valor está mais perto de -27 em -1/6, 209, 0.05, -3? +-3 +Qual está mais perto de -0.8? (a) 161 (b) 0 (c) 4.4 (d) 1/20 +b +Qual valor está mais perto de 0.27 em -0.18, 2, 163, -0.1, 0.2? +0.2 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/comparison__closest_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/comparison__closest_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..ef42e39c8be5f1a2b5e285ad48b59bc826c95ca0 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/comparison__closest_composed.txt @@ -0,0 +1,6 @@ +Seja g = 43.109 - 0.109. Seja x = g - 47. Seja v = 0.74 - 0.24. Qual valor está mais perto de -0.1 em v, -0.01, x? +-0.01 +Supõe 0*d = 3*d - 147. Seja y = -244/5 + d. Qual valor está mais próximo de -1 em -0.1, y, -8? +-0.1 +Supõe 6*i = 3*i - 6. Assume que g é ((-5)/(-4))/(i/(-8)). Assume que u é 4 + (100/(-30))/1. Qual está mais próximo de u? (a) 4 (b) 0.4 (c) g +b diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/comparison__kth_biggest.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/comparison__kth_biggest.txt new file mode 100644 index 0000000000000000000000000000000000000000..202f300ac00971dbf387450f193bc01edc4b2388 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/comparison__kth_biggest.txt @@ -0,0 +1,6 @@ +Qual é o quarto menor valor em 0.9, -5, -403, 5, -47? +0.9 +Qual é o maior valor em -7, 0.034, 1542.2? +1542.2 +Qual valor é terceiro maior? (a) -0.04 (b) 1380 (c) -19 (d) -0.042 (e) 1 +a diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/comparison__kth_biggest_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/comparison__kth_biggest_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..9210a17bf106fa9fc3671021c59b428980202c63 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/comparison__kth_biggest_composed.txt @@ -0,0 +1,6 @@ +Seja p = -3815 - -3815.37. Qual é o terceiro maior valor em -1/7, -0.32, p? +-0.32 +Seja j = 409927/39 - 10511. Qual é o menor valor em j, -8/25, 5, -3? +-3 +Seja t = 1.88 - 5.56. Seja p = t + -0.32. Seja w = 0.04 - 2.04. Qual é o maior valor em w, 16, p? +16 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/comparison__pair.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/comparison__pair.txt new file mode 100644 index 0000000000000000000000000000000000000000..ce16ff3e4502a010c1fff7f22159e0459cd89631 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/comparison__pair.txt @@ -0,0 +1,6 @@ +Será que 3521/18908 e -1 possuem o mesmo valor? +False +Qual é maior: -1 ou -9/4030535? +-9/4030535 +Será -0.02 <= -33887? +False diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/comparison__pair_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/comparison__pair_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..6e2a47ce9b10deb1a9b560dbf93c444f1103438d --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/comparison__pair_composed.txt @@ -0,0 +1,6 @@ +Assume que y é (-4)/(-10) - (-52)/(-5). Seja k = -317.834 + 329.834. Será y menor do que k? +True +Supõe 4*w + 5*c + 115 = -193, 236 = -3*w - 5*c. Qual é superior: -68 ou w? +-68 +Seja v(q) = 2074*q + 10370. Seja w, v(-5). Qual é superior: 56/321 ou w? +56/321 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/comparison__sort.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/comparison__sort.txt new file mode 100644 index 0000000000000000000000000000000000000000..1f4fbe5eb16a1924e300386c85edebde35143d40 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/comparison__sort.txt @@ -0,0 +1,6 @@ +Coloca -479, 3, 19, -1 em ordem crescente. +-479, -1, 3, 19 +Ordena 4023, 5, 105, -8, -3 por ordem decrescente. +4023, 105, 5, -3, -8 +Coloca -89579, -86, -7 em ordem descendente. +-7, -86, -89579 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/comparison__sort_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/comparison__sort_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..e8f3f30ed46cdf26dafed3b2c83a419568adbda7 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/comparison__sort_composed.txt @@ -0,0 +1,6 @@ +Seja a(z) = z**2 - 5*z - 6. Seja w, a(5). Seja g(k) = 31*k + 4*k + 2*k**2 - 4*k + 10. Seja c, g(-15). Coloca -4, c, w em ordem decrescente. +-4, c, w +Seja r(o) = o**3 - o**2 + o. Seja i, r(0). Supõe -3*b + 21 = d, 43 = -3042*b + 3046*b + 3*d. Ordena b, -11, i por ordem decrescente. +b, i, -11 +Seja d = 4.43 - 4.13. Seja q = 16.3 - d. Ordena q, -1, -6 por ordem decrescente. +q, -1, -6 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/measurement__conversion.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/measurement__conversion.txt new file mode 100644 index 0000000000000000000000000000000000000000..0b2649d7af33adc70eaa0d69b936c1c50ae32815 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/measurement__conversion.txt @@ -0,0 +1,6 @@ +Quanto é 42/5 de um(a) litro em um(a) mililitros? +8400 +Quanto é 0.2856971 dias em nanosegundos? +24684229440000 +Quanto é 23/8 de um(a) semana em um(a) minutos? +28980 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/measurement__time.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/measurement__time.txt new file mode 100644 index 0000000000000000000000000000000000000000..0f761bef281f71685f839c7cf88d87869d8926fc --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/measurement__time.txt @@ -0,0 +1,6 @@ +Quantos minutos existem entre 7:00 AM e 7:35 AM? +35 +O que é 120 minutos antes de 12:40 AM? +10:40 PM +Quantos minutos existem entre 4:23 AM e 3:07 PM? +644 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__base_conversion.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__base_conversion.txt new file mode 100644 index 0000000000000000000000000000000000000000..5b691ca4149f16da00f6784ac86f887123a0c204 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__base_conversion.txt @@ -0,0 +1,6 @@ +Quanto é 112021211211022 (base 3) em base 11? +4317a28 +Quanto é -10051126 (base 8) em base 14? +-3d1d42 +115fe2 (em base 16) para base 8 +4257742 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__div_remainder.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__div_remainder.txt new file mode 100644 index 0000000000000000000000000000000000000000..0a7db9f38c6921efc129b8a9fd47b294efd42d22 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__div_remainder.txt @@ -0,0 +1,6 @@ +Calcula o resto da divisão entre 7067451 e 23. +11 +Calcula o resto da divisão entre 167204 e 40. +4 +Calcula o resto da divisão entre 348056 e 5705. +51 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__div_remainder_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__div_remainder_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..ee8d9c2960cc723f88b11ac3fbd3520f7eb2b618 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__div_remainder_composed.txt @@ -0,0 +1,6 @@ +Qual é o resto da divisão entre -6 + (1667 + 58 - (-3 - (1 + 3))) e 12? +10 +Supõe 181*s - 179*s = 198. Supõe -180 = -9*z + s. Qual é o resto da divisão entre z e 18? +13 +Seja y(v) = v**3 - v - 89. Seja o, y(0). Seja j = o - -59. Calcula o resto da divisão entre 16 e j/4*(-16)/20. +4 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__gcd.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__gcd.txt new file mode 100644 index 0000000000000000000000000000000000000000..9e1ba4fb2e0a1dbddc1037afbcc277ac48b0e186 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__gcd.txt @@ -0,0 +1,6 @@ +Qual é o maior divisor comum de 3354966 e 972? +54 +Calcula o maior divisor comum de 206 e 4250501. +103 +Calcula o maior fator comum de 64863 e 7569. +9 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__gcd_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__gcd_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..e92ae26d007638d402c4ae68baa66d76a7842838 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__gcd_composed.txt @@ -0,0 +1,6 @@ +Seja d(y) a segunda derivada de y**5/20 - y**4/3 - y**3/6 + 4*y**2 - 7*y. Seja p, d(4). Supõe h + 18 = p*h. Qual é o maior divisor comum de h e 54? +6 +Seja s(p) = p**3 - 4*p**2 - 2*p - 2. Seja a, s(5). Seja o = 167 + -110. Seja b = o - 5. Calcula o maior fator comum de b e a. +13 +Seja t(x) = -x**2 + 24*x - 18. Seja o, t(32). Seja g = 277 + o. Qual é o maior fator comum de g e 5? +1 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__is_factor.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__is_factor.txt new file mode 100644 index 0000000000000000000000000000000000000000..50e9d42470c627b3c111e3cdcfedd00bf6212b87 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__is_factor.txt @@ -0,0 +1,6 @@ +Será que 1897 divide 129639083? +True +Será 3388 um fator de 68522300? +True +Será 2274990355 um múltiplo de 151? +False diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__is_factor_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__is_factor_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..196ecb3c6895904ca65a9c8ee744e6e8e8a44f32 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__is_factor_composed.txt @@ -0,0 +1,6 @@ +Assume que r é (-3)/15*(-5)/(-2)*8. Será 31 um fator de 4*(6/r + (-8 - -66))? +False +Seja u(w) = w**2 - 4*w - 29. Seja v, u(-4). Supõe -3*d = -v, 2*m - 138 = -d + 3*d. Será 17 um fator de m? +False +Supõe -374*c - 358*c + 719*c + 221208 = 0. Será que 12 divide c? +True diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__is_prime.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__is_prime.txt new file mode 100644 index 0000000000000000000000000000000000000000..83649f45ffaee44d1c6236fc4d7c98cd17616a87 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__is_prime.txt @@ -0,0 +1,6 @@ +Será 15164814809 um número primo? +False +Será 50244651731 um número primo? +False +Será 80964269 compósito? +False diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__is_prime_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__is_prime_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..00828be3ef27cd7b39e410c78953a6a24094b439 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__is_prime_composed.txt @@ -0,0 +1,6 @@ +Assume que z é (0 + (-6)/4)/(21/(-70)). Seja x = -3 + z. Supõe x*q - 534 = 1984. Será q um número primo? +True +Supõe 3*w + 15 = 2*x, -69*x - 5*w - 29 = -71*x. Assume que q é 1*-15*-9*41. Será (q - -6)*(-1)/x primo? +True +Supõe -2*p + 1165237 = -848457. Será p um número primo? +True diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__lcm.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__lcm.txt new file mode 100644 index 0000000000000000000000000000000000000000..2cd2c5ca48bc1a6a70f32fe43d0d31e08e0282c9 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__lcm.txt @@ -0,0 +1,6 @@ +Encontra o denominador comum de -26/2089055227 e -46/9. +18801497043 +Calcula o denominador comum de -77/15053842 e -13/11939254. +346238366 +Calcula o menor múltiplo comum de 1947328 e 7464. +1816857024 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__lcm_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__lcm_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..c3046460a52d23a980ee9556998b1a514495d334 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__lcm_composed.txt @@ -0,0 +1,6 @@ +Seja b(v) = -v - 24. Seja a(k) = -2*k - 24. Seja f(z) = 3*a(z) - 4*b(z). Supõe -3*u - 5*i + 12 = 0, u - 8 + 4 = 4*i. Qual é o menor múltiplo comum de f(8) e u? +8 +Seja i(n) a primeira derivada de -n**4/4 + 7*n**3/3 + n**2 + 4*n - 1. Seja u(s) = -s**2 - 93*s - 426. Qual é o menor múltiplo comum de u(-88) e i(7)? +126 +Assume que a é (2/1 + -3)*(-2 - -2). Assume que l é 2 + a - 2 - -2. Encontra o denominador comum de -46/15 e (l - 2) + -1 + (-66)/45. +15 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__list_prime_factors.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__list_prime_factors.txt new file mode 100644 index 0000000000000000000000000000000000000000..f6dad0ba68f0b48e200a7fc3730d8cf63c1b6192 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__list_prime_factors.txt @@ -0,0 +1,6 @@ +Quais são os fatores primos 209225851? +17, 31, 397013 +Quais são os fatores primos 1261838204? +2, 11, 53, 541097 +Enumera os fatores primos de 236683397. +59, 4011583 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__list_prime_factors_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__list_prime_factors_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..fbf8b5dc663bcddec4879591fff89b91f65af05d --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__list_prime_factors_composed.txt @@ -0,0 +1,6 @@ +Supõe -17*x = 5 + 29. Seja t(y) = -3*y**2 - 3*y. Seja j, t(x). Seja z(g) = 2 - 38*g. Quais são os fatores primos z(j)? +2, 5, 23 +Assume que a é -8*((-2)/4 - -1). Seja i(t) a terceira derivada de -13*t**4/24 - 3*t**3/2 - 12*t**2 - 5. Quais são os fatores primos i(a)? +43 +Assume que a é (6 - 7)/(3 - 10/3). Assume que y é 840/72 - (8/a - 2). Supõe -y*u + 7*u = -876. Quais são os fatores primos u? +3, 73 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__place_value.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__place_value.txt new file mode 100644 index 0000000000000000000000000000000000000000..190434925022fb81c580581de7a729934514939f --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__place_value.txt @@ -0,0 +1,6 @@ +Qual é o dígito das dezenas de 1862597320? +2 +Qual é o dígito das milhares de 2210669121? +9 +Qual é o dígito das centenas de 142920283? +2 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__place_value_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__place_value_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..9dc0567c36c62f9acdcca3cccce65716152185fe --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__place_value_composed.txt @@ -0,0 +1,6 @@ +Supõe -5*m - d + 3 = -14, 10 = m - 2*d. Seja c = 4 - 1. Supõe 0*b + 78 = 5*z - m*b, 2*b - 38 = -c*z. Qual é o dígito das unidades de z? +4 +Seja i = -21495 - -26319. Qual é o dígito das milhares de i? +4 +Supõe -8*b = h - 5*b - 3, 5*h - 5*b = -5. Supõe -4*w + 113 + 2047 = h. Qual é o dígito das dezenas de w? +4 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__round_number.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__round_number.txt new file mode 100644 index 0000000000000000000000000000000000000000..fe435d67c3b35df920ea84d5ca3289cc28813f6e --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__round_number.txt @@ -0,0 +1,6 @@ +Quanto é 23494844.88 arredondado para as 10000 mais próxima? +23490000 +Arredonda 460.9310374 para as dez mais próxima. +460 +Arredonda 428.44828 para as um centena mais próxima. +400 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__round_number_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__round_number_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..1c3f5d93b63c12265b32b991bfb9bdce8e64b144 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/numbers__round_number_composed.txt @@ -0,0 +1,6 @@ +Seja r = -2416 - -2409.501. Quanto é r arredondado para as inteiro mais próximo? +-6 +Supõe 32*p - 34*p - 10753 = -5*a, 4*p = -4*a + 8580. Arredonda a para as um centena mais próxima. +2100 +Supõe 0 = -3*v - 5*w - 14, 3*v = -10*w + 8*w - 2. Supõe z - 1805004 = v*b, -26*z + 31*z - 4*b - 9025008 = 0. Quanto é z arredondado para as 100000 mais próxima? +1800000 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/polynomials__add.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/polynomials__add.txt new file mode 100644 index 0000000000000000000000000000000000000000..91fbd1a2a06f3f95eb1f2778f643fac6e07b0b93 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/polynomials__add.txt @@ -0,0 +1,6 @@ +Seja f(x) = 14*x - 1793. Seja a(k) = 3*k - 2. Calcula 5*a(i) - f(i). +i + 1783 +Seja w = -3635 - -3631. Seja u(b) = -b**3 - 4*b**2 + 9. Seja t(i) = 2*i**3 + 9*i**2 - 19. Assume que g é 1*2/(6/(-27)). Determina g*u(j) + w*t(j). +j**3 - 5 +Assume que r é (-1830)/57 + 33 + (2 - 36/19). Seja p(l) = 1. Seja b(x) = 10*x + 2. Determina r*p(w) - b(w). +-10*w - 1 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/polynomials__coefficient_named.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/polynomials__coefficient_named.txt new file mode 100644 index 0000000000000000000000000000000000000000..6df40148f6c8124906aa34ea2e29b606ea3852c8 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/polynomials__coefficient_named.txt @@ -0,0 +1,6 @@ +Expressa (3*a**3 - 4*a**3 - 2*a**3)*(1 + 3 - 2) + 3*a**3 - 13*a**3 + 3*a**3 + (4 + 0 + 1)*(0*a + 0*a + a**3) como q*a**3 + m*a + c + v*a**2 e dá q. +-8 +Expressa 598*d + 15*d**2 + 1 - 299*d + 0 - 4 - 280*d na forma j + z*d**2 + b*d e dá z. +15 +Rearranja (11*a - 13*a + 15 + 0)*(1 + 6 + 0)*(0 + 0 - 3)*(6 + 0 + 8) na forma b*a + d e dá b. +588 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/polynomials__collect.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/polynomials__collect.txt new file mode 100644 index 0000000000000000000000000000000000000000..142a24cba62d040b692c5cd9b35a94b1f3eedbaf --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/polynomials__collect.txt @@ -0,0 +1,6 @@ +Coleta os termos em -12 - 51 + 63 - 268*c - 66*c + 21*c. +-313*c +Coleta os termos em 17*i - 36*i + 24*i + 133*i + 9*i. +147*i +Coleta os termos em 301 - 301 + 64316*q - 64314*q + 18*q**3 - q**2 + q**2. +18*q**3 + 2*q diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/polynomials__compose.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/polynomials__compose.txt new file mode 100644 index 0000000000000000000000000000000000000000..5937abf9ddb47ed015f6e8b61eb1144c00f7bb9d --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/polynomials__compose.txt @@ -0,0 +1,6 @@ +Seja n(b) = 5 - 12*b. Seja a(u) a primeira derivada de 4*u**3 - 1019. Calcula n(a(w)). +5 - 144*w**2 +Seja d(p) = -p**3 - 11*p**2 - p - 3. Seja n, d(-11). Seja s(x) = -15 - x + 5 - n - 3. Seja t(q) = -3*q. Determina s(t(o)). +3*o - 21 +Seja g(m) a primeira derivada de -4*m**2 - 10*m + 9495. Seja k(x) = 97*x. O que é g(k(t))? +-776*t - 10 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/polynomials__evaluate.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/polynomials__evaluate.txt new file mode 100644 index 0000000000000000000000000000000000000000..857a213bf76aec0610fd7b12549bcae8ed97df6b --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/polynomials__evaluate.txt @@ -0,0 +1,6 @@ +Seja p(f) = 593*f**2 - 8350*f + 14. Obtém p(14). +-658 +Seja t(x) = 30893*x - 2471431. Calcula t(80). +9 +Seja g(c) = 356*c + 11775. O que é g(-33)? +27 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/polynomials__evaluate_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/polynomials__evaluate_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..c3887d90ce7d921d3359800147f8ea5a3e28444f --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/polynomials__evaluate_composed.txt @@ -0,0 +1,6 @@ +Supõe q - 22 - 32 = 0. Seja d(h) = -4*h + 126 - 65 - q + h**2 - h. O que é d(7)? +21 +Seja g(z) = -z**3 + 3*z**2 + 2*z + 1. Supõe -102*k = -107*k + 30. Supõe -k*q + 168 = q. Supõe 5*l + 3*l - q = 0. Obtém g(l). +7 +Seja t(f) a segunda derivada de -7*f + 1 + 1/20*f**5 + 19/6*f**3 - 11/2*f**2 - 5/6*f**4. Calcula t(8). +13 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/polynomials__expand.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/polynomials__expand.txt new file mode 100644 index 0000000000000000000000000000000000000000..0101f12b3d041f48f18097c4d9e01b7e1a6ea15e --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/polynomials__expand.txt @@ -0,0 +1,6 @@ +Expande (4460*i + 1780*i - 7497*i + 4778*i)*(6 + 2 + 5). +45773*i +Expande 287*p + 1382601 - 1382601 + (0 - 2 + 1)*(-p + 1 - 1) + 2*p + p - 2*p + p - 2*p + 2*p. +290*p +Expande (-228 - 164 - 158 + 30)*(u**2 - 4*u**3 - 2*u**3 + 12*u**3). +-3120*u**3 - 520*u**2 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/polynomials__simplify_power.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/polynomials__simplify_power.txt new file mode 100644 index 0000000000000000000000000000000000000000..82632a00f374a754764ca873bc1a413dd16ec7ce --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/polynomials__simplify_power.txt @@ -0,0 +1,6 @@ +Simplifica ((v/v**3*v)**(2/27))**18*(v**(-1))**44*v/(v/((v*(v/(v*v*v**(-7)/v*v*v))/v*v)/v*v))*v*v**(2/19)*v assumindo que v é positiva. +v**(-2122/57) +Simplifica ((n/n**(-4/11))/(n/n**(1/18))*(n*n**11)**(-2/37))**(-30/13) assumindo que n é positiva. +n**(8405/15873) +Simplifica ((n/n**(-1)*n)/(n*n**(6/17))*n**10*n*n*n**(-3/4))**(-10) assumindo que n é positiva. +n**(-4385/34) diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/probability__swr_p_level_set.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/probability__swr_p_level_set.txt new file mode 100644 index 0000000000000000000000000000000000000000..28f27d12792b1e3f740875a51d5c2679075cc732 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/probability__swr_p_level_set.txt @@ -0,0 +1,6 @@ +Dois caractéres são escolhidos sem reposição de djpp. Dá a probabilidade de(a) escolher 1 p e 1 j. +1/3 +Calcula da probabilidade de(a) escolher 1 f e 3 i quando quatro caractéres são escolhidos sem reposição de fyifyizyiyiyeeyye. +2/595 +Qual é a probabilidade de(a) escolher 1 k, 1 c e 1 j quando três caractéres são escolhidos sem reposição de ckecjnne? +1/28 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-hard/probability__swr_p_sequence.txt b/mathematics_dataset/mathematics_dataset/ds/train-hard/probability__swr_p_sequence.txt new file mode 100644 index 0000000000000000000000000000000000000000..881d98e7c71fc62e3f8697ca23efdd39108367b1 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-hard/probability__swr_p_sequence.txt @@ -0,0 +1,6 @@ +Quatro caractéres são escolhidos sem reposição de {r: 1, d: 4, y: 1, l: 1, f: 2}. Qual é a probabilidade de(a) sequência fydf? +1/378 +Três caractéres são escolhidos sem reposição de bbyyvyybv. Qual é a probabilidade de(a) sequência vbb? +1/42 +Calcula da probabilidade de(a) sequência wnk quando três caractéres são escolhidos sem reposição de {w: 2, f: 1, k: 2, n: 1}. +1/30 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/algebra__linear_1d.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/algebra__linear_1d.txt new file mode 100644 index 0000000000000000000000000000000000000000..f4629f3a26df9d38ce0709fac8e20b1d98590da1 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/algebra__linear_1d.txt @@ -0,0 +1,6 @@ +Resolve -26*s + 6402 = 121*s + 144*s para s. +22 +Resolve 42959*d - 42919*d = -720 para d. +-18 +Resolve 278 + 539 - 47 = 385*d para d. +2 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/algebra__linear_1d_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/algebra__linear_1d_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..cbf4aa24cb1dd7618f94ac658877340a26139a06 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/algebra__linear_1d_composed.txt @@ -0,0 +1,6 @@ +Seja o = 15 + -10. Supõe -9 = 3*f - 15. Supõe 11 = 5*h + 2*p, -f*h + 2*p + p = -12. Resolve o = -h*i + 2 para i. +-1 +Seja s = 792 + -785. Supõe 0 = j + j - 56. Assume que m é s*8/j*1. Resolve 0 = m*y + 3 + 5 para y. +-4 +Seja h(y) = -y**3 + y**2 + y + 4. Seja t, h(0). Supõe -30 = -2*p + 5*f, p + 4*f = -3*p + t. Assume que x é p*(-3 - (3 - 7)). Resolve -q - 12 = -x*q para q. +3 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/algebra__linear_2d.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/algebra__linear_2d.txt new file mode 100644 index 0000000000000000000000000000000000000000..2cca63cb181673e0a89b8122a1af921da8ac4f7f --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/algebra__linear_2d.txt @@ -0,0 +1,6 @@ +Resolve -2*z + 7 = 3*h, -4*z = -2360*h + 2364*h - 4 para h. +5 +Resolve -5*r + 5 = -48*p + 50*p, -r + p = -1 para r. +1 +Resolve i + 5*i = 5*i - 5*l - 47, 0 = l + 9 para i. +-2 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/algebra__linear_2d_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/algebra__linear_2d_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..6e21c35b7d8ae40b787aa7445990be0b5966710d --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/algebra__linear_2d_composed.txt @@ -0,0 +1,6 @@ +Seja g(s) = 4*s**2 - 21*s - 5. Seja m, g(5). Assume que h é 4/m + 18/45. Resolve -5*r - 5 = -3*c, h = 3*c - 6*c + r - 11 para c. +-5 +Seja u(s) = 7 - s. Supõe -35 = 5*z + 25. Seja l, u(z). Resolve -5*j - 12 = 4*w - 3, w = 3*j + l para j. +-5 +Assume que a é 1/(2/((-44)/(-2))). Supõe -5*y = -3*b - y - a, -10 = -2*y. Supõe n = b*n - 32. Resolve 5*w - 6 - 9 = 0, -u = 4*w - n para u. +4 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/algebra__polynomial_roots.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/algebra__polynomial_roots.txt new file mode 100644 index 0000000000000000000000000000000000000000..7b5ece38a51724ea65b4378cec2a0142b69e1239 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/algebra__polynomial_roots.txt @@ -0,0 +1,6 @@ +Determina l, dado que 25*l**4 + 7840*l**3 + 613086*l**2 - 246176*l + 24649 = 0. +-157, 1/5 +Factoriza -3*q**5/7 + 96*q**4/7 - 183*q**3/7 + 90*q**2/7. +-3*q**2*(q - 30)*(q - 1)**2/7 +Determina a, dado que 3*a**2/5 - 1773*a/5 + 3534/5 = 0. +2, 589 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/algebra__polynomial_roots_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/algebra__polynomial_roots_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..deba19dca66fed3cfb75027ad8e069a23a02ccef --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/algebra__polynomial_roots_composed.txt @@ -0,0 +1,6 @@ +Seja m(p) a primeira derivada de 17 + 0*p + 3*p**5 + 5/3*p**3 + 0*p**2 - 5*p**4. Seja m(c) = 0. Qual é c? +0, 1/3, 1 +Seja l(q) a primeira derivada de 1/10*q**5 + q**2 - 1/2*q**3 - 9 - 1/4*q**4 + 2*q. Factoriza l(i). +(i - 2)**2*(i + 1)**2/2 +Assume que x é 0 - ((-2)/1 - -8). Seja g(n) = -n - 4. Seja d, g(x). Seja -2 + 1 - 5*b**2 + b**3 - b + 6*b**d = 0. Qual é b? +-1, 1 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/algebra__sequence_next_term.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/algebra__sequence_next_term.txt new file mode 100644 index 0000000000000000000000000000000000000000..392e9313db0ee5ef212f4eac1f02e886d1e4f907 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/algebra__sequence_next_term.txt @@ -0,0 +1,6 @@ +O que se segue em 15, -21, -69, -129? +-201 +O que se segue em 1644, 3286, 4926, 6564, 8200, 9834, 11466? +13096 +O que se segue em 38808, 38807, 38806, 38805, 38804, 38803? +38802 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/algebra__sequence_nth_term.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/algebra__sequence_nth_term.txt new file mode 100644 index 0000000000000000000000000000000000000000..93b4f3a72a7d36aeb542d65e1ed31fd06610e47d --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/algebra__sequence_nth_term.txt @@ -0,0 +1,6 @@ +Qual é termo nº y na sequência -4397, -8806, -13223, -17648? +-4*y**2 - 4397*y + 4 +Qual é termo nº r na sequência -2432, -2418, -2404, -2390, -2376, -2362? +14*r - 2446 +Qual é termo nº n na sequência 533, 1025, 1425, 1685, 1757, 1593, 1145? +-8*n**3 + 2*n**2 + 542*n - 3 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/arithmetic__add_or_sub.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/arithmetic__add_or_sub.txt new file mode 100644 index 0000000000000000000000000000000000000000..1ff6571f2040c829febe494c247066bf60ecd073 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/arithmetic__add_or_sub.txt @@ -0,0 +1,6 @@ +Qual é a distância entre -2855 e -2.47099? +2852.52901 +Quanto é -6.1414 - 0.051822? +-6.193222 +-73+-12559367.6 +-12559440.6 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/arithmetic__add_or_sub_in_base.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/arithmetic__add_or_sub_in_base.txt new file mode 100644 index 0000000000000000000000000000000000000000..09c9cbd7e51c693e6f16bb57d3c2c7c6f7ea171b --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/arithmetic__add_or_sub_in_base.txt @@ -0,0 +1,6 @@ +Em base 15, quanto é -1 - 45e7? +-45e8 +Em base 5, quanto é 22 - -22414? +22441 +Em base 16, quanto é 0 - -2074? +2074 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/arithmetic__add_sub_multiple.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/arithmetic__add_sub_multiple.txt new file mode 100644 index 0000000000000000000000000000000000000000..ca0d2dce2f6d591323f01c7baea38895feaad4d7 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/arithmetic__add_sub_multiple.txt @@ -0,0 +1,6 @@ +Avalia -6 + (-11 - -17) - 19. +-19 +Avalia -3 - (26 + -9 - 8) - 2. +-14 +Calcula -3 + (14 - 10 - (2 + 15 + 0)). +-16 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/arithmetic__div.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/arithmetic__div.txt new file mode 100644 index 0000000000000000000000000000000000000000..de57bc42a33f9e271b9c2366fa5b9873349deebc --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/arithmetic__div.txt @@ -0,0 +1,6 @@ +Quanto é -84132 dividido por 114? +-738 +Divide -904 por -808. +113/101 +Divide -52606 por -26303. +2 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/arithmetic__mixed.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/arithmetic__mixed.txt new file mode 100644 index 0000000000000000000000000000000000000000..27e69ba40404b928bfe82011038841ce652c23d2 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/arithmetic__mixed.txt @@ -0,0 +1,6 @@ +Avalia (5/(-15)*(0 + 15))/7. +-5/7 +Quanto é (-3515)/323 - (-6)/(-51)? +-11 +Avalia ((-426)/(-90))/((-6)/10) - (-12)/54. +-23/3 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/arithmetic__mul.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/arithmetic__mul.txt new file mode 100644 index 0000000000000000000000000000000000000000..a7242ca39b3be08fb59ef19a34c71fb575a0bf35 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/arithmetic__mul.txt @@ -0,0 +1,6 @@ +264.5 * 7 +1851.5 +-0.5 vezes -708.9 +354.45 +853813 vezes -0.2 +-170762.6 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/arithmetic__mul_div_multiple.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/arithmetic__mul_div_multiple.txt new file mode 100644 index 0000000000000000000000000000000000000000..9a40a555cdc98220516f08c11374619530dd1388 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/arithmetic__mul_div_multiple.txt @@ -0,0 +1,6 @@ +Quanto é (207/3933)/((-1)/(-3))? +3/19 +Calcula (28*(-33)/(-99))/((-4)/15). +-35 +Qual é o valor de ((-5)/(-7))/(3/3)? +5/7 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/arithmetic__nearest_integer_root.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/arithmetic__nearest_integer_root.txt new file mode 100644 index 0000000000000000000000000000000000000000..3f3fac19caa8c112a46376198834d8b71924c72d --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/arithmetic__nearest_integer_root.txt @@ -0,0 +1,6 @@ +Qual é a quinta raíz de 805081 arredondada para o inteiro mais próximo? +15 +Quanto é 6819931 elevado a 1/3, arredondado para o inteiro mais próximo? +190 +Qual é a raíz quadrada de 451226 arredondada para o inteiro mais próximo? +672 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/arithmetic__simplify_surd.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/arithmetic__simplify_surd.txt new file mode 100644 index 0000000000000000000000000000000000000000..ff1af8c1f2b769bb221e2840324c446ec827020b --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/arithmetic__simplify_surd.txt @@ -0,0 +1,6 @@ +Simplificar ((sqrt(196) - (sqrt(196)*-4 - sqrt(196)))/sqrt(4))/(sqrt(448)*-4). +-3*sqrt(7)/16 +Simplificar (-4 + 0 + sqrt(5) + 5 - (2*sqrt(120))/sqrt(6))**2. +46 - 6*sqrt(5) +Simplificar (-1*sqrt(180)*-1 - (2*sqrt(180)*3 - sqrt(180)))**2. +2880 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/calculus__differentiate.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/calculus__differentiate.txt new file mode 100644 index 0000000000000000000000000000000000000000..5e201add61fedd37bf74f108fc87040660328697 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/calculus__differentiate.txt @@ -0,0 +1,6 @@ +Qual é a primeira derivada de 3310*d*z**2 - 218*d*z + 101*z**2 - 1188 em relação a d? +3310*z**2 - 218*z +Qual é a segunda derivada de -s**3*w + 3060*s**3 + 2*s**2*w - 3*s*w - 60036*w em relação a s? +-6*s*w + 18360*s + 4*w +Deriva -a*h**3*t - 460274*a*h + h**3 + 6*h**2*t - 2*h*t + h - 13335*t em relação a a. +-h**3*t - 460274*h diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/calculus__differentiate_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/calculus__differentiate_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..14c41bb5b82ab2fb34c8dd61692a4e6ed4dd86a9 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/calculus__differentiate_composed.txt @@ -0,0 +1,6 @@ +Diferencia -23*m**4 - 64*m**4 - 4*m**4 - 129 + 6*m**4 em relação a m. +-340*m**3 +Seja l(z) a terceira derivada de -73*z**7/42 - z**5/60 - z**4/6 - 308*z**2 - 2. Encontra a terceira derivada de l(f) em relação a f. +-8760*f +Qual é a segunda derivada de 2 - 111*y**5 - 62*y**5 - 158*y**5 - 371*y - 94*y**5 em relação a y? +-8500*y**3 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/comparison__closest.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/comparison__closest.txt new file mode 100644 index 0000000000000000000000000000000000000000..d4b43486c245a0e27e8bf4b4154a0f5a318be74d --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/comparison__closest.txt @@ -0,0 +1,6 @@ +Qual está mais perto de -75? (a) 9 (b) -3 (c) -0.1038 +b +Qual valor está mais próximo de -44 em -2/9, -1/3, -3? +-3 +Qual valor está mais perto de 0 em -5/2, -1, -1/2, 0? +0 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/comparison__closest_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/comparison__closest_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..4236c5e40eb469a53a3c38126a7c612b86bd0f1c --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/comparison__closest_composed.txt @@ -0,0 +1,6 @@ +Supõe 0 = -45*a - 5 + 5. Qual valor está mais perto de -1 em -0.1, -1, a? +-1 +Assume que s é ((-9)/24)/((-1)/2). Seja q = 61 - 425/7. Seja x = 4 - 0. Qual valor está mais próximo de q em x, s, 3? +s +Seja y = 10.9 - 10.4. Qual valor está mais próximo de 0 em y, -1, -2? +y diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/comparison__kth_biggest.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/comparison__kth_biggest.txt new file mode 100644 index 0000000000000000000000000000000000000000..aa844f8305977688f29a374b147a267f0fa3c47d --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/comparison__kth_biggest.txt @@ -0,0 +1,6 @@ +Qual valor é segundo maior? (a) -17 (b) -1/6 (c) -103 (d) 0.3 +b +Qual é o quinto maior valor em -0.03, -4, 0.4, -2/9585, -0.3? +-4 +Qual valor é maior? (a) 14/79 (b) 4 (c) -4 (d) -8 +b diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/comparison__kth_biggest_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/comparison__kth_biggest_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..37d883d9ab68014558226405e2c8f96114928713 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/comparison__kth_biggest_composed.txt @@ -0,0 +1,6 @@ +Assume que z é ((-3)/(-63))/(3/9). Qual é o segundo maior valor em z, 2/7, 2/3, 0.32? +0.32 +Seja m = 220.057 + -0.057. Qual é o quarto maior valor em -2, m, -0.2, -5? +-5 +Supõe 264 = -4*v + 4*y, 4*y - 54 = v + 6*y. Seja q = -57 - v. Qual valor é segundo menor? (a) 19 (b) -3 (c) q (d) -5 +b diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/comparison__pair.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/comparison__pair.txt new file mode 100644 index 0000000000000000000000000000000000000000..9fa69d112bfc6485379606ff90e9179875a8609d --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/comparison__pair.txt @@ -0,0 +1,6 @@ +Qual é maior: 10030 ou 10016? +10030 +Será -178, no máximo, -241? +False +Será 8 >= -10545? +True diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/comparison__pair_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/comparison__pair_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..85f5c9404334044a2962a842033e9594eec61a69 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/comparison__pair_composed.txt @@ -0,0 +1,6 @@ +Assume que n é 1/(-36)*252/1134. Qual é menor: n ou 0? +n +Seja y = 1545645/52 - 117885/4. Seja r = y - 253. Supõe -4*m - 8 + 4 = 0. Qual é superior: m ou r? +r +Assume que p é 12/3 + (-18 - (-28)/4). Qual é superior: p ou 15? +15 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/comparison__sort.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/comparison__sort.txt new file mode 100644 index 0000000000000000000000000000000000000000..1f8d42f881fbdabd19e6a1454342cd905ae858e6 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/comparison__sort.txt @@ -0,0 +1,6 @@ +Ordena -6, 9, 11067 por ordem crescente. +-6, 9, 11067 +Coloca 2, 0.34, -1, -1/6, 3 em ordem decrescente. +3, 2, 0.34, -1/6, -1 +Ordena -73, 3/5, -5, -1.4 por ordem ascendente. +-73, -5, -1.4, 3/5 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/comparison__sort_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/comparison__sort_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..369ead2bf71ca76043e8e12108d196da5aecce02 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/comparison__sort_composed.txt @@ -0,0 +1,6 @@ +Seja u = 443 - 446. Ordena 0.4, u, -0.059, -0.2 por ordem decrescente. +0.4, -0.059, -0.2, u +Seja p = -20 - 8. Seja b = -28.3 - p. Ordena b, -0.5, 0.1 por ordem decrescente. +0.1, b, -0.5 +Seja l = 12.64 + -22.64. Seja j = -1 - -1. Ordena l, 0.2, j. +l, j, 0.2 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/measurement__conversion.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/measurement__conversion.txt new file mode 100644 index 0000000000000000000000000000000000000000..83a20e522b205142462ec59fba32215edcdf25ca --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/measurement__conversion.txt @@ -0,0 +1,6 @@ +Quantos(as) mililitros estão em 3/10 de um(a) litro? +300 +Converte 2.0196201 meses para anos. +0.168301675 +Quanto é 24705.99mm em centímetros? +2470.599 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/measurement__time.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/measurement__time.txt new file mode 100644 index 0000000000000000000000000000000000000000..06d48076cffd73d2c5174afebf022544f9804d74 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/measurement__time.txt @@ -0,0 +1,6 @@ +O que é 589 minutos antes de 6:54 PM? +9:05 AM +Quantos minutos existem entre 10:19 AM e 6:41 PM? +502 +Quantos minutos existem entre 10:07 PM e 4:01 AM? +354 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__base_conversion.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__base_conversion.txt new file mode 100644 index 0000000000000000000000000000000000000000..b2bd384a9faa722cf8b4c8f1cec0de5f30dd6dbf --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__base_conversion.txt @@ -0,0 +1,6 @@ +Quanto é -216 (base 15) em base 6? +-2103 +-5b8 (em base 15) para base 3 +-1210002 +Quanto é -20112 (base 4) em base 2? +-1000010110 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__div_remainder.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__div_remainder.txt new file mode 100644 index 0000000000000000000000000000000000000000..7ce08bcf092d45d01f5aec9aa8c98e572cf6d047 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__div_remainder.txt @@ -0,0 +1,6 @@ +Calcula o resto da divisão entre 258345 e 708. +633 +Calcula o resto da divisão entre 5533 e 378. +241 +Calcula o resto da divisão entre 594877 e 297435. +7 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__div_remainder_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__div_remainder_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..f014bbe5521b985276d110691426b2e42abef251 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__div_remainder_composed.txt @@ -0,0 +1,6 @@ +Supõe 4*a - 94 = 1014. Qual é o resto da divisão entre a e 35? +32 +Supõe 34 = -5*f + 174. Seja u(q) = -q**3 - 10*q**2 - 6*q + 36. Qual é o resto da divisão entre f e u(-9)? +1 +Calcula o resto da divisão entre 454 e 638/(-1595) - -257*(-2)/(-10). +46 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__gcd.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__gcd.txt new file mode 100644 index 0000000000000000000000000000000000000000..f78eb3db0c0b8512d04f45055238d5c9e7425a13 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__gcd.txt @@ -0,0 +1,6 @@ +Calcula o maior fator comum de 418 e 3167186. +418 +Calcula o maior divisor comum de 15834 e 343. +7 +Qual é o maior divisor comum de 5360 e 191360? +80 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__gcd_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__gcd_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..1f4f61e313097a5f0e78f64f872699a6eb639581 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__gcd_composed.txt @@ -0,0 +1,6 @@ +Seja p(w) a terceira derivada de w**5/30 + 3*w**4/8 + 4*w**3/3 + 6*w**2. Seja u, p(-6). Qual é o maior divisor comum de 182 e u? +26 +Supõe 55*u = 3*a + 51*u - 5174, 0 = 4*a + u - 6886. Qual é o maior divisor comum de 42 e a? +42 +Assume que c é (1/(-2))/((-9)/(-1746)). Seja z = 29 + c. Seja b = -40 - z. Qual é o maior fator comum de b e 14? +14 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__is_factor.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__is_factor.txt new file mode 100644 index 0000000000000000000000000000000000000000..e26ce7bbe28297b1f23b1798d4ad20605d9bd2b2 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__is_factor.txt @@ -0,0 +1,6 @@ +Será 7 um fator de 372950? +False +Será 1051916 um múltiplo de 446? +False +Será que 144 divide 51500? +False diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__is_factor_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__is_factor_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..72b7ecb9836c3a2d23a103ab8065535ed3acc949 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__is_factor_composed.txt @@ -0,0 +1,6 @@ +Supõe -30*m = -37*m + 35. Seja z = -7 + 12. Supõe m*f = f - 12, z*f - 39 = -3*q. Será que 4 divide q? +False +Seja c(a) = a**2 - 8*a + 7. Seja k(y) = y**2 - 13*y - 4. Seja t, k(14). Será c(t) um múltiplo de 9? +True +Seja v = -677 - -817. Será 28 um fator de v? +True diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__is_prime.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__is_prime.txt new file mode 100644 index 0000000000000000000000000000000000000000..e55ba0575a39c92770a5e54af3c4cc538276660c --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__is_prime.txt @@ -0,0 +1,6 @@ +Será 2081537 um número primo? +True +Será 82103701 compósito? +True +Será 31276157 compósito? +True diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__is_prime_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__is_prime_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..4092582d75c7718ce33aba1a5bb376f7d53e253d --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__is_prime_composed.txt @@ -0,0 +1,6 @@ +Supõe 6*x - 34613 = 68305. Será x compósito? +True +Supõe 4 = 5*n + 2*a + 34, -2*n = 5*a - 9. Assume que v é 1/(1/n)*-1. Seja i = 13 + v. Será i um número primo? +False +Supõe -78*w + 882 = -72*w. Supõe 149*u - 354 = w*u. Será u um número primo? +False diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__lcm.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__lcm.txt new file mode 100644 index 0000000000000000000000000000000000000000..1681e5663cba18dedb3dbb3d15076a79000ed0e8 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__lcm.txt @@ -0,0 +1,6 @@ +Calcula o menor múltiplo comum de 68 e 50218. +100436 +Calcula o denominador comum de 59/91542 e 45. +91542 +Qual é o denominador comum de 77/1752351 e 59/27? +15771159 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__lcm_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__lcm_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..f35fca6a38034b11b51ab92877f30b69ac4e3147 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__lcm_composed.txt @@ -0,0 +1,6 @@ +Seja g = 259/8 - 23. Qual é o denominador comum de g e (70/4*72/(-3750))/((-4)/10)? +200 +Assume que w é (-81)/(-15)*614/(-2). Seja u = -1650 - w. Encontra o denominador comum de u e -47/3. +15 +Seja o(k) = 3*k**2 - k - 9*k - 12*k**2 + k - k**3 - 3. Seja x, o(-8). Calcula o menor múltiplo comum de 4 e x*3/((-9)/(-6)). +20 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__list_prime_factors.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__list_prime_factors.txt new file mode 100644 index 0000000000000000000000000000000000000000..b51307bceec3570618057fc34651105beadc3b43 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__list_prime_factors.txt @@ -0,0 +1,6 @@ +Enumera os fatores primos de 1254566. +2, 17, 36899 +Enumera os fatores primos de 30762. +2, 3, 1709 +Enumera os fatores primos de 453538. +2, 226769 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__list_prime_factors_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__list_prime_factors_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..a8df815d8faed4653785978600ee7405895f9e6f --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__list_prime_factors_composed.txt @@ -0,0 +1,6 @@ +Seja u(r) = 2*r - 4. Seja d, u(4). Supõe 0 = -3*h - 4*l - 1091, h - 2*l = -d*l - 367. Enumera os fatores primos de ((-4)/(-6))/((-14)/h). +17 +Seja i = 53 - 63. Quais são os fatores primos (-719)/(-5) - (32/i - -3)? +2, 3 +Seja t = 92 + -65. Supõe 0 = 5*m - 5*p - 1000, -4*m - 2*p = -t - 803. Enumera os fatores primos de m. +5, 41 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__place_value.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__place_value.txt new file mode 100644 index 0000000000000000000000000000000000000000..db19514e7d2457fd75b43b2f008285991a22b55d --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__place_value.txt @@ -0,0 +1,6 @@ +Qual é o dígito das milhares de 1873939? +3 +Qual é o dígito das centenas de 754650? +6 +Qual é o dígito das unidades de 13088799? +9 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__place_value_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__place_value_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..a7b1b017d673a165203e661e4a77212b1076ac64 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__place_value_composed.txt @@ -0,0 +1,6 @@ +Seja n = -17 + 27. Seja y(q) = q**3 + 6*q**2 + 4*q - 1. Seja m, y(-5). Supõe m*c = 4*a - 32, -46 - n = -4*a - 4*c. Qual é o dígito das dezenas de a? +1 +Supõe 4*b = 4 + 12. Supõe 0*i - i - 3 = b*r, -r - 9 = 3*i. Supõe r = -p - 0*p + 27. Qual é o dígito das dezenas de p? +2 +Seja t(s) = -115*s. Seja d = -56 + 55. Qual é o dígito das dezenas de t(d)? +1 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__round_number.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__round_number.txt new file mode 100644 index 0000000000000000000000000000000000000000..e23abf0c11ecab21ba1cba765bac5255dae960bd --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__round_number.txt @@ -0,0 +1,6 @@ +Arredonda 324.582 para as dez mais próxima. +320 +Quanto é 0.0008865303 arredondado para as casa decimal das 6s? +0.000887 +Quanto é -55971.03 arredondado para as um milhar mais próxima? +-56000 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__round_number_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__round_number_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..1a9bf6115ef054e5ffe61f17a69e56660435c7de --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/numbers__round_number_composed.txt @@ -0,0 +1,6 @@ +Seja w = -1 + -7. Seja b = 17 + w. Seja j = 9.00000031 - b. Arredonda j para as casa decimal das 7s. +0.0000003 +Seja l = -35 - -35.019. Seja a = 0.0190112 - l. Arredonda a para as casa decimal das seiss. +0.000011 +Seja g = -97.0007 + 97. Quanto é g arredondado para as casa decimal das trêss? +-0.001 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/polynomials__add.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/polynomials__add.txt new file mode 100644 index 0000000000000000000000000000000000000000..c3be14519a2637551378b42753c52e3da3c341fb --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/polynomials__add.txt @@ -0,0 +1,6 @@ +Seja a(h) = -h**3 + h**2. Seja k = -20 + 24. Supõe 5 = -q - k*q. Seja u(v) = 7*v**3 - 3*v**2 + 1. Determina q*u(m) - 5*a(m). +-2*m**3 - 2*m**2 - 1 +Seja z(n) = 7*n + 2. Supõe -13*v + 400 = 465. Seja o(k) a terceira derivada de 0*k + 0 - 1/2*k**3 - 1/3*k**4 - k**2. Obtém v*z(j) - 4*o(j). +2 - 3*j +Seja o(b) = 3*b - 2. Supõe 0*a + 4*a - 42 = -3*d, -2*d = -3*a - 45. Seja c(t) = -d*t + 36*t - 19*t. O que é 2*c(x) + o(x)? +x - 2 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/polynomials__coefficient_named.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/polynomials__coefficient_named.txt new file mode 100644 index 0000000000000000000000000000000000000000..b2567164de8e33a1e383bb27ed76b07a9a2814f3 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/polynomials__coefficient_named.txt @@ -0,0 +1,6 @@ +Expressa 2*t - 2*t + t**4 + (-t + t**2 + t)*(-120 + 120 - 43*t)*(-t - t - 3*t) na forma p + b*t**2 + i*t**4 + w*t**3 + c*t e dá i. +216 +Expressa -116*f**2 + 15*f**2 + 13 - 13 como m + i*f**2 + r*f e dá i. +-101 +Expressa 4*v**4 + 0*v - 9*v**4 + 4*v + 3*v**3 + 2 - 2*v**3 + 7*v**4 na forma o*v**3 + a*v + j*v**2 + c + z*v**4 e dá c. +2 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/polynomials__collect.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/polynomials__collect.txt new file mode 100644 index 0000000000000000000000000000000000000000..8b8d4d3e2acf9c57aaede7b6fbb428df1851890e --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/polynomials__collect.txt @@ -0,0 +1,6 @@ +Coleta os termos em 1000*z**3 + 480*z**3 + z + z - 2*z. +1480*z**3 +Coleta os termos em -42*j**2 + 452 - 27*j**2 - 452. +-69*j**2 +Coleta os termos em 58*m**3 + 115 + 19 + 81 - 68*m**3. +215 - 10*m**3 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/polynomials__compose.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/polynomials__compose.txt new file mode 100644 index 0000000000000000000000000000000000000000..edf3be5052dfa0d99376b2fb2e2529e7db99863a --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/polynomials__compose.txt @@ -0,0 +1,6 @@ +Seja w(x) = -108*x - 239*x + 1152*x - 328*x. Seja f(b) = 2*b. O que é f(w(j))? +954*j +Seja h(j) = 17 - 186*j. Seja p(u) = 23*u - 2. Seja b(w) = 6*h(w) + 51*p(w). Seja z(n) = -3*n. Calcula b(z(f)). +-171*f +Seja i(a) = -a**2 + 4*a. Seja d(z) = 3*z. Seja b(f) = -4*d(f) + 3*i(f). Seja q(o) = -5*o. O que é b(q(h))? +-75*h**2 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/polynomials__evaluate.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/polynomials__evaluate.txt new file mode 100644 index 0000000000000000000000000000000000000000..15767e0be2ac99728fcd9d23fff281bcf47195ad --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/polynomials__evaluate.txt @@ -0,0 +1,6 @@ +Seja s(l) = 2*l**2 + 286*l + 3832. Calcula s(-15). +-8 +Seja t(v) = -4*v**2 + 325*v + 244. Determina t(82). +-2 +Seja c(u) = -u**2 + 18*u + 402. Determina c(-13). +-1 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/polynomials__evaluate_composed.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/polynomials__evaluate_composed.txt new file mode 100644 index 0000000000000000000000000000000000000000..55320fdefe6ae0dbc94f74a785fe9055f328b714 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/polynomials__evaluate_composed.txt @@ -0,0 +1,6 @@ +Seja m(z) = 1 - 2*z. Supõe -x = 5*f - 2*f - 1, 2*x - 4 = -4*f. Supõe 0 = -4*w + 6*w - x. O que é m(w)? +-3 +Seja p(b) = -b**3 + 10*b**2 - 9*b + 3. Seja i, p(9). Seja y(r) a terceira derivada de 0*r + 2*r**2 - 1/12*r**4 - 1/3*r**i + 0. Determina y(3). +-8 +Seja r(t) = t. Seja p = 529 - 525. Obtém r(p). +4 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/polynomials__expand.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/polynomials__expand.txt new file mode 100644 index 0000000000000000000000000000000000000000..a2ab5fc2d50743e8c62d5f32687692fe43d22c42 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/polynomials__expand.txt @@ -0,0 +1,6 @@ +Expande (-26 + 5 + 1)*(-4 + 4 + 3*b). +-60*b +Expande ((-3*a + a - a)*(-5*a**2 + 623 - 623) + 0 - 2*a**3 + 0)*(5*a + 0*a - 2*a). +39*a**4 +Expande (n**2 - 3*n**2 + 3*n**2)*(-8 - 23*n - 8 + 16). +-23*n**3 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/polynomials__simplify_power.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/polynomials__simplify_power.txt new file mode 100644 index 0000000000000000000000000000000000000000..ec329c200ba2a5d1c39958f300860c07543823d8 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/polynomials__simplify_power.txt @@ -0,0 +1,6 @@ +Simplifica ((((y*y/(y/y**(-8)*y)*y)/y)/y)/y**3)/((y**8*y)/(y/(y/(y**11*y)*y))) assumindo que y é positiva. +y**(-10) +Simplifica (((v**(-11)/v)/(((v*v*(v/v**12)/v)/v)/v))**27)**(-1/42) assumindo que v é positiva. +1 +Simplifica (q/(q/(q/(q*(((q/(q*q**6*q))/q)/q)/q))))**12*(q**0/q)**(-1/5) assumindo que q é positiva. +q**(601/5) diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/probability__swr_p_level_set.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/probability__swr_p_level_set.txt new file mode 100644 index 0000000000000000000000000000000000000000..6844d3f6cb76a61a22d9323494323959395e27cf --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/probability__swr_p_level_set.txt @@ -0,0 +1,6 @@ +Três caractéres são escolhidos sem reposição de syaasyattyttaayyt. Qual é a probabilidade de(a) escolher 2 y e 1 s? +1/34 +Qual é a probabilidade de(a) escolher 1 v e 1 r quando dois caractéres são escolhidos sem reposição de lvllrlvrlrv? +9/55 +Três caractéres são escolhidos sem reposição de vvvqqrrvvrqvrvrq. Dá a probabilidade de(a) escolher 1 q e 2 v. +3/20 diff --git a/mathematics_dataset/mathematics_dataset/ds/train-medium/probability__swr_p_sequence.txt b/mathematics_dataset/mathematics_dataset/ds/train-medium/probability__swr_p_sequence.txt new file mode 100644 index 0000000000000000000000000000000000000000..b658c96b748c4549fe372c9d84110b318e4c3fb8 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/ds/train-medium/probability__swr_p_sequence.txt @@ -0,0 +1,6 @@ +Quatro caractéres são escolhidos sem reposição de {y: 4, r: 9, m: 1}. Dá a probabilidade de(a) sequência myrr. +12/1001 +Três caractéres são escolhidos sem reposição de {n: 5, v: 3, t: 1}. Qual é a probabilidade de(a) sequência tnn? +5/126 +Qual é a probabilidade de(a) sequência lls quando três caractéres são escolhidos sem reposição de {l: 2, s: 1}? +1/3 diff --git a/mathematics_dataset/mathematics_dataset/example.py b/mathematics_dataset/mathematics_dataset/example.py new file mode 100644 index 0000000000000000000000000000000000000000..1aa3b27fc428743248234a18c3637a1e3242f43a --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/example.py @@ -0,0 +1,59 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Containers for "[example] problems" (i.e., question/answer) pairs.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import collections + +from util import composition + + +def question(context, template, **kwargs): + """Makes a question, using the given context and template. + + The format is similar to that for python's `format` function, for example: + + ``` + question(context, 'What is {} plus {p} over {q}?', 2, p=3, q=4) + ``` + + The main difference between this and the standard python formatting is that + this understands `Entity`s in the arguments, and will do appropriate expansion + of text and prefixing of their descriptions. + + Arguments: + context: Instance of `composition.Context`, for extracting entities needed + for describing the problem. + template: A string, like "Calculate the value of {exp}.". + **kwargs: A dictionary mapping arguments to values, e.g., + `{'exp': sympy.Add(2, 3, evaluate=False)}`. + + Returns: + String. + """ + assert isinstance(context, composition.Context) + assert isinstance(template, str) + prefix, kwargs = composition.expand_entities(context, **kwargs) + if prefix: + prefix += ' ' + return prefix + template.format(**kwargs) + + +Problem = collections.namedtuple('Problem', ('question', 'answer')) + + diff --git a/mathematics_dataset/mathematics_dataset/generate.py b/mathematics_dataset/mathematics_dataset/generate.py new file mode 100644 index 0000000000000000000000000000000000000000..22565e10f5f7cfb7dfab1737b7f73846135874ec --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/generate.py @@ -0,0 +1,172 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Prints to stdout different curriculum questions.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import collections +import textwrap + +# Dependency imports +from absl import app +from absl import flags +from absl import logging +import generate_settings +from modules import modules +import six +from six.moves import range + + +FLAGS = flags.FLAGS + +flags.DEFINE_string('filter', '', 'restrict to matching module names') +flags.DEFINE_integer('per_train_module', 10, 'Num of examples per train module') +flags.DEFINE_integer('per_test_module', 10, 'Num of examples per test module') +flags.DEFINE_bool('show_dropped', False, 'Whether to print dropped questions') + + +filtered_modules = collections.OrderedDict([]) +counts = {} + + +def _make_entropy_fn(level, num_levels): + """This returns a function that returns a subrange of entropy. + + E.g., if level=1 (medium) and num_levels=3, then the returned function will + map the range [x, x + y] to [x + y/3, x + 2y/3]. + + Args: + level: Integer in range [0, num_levels - 1]. + num_levels: Number of difficulty levels. + + Returns: + Function to restrict entropy range. + """ + lower = level / num_levels + upper = (level + 1) / num_levels + def modify_entropy(range_): + assert len(range_) == 2 + length = range_[1] - range_[0] + return (range_[0] + lower * length, range_[0] + upper * length) + return modify_entropy + + +def _filter_and_flatten(modules_): + """Returns flattened dict, filtered according to FLAGS.""" + flat = collections.OrderedDict() + + def add(submodules, prefix=None): + for key, module_or_function in six.iteritems(submodules): + full_name = prefix + '__' + key if prefix is not None else key + if isinstance(module_or_function, dict): + add(module_or_function, full_name) + else: + if FLAGS.filter not in full_name: + continue + flat[full_name] = module_or_function + + add(modules_) + + # Make sure list of modules are in deterministic order. This is important when + # generating across multiple machines. + flat = collections.OrderedDict( + [(key, flat[key]) for key in sorted(six.iterkeys(flat))]) + + return flat + + +def init_modules(train_split=False): + """Inits the dicts containing functions for generating modules.""" + if filtered_modules: + return # already initialized + + all_modules = collections.OrderedDict([]) + if train_split: + all_modules['train-easy'] = modules.train(_make_entropy_fn(0, 3)) + all_modules['train-medium'] = modules.train(_make_entropy_fn(1, 3)) + all_modules['train-hard'] = modules.train(_make_entropy_fn(2, 3)) + else: + all_modules['train'] = modules.train(_make_entropy_fn(0, 1)) + + all_modules['interpolate'] = modules.test() + all_modules['extrapolate'] = modules.test_extra() + + counts['train'] = FLAGS.per_train_module + counts['train-easy'] = FLAGS.per_train_module // 3 + counts['train-medium'] = FLAGS.per_train_module // 3 + counts['train-hard'] = FLAGS.per_train_module // 3 + counts['interpolate'] = FLAGS.per_test_module + counts['extrapolate'] = FLAGS.per_test_module + + for regime_, modules_ in six.iteritems(all_modules): + filtered_modules[regime_] = _filter_and_flatten(modules_) + + +def sample_from_module(module): + """Samples a problem, ignoring samples with overly long questions / answers. + + Args: + module: Callable returning a `Problem`. + + Returns: + Pair `(problem, num_dropped)`, where `problem` is an instance of `Problem` + and `num_dropped` is an integer >= 0 indicating the number of samples that + were dropped. + """ + num_dropped = 0 + while True: + problem = module() + question = str(problem.question) + if len(question) > generate_settings.MAX_QUESTION_LENGTH: + num_dropped += 1 + if FLAGS.show_dropped: + logging.warning('Dropping question: %s', question) + continue + answer = str(problem.answer) + if len(answer) > generate_settings.MAX_ANSWER_LENGTH: + num_dropped += 1 + if FLAGS.show_dropped: + logging.warning('Dropping question with answer: %s', answer) + continue + return problem, num_dropped + + +def main(unused_argv): + """Prints Q&As from modules according to FLAGS.filter.""" + init_modules() + + text_wrapper = textwrap.TextWrapper( + width=80, initial_indent=' ', subsequent_indent=' ') + + for regime, flat_modules in six.iteritems(filtered_modules): + per_module = counts[regime] + for module_name, module in six.iteritems(flat_modules): + # These magic print constants make the header bold. + print('\033[1m{}/{}\033[0m'.format(regime, module_name)) + num_dropped = 0 + for _ in range(per_module): + problem, extra_dropped = sample_from_module(module) + num_dropped += extra_dropped + text = text_wrapper.fill( + '{} \033[92m{}\033[0m'.format(problem.question, problem.answer)) + print(text) + if num_dropped > 0: + logging.warning('Dropped %d examples', num_dropped) + + +if __name__ == '__main__': + app.run(main) diff --git a/mathematics_dataset/mathematics_dataset/generate_settings.py b/mathematics_dataset/mathematics_dataset/generate_settings.py new file mode 100644 index 0000000000000000000000000000000000000000..29e0c69bf58dc8c15ac5e70b71afe031a7311b2f --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/generate_settings.py @@ -0,0 +1,32 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Settings for generation.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import os +import string + +MAX_QUESTION_LENGTH = 160 +MAX_ANSWER_LENGTH = 30 +QUESTION_CHARS = ( + ['', ' '] + list(string.ascii_letters + string.digits + string.punctuation)) +EMPTY_INDEX = QUESTION_CHARS.index('') +NUM_INDICES = len(QUESTION_CHARS) +CHAR_TO_INDEX = {char: index for index, char in enumerate(QUESTION_CHARS)} +INDEX_TO_CHAR = {index: char for index, char in enumerate(QUESTION_CHARS)} + diff --git a/mathematics_dataset/mathematics_dataset/generate_test.py b/mathematics_dataset/mathematics_dataset/generate_test.py new file mode 100644 index 0000000000000000000000000000000000000000..ae28822b3236dd7e9e4885b8a93b87bc637aca4b --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/generate_test.py @@ -0,0 +1,47 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Tests for mathematics_dataset.generate.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +# Dependency imports +from absl.testing import absltest +from absl.testing import parameterized +import generate +import six +from six.moves import range + + +class GenerateTest(parameterized.TestCase): + + def testMakeEntropyFn(self): + entropy_full = generate._make_entropy_fn(0, 1) + self.assertEqual(entropy_full((2, 3)), (2, 3)) + entropy_third = generate._make_entropy_fn(2, 3) + self.assertEqual(entropy_third((3, 6)), (5, 6)) + + @parameterized.parameters('train', 'interpolate', 'extrapolate') + def testGenerate(self, regime): + generate.init_modules() + for module in six.itervalues(generate.filtered_modules[regime]): + for _ in range(3): + question = module() + str(question) + + +if __name__ == '__main__': + absltest.main() diff --git a/mathematics_dataset/mathematics_dataset/generate_to_file.py b/mathematics_dataset/mathematics_dataset/generate_to_file.py new file mode 100644 index 0000000000000000000000000000000000000000..6e73154299c005c0fafd0307876c3441a89e5183 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/generate_to_file.py @@ -0,0 +1,79 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Example of how to write generated questions to text files. + +Given an output directory, this will create the following subdirectories: + +* train-easy +* train-medium +* train-hard +* interpolate +* extrapolate + +and populate each of these directories with a text file for each of the module, +where the text file contains lines alternating between the question and the +answer. + +Passing --train_split=False will create a single output directory 'train' for +training data. +""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import os + +# Dependency imports +from absl import app +from absl import flags +from absl import logging +import generate +import six +from six.moves import range + +FLAGS = flags.FLAGS + +flags.DEFINE_string('output_dir', None, 'Where to write output text') +flags.DEFINE_boolean('train_split', True, + 'Whether to split training data by difficulty') +flags.mark_flag_as_required('output_dir') + + +def main(unused_argv): + generate.init_modules(FLAGS.train_split) + + output_dir = os.path.expanduser(FLAGS.output_dir) + if os.path.exists(output_dir): + logging.fatal('output dir %s already exists', output_dir) + logging.info('Writing to %s', output_dir) + os.makedirs(output_dir) + + for regime, flat_modules in six.iteritems(generate.filtered_modules): + regime_dir = os.path.join(output_dir, regime) + os.mkdir(regime_dir) + per_module = generate.counts[regime] + for module_name, module in six.iteritems(flat_modules): + path = os.path.join(regime_dir, module_name + '.txt') + with open(path, 'w',encoding='utf-8') as text_file: + for _ in range(per_module): + problem, _ = generate.sample_from_module(module) + text_file.write(str(problem.question) + '\n') + text_file.write(str(problem.answer) + '\n') + logging.info('Written %s', path) + + +if __name__ == '__main__': + app.run(main) diff --git a/mathematics_dataset/mathematics_dataset/modules/__init__.py b/mathematics_dataset/mathematics_dataset/modules/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..d780829a1f5101333577a1ca9adcb960529213f1 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/modules/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/mathematics_dataset/mathematics_dataset/modules/algebra.py b/mathematics_dataset/mathematics_dataset/modules/algebra.py new file mode 100644 index 0000000000000000000000000000000000000000..f1f15932dbb95fba3275b2df433d3c947ad238c7 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/modules/algebra.py @@ -0,0 +1,378 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Algebra-related questions, e.g., "Solve 1 + x = 2.".""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import functools +import random + +# Dependency imports +import example +from sample import linear_system +from sample import number +from sample import ops +from sample import polynomials +from util import composition +from util import display +import numpy as np +from six.moves import range +import sympy + + +_ENTROPY_TRAIN = (3, 10) +_ENTROPY_INTERPOLATE = (8, 8) +_ENTROPY_EXTRAPOLATE = (12, 12) + +# In generating a polynomial with real roots (where the roots are generated +# sequentially), this is the probability of taking a previous root, thus giving +# at least one repeated root, rather than sampling a new number. The value is +# somewhat arbitrary, but gives a "medium probability" of seeing a repeated root +# for lowish degree polynomials. +_POLY_PROBABILITY_REPEATED_ROOT = 0.2 + + +def _make_modules(entropy): + """Returns modules given "difficulty" parameters.""" + sample_args_pure = composition.PreSampleArgs(1, 1, *entropy) + sample_args_composed = composition.PreSampleArgs(2, 4, *entropy) + + return { + # Solving equations: + 'polynomial_roots': functools.partial( + polynomial_roots, None, sample_args_pure), + 'polynomial_roots_composed': functools.partial( + polynomial_roots, None, sample_args_composed), + 'linear_1d': functools.partial( + solve_linear_1d, None, sample_args_pure), + 'linear_1d_composed': functools.partial( + solve_linear_1d, None, sample_args_composed), + 'linear_2d': functools.partial( + solve_linear_2d, None, sample_args_pure), + 'linear_2d_composed': functools.partial( + solve_linear_2d, None, sample_args_composed), + + # Sequences: + 'sequence_next_term': functools.partial(sequence_next_term, *entropy), + 'sequence_nth_term': functools.partial(sequence_nth_term, *entropy), + } + + +def train(entropy_fn): + """Returns dict of training modules.""" + return _make_modules(entropy_fn(_ENTROPY_TRAIN)) + + +def test(): + """Returns dict of testing modules.""" + return _make_modules(_ENTROPY_INTERPOLATE) + + +def test_extra(): + """Returns dict of extrapolation testing modules.""" + sample_args_pure = composition.PreSampleArgs(1, 1, *_ENTROPY_EXTRAPOLATE) + return { + 'polynomial_roots_big': functools.partial( + polynomial_roots, None, sample_args_pure), + } + + +def _sample_roots(entropy): + """Generates `num_distinct + num_repeated` polynomial roots.""" + num_roots = random.randint(2, 5) + + num_repeated = np.random.binomial( + num_roots - 1, _POLY_PROBABILITY_REPEATED_ROOT) + # Slight hack: don't allow all the roots to be repeated when the entropy is + # high, as this can create very large coefficients. + if entropy > 4: + num_repeated = min(num_repeated, int(num_roots / 2)) + + num_distinct = num_roots - num_repeated + + entropies = entropy * np.random.dirichlet(np.ones(num_distinct)) + + roots = [] + + for root_entropy in entropies: + # Generates a root with small probability of being rational. + # (Otherwise when we multiply out the denominators, we get really large + # coefficients in our polynomial.) + if random.random() < 0.1: + root = number.non_integer_rational(root_entropy, True) + else: + root = number.integer(root_entropy, True) + roots.append(root) + + for _ in range(num_repeated): + roots.append(random.choice(roots[:num_distinct])) + + return roots + + +def _polynomial_coeffs_with_roots(roots, scale_entropy): + """Returns a polynomial with the given roots. + + The polynomial is generated by expanding product_{root in roots} (x - root), + and then (1) scaling by the coefficients so they are all integers with lcm 1, + and then (2) further scaling the coefficients by a random integer or rational + with `scale_entropy` digits. + + Args: + roots: List of values. + scale_entropy: Float; entropy of the random coefficient scaling. + + Returns: + List of coefficients `coeffs`, such that `coeffs[i]` is the coefficient of + variable ** i. + """ + variable = sympy.Symbol('x') # doesn't matter, only use coefficients + polynomial = sympy.Poly(sympy.prod([variable - root for root in roots])) + coeffs_reversed = polynomial.all_coeffs() + assert len(coeffs_reversed) == len(roots) + 1 + coeffs = list(reversed(coeffs_reversed)) + # Multiply terms to change rationals to integers, and then maybe reintroduce. + lcm = sympy.lcm([sympy.denom(coeff) for coeff in coeffs]) + if scale_entropy > 0: + while True: + scale = number.integer_or_rational(scale_entropy, signed=True) + if scale != 0: + break + else: + scale = 1 + return [coeff * scale * lcm for coeff in coeffs] + + +def polynomial_roots(value, sample_args, context=None): + """E.g., "Solve 2*x**2 - 18 = 0.".""" + del value # not currently used + # is_question = context is None + if context is None: + context = composition.Context() + + entropy, sample_args = sample_args.peel() + scale_entropy = min(entropy / 2, 1) + + roots = _sample_roots(entropy - scale_entropy) + solutions = sorted(list(sympy.FiniteSet(*roots))) + coeffs = _polynomial_coeffs_with_roots(roots, scale_entropy) + (polynomial_entity,) = context.sample( + sample_args, [composition.Polynomial(coeffs)]) + + if random.choice([False, True]): + # Ask for explicit roots. + if len(solutions) == 1: + answer = solutions[0] + else: + answer = display.NumberList(solutions) + + if polynomial_entity.has_expression(): + equality = ops.Eq(polynomial_entity.expression, 0) + variable = polynomial_entity.polynomial_variables[0] + else: + variable = sympy.Symbol(context.pop()) + equality = ops.Eq(polynomial_entity.handle.apply(variable), 0) + template = random.choice([ + 'Seja {equality}. Qual é {variable}?', + 'Seja {equality}. Calcula {variable}.', + 'Supõe {equality}. Qual é {variable}?', + 'Supõe {equality}. Calcula {variable}?', + 'Qual é o valor de {variable} em {equality}?', + 'Resolve {equality} em relação a {variable}.', + 'Encontra {variable} tal que {equality}.', + 'Encontra {variable}, dado que {equality}.', + 'Determina {variable} para que {equality}.', + 'Determina {variable}, dado que {equality}.', + 'Resolve {equality}.' + ]) + return example.Problem( + question=example.question( + context, template, equality=equality, variable=variable), + answer=answer) + else: + if polynomial_entity.has_expression(): + expression = polynomial_entity.expression + variable = polynomial_entity.polynomial_variables[0] + else: + variable = sympy.Symbol(context.pop()) + expression = polynomial_entity.handle.apply(variable) + factored = sympy.factor( + polynomials.coefficients_to_polynomial(coeffs, variable)) + template = random.choice([ + 'Factoriza {expression}.', + ]) + return example.Problem( + question=example.question(context, template, expression=expression), + answer=factored) + + +def _solve_linear_system(degree, value, sample_args, context=None): + """Solve linear equations.""" + is_question = context is None + if context is None: + context = composition.Context() + + entropy, sample_args = sample_args.peel() + + solutions = [] + if value is not None: + solutions.append(value) + + extra_solutions_needed = degree - len(solutions) + if extra_solutions_needed > 0: + entropies = (entropy / 4) * np.random.dirichlet( + np.ones(extra_solutions_needed)) + entropies = np.maximum(1, entropies) # min per-solution entropy + entropy -= sum(entropies) + solutions += [number.integer(solution_entropy, True) + for solution_entropy in entropies] + entropy = max(1, entropy) + + variables = [sympy.Symbol(context.pop()) for _ in range(degree)] + + solution_index = 0 + # If we're going to be creating a linear system with constants to replace by + # handles from other modules, then we need a linear system with constants + # occurring. Very occasionally this can fail to happen, e.g., "x = -x"; + # normally this while loop will only see one iteration. + while True: + equations = linear_system.linear_system( + variables=variables, solutions=solutions, entropy=entropy, + non_trivial_in=solution_index) + constants = ops.number_constants(equations) + if sample_args.num_modules <= 1 or constants: + break + + context.sample_by_replacing_constants(sample_args, equations) + + variable = variables[solution_index] + answer = solutions[solution_index] + + equations = ', '.join([str(equation) for equation in equations]) + + if is_question: + template = random.choice([ + 'Resolve {equations} para {variable}.', + ]) + return example.Problem( + example.question( + context, template, equations=equations, + variable=variable), + answer) + else: + return composition.Entity( + context=context, + value=answer, + description='Supõe {equations}.', + handle=variable, + equations=equations) + + +@composition.module(number.is_integer) +def solve_linear_1d(*args, **kwargs): + return _solve_linear_system(1, *args, **kwargs) + + +@composition.module(number.is_integer) +def solve_linear_2d(*args, **kwargs): + return _solve_linear_system(2, *args, **kwargs) + + +class _PolynomialSequence(object): + """A sequence given by a polynomial.""" + + def __init__(self, variable, entropy, min_degree=1, max_degree=3): + """Initializes a random polynomial sequence. + + Args: + variable: Variable to use. + entropy: Entropy for polynomial coefficients. + min_degree: Minimum order of polynomial. + max_degree: Maximum order of polynomial. + """ + self._degree = random.randint(min_degree, max_degree) + self._variable = variable + polynomial = polynomials.sample_with_small_evaluation( + variable=self._variable, degree=self._degree, + max_abs_input=self._degree + 2, entropy=entropy) + self._sympy = polynomial.sympy() + + @property + def min_num_terms(self): + """Returns the minimum number of terms to identify the sequence. + + This assumes a human-like prior over types of sequences. + + Returns: + Integer >= 1. + """ + return self._degree + 2 + + @property + def sympy(self): + return self._sympy + + def term(self, n): + """Returns the `n`th term of the sequence.""" + return self._sympy.subs(self._variable, n) + + +def sequence_next_term(min_entropy, max_entropy): + """E.g., "What is the next term in the sequence 1, 2, 3?".""" + entropy = random.uniform(min_entropy, max_entropy) + context = composition.Context() + variable = sympy.Symbol(context.pop()) + + sequence = _PolynomialSequence(variable, entropy) + min_num_terms = sequence.min_num_terms + num_terms = random.randint(min_num_terms, min_num_terms + 3) + sequence_sample = [sequence.term(n + 1) for n in range(num_terms)] + sequence_sample = display.NumberList(sequence_sample) + + template = random.choice([ + 'O que se segue em {sequence}?', + 'O que vem a seguir: {sequence}?', + 'Qual é o termo seguinte em {sequence}?', + ]) + answer = sequence.term(num_terms + 1) + + return example.Problem( + question=example.question(context, template, sequence=sequence_sample), + answer=answer) + + +def sequence_nth_term(min_entropy, max_entropy): + """E.g., "What is the nth term in the sequence 1, 2, 3?".""" + entropy = random.uniform(min_entropy, max_entropy) + context = composition.Context() + variable = sympy.Symbol(context.pop()) + + sequence = _PolynomialSequence(variable, entropy) + min_num_terms = sequence.min_num_terms + num_terms = random.randint(min_num_terms, min_num_terms + 3) + sequence_sample = [sequence.term(n + 1) for n in range(num_terms)] + sequence_sample = display.NumberList(sequence_sample) + + template = random.choice([ + 'Qual é termo nº {variable} na sequência {sequence}?', + ]) + answer = sequence.sympy + + return example.Problem( + question=example.question( + context, template, variable=variable, sequence=sequence_sample), + answer=answer) diff --git a/mathematics_dataset/mathematics_dataset/modules/algebra_test.py b/mathematics_dataset/mathematics_dataset/modules/algebra_test.py new file mode 100644 index 0000000000000000000000000000000000000000..be4c47a6fca93b3489a81126702f000d53fc58ef --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/modules/algebra_test.py @@ -0,0 +1,48 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Tests for mathematics_dataset.modules.algebra.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import random + +# Dependency imports +from absl.testing import absltest +from modules import algebra +from sample import polynomials +from six.moves import range +import sympy + + +class AlgebraTest(absltest.TestCase): + + def testPolynomialCoeffsWithRoots(self): + coeffs = algebra._polynomial_coeffs_with_roots([1, 2], scale_entropy=0.0) + self.assertEqual(coeffs, [2, -3, 1]) + + def testPolynomialRoots(self): + variable = sympy.Symbol('x') + for _ in range(10): + roots = random.sample(list(range(-9, 10)), 3) + coeffs = algebra._polynomial_coeffs_with_roots(roots, scale_entropy=10.0) + polynomial = polynomials.coefficients_to_polynomial(coeffs, variable) + calc_roots = sympy.polys.polytools.real_roots(polynomial) + self.assertEqual(calc_roots, sorted(roots)) + + +if __name__ == '__main__': + absltest.main() diff --git a/mathematics_dataset/mathematics_dataset/modules/arithmetic.py b/mathematics_dataset/mathematics_dataset/modules/arithmetic.py new file mode 100644 index 0000000000000000000000000000000000000000..559be777025b3bed887954314763ffc902916380 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/modules/arithmetic.py @@ -0,0 +1,597 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Arithmetic, e.g., "calculate 2+3".""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import functools +import math +import random + +# Dependency imports +import example +from sample import arithmetic +from sample import number +from sample import ops +from util import composition +from util import display +import sympy + + +_ENTROPY_TRAIN = (3, 10) +_ENTROPY_INTERPOLATE = (8, 8) +_ENTROPY_EXTRAPOLATE = (10, 12) + +_ADD_SUB_ENTROPY_TRAIN = (4, 16) +_ADD_SUB_ENTROPY_INTERPOLATE = (12, 12) +_ADD_SUB_ENTROPY_EXTRAPOLATE = (16, 20) + +# In arithmetic expressions: +_EXTRAPOLATE_EXTRA_LENGTH = 3 + +_INT = 'int' +_INT_OR_RATIONAL = 'rational' + + +def _make_modules(entropy, add_sub_entropy): + """Returns modules given "difficulty" parameters.""" + sample_args_pure = composition.PreSampleArgs(1, 1, *entropy) + add_sub_sample_args_pure = composition.PreSampleArgs(1, 1, *add_sub_entropy) + + # TODO(b/124039105): consider composed modules? + return { + # Addition and subtraction of integers (and decimals) + 'add_or_sub': functools.partial( + add_or_sub, None, add_sub_sample_args_pure), + 'add_sub_multiple': functools.partial( + add_sub_multiple, _INT, sample_args_pure), + 'add_or_sub_in_base': functools.partial( + add_or_sub_in_base, sample_args_pure), + + # Multiplication and division + 'mul': functools.partial(mul, None, sample_args_pure), + 'div': functools.partial(div, None, sample_args_pure), + 'mul_div_multiple': functools.partial( + mul_div_multiple, _INT_OR_RATIONAL, sample_args_pure), + + # All together! + 'mixed': functools.partial(mixed, _INT_OR_RATIONAL, sample_args_pure), + + # And some other arithmetic-related stuff. + 'nearest_integer_root': functools.partial( + nearest_integer_root, sample_args_pure), + 'simplify_surd': functools.partial(simplify_surd, None, sample_args_pure), + } + + +def train(entropy_fn): + """Returns dict of training modules.""" + return _make_modules( + entropy=entropy_fn(_ENTROPY_TRAIN), + add_sub_entropy=entropy_fn(_ADD_SUB_ENTROPY_TRAIN)) + + +def test(): + """Returns dict of testing modules.""" + return _make_modules( + entropy=_ENTROPY_INTERPOLATE, + add_sub_entropy=_ADD_SUB_ENTROPY_INTERPOLATE) + + +def test_extra(): + """Returns dict of extrapolation testing modules.""" + sample_args_pure = composition.PreSampleArgs(1, 1, *_ENTROPY_EXTRAPOLATE) + add_sub_sample_args_pure = composition.PreSampleArgs( + 1, 1, *_ADD_SUB_ENTROPY_EXTRAPOLATE) + + train_length = arithmetic.length_range_for_entropy(_ENTROPY_TRAIN[1])[1] + def extrapolate_length(): + return random.randint( + train_length + 1, train_length + _EXTRAPOLATE_EXTRA_LENGTH) + + def add_sub_multiple_longer(): + return add_sub_multiple(_INT, sample_args_pure, length=extrapolate_length()) + def mul_div_multiple_longer(): + return mul_div_multiple(_INT, sample_args_pure, length=extrapolate_length()) + def mixed_longer(): + return mixed(_INT, sample_args_pure, length=extrapolate_length()) + + return { + 'add_or_sub_big': functools.partial( + add_or_sub, None, add_sub_sample_args_pure), + 'mul_big': functools.partial(mul, None, sample_args_pure), + 'div_big': functools.partial(div, None, sample_args_pure), + 'add_sub_multiple_longer': add_sub_multiple_longer, + 'mul_div_multiple_longer': mul_div_multiple_longer, + 'mixed_longer': mixed_longer, + } + + +def _value_sampler(value): + """Returns sampler (e.g., number.integer) appropriate for `value`.""" + if value == _INT or number.is_integer(value): + return functools.partial(number.integer, signed=True) + if value == _INT_OR_RATIONAL or isinstance(value, sympy.Rational): + return functools.partial(number.integer_or_rational, signed=True) + if isinstance(value, display.Decimal): + return functools.partial(number.integer_or_decimal, signed=True) + raise ValueError('Unrecognized value {} of type {}' + .format(value, type(value))) + + +def _add_question_or_entity(context, p, q, is_question): + """Generates entity or question for adding p + q.""" + value = p.value + q.value + + if is_question: + template = random.choice([ + '{p} + {q}', + '{p}+{q}', + 'Determina {p} + {q}.', + 'Adiciona {p} a {q}.', + 'Junta {p} e {q}.', + 'Soma {p} e {q}.', + 'O total de {p} mais {q}.', + 'Acresce {p} a {q}.', + 'Quanto é {p} mais {q}?', + 'Calcula {p} + {q}.', + 'Quanto é {p} + {q}?', + ]) + return example.Problem( + question=example.question(context, template, p=p, q=q), + answer=value) + else: + return composition.Entity( + context=context, + value=value, + description='Seja {self} = {p} + {q}.', + p=p, q=q) + + +def _sub_question_or_entity(context, p, q, is_question): + """Generates entity or question for subtraction p - q.""" + value = p.value - q.value + + if is_question: + templates = [ + '{p} - {q}', + 'Determina {p} - {q}.', + 'Quanto é {p} menos {q}?', + 'Quanto fica {p} retirando {q}?', + 'Quanto é {q} retirado de {p}?', + 'Subtrai {q} de {p}.', + 'Calcula {p} - {q}.', + 'Quanto é {p} - {q}?', + ] + if sympy.Ge(p.value, q.value): + # We calculate p - q, so the difference (|p - q|) is the correct answer. + for adjective in ['distância', 'diferença']: + for pair in ['{p} e {q}', '{q} e {p}']: + templates.append('Qual é a {} entre {}?'.format(adjective, pair)) + template = random.choice(templates) + return example.Problem( + question=example.question(context, template, p=p, q=q), + answer=value) + else: + return composition.Entity( + context=context, + value=value, + description='Seja {self} = {p} - {q}.', + p=p, q=q) + + +def _entropy_for_pair(entropy): + entropy_1 = max(1, random.uniform(0, entropy)) + entropy_2 = max(1, entropy - entropy_1) + return entropy_1, entropy_2 + + +@composition.module(number.is_integer_or_rational_or_decimal) +def add_or_sub(value, sample_args, context=None): + """Module for adding or subtracting two values.""" + is_question = context is None + if context is None: + context = composition.Context() + + is_addition = random.choice([False, True]) + entropy, sample_args = sample_args.peel() + + if value is None: + entropy_p, entropy_q = _entropy_for_pair(entropy) + p = number.integer_or_decimal(entropy_p, signed=True) + q = number.integer_or_decimal(entropy_q, signed=True) + else: + entropy = max(entropy, number.entropy_of_value(value)) + sampler = _value_sampler(value) + p = sampler(entropy) + if is_addition: + q = value - p + # Maybe swap for symmetry. + if random.choice([False, True]): + p, q = q, p + else: + q = p - value + # Maybe swap for symmetry. + if random.choice([False, True]): + p, q = -q, -p + + p, q = context.sample(sample_args, [p, q]) + + if is_addition: + return _add_question_or_entity(context, p, q, is_question) + else: + return _sub_question_or_entity(context, p, q, is_question) + + +def add_or_sub_in_base(sample_args): + """Module for addition and subtraction in another base.""" + context = composition.Context() + entropy, sample_args = sample_args.peel() + entropy_p, entropy_q = _entropy_for_pair(entropy) + p = number.integer(entropy_p, signed=True) + q = number.integer(entropy_q, signed=True) + base = random.randint(2, 16) + if random.choice([False, True]): + answer = p + q + template = 'Em base {base}, quanto é {p} + {q}?' + else: + answer = p - q + template = 'Em base {base}, quanto é {p} - {q}?' + return example.Problem( + question=example.question( + context, + template, + base=base, + p=display.NumberInBase(p, base), + q=display.NumberInBase(q, base)), + answer=display.NumberInBase(answer, base)) + + +def mul(value, sample_args, context=None): + """Returns random question for multiplying two numbers.""" + del value # unused + is_question = context is None + if context is None: + context = composition.Context() + entropy, sample_args = sample_args.peel() + entropy_p, entropy_q = _entropy_for_pair(entropy) + p = number.integer_or_decimal(entropy_p, True) + q = number.integer_or_decimal(entropy_q, True) + p, q = context.sample(sample_args, [p, q]) + answer = p.value * q.value + + if is_question: + templates = [ + '{p}' + ops.MUL_SYMBOL + '{q}', + '{p} ' + ops.MUL_SYMBOL + ' {q}', + 'Calcula {p} * {q}.', + 'Determina {p} * {q}.', + 'Multiplica {p} e {q}.', + 'Produto de {p} e {q}.', + 'Qual é o produto de {p} e {q}?', + '{p} vezes {q}', + 'Quanto é {p} vezes {q}?', + ] + template = random.choice(templates) + return example.Problem( + question=example.question(context, template, p=p, q=q), + answer=answer + ) + else: + return composition.Entity( + context=context, + value=answer, + description='Seja {self} = {p} * {q}.', + p=p, q=q) + + +def div(value, sample_args, context=None): + """Returns random question for dividing two numbers.""" + del value # unused + is_question = context is None + if context is None: + context = composition.Context() + + entropy, sample_args = sample_args.peel() + entropy_1, entropy_q = _entropy_for_pair(entropy) + + q = number.integer(entropy_q, True, min_abs=1) + + if random.choice([False, True]): + # Pick p/q with nice integer result. + answer = number.integer(entropy_1, True) + p = answer * q + else: + p = number.integer(entropy_1, True) + answer = p / q + + p, q = context.sample(sample_args, [p, q]) + + if is_question: + template = random.choice([ + 'Divide {p} por {q}.', + '{p} dividido por {q}', + 'Quanto é {p} dividido por {q}?', + 'Calcula {p} dividido por {q}.', + ]) + return example.Problem( + question=example.question(context, template, p=p, q=q), + answer=answer + ) + else: + return composition.Entity( + context=context, + value=answer, + description='Seja {self} ser {p} dividido por {q}.', + p=p, q=q) + + +def nearest_integer_root(sample_args): + """E.g., "Calculate the cube root of 35 to the nearest integer.".""" + context = composition.Context() + + # With at least 50% probability, pick square or cube root (these are most + # important roots!). + if random.choice([False, True]): + one_over_exponent = random.randint(2, 3) + else: + one_over_exponent = random.randint(2, 10) + + entropy, sample_args = sample_args.peel() + value = number.integer(entropy, signed=False) + answer = int(round(value ** (1 / one_over_exponent))) + + templates = [ + 'Quanto é {value} elevado a 1/{one_over_exponent}, arredondado para o ' + 'inteiro mais próximo?', + ] + + if one_over_exponent != 2: # "What is the second root of 4?" never used. + ordinal = str() + templates += [ + 'Qual é a {ordinal} raíz de {value} arredondada para o inteiro mais próximo?', + ] + + if one_over_exponent == 2: + templates += [ + 'Qual é a raíz quadrada de {value} arredondada para o inteiro mais próximo?', + ] + elif one_over_exponent == 3: + templates += [ + 'Qual é a raíz cúbica de {value} arredondada para o inteiro mais próximo?', + ] + + template = random.choice(templates) + + ordinal = display.StringOrdinal(one_over_exponent) + return example.Problem( + question=example.question( + context, template, value=value, ordinal=ordinal, + one_over_exponent=one_over_exponent), + answer=answer) + + +def _calculate(value, sample_args, context, add_sub, mul_div, length=None): + """Questions for evaluating arithmetic expressions.""" + is_question = context is None + if context is None: + context = composition.Context() + + entropy, sample_args = sample_args.peel() + + if value in [_INT, _INT_OR_RATIONAL]: + value_entropy = max(1.0, entropy / 4) + entropy = max(1.0, entropy - value_entropy) + sampler = _value_sampler(value) + value = sampler(value_entropy) + + op = arithmetic.arithmetic( + value=value, entropy=entropy, add_sub=add_sub, mul_div=mul_div, + length=length) + context.sample_by_replacing_constants(sample_args, op) + + if is_question: + template = random.choice([ + '{op}', + 'Quanto é {op}?', + 'Avalia {op}.', + 'Calcula {op}.', + 'Qual é o valor de {op}?', + ]) + return example.Problem( + question=example.question(context, template, op=op), + answer=value) + else: + return composition.Entity( + context=context, + value=value, + expression=op, + description='Assume que {self} é {op}.', + op=op) + + +def add_sub_multiple(value, sample_args, length=None): + return _calculate( + value, sample_args, None, add_sub=True, mul_div=False, length=length) + + +def mul_div_multiple(value, sample_args, length=None): + return _calculate( + value, sample_args, None, add_sub=False, mul_div=True, length=length) + + +@composition.module(number.is_integer_or_rational) +def mixed(value, sample_args, context=None, length=None): + return _calculate( + value, sample_args, context, add_sub=True, mul_div=True, length=length) + + +def _surd_coefficients(sympy_exp): + """Extracts coefficients a, b, where sympy_exp = a + b * sqrt(base).""" + sympy_exp = sympy.simplify(sympy.expand(sympy_exp)) + + def extract_b(b_sqrt_base): + """Returns b from expression of form b * sqrt(base).""" + if isinstance(b_sqrt_base, sympy.Pow): + # Just form sqrt(base) + return 1 + else: + assert isinstance(b_sqrt_base, sympy.Mul) + assert len(b_sqrt_base.args) == 2 + assert b_sqrt_base.args[0].is_rational + assert isinstance(b_sqrt_base.args[1], sympy.Pow) # should be sqrt. + return b_sqrt_base.args[0] + + if sympy_exp.is_rational: + # Form: a. + return sympy_exp, 0 + elif isinstance(sympy_exp, sympy.Add): + # Form: a + b * sqrt(base) + assert len(sympy_exp.args) == 2 + assert sympy_exp.args[0].is_rational + a = sympy_exp.args[0] + b = extract_b(sympy_exp.args[1]) + return a, b + else: + # Form: b * sqrt(base). + return 0, extract_b(sympy_exp) + + +def _surd_split_entropy_two(entropy): + entropy_left = entropy / 2 + if entropy_left < 1: + entropy_left = 0 + entropy_right = entropy - entropy_left + if random.choice([False, True]): + entropy_left, entropy_right = entropy_right, entropy_left + return entropy_left, entropy_right + + +def _sample_surd(base, entropy, max_power, multiples_only): + """An expression that can be reduced to a + b * sqrt(base). + + For example, if base=3, then the following are valid expressions: + + * sqrt(12) (reduces to 2 * sqrt(3)) + * sqrt(3) - 10 * sqrt(3) (reduces to -9 * sqrt(3)) + * sqrt(15) / sqrt(5) (reduces to sqrt(3)). + * 4 * sqrt(3) / 2 + * 2 + sqrt(3) + * 1 / (1 + sqrt(3)) (reduces to -1/2 + (-1/2) sqrt(3)) + + However, 1 + 2 * sqrt(3) is not valid, as it does not reduce to the form + a * sqrt(3). + + Args: + base: The value inside the square root. + entropy: Float >= 0; used for randomness. + max_power: Integer >= 1; the max power used in expressions. If 1 then + disables. + multiples_only: Whether the surd should be an integer multiple of + sqrt(base). + + Returns: + Instance of `ops.Op`. + """ + if entropy <= 0: + return ops.Sqrt(base) + + def add_or_sub_(): + # Add or subtract two such types. + entropy_left, entropy_right = _surd_split_entropy_two(entropy) + left = _sample_surd(base, entropy_left, max_power, multiples_only) + right = _sample_surd(base, entropy_right, max_power, multiples_only) + op = random.choice([ops.Add, ops.Sub]) + return op(left, right) + + def mul_by_integer(): + entropy_k = min(1, entropy) + left = number.integer(entropy_k, signed=True, min_abs=1) + right = _sample_surd(base, entropy - entropy_k, max_power, multiples_only) + if random.choice([False, True]): + left, right = right, left + return ops.Mul(left, right) + + def div_by_sqrt_k(): + """Do sqrt(k * base) / sqrt(k).""" + entropy_k = min(1, entropy) + k = number.integer(entropy_k, signed=False, min_abs=2) + entropy_left, entropy_right = _surd_split_entropy_two(entropy - entropy_k) + k_base_expr = _sample_surd(k * base, entropy_left, max_power, True) + while True: + k_expr = _sample_surd(k, entropy_right, max_power, True) + if k_expr.sympy() != 0: + break + return ops.Div(k_base_expr, k_expr) + + def square_k(): + """Do sqrt(k * k * base).""" + entropy_k = min(1, entropy) + k = number.integer(entropy_k, signed=False, min_abs=2) + return _sample_surd( + k * k * base, entropy - entropy_k, max_power, multiples_only) + + def surd_plus_integer(): + """Do surd + integer.""" + entropy_k = min(1, entropy) + left = number.integer(entropy_k, signed=True) + assert not multiples_only + right = _sample_surd(base, entropy - entropy_k, max_power, False) + if random.choice([True, False]): + left, right = right, left + return ops.Add(left, right) + + def power(): + """Do surd**2.""" + assert not multiples_only + surd = _sample_surd(base, entropy, max_power=1, multiples_only=False) + return ops.Pow(surd, 2) + + choices = [add_or_sub_, mul_by_integer] + if not multiples_only: + choices += [surd_plus_integer] + if max_power > 1: + choices += [power] + if base < 64: # prevent value inside sqrt from getting too big + choices += [div_by_sqrt_k, square_k] + which = random.choice(choices) + return which() + + +def simplify_surd(value, sample_args, context=None): + """E.g., "Simplify (2 + 5*sqrt(3))**2.".""" + del value # unused + if context is None: + context = composition.Context() + + entropy, sample_args = sample_args.peel() + + while True: + base = random.randint(2, 20) + if sympy.Integer(base).is_prime: + break + num_primes_less_than_20 = 8 + entropy -= math.log10(num_primes_less_than_20) + exp = _sample_surd(base, entropy, max_power=2, multiples_only=False) + simplified = sympy.expand(sympy.simplify(exp)) + + template = random.choice([ + 'Simplificar {exp}.', + ]) + return example.Problem( + question=example.question(context, template, exp=exp), + answer=simplified) diff --git a/mathematics_dataset/mathematics_dataset/modules/arithmetic_test.py b/mathematics_dataset/mathematics_dataset/modules/arithmetic_test.py new file mode 100644 index 0000000000000000000000000000000000000000..0be9ff7b54bfae52514f4160257e7f3fbf9428c0 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/modules/arithmetic_test.py @@ -0,0 +1,64 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Tests for mathematics_dataset.modules.arithmetic.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +# Dependency imports +from absl.testing import absltest +from modules import arithmetic +import sympy + + +class ArithmeticTest(absltest.TestCase): + + def testSurdCoefficients(self): + exp = sympy.sympify('1') + self.assertEqual(arithmetic._surd_coefficients(exp), + (1, 0)) + + exp = sympy.sympify('1/2') + self.assertEqual(arithmetic._surd_coefficients(exp), + (1/2, 0)) + + exp = sympy.sympify('sqrt(2)') + self.assertEqual(arithmetic._surd_coefficients(exp), + (0, 1)) + + exp = sympy.sympify('3*sqrt(2)') + self.assertEqual(arithmetic._surd_coefficients(exp), + (0, 3)) + + exp = sympy.sympify('3*sqrt(5)/2') + self.assertEqual(arithmetic._surd_coefficients(exp), + (0, 3/2)) + + exp = sympy.sympify('1 + 3 * sqrt(2)') + self.assertEqual(arithmetic._surd_coefficients(exp), + (1, 3)) + + exp = sympy.sympify('1/2 + 3 * sqrt(5) / 2') + self.assertEqual(arithmetic._surd_coefficients(exp), + (1/2, 3/2)) + + exp = sympy.sympify('sqrt(2)/(-1 + 2*sqrt(2))**2') + self.assertEqual(arithmetic._surd_coefficients(exp), + (8/49, 9/49)) + + +if __name__ == '__main__': + absltest.main() diff --git a/mathematics_dataset/mathematics_dataset/modules/calculus.py b/mathematics_dataset/mathematics_dataset/modules/calculus.py new file mode 100644 index 0000000000000000000000000000000000000000..46e6c9948f86d5fdf38e6ef18424ea6189496654 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/modules/calculus.py @@ -0,0 +1,198 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Calculus related questions, e.g., "differentiate x**2".""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import functools +import math +import random + +# Dependency imports +import example +from sample import polynomials +from util import composition +from util import display +import numpy as np +from six.moves import range +import sympy + + +_ENTROPY_TRAIN = (3, 10) +_ENTROPY_INTERPOLATE = (8, 8) + + +def _make_modules(entropy): + """Returns modules given "difficulty" parameters.""" + sample_args_pure = composition.PreSampleArgs(1, 1, *entropy) + sample_args_composed = composition.PreSampleArgs(2, 4, *entropy) + + return { + 'differentiate_composed': functools.partial( + differentiate_univariate, None, sample_args_composed), + 'differentiate': functools.partial(differentiate, None, sample_args_pure), + } + + +def train(entropy_fn): + """Returns dict of training modules.""" + return _make_modules(entropy_fn(_ENTROPY_TRAIN)) + + +def test(): + """Returns dict of testing modules.""" + return _make_modules(_ENTROPY_INTERPOLATE) + + +def test_extra(): + """Returns dict of extrapolation testing modules.""" + return { + } + + +def _generate_polynomial(num_variables, entropy, derivative_order, + derivative_axis): + """Returns polynomial.""" + # Note: numpy randint has upper bound as ) not ], unlike python random.randint + degrees = np.random.randint(1, 4, [num_variables]) + degrees[derivative_axis] = np.random.randint(0, 4) # allow to be zero here. + + coefficients = polynomials.sample_coefficients(degrees, entropy) + + # We also generate coefficients that will disappear when differentiated. + # Thus we don't account for the entropy used here. + assert derivative_order > 0 + degrees[derivative_axis] = derivative_order - 1 + extra_coefficients = polynomials.sample_coefficients(degrees, entropy) + + return np.concatenate( + [extra_coefficients, coefficients], axis=derivative_axis) + + +def _template(module_count, derivative_order, num_variables): + """Selects appropriate template.""" + templates = [ + 'Encontra a {nth} derivada de {eq} em relação a {var}.', + 'Qual é a {nth} derivada de {eq} em relação a {var}?', + ] + if derivative_order == 1: + templates += [ + 'Deriva {eq} em relação a {var}.', + 'Diferencia {eq} em relação a {var}.', + 'Qual é a derivada de {eq} em relação a {var}?', + ] + + derivative_variable_is_unambiguous = num_variables == 1 and module_count == 1 + if derivative_variable_is_unambiguous: + templates += [ + 'Encontra a {nth} derivada de {eq}.', + 'Qual é a {nth} derivada de {eq}?', + ] + if derivative_order == 1: + templates += [ + 'Deriva {eq}.', + 'Qual é a derivada de {eq}?', + ] + + return random.choice(templates) + + +def _sample_integrand(coefficients, derivative_order, derivative_axis, entropy): + """Integrates `coefficients` and adds sampled "constant" terms.""" + coefficients = np.asarray(coefficients) + + # Integrate (with zero for constant terms). + integrand = coefficients + for _ in range(derivative_order): + integrand = polynomials.integrate(integrand, derivative_axis) + + # Add on sampled constant terms. + constant_degrees = np.array(integrand.shape) - 1 + constant_degrees[derivative_axis] = derivative_order - 1 + extra_coeffs = polynomials.sample_coefficients(constant_degrees, entropy) + pad_amount = coefficients.shape[derivative_axis] + pad = [(0, pad_amount if i == derivative_axis else 0) + for i in range(coefficients.ndim)] + extra_coeffs = np.pad(extra_coeffs, pad, 'constant', constant_values=0) + return integrand + extra_coeffs + + +def _differentiate_polynomial(value, sample_args, context, num_variables): + """Generates a question for differentiating a polynomial.""" + is_question = context is None + if context is None: + context = composition.Context() + + if value is not None: + num_variables = value.coefficients.ndim + + entropy, sample_args = sample_args.peel() + max_derivative_order = 3 + derivative_order = random.randint(1, max_derivative_order) + entropy = max(0, entropy - math.log10(max_derivative_order)) + + derivative_axis = random.randint(0, num_variables - 1) + if value is None: + coefficients = _generate_polynomial( + num_variables, entropy, derivative_order, derivative_axis) + else: + coefficients = _sample_integrand( + value.coefficients, derivative_order, derivative_axis, entropy) + + (entity,) = context.sample( + sample_args, [composition.Polynomial(coefficients)]) + + value = coefficients + for _ in range(derivative_order): + value = polynomials.differentiate(value, axis=derivative_axis) + nth = display.StringOrdinal(derivative_order) + + if entity.has_expression(): + polynomial = entity.expression + variables = entity.polynomial_variables + else: + variables = [sympy.Symbol(context.pop()) for _ in range(num_variables)] + polynomial = entity.handle.apply(*variables) + variable = variables[derivative_axis] + + if is_question: + template = _template(context.module_count, derivative_order, len(variables)) + answer = polynomials.coefficients_to_polynomial(value, variables).sympy() + return example.Problem( + question=example.question( + context, template, eq=polynomial, var=variable, nth=nth), + answer=answer) + else: + fn_symbol = context.pop() + variables_string = ', '.join(str(variable) for variable in variables) + assert len(variables) == 1 # since below we don't specify var we diff wrt + return composition.Entity( + context=context, + value=composition.Polynomial(value), + description='Seja {fn}({variables}) a {nth} derivada de {eq}.', + handle=composition.FunctionHandle(fn_symbol), + fn=fn_symbol, variables=variables_string, nth=nth, eq=polynomial) + + +def differentiate_univariate(value, sample_args, context=None): + return _differentiate_polynomial(value, sample_args, context, 1) + + +@composition.module(composition.is_polynomial) +def differentiate(value, sample_args, context=None): + num_variables = random.randint(1, 4) + return _differentiate_polynomial(value, sample_args, context, num_variables) diff --git a/mathematics_dataset/mathematics_dataset/modules/calculus_test.py b/mathematics_dataset/mathematics_dataset/modules/calculus_test.py new file mode 100644 index 0000000000000000000000000000000000000000..c7693d1f6f498ed34e450b58eebb323fea254e5d --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/modules/calculus_test.py @@ -0,0 +1,43 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Tests for mathematics_dataset.modules.calculus.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +# Dependency imports +from modules import calculus +import tensorflow as tf + + +class CalculusTest(tf.test.TestCase): + + def testSampleIntegrand(self): + # y + 2*x + 3*x**2 + coefficients = [[0, 1], [2, 0], [3, 0]] + derivative_order = 1 + derivative_axis = 0 + # const + x*y + x**2 + x**3 + expected = [[0, 1], [1, 0], [1, 0]] + entropy = 4 + result = calculus._sample_integrand( + coefficients, derivative_order, derivative_axis, entropy) + result = result[1:, :] # ignore random constant terms + self.assertAllEqual(result, expected) + + +if __name__ == '__main__': + tf.test.main() diff --git a/mathematics_dataset/mathematics_dataset/modules/comparison.py b/mathematics_dataset/mathematics_dataset/modules/comparison.py new file mode 100644 index 0000000000000000000000000000000000000000..c88ce8c8c9d76d97bf134479e46d13eca9f82fb7 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/modules/comparison.py @@ -0,0 +1,455 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Comparisons, e.g. "is 2 > 3?".""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import functools +import random + +# Dependency imports +import example +from sample import number +from sample import ops +from util import composition +from util import display +import numpy as np +from six.moves import range +import sympy + + +_ENTROPY_TRAIN = (3, 10) +_ENTROPY_INTERPOLATE = (8, 8) +_ENTROPY_EXTRAPOLATE = (12, 12) + +_EXTRAPOLATION_EXTRA_COUNT = 2 + +_PROB_EQUAL = 0.2 + + +def _make_modules(entropy): + """Returns modules given "difficulty" parameters.""" + sample_args_pure = composition.PreSampleArgs(1, 1, *entropy) + sample_args_composed = composition.PreSampleArgs(2, 4, *entropy) + + return { + 'pair': functools.partial(pair, sample_args_pure), + 'pair_composed': functools.partial(pair, sample_args_composed), + 'kth_biggest': functools.partial(kth_biggest, sample_args_pure), + 'kth_biggest_composed': functools.partial( + kth_biggest, sample_args_composed), + 'closest': functools.partial(closest, sample_args_pure), + 'closest_composed': functools.partial(closest, sample_args_composed), + 'sort': functools.partial(sort, sample_args_pure), + 'sort_composed': functools.partial(sort, sample_args_composed), + } + + +def train(entropy_fn): + """Returns dict of training modules.""" + return _make_modules(entropy_fn(_ENTROPY_TRAIN)) + + +def test(): + """Returns dict of testing modules.""" + return _make_modules(_ENTROPY_INTERPOLATE) + + +def test_extra(): + """Returns dict of extrapolation testing modules.""" + sample_args_pure = composition.PreSampleArgs(1, 1, *_ENTROPY_EXTRAPOLATE) + + def sort_count(): + lower = _sort_count_range(_ENTROPY_TRAIN[1])[1] + return random.randint(lower + 1, lower + _EXTRAPOLATION_EXTRA_COUNT) + def closest_count(): + lower = _closest_count_range(_ENTROPY_TRAIN[1])[1] + return random.randint(lower + 1, lower + _EXTRAPOLATION_EXTRA_COUNT) + def kth_biggest_more(): + return kth_biggest(sample_args_pure, count=sort_count()) + def sort_more(): + return sort(sample_args_pure, count=sort_count()) + def closest_more(): + return closest(sample_args_pure, count=closest_count()) + + return { + 'kth_biggest_more': kth_biggest_more, + 'sort_more': sort_more, + 'closest_more': closest_more, + } + + +def _make_comparison_question(context, left, right): + """Makes a question for comparing two values.""" + if random.choice([False, True]) and sympy.Ne(left.value, right.value): + # Do question of form: "Which is bigger: a or b?". + if random.choice([False, True]): + answer = ( + left.handle if sympy.Gt(left.value, right.value) else right.handle) + template = random.choice([ + 'Qual é maior: {left} ou {right}?', + 'Qual é superior: {left} ou {right}?', + ]) + else: + answer = ( + left.handle if sympy.Lt(left.value, right.value) else right.handle) + template = random.choice([ + 'Qual é menor: {left} ou {right}?', + ]) + return example.Problem( + question=example.question(context, template, left=left, right=right), + answer=answer) + + comparisons = { + '<': sympy.Lt, + '<=': sympy.Le, + '>': sympy.Gt, + '>=': sympy.Ge, + '=': sympy.Eq, + '!=': sympy.Ne, + } + + templates = { + '<': [ + 'Será {left} ' + ops.LT_SYMBOL + ' {right}?', + 'Será {left} menor que {right}?', + 'Será {left} menor do que {right}?', + ], + '<=': [ + 'Será {left} ' + ops.LE_SYMBOL + ' {right}?', + 'Será {left} menor ou igual a {right}?', + 'Será {left}, no máximo, {right}?', + 'Será {left}, no máximo, tão grande quanto {right}?', + ], + '>': [ + 'Será {left} ' + ops.GT_SYMBOL + ' {right}?', + 'Será {left} maior que {right}?', + 'Será {left} maior do que {right}?', + ], + '>=': [ + 'Será {left} ' + ops.GE_SYMBOL + ' {right}?', + 'É verdade que {left} é maior ou igual a {right}?', + 'É verdade que {left} é, no mínimo, {right}?', + 'É verdade que {left} é, pelo menos, maior do que {right}?', + ], + '=': [ + 'Será que {left} ' + ops.EQ_SYMBOL + ' {right}?', + 'Serão {left} e {right} iguais?', + 'Será {left} igual a {right}?', + 'Será que {left} e {right} possuem o mesmo valor?', + ], + '!=': [ + 'Será que {left} ' + ops.NE_SYMBOL + ' {right}?', + 'Será {left} diferente de {right}?', + 'Será que {left} e {right} são desiguais?', + 'Será que {left} e {right} não são equivalentes?', + 'Será que {left} e {right} não são iguais?', + 'Será que {left} e {right} possuem valores diferentes?', + ], + } + + comparison = random.choice(list(comparisons.keys())) + template = random.choice(templates[comparison]) + question = example.question(context, template, left=left, right=right) + answer = comparisons[comparison](left.value, right.value) + + return example.Problem(question=question, answer=answer) + + +def integer_or_rational_or_decimal(entropy): + if random.choice([False, True]): + return number.integer_or_decimal(entropy, signed=True) + else: + return number.integer_or_rational(entropy, signed=True) + + +def pair(sample_args, context=None): + """Compares two numbers, e.g., "is 1/2 < 0.5?".""" + if context is None: + context = composition.Context() + entropy, sample_args = sample_args.peel() + + def integers_close(): + entropy_diff, entropy_left = entropy * np.random.dirichlet([1, 3]) + left = number.integer(entropy_left, True) + right = left + number.integer(entropy_diff, True) + return left, right + + def rational_and_integer(): + # Pick rational, and integer close to rational evaluation + left = number.non_integer_rational(entropy, True) + right = int(round(left)) + random.randint(-1, 1) + return left, right + + def independent(): + # Return an independent pair. + entropy_left, entropy_right = entropy * np.random.dirichlet([1, 1]) + left = integer_or_rational_or_decimal(entropy_left) + right = integer_or_rational_or_decimal(entropy_right) + return left, right + + generator = random.choice([integers_close, rational_and_integer, independent]) + + left, right = generator() + + # maybe swap for symmetry + if random.choice([False, True]): + left, right = right, left + left, right = context.sample(sample_args, [left, right]) + + return _make_comparison_question(context, left, right) + + +def _entities_to_list(entities): + entity_dict = {} + values_template = '' + for i, entity in enumerate(entities): + if i > 0: + values_template += ', ' + entity_name = 'entity_{}'.format(i) + entity_dict[entity_name] = entity + values_template += '{' + entity_name + '}' + return entity_dict, values_template + + +def _entities_to_choices(entities, answer): + """Generate a multichoice question template.""" + if len(entities) > 26: + raise ValueError('Too many choices: {}'.format(len(entities))) + + entity_dict = {} + choices_template = '' + answer_choice = None + for i, entity in enumerate(entities): + choices_template += ' ' + entity_name = 'entity_{}'.format(i) + entity_dict[entity_name] = entity + letter = chr(ord('a') + i) + choices_template += '({letter}) {{{entity_name}}}'.format( + letter=letter, entity_name=entity_name) + if entity is answer: + assert answer_choice is None + answer_choice = letter + + assert answer_choice is not None + return entity_dict, choices_template, answer_choice + + +def _mark_choice_letters_used(count, context): + """Marks the choice letters as used.""" + for i in range(count): + context.mark_used(chr(ord('a') + i)) + + +def _kth_biggest_list_question(context, entities, adjective, answer): + """Ask for the biggest (or smallest, or second biggest, etc) in a list.""" + entity_dict, values_template = _entities_to_list(entities) + + question = example.question( + context, 'Qual é o {adjective} valor em ' + values_template + '?', + adjective=adjective, **entity_dict) + return example.Problem(question=question, answer=answer.handle) + + +def _kth_biggest_multichoice_question(context, entities, adjective, answer): + """Ask for the biggest (or smallest, or second biggest, etc) of choices.""" + entity_dict, choices_template, answer_choice = _entities_to_choices( + entities, answer) + question = example.question( + context, 'Qual valor é {adjective}?' + choices_template, + adjective=adjective, **entity_dict) + return example.Problem(question=question, answer=answer_choice) + + +def _entity_sort_key(entity): + return sympy.default_sort_key(entity.value) + + +def _sort_count_range(entropy): + min_ = 3 + return min_, min_ + int(entropy/2) + + +def _unique_values(entropy, only_integers=False, count=None): + """Generates unique values.""" + if count is None: + count = random.randint(*_sort_count_range(entropy)) + + if only_integers: + sampler = functools.partial(number.integer, signed=True) + else: + sampler = integer_or_rational_or_decimal + + for _ in range(1000): + entropies = entropy * np.random.dirichlet(np.ones(count)) + entropies = np.maximum(1, entropies) + values = [sampler(ent) for ent in entropies] + if len(sympy.FiniteSet(*values)) == len(values): + return values + raise ValueError('Could not generate {} unique values with entropy={}' + .format(count, entropy)) + + +def kth_biggest(sample_args, count=None): + """Asks for the kth biggest value in a list.""" + sample_args = sample_args() + context = composition.Context() + + entropy, sample_args = sample_args.peel() + values = _unique_values(entropy, count=count) + count = len(values) + + display_multichoice = random.choice([False, True]) + if display_multichoice: + _mark_choice_letters_used(count, context) + + entities = context.sample(sample_args, values) + sorted_entities = sorted(entities, key=_entity_sort_key) + ordinal = random.randint(1, count) + + if random.choice([False, True]): + # Do from biggest. + answer = sorted_entities[-ordinal] + adjective = 'maior' + else: + # Do from smallest. + answer = sorted_entities[ordinal - 1] + adjective = 'menor' + + if ordinal > 1: + ordinal_PT_masc = "" + for palavra in str(display.StringOrdinal(ordinal)).split(): + ordinal_PT_masc += palavra[:-1] + "o" + adjective = ordinal_PT_masc + ' ' + adjective + + if display_multichoice: + return _kth_biggest_multichoice_question( + context=context, entities=entities, adjective=adjective, answer=answer) + else: + return _kth_biggest_list_question( + context=context, entities=entities, adjective=adjective, answer=answer) + + +def _closest_in_list_question(context, entities, target, adjective, answer): + """Ask for the closest to a given value in a list.""" + entity_dict, values_template = _entities_to_list(entities) + + question = example.question( + context, + 'Qual valor está {adjective} de {target} em ' + values_template + '?', + adjective=adjective, target=target, **entity_dict) + return example.Problem(question=question, answer=answer.handle) + + +def _closest_multichoice_question(context, entities, target, adjective, answer): + """Ask for the closest to a given value in a set of choices.""" + entity_dict, choices_template, answer_choice = _entities_to_choices( + entities, answer) + + question = example.question( + context, + 'Qual está {adjective} de {target}?' + choices_template, + adjective=adjective, target=target, **entity_dict) + return example.Problem(question=question, answer=answer_choice) + + +def _closest_count_range(entropy): + min_ = 3 + return min_, min_ + int(entropy/3) + + +def closest(sample_args, count=None): + """Ask for the closest to a given value in a list.""" + sample_args = sample_args() + context = composition.Context() + + entropy, sample_args = sample_args.peel() + if count is None: + count = random.randint(*_closest_count_range(entropy)) + + display_multichoice = random.choice([False, True]) + if display_multichoice: + _mark_choice_letters_used(count, context) + + entropy_target, entropy_list = entropy * np.random.dirichlet([1, count]) + target = integer_or_rational_or_decimal(entropy_target) + + while True: + value_entropies = entropy_list * np.random.dirichlet(np.ones(count)) + value_entropies = np.maximum(1, value_entropies) + values = [integer_or_rational_or_decimal(ent) for ent in value_entropies] + differences = [abs(sympy.sympify(value) - target) for value in values] + if len(sympy.FiniteSet(*differences)) == count: # all differences unique + break + + target_and_entities = context.sample(sample_args, [target] + values) + target = target_and_entities[0] + entities = target_and_entities[1:] + + min_difference = min(differences) + answer_index = differences.index(min_difference) + answer = entities[answer_index] + adjective = random.choice(['mais próximo', 'mais perto']) + + if display_multichoice: + return _closest_multichoice_question( + context=context, entities=entities, target=target, adjective=adjective, + answer=answer) + else: + return _closest_in_list_question( + context=context, entities=entities, target=target, adjective=adjective, + answer=answer) + + +def sort(sample_args, count=None): + """Ask to sort numbers in increasing or decreasing order.""" + sample_args = sample_args() + context = composition.Context() + + entropy, sample_args = sample_args.peel() + # Sometimes just integers, to allow for more terms in a short space. + values = _unique_values( + entropy, only_integers=random.choice([False, True]), count=count) + + entities = context.sample(sample_args, values) + + unsorted_dict, unsorted_template = _entities_to_list(entities) + + ascending = random.choice([False, True]) + templates = [ + 'Ordena ' + unsorted_template + ' por ordem {direction}.', + 'Coloca ' + unsorted_template + ' em ordem {direction}.', + ] + if ascending: + templates.append('Ordena ' + unsorted_template + '.') + direction = random.choice(['ascendente', 'crescente']) + else: + direction = random.choice(['descendente', 'decrescente']) + template = random.choice(templates) + + sorted_entities = sorted( + entities, key=_entity_sort_key, reverse=(not ascending)) + answer = '' + for i, entity in enumerate(sorted_entities): + if i > 0: + answer += ', ' + answer += str(entity.handle) + + return example.Problem( + question=example.question( + context, template, direction=direction, **unsorted_dict), + answer=answer) diff --git a/mathematics_dataset/mathematics_dataset/modules/measurement.py b/mathematics_dataset/mathematics_dataset/modules/measurement.py new file mode 100644 index 0000000000000000000000000000000000000000..08a1a45d6e512346f162fbc7f87879b6bd7042e0 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/modules/measurement.py @@ -0,0 +1,279 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Measurement questions, e.g., "How many hours are there in a day?".""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import collections +import functools +import random + +# Dependency imports +import example +from modules import train_test_split +from sample import number +from util import composition +from util import display +import six +import sympy + + +def _make_modules(is_train): + """Returns modules, with split based on the boolean `is_train`.""" + return { + 'conversion': functools.partial( + conversion, is_train=is_train, is_extrapolation=False), + 'time': functools.partial(time, is_train=is_train), + } + + +def train(entropy_fn): + """Returns dict of training modules.""" + del entropy_fn # unused + return _make_modules(is_train=True) + + +def test(): + """Returns dict of testing modules.""" + return _make_modules(is_train=False) + + +def test_extra(): + """Returns dict of extrapolation testing modules.""" + return { + 'conversion': functools.partial( + conversion, is_train=False, is_extrapolation=True), + } + + +Unit = collections.namedtuple('Unit', ('name', 'symbol')) + + +MICRO_SYMBOL = 'u' + + +LENGTH = { + Unit('metro', 'm'): 1, + Unit('quilómetro', 'km'): 1000, + Unit('centímetro', 'cm'): sympy.Rational(1, 100), + Unit('millímetro', 'mm'): sympy.Rational(1, 1000), + Unit('micrómetro', 'um'): sympy.Rational(1, 1e6), + Unit('nanómetro', 'nm'): sympy.Rational(1, 1e9), +} + +TIME = { + Unit('segundo', 's'): 1, + Unit('minuto', None): 60, + Unit('hora', None): 60*60, + Unit('dia', None): 24*60*60, + Unit('semana', None): 7*24*60*60, + Unit('miliseguno', 'ms'): sympy.Rational(1, 1e3), + Unit('microsegundo', MICRO_SYMBOL + 's'): sympy.Rational(1, 1e6), + Unit('nanosegundo', 'ns'): sympy.Rational(1, 1e9), +} + +TIME_YEARLY = { + Unit('ano', None): 1, + Unit('década', None): 10, + Unit('século', None): 100, + Unit('milénio', None): 1000, + Unit('mês', None): sympy.Rational(1, 12), +} + +MASS = { + Unit('quilograma', 'kg'): 1, # Yes, the *kilo*gram is the SI base unit. + Unit('tonelada', 't'): 1000, + Unit('grama', 'g'): sympy.Rational(1, 1e3), + Unit('milligrama', 'mg'): sympy.Rational(1, 1e6), + Unit('micrograma', MICRO_SYMBOL + 'g'): sympy.Rational(1, 1e9), + Unit('nanograma', 'ng'): sympy.Rational(1, 1e12), +} + +VOLUME = { + Unit('litro', 'l'): 1, + Unit('mililitro', 'ml'): sympy.Rational(1, 1000), +} + + +DIMENSIONS = [LENGTH, TIME, TIME_YEARLY, MASS, VOLUME] + + +def pluralize(name): + if name == 'century': + return 'centuries' + if name == 'mês': + return 'meses' + if name == 'millennium': + return 'millennia' + return name + 's' + + +def _factor_non_decimal(value): + """Extras x dividing value such that x is coprime to 2 and 5.""" + result = 1 + factors = sympy.factorint(value) + for factor, power in six.iteritems(factors): + if factor not in [2, 5]: + result *= factor ** power + return result + + +def _sample_conversion_decimal(dimension, is_extrapolation): + """Samples to and from units and values.""" + base_unit, target_unit = random.sample(list(dimension.keys()), 2) + scale = sympy.Rational(dimension[base_unit]) / dimension[target_unit] + scale_non_decimal = _factor_non_decimal(sympy.denom(scale)) + entropy = 9 if is_extrapolation else 7 + base_value = number.non_integer_decimal(entropy, signed=False) + base_value = display.Decimal(base_value.value * scale_non_decimal) + target_value = display.Decimal(base_value.value * scale) + return base_value, base_unit, target_value, target_unit + + +def _conversion_decimal(context, is_train, is_extrapolation): + """E.g., "How many grams are in 5kg?".""" + dimension = random.choice(DIMENSIONS) + while True: + base_value, base_unit, target_value, target_unit = ( + _sample_conversion_decimal(dimension, is_extrapolation)) + if train_test_split.is_train(base_value) == is_train: + break + + templates = [ + 'Quantos(as) {target_name} estão em {base_value} {base_name}?', + 'Quanto é {base_value} {base_name} em {target_name}?', + 'Converte {base_value} {base_name} para {target_name}.', + ] + if base_unit.symbol is not None: + templates += [ + 'Quantos(as) {target_name} estão em {base_value}{base_symbol}?', + 'Quanto é {base_value}{base_symbol} em {target_name}?', + 'Converte {base_value}{base_symbol} para {target_name}.', + ] + template = random.choice(templates) + + base_name = pluralize(base_unit.name) + target_name = pluralize(target_unit.name) + + question = example.question( + context, + template, + base_name=base_name, + base_symbol=base_unit.symbol, + base_value=base_value, + target_name=target_name) + return example.Problem(question=question, answer=target_value) + + +def _conversion_fraction(context, is_train): + """E.g., "How many grams are in three quarters of a kg?".""" + dimension = random.choice(DIMENSIONS) + + # Limit probability of giving zero answer. + allow_zero = random.random() < 0.2 + + # Repeat until we find a pair with an integral answer. (Avoids ambiguity with + # decimals.) + while True: + base_unit, target_unit = random.sample(list(dimension.keys()), 2) + base_value = number.non_integer_rational(2, signed=False) + if train_test_split.is_train(base_value) != is_train: + continue + answer = (base_value * sympy.Rational(dimension[base_unit]) + / sympy.Rational(dimension[target_unit])) + if (abs(answer) <= 100000 + and sympy.denom(answer) == 1 + and (allow_zero or answer != 0)): + break + + template = random.choice([ + 'Quantos(as) {target_name} estão em {base_value} de um(a) {base_name}?', + 'Quanto é {base_value} de um(a) {base_name} em um(a) {target_name}?', + ]) + + if sympy.denom(base_value) > 20 or random.choice([False, True]): + base_value_string = base_value # Will be represented as e.g., 2/3. + else: + base_value_string = display.StringNumber(base_value) # e.g., two thirds + + question = example.question( + context, template, + base_name=base_unit.name, + base_value=base_value_string, + target_name=pluralize(target_unit.name)) + return example.Problem(question=question, answer=answer) + + +def conversion(is_train, is_extrapolation): + """Conversion question, in decimal or fraction.""" + context = composition.Context() + # TODO(b/124038528): implement extrapolation for fraction conversions too + if is_extrapolation or random.choice([False, True]): + return _conversion_decimal( + context, is_train=is_train, is_extrapolation=is_extrapolation) + else: + return _conversion_fraction(context, is_train=is_train) + + +def time(is_train): + """Questions for calculating start, end, or time differences.""" + context = composition.Context() + start_minutes = random.randint(1, 24*60 - 1) + while True: + duration_minutes = random.randint(1, 12*60 - 1) + if train_test_split.is_train(duration_minutes) == is_train: + break + end_minutes = start_minutes + duration_minutes + + def format_12hr(minutes): + """Format minutes from midnight in 12 hr format.""" + hours = (minutes // 60) % 24 + minutes %= 60 + am_pm = 'AM' if hours < 12 else 'PM' + hours = (hours - 1) % 12 + 1 + return '{}:{:02} {}'.format(hours, minutes, am_pm) + + start = format_12hr(start_minutes) + end = format_12hr(end_minutes) + + which_question = random.randint(0, 3) + if which_question == 0: + # Question: What is start = end - duration? + template = random.choice([ + 'O que é {duration} minutos antes de {end}?', + ]) + return example.Problem( + question=example.question( + context, template, duration=duration_minutes, end=end), + answer=start) + elif which_question == 1: + # Question: What is end = start + duration? + template = random.choice([ + 'O que é {duration} minutos despois de {start}?', + ]) + return example.Problem( + question=example.question( + context, template, duration=duration_minutes, start=start), + answer=end) + else: + # Question: What is duration = end - start? + template = random.choice([ + 'Quantos minutos existem entre {start} e {end}?', + ]) + return example.Problem( + question=example.question(context, template, start=start, end=end), + answer=duration_minutes) diff --git a/mathematics_dataset/mathematics_dataset/modules/modules.py b/mathematics_dataset/mathematics_dataset/modules/modules.py new file mode 100644 index 0000000000000000000000000000000000000000..a96a6741bb23d80d2f9fe5f512b21712647e29f2 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/modules/modules.py @@ -0,0 +1,58 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""The various mathematics modules.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +from modules import algebra +from modules import arithmetic +from modules import calculus +from modules import comparison +from modules import measurement +from modules import numbers +from modules import polynomials +from modules import probability +import six + + +all_ = { + 'algebra': algebra, + 'arithmetic': arithmetic, + 'calculus': calculus, + 'comparison': comparison, + 'measurement': measurement, + 'numbers': numbers, + 'polynomials': polynomials, + 'probability': probability, +} + + +def train(entropy_fn): + """Returns dict of training modules.""" + return { + name: module.train(entropy_fn) for name, module in six.iteritems(all_) + } + + +def test(): + """Returns dict of testing modules.""" + return {name: module.test() for name, module in six.iteritems(all_)} + + +def test_extra(): + """Returns dict of extrapolation testing modules.""" + return {name: module.test_extra() for name, module in six.iteritems(all_)} diff --git a/mathematics_dataset/mathematics_dataset/modules/numbers.py b/mathematics_dataset/mathematics_dataset/modules/numbers.py new file mode 100644 index 0000000000000000000000000000000000000000..f261fdc481ab69dbc1a71b696d14facecec1dfaa --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/modules/numbers.py @@ -0,0 +1,516 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Number-related questions, e.g., "write seventy-two as a number".""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import functools +import math +import random + +# Dependency imports +import example +from sample import number +from util import composition +from util import display +import numpy as np +import six +from six.moves import range +import sympy + + +_ENTROPY_TRAIN = (3, 10) +_ENTROPY_INTERPOLATE = (8, 8) +_ENTROPY_EXTRAPOLATE = (12, 12) + + +# Number of module compositions appearing in train/test, and extrapolation data. +_NUM_MODULES_COMPOSED = [2, 4] + + +def _make_modules(entropy, num_modules_composed): + """Returns modules given "difficulty" parameters.""" + fns = { + 'gcd': gcd, + 'lcm': lcm, + 'div_remainder': div_remainder, + 'is_prime': is_prime, + 'is_factor': is_factor, + 'round_number': round_number, + 'place_value': place_value, + 'list_prime_factors': list_prime_factors, + } + + # These modules don't have both pure and composed. + modules = { + 'base_conversion': functools.partial(base_conversion, *entropy), + } + + sample_args_pure = composition.PreSampleArgs(1, 1, *entropy) + sample_args_composed = composition.PreSampleArgs( + num_modules_composed[0], num_modules_composed[1], *entropy) + + for name, module in six.iteritems(fns): + modules[name] = functools.partial(module, None, sample_args_pure) + modules[name + '_composed'] = functools.partial( + module, None, sample_args_composed) + + return modules + + +def train(entropy_fn): + """Returns dict of training modules.""" + return _make_modules( + entropy=entropy_fn(_ENTROPY_TRAIN), + num_modules_composed=_NUM_MODULES_COMPOSED) + + +def test(): + """Returns dict of testing modules.""" + return _make_modules( + entropy=_ENTROPY_INTERPOLATE, + num_modules_composed=_NUM_MODULES_COMPOSED) + + +def test_extra(): + """Returns dict of extrapolation testing modules.""" + sample_args_pure = composition.PreSampleArgs(1, 1, *_ENTROPY_EXTRAPOLATE) + return { + 'round_number_big': functools.partial( + round_number, None, sample_args_pure), + 'place_value_big': functools.partial(place_value, None, sample_args_pure), + } + + +def place_value(value, sample_args, context=None): + """E.g., "Q: What is the tens digit of 31859? A: 5.""" + del value # unused for now + if context is None: + context = composition.Context() + + entropy, sample_args = sample_args.peel() + integer = number.integer(entropy, signed=False, min_abs=1) + (entity,) = context.sample(sample_args, [integer]) + + integer_as_string = str(integer) + num_digits = len(integer_as_string) + + firsts = ['', 'dezena ', 'centena '] + seconds = [ + 'milhares', 'milhões', 'mil milhões', 'biliões', 'mil biliões', + 'quinquiliões', 'sextilhões', 'septiliões', 'octiliões', 'nonalhões', + 'decilhões', + ] + place_names = ['unidades', 'dezenas', 'centenas'] + for second in seconds: + for first in firsts: + place_names.append(first + second) + + place = random.randint(1, num_digits) # 1 = units, 2 = tens, etc. + place_name = place_names[place - 1] + answer = sympy.Integer(integer_as_string[num_digits - place]) + + return example.Problem( + question=example.question( + context, + 'Qual é o dígito das {place_name} de {integer}?', + place_name=place_name, integer=entity.expression_else_handle), + answer=answer) + + +# TODO(b/124040078): add to composition system? +def round_number(value, sample_args, context=None): + """Question for rounding integers and decimals.""" + del value # unused for now + if context is None: + context = composition.Context() + + entropy, sample_args = sample_args.peel() + + # This is the power of 10 to round to. E.g., power == 0 corresponds to + # rounding to the nearest integer; power == -2 corresponds to rounding to two + # decimal places, and power == 3 corresponds to rounding to the nearest 1000. + power = random.randint(-7, 6) + + answer_entropy = 1 + random.uniform(0, entropy / 2) + entropy = max(1, entropy - answer_entropy) + value_integer = number.integer(answer_entropy, signed=True) + + remainder_divisor = 10 ** int(math.ceil(entropy)) + remainder_range_lower = -remainder_divisor / 2 + remainder_range_upper = remainder_divisor / 2 + + if value_integer <= 0: + remainder_range_lower += 1 + if value_integer >= 0: + remainder_range_upper -= 1 + + remainder = random.randint(int(remainder_range_lower), int(remainder_range_upper)) + input_ = value_integer + sympy.Rational(remainder, remainder_divisor) + scale = 10**power if power >= 0 else sympy.Rational(1, 10**(-power)) + input_ = input_ * scale + value = value_integer * scale + if not number.is_integer(input_): + input_ = display.Decimal(input_) + if not number.is_integer(value): + value = display.Decimal(value) + + (input_,) = context.sample(sample_args, [input_]) + + if power > 0: + # Rounding to a power of ten. + round_to = 10**power + if random.choice([False, True]): + # Write the rounding value as a word instead. + round_to = display.StringNumber(round_to, + join_number_words_with_hyphens=False) + description = '{round_to} mais próxima'.format(round_to=round_to) + elif power == 0 and random.choice([False, True]): + # Round to nearest integer. + description = 'inteiro mais próximo' + else: + # Round to decimal places. + description = 'casa decimal das {dps}' + if power != -1: + # Plural + description += 's' + dps = -power + if random.choice([False, True]): + dps = display.StringNumber(dps) + description = description.format(dps=dps) + + template = random.choice([ + 'Arredonda {input} para as {description}.', + 'Quanto é {input} arredondado para as {description}?', + ]) + + return example.Problem( + question=example.question( + context, template, input=input_, description=description), + answer=value) + + +def _semi_prime(entropy): + """Generates a semi-prime with the given entropy.""" + # Add on extra entropy to account for the sparsity of the primes; we don't + # actually use the integers sampled, but rather a random prime close to them; + # thus some entropy is lost, which we must account for + entropy += math.log10(max(1, entropy * math.log(10))) + + # We intentionally uniformy sample the "entropy" (i.e., approx number digits) + # of the two factors. + entropy_1, entropy_2 = entropy * np.random.dirichlet([1, 1]) + + # Need >= 2 for randprime to always work (Betrand's postulate). + approx_1 = number.integer(entropy_1, signed=False, min_abs=2) + approx_2 = number.integer(entropy_2, signed=False, min_abs=2) + + factor_1 = sympy.ntheory.generate.randprime(approx_1 / 2, approx_1 * 2) + factor_2 = sympy.ntheory.generate.randprime(approx_2 / 2, approx_2 * 2) + + return factor_1 * factor_2 + + +def is_prime(value, sample_args, context=None): + """Questions asking about primality.""" + del value # unused for now + if context is None: + context = composition.Context() + + entropy, sample_args = sample_args.peel() + composite = _semi_prime(entropy) + + if random.choice([False, True]): + # Use the composite + integer = composite + is_prime_ = False + else: + # Take the next prime after the composite, to ensure the same distribution + # as composites. Do "composite - 4" so we occasionally see "2" as a prime. + integer = sympy.ntheory.generate.nextprime(composite - 4) + is_prime_ = True + + (integer_entity,) = context.sample(sample_args, [integer]) + + if random.choice([False, True]) and integer != 1: + answer = not is_prime_ + attribute_name = random.choice(['compósito', 'um número compósito']) + else: + answer = is_prime_ + attribute_name = random.choice(['primo', 'um número primo']) + + return example.Problem( + question=example.question( + context, 'Será {integer} {attribute}?', + integer=integer_entity.expression_else_handle, + attribute=attribute_name), + answer=answer) + + +def is_factor(value, sample_args, context=None): + """E.g., "Is 5 a factor of 48?".""" + del value # unused + if context is None: + context = composition.Context() + + entropy, sample_args = sample_args.peel() + + entropy_factor = 1 + random.uniform(0, entropy/3) + entropy = max(0, entropy - entropy_factor) + maybe_factor = number.integer(entropy_factor, False, min_abs=2) + + integer = maybe_factor * number.integer(entropy, False, min_abs=1) + # Produce balanced classes. + if random.choice([False, True]): + # The following makes it not a factor. + integer += random.randint(1, maybe_factor - 1) + + (entity,) = context.sample(sample_args, [integer]) + + templates = [ + 'Será {maybe_factor} um fator de {value}?', + 'Será {value} um múltiplo de {maybe_factor}?', + 'Será que {maybe_factor} divide {value}?', + ] + if maybe_factor == 2: + templates += [ + '{value} é par?', + ] + template = random.choice(templates) + + answer = integer % maybe_factor == 0 + return example.Problem( + question=example.question( + context, template, maybe_factor=maybe_factor, + value=entity.expression_else_handle), + answer=answer) + + +def list_prime_factors(value, sample_args, context=None): + """E.g., "What are the prime factors of 36?".""" + del value # unused for now + if context is None: + context = composition.Context() + + entropy, sample_args = sample_args.peel() + entropy = max(1, entropy) + + integer = number.integer(entropy, signed=False, min_abs=2) + + (entity,) = context.sample(sample_args, [integer]) + prime_factors = sorted(sympy.factorint(integer).keys()) + template = random.choice([ + 'Quais são os fatores primos {integer}?', + 'Enumera os fatores primos de {integer}.', + ]) + return example.Problem( + question=example.question( + context, template, integer=entity.expression_else_handle), + answer=display.NumberList(prime_factors)) + + +def _pair_with_large_hidden_factor(entropy): + """Returns pair of numbers with possibly large common factor hidden.""" + entropy_p, entropy_q, _ = entropy * np.random.dirichlet([1, 1, 1]) + # Min entropy on p and q to minimize trivial solutions. + entropy_p = max(1, entropy_p) + entropy_q = max(1, entropy_q) + entropy_mult = max(0, entropy - entropy_p - entropy_q) + + p = number.integer(entropy_p, False, min_abs=1) + q = number.integer(entropy_q, False, min_abs=1) + mult = number.integer(entropy_mult, False, min_abs=1) + p *= mult + q *= mult + return p, q + + +def lcm(value, sample_args, context=None): + """Question for least common multiple of p and q.""" + del value # unused + if context is None: + context = composition.Context() + + entropy, sample_args = sample_args.peel() + + p, q = _pair_with_large_hidden_factor(entropy) + answer = sympy.lcm(p, q) + + if random.choice([False, True]): + p, q = context.sample(sample_args, [p, q]) + # Ask the question directly. + adjective = 'menor' + template = random.choice([ + 'Calcula o {adjective} múltiplo comum de {p} e {q}.', + 'Qual é o {adjective} múltiplo comum de {p} e {q}?', + ]) + return example.Problem( + question=example.question( + context, template, adjective=adjective, p=p.expression_else_handle, + q=q.expression_else_handle), + answer=answer) + else: + # Phrase the question as finding the common denominator of two fractions. + p = number.integer(2, signed=True, coprime_to=p) / p + q = number.integer(2, signed=True, coprime_to=q) / q + p, q = context.sample(sample_args, [p, q]) + + template = random.choice([ + 'Qual é o denominador comum de {p} e {q}?', + 'Encontra o denominador comum de {p} e {q}.', + 'Calcula o denominador comum de {p} e {q}.', + ]) + return example.Problem( + question=example.question( + context, template, p=p.expression_else_handle, + q=q.expression_else_handle), + answer=answer) + + +def _random_coprime_pair(entropy): + """Returns a pair of random coprime integers.""" + coprime_product = number.integer(entropy, False, min_abs=1) + factors = sympy.factorint(coprime_product) + def take(): + prime = random.choice(list(factors.keys())) + power = factors[prime] + del factors[prime] + return prime ** power + + if random.random() < 0.8 and len(factors) >= 2: + # Disallow trivial factoring where possible. + count_left = random.randint(1, len(factors) - 1) + count_right = len(factors) - count_left + else: + count_left = random.randint(0, len(factors)) + count_right = len(factors) - count_left + + left = sympy.prod([take() for _ in range(count_left)]) + right = sympy.prod([take() for _ in range(count_right)]) + assert left * right == coprime_product + return left, right + + +# @composition.module(number.is_positive_integer) +def gcd(value, sample_args, context=None): + """Question for greatest common divisor of p and q.""" + is_question = context is None + if context is None: + context = composition.Context() + + entropy, sample_args = sample_args.peel() + if value is None: + value_entropy = 1 + random.uniform(0, entropy/3) + entropy = max(1, entropy - value_entropy) + value = number.integer(value_entropy, False, min_abs=1) + + p_mult, q_mult = _random_coprime_pair(entropy) + + p = value * p_mult + q = value * q_mult + assert sympy.gcd(p, q) == value + + p, q = context.sample(sample_args, [p, q]) + + adjective = (random.choice(['maior ']) + + random.choice(['divisor', 'fator']) + ' comum ') + + if is_question: + template = random.choice([ + 'Calcula o {adjective} de {p} e {q}.', + 'Qual é o {adjective} de {p} e {q}?', + ]) + return example.Problem( + question=example.question( + context, template, adjective=adjective, p=p, q=q), + answer=value) + else: + return composition.Entity( + context=context, + value=value, + description='Seja {self}, o {adjective} de {p} e {q}.', + adjective=adjective, p=p, q=q) + + +# @composition.module(number.is_positive_integer) +def div_remainder(value, sample_args, context=None): + """E.g., "What is the remainder when 27 is divided by 5?".""" + is_question = context is None + if context is None: + context = composition.Context() + + entropy, sample_args = sample_args.peel() + + if value is None: + entropy_value = 1 + random.uniform(0, entropy/3) + entropy = max(0, entropy - entropy_value) + value = number.integer(entropy_value, signed=False) + + entropy_a, entropy_q = entropy * np.random.dirichlet([1, 1]) + a = number.integer(entropy_a, signed=False, min_abs=1) + q = value + number.integer(entropy_q, signed=False, min_abs=1) + + p = a * q + value + assert p % q == value + p, q = context.sample(sample_args, [p, q]) + + if is_question: + template = random.choice([ + 'Calcula o resto da divisão entre {p} e {q}.', + 'Qual é o resto da divisão entre {p} e {q}?', + ]) + return example.Problem( + question=example.question( + context, template, p=p.expression_else_handle, + q=q.expression_else_handle), + answer=value) + else: + return composition.Entity( + context=context, + value=value, + description='Seja {self}, o resto da divisão entre {p} e {q}.', + p=p, q=q) + + +def base_conversion(min_entropy, max_entropy): + """E.g., "What is 17 base 8 in base 10?".""" + context = composition.Context() + + from_base = random.randint(2, 16) + while True: + to_base = random.randint(2, 16) + if to_base != from_base: + break + + # Entropy used up in selecting bases. + entropy_used = math.log10(16 * 15) + entropy = random.uniform( + min_entropy - entropy_used, max_entropy - entropy_used) + + value = number.integer(entropy, signed=True) + template = random.choice([ + '{from_str} (em base {from_base}) para base {to_base}', + 'Converte {from_str} (em base {from_base}) para base {to_base}.', + 'Quanto é {from_str} (base {from_base}) em base {to_base}?', + ]) + return example.Problem( + question=example.question( + context, template, + from_str=display.NumberInBase(value, from_base), + from_base=from_base, + to_base=to_base), + answer=display.NumberInBase(value, to_base)) diff --git a/mathematics_dataset/mathematics_dataset/modules/polynomials.py b/mathematics_dataset/mathematics_dataset/modules/polynomials.py new file mode 100644 index 0000000000000000000000000000000000000000..8890e4267e9f340358f0e0d0cc6c8408ef4fb675 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/modules/polynomials.py @@ -0,0 +1,376 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Polynomial manipulation (adding, composing, finding coefficients, etc).""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import functools +import math +import random + +# Dependency imports +import example +from sample import number +from sample import ops +from sample import polynomials +from util import composition +import numpy as np +from six.moves import range +import sympy + + +_ENTROPY_TRAIN = (3, 10) +_ENTROPY_INTERPOLATE = (8, 8) + + +def _make_modules(entropy): + """Returns modules given "difficulty" parameters.""" + sample_args_pure = composition.PreSampleArgs(1, 1, *entropy) + sample_args_composed = composition.PreSampleArgs(2, 4, *entropy) + sample_args_mixed = composition.PreSampleArgs(1, 4, *entropy) + + return { + 'coefficient_named': + functools.partial(coefficient_named, None, sample_args_pure), + 'evaluate': + functools.partial(evaluate, None, sample_args_pure), + 'evaluate_composed': + functools.partial(evaluate, None, sample_args_composed), + # TODO(b/124038948): consider doing pure sample args for 'add'? + 'add': + functools.partial(add, None, sample_args_mixed), + 'expand': + functools.partial(expand, None, sample_args_pure), + 'collect': + functools.partial(collect, None, sample_args_pure), + 'compose': + functools.partial(compose, None, sample_args_mixed), + + # Rearranging powers: + 'simplify_power': + functools.partial(simplify_power, None, sample_args_pure), + } + + +def train(entropy_fn): + """Returns dict of training modules.""" + return _make_modules(entropy_fn(_ENTROPY_TRAIN)) + + +def test(): + """Returns dict of testing modules.""" + return _make_modules(_ENTROPY_INTERPOLATE) + + +def test_extra(): + """Returns dict of extrapolation testing modules.""" + return { + } + + +def coefficient_named(value, sample_args, context=None): + """E.g., "Express x^2 + 2x in the form h * x^2 + k * x + t and give h.".""" + del value # not used + if context is None: + context = composition.Context() + variable = sympy.Symbol(context.pop()) + + entropy, sample_args = sample_args.peel() + degree = random.randint(1, 4) + if random.choice([False, True]): + coefficients = polynomials.sample_coefficients( + degree, entropy/2, min_non_zero=random.randint(degree - 1, degree)) + expanded = polynomials.expand_coefficients(coefficients, entropy/2) + expression = polynomials.coefficients_to_polynomial(expanded, variable) + else: + expression = polynomials.sample_with_brackets(variable, degree, entropy) + coefficients = list(reversed(sympy.Poly(expression).all_coeffs())) + + named_coeffs = [sympy.Symbol(context.pop()) for _ in range(degree + 1)] + canonical = polynomials.coefficients_to_polynomial(named_coeffs, variable) + + if random.random() < 0.2: # only small probability of non-zero power + power = random.randint(0, degree) + else: + non_zero_powers = [i for i in range(degree + 1) if coefficients[i] != 0] + power = random.choice(non_zero_powers) + + value = coefficients[power] + named_coeff = named_coeffs[power] + + template = random.choice([ + 'Expressa {expression} como {canonical} e dá {target}.', + 'Rearranja {expression} como {canonical} e dá {target}.', + 'Expressa {expression} na forma {canonical} e dá {target}.', + 'Rearranja {expression} na forma {canonical} e dá {target}.', + ]) + return example.Problem( + question=example.question( + context, template, expression=expression, canonical=canonical, + target=named_coeff), + answer=value) + + +_TEMPLATES = [ + 'O que é {composed}?', + 'Calcula {composed}.', + 'Obtém {composed}.', + 'Determina {composed}.', +] + + +@composition.module(number.is_integer) +def evaluate(value, sample_args, context=None): + """Entity for evaluating an integer-valued polynomial at a given point.""" + is_question = context is None + if context is None: + context = composition.Context() + + entropy, sample_args = sample_args.peel() + + if value is None: + entropy_value = random.uniform(1, 1 + entropy/3) + entropy = max(0, entropy - entropy_value) + value = number.integer(entropy_value, signed=True) + + entropy_input = random.uniform(1, 1 + entropy/3) + entropy = max(0, entropy - entropy_input) + input_ = number.integer(entropy_input, signed=True) + + degree = random.randint(1, 3) + + entropies = entropy * np.random.dirichlet(list(range(1, degree + 1))) + # Calculate coefficients in reverse order. + target = value + coeffs_reversed = [] + for i, coeff_entropy in enumerate(entropies): + power = degree - i + coeff = number.integer(coeff_entropy, signed=True) + if input_ != 0: + coeff += int(round(target / input_ ** power)) + if coeff == 0 and i == 0: + # Don't allow zero in leading coefficient. + coeff += random.choice([-1, 1]) + coeffs_reversed.append(coeff) + target -= coeff * (input_ ** power) + coeffs_reversed.append(target) + + coefficients = list(reversed(coeffs_reversed)) + + (polynomial_entity, input_) = context.sample( + sample_args, [composition.Polynomial(coefficients), input_]) + composed = polynomial_entity.handle.apply(input_.handle) + + if is_question: + template = random.choice(_TEMPLATES) + return example.Problem( + question=example.question(context, template, composed=composed), + answer=value) + else: + return composition.Entity( + context=context, + value=value, + expression=composed, + description='Seja {self}, {composed}.', + composed=composed) + + +# TODO(b/124039290): merge with compose? both add and compose do similar things. +@composition.module(composition.is_integer_polynomial) +def add(value, sample_args, context=None): + """E.g., "Let f(x)=2x+1, g(x)=3x+2. What is 5*f(x) - 7*g(x)?".""" + is_question = context is None + if context is None: + context = composition.Context() + + entropy, sample_args = sample_args.peel() + + if value is None: + max_degree = 3 + degree = random.randint(1, max_degree) + entropy -= math.log10(max_degree) + entropy_value = entropy / 2 + entropy -= entropy_value + value = polynomials.sample_coefficients( + degree, entropy=entropy_value, min_non_zero=random.randint(1, 3)) + value = composition.Polynomial(value) + + c1, c2, coeffs1, coeffs2 = polynomials.coefficients_linear_split( + value.coefficients, entropy) + coeffs1 = polynomials.trim(coeffs1) + coeffs2 = polynomials.trim(coeffs2) + + c1, c2, fn1, fn2 = context.sample( + sample_args, + [c1, c2, composition.Polynomial(coeffs1), composition.Polynomial(coeffs2)] + ) + + var = sympy.var(context.pop()) + + expression = ( + c1.handle * fn1.handle.apply(var) + c2.handle * fn2.handle.apply(var)) + + if is_question: + answer = polynomials.coefficients_to_polynomial(value.coefficients, var) + answer = answer.sympy() + template = random.choice(_TEMPLATES) + return example.Problem( + question=example.question(context, template, composed=expression), + answer=answer) + else: + intermediate_symbol = context.pop() + intermediate = sympy.Function(intermediate_symbol)(var) + return composition.Entity( + context=context, + value=value, + description='Seja {intermediate} = {composed}.', + handle=composition.FunctionHandle(intermediate_symbol), + intermediate=intermediate, + composed=expression) + + +def expand(value, sample_args, context=None): + """E.g., "Expand (x**2 + 1)**2.".""" + del value # not used + if context is None: + context = composition.Context() + variable = sympy.Symbol(context.pop()) + entropy, sample_args = sample_args.peel() + + min_order = 1 + max_order = 5 + order = random.randint(min_order, max_order) + entropy -= math.log10(max_order - min_order + 1) + expression_ = polynomials.sample_with_brackets(variable, order, entropy) + expanded = sympy.expand(expression_) + template = random.choice([ + 'Expande {expression}.' + ]) + return example.Problem( + question=example.question(context, template, expression=expression_), + answer=expanded) + + +@composition.module(composition.is_polynomial) +def collect(value, sample_args, context=None): + """Collect terms in an unsimplified polynomial.""" + is_question = context is None + if context is None: + context = composition.Context() + + entropy, sample_args = sample_args.peel() + if value is None: + entropy_value, entropy = entropy * np.random.dirichlet([2, 3]) + degrees = [random.randint(1, 3)] + value = composition.Polynomial( + polynomials.sample_coefficients(degrees, entropy_value)) + + assert isinstance(value, composition.Polynomial) + coefficients = value.coefficients + + all_coefficients_are_integer = True + for coeff in coefficients.flat: + if not number.is_integer(coeff): + all_coefficients_are_integer = False + break + + if all_coefficients_are_integer: + coefficients = polynomials.expand_coefficients(coefficients, entropy) + else: + # put back the unused entropy + sample_args = composition.SampleArgs( + sample_args.num_modules, sample_args.entropy + entropy) + + num_variables = coefficients.ndim + variables = [sympy.Symbol(context.pop()) for _ in range(num_variables)] + unsimplified = polynomials.coefficients_to_polynomial(coefficients, variables) + simplified = unsimplified.sympy().expand() + + # Bit of a hack: handle the very rare case where no number constants appearing + if not ops.number_constants(unsimplified): + unsimplified = ops.Add(unsimplified, ops.Constant(0)) + context.sample_by_replacing_constants(sample_args, unsimplified) + + if is_question: + template = 'Coleta os termos em {unsimplified}.' + return example.Problem( + question=example.question(context, template, unsimplified=unsimplified), + answer=simplified) + else: + function_symbol = context.pop() + function = sympy.Function(function_symbol)(*variables) + return composition.Entity( + context=context, + value=value, + handle=composition.FunctionHandle(function_symbol), + expression=unsimplified, + polynomial_variables=variables, + description='Seja {function} = {unsimplified}.', + function=function, + unsimplified=unsimplified) + + +def compose(value, sample_args, context=None): + """E.g., "Let f(x)=2x+1, let g(x)=3x+10. What is f(g(x))?".""" + del value # unused + if context is None: + context = composition.Context() + + entropy, sample_args = sample_args.peel() + entropy_f, entropy_g = entropy * np.random.dirichlet([1, 1]) + + coeffs_f = polynomials.sample_coefficients([random.randint(1, 2)], entropy_f) + coeffs_g = polynomials.sample_coefficients([random.randint(1, 2)], entropy_g) + + entity_f, entity_g = context.sample( + sample_args, + [composition.Polynomial(coeffs_f), composition.Polynomial(coeffs_g)]) + + variable = sympy.var(context.pop()) + + poly_f = polynomials.coefficients_to_polynomial(coeffs_f, variable) + poly_g = polynomials.coefficients_to_polynomial(coeffs_g, variable) + + poly_f_g = poly_f.sympy().subs(variable, poly_g.sympy()).expand() + + expression = composition.FunctionHandle(entity_f, entity_g).apply(variable) + + template = random.choice(_TEMPLATES) + return example.Problem( + question=example.question(context, template, composed=expression), + answer=poly_f_g) + + +def simplify_power(value, sample_args, context=None): + """E.g., "Simplify ((x**2)**3/x**4)**2/x**3.".""" + del value # unused + if context is None: + context = composition.Context() + + entropy, sample_args = sample_args.peel() + + variable = sympy.symbols(context.pop(), positive=True) + unsimplified = polynomials.sample_messy_power(variable, entropy) + answer = unsimplified.sympy() + + template = random.choice([ + 'Simplifica {unsimplified} assumindo que {variable} é positiva.', + ]) + return example.Problem( + example.question( + context, template, unsimplified=unsimplified, variable=variable), + answer) diff --git a/mathematics_dataset/mathematics_dataset/modules/probability.py b/mathematics_dataset/mathematics_dataset/modules/probability.py new file mode 100644 index 0000000000000000000000000000000000000000..5982ddeb0c50c4c0aab90700e8bba4c5174460c8 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/modules/probability.py @@ -0,0 +1,262 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Probability questions (sampling, independence, expectations, ...).""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import collections +import functools +import random +import string + +# Dependency imports +import example +from modules import train_test_split +from util import combinatorics +from util import composition +from util import display +from util import probability +import numpy as np +from six.moves import range +from six.moves import zip + + +_LETTERS = string.ascii_lowercase + +_MAX_FRAC_TRIVIAL_PROB = 0.1 + +# Maximum number of colours and objects in a bag. +_MAX_DISTINCT_LETTERS = 6 +_MAX_TOTAL_LETTERS = 20 +_MAX_LETTER_REPEAT = 10 + +_SWR_SAMPLE_COUNT = [2, 4] +_SWR_SAMPLE_COUNT_EXTRAPOLATE = [5, 5] + +_GERUNDS = { + 'escolher': 'escolher', +} + + +def _make_modules(is_train): + """Returns modules, with split based on the boolean `is_train`.""" + return { + 'swr_p_sequence': functools.partial( + swr_prob_sequence, is_train=is_train, sample_range=_SWR_SAMPLE_COUNT), + 'swr_p_level_set': functools.partial( + swr_prob_level_set, is_train=is_train, + sample_range=_SWR_SAMPLE_COUNT), + } + + +def train(entropy_fn): + """Returns dict of training modules.""" + del entropy_fn # unused + return _make_modules(is_train=True) + + +def test(): + """Returns dict of testing modules.""" + return _make_modules(is_train=False) + + +def test_extra(): + """Returns dict of extrapolation testing modules.""" + return { + 'swr_p_sequence_more_samples': functools.partial( + swr_prob_sequence, is_train=None, + sample_range=_SWR_SAMPLE_COUNT_EXTRAPOLATE), + 'swr_p_level_set_more_samples': functools.partial( + swr_prob_level_set, is_train=None, + sample_range=_SWR_SAMPLE_COUNT_EXTRAPOLATE), + } + + +def _sequence_event(values, length, verb): + """Returns sequence (finite product) event. + + Args: + values: List of values to sample from. + length: Length of the sequence to generate. + verb: Verb in infinitive form. + + Returns: + Instance of `probability.FiniteProductEvent`, together with a text + description. + """ + del verb # unused + samples = [random.choice(values) for _ in range(length)] + events = [probability.DiscreteEvent([sample]) for sample in samples] + event = probability.FiniteProductEvent(events) + sequence = ''.join(str(sample) for sample in samples) + event_description = 'sequência {sequence}'.format(sequence=sequence) + return event, event_description + + +def _word_series(words, conjunction='e'): + """Combines the words using commas and the final conjunction.""" + len_words = len(words) + if len_words == 0: + return '' + if len_words == 1: + return words[0] + return '{} {} {}'.format(', '.join(words[:-1]), conjunction, words[-1]) + + +def _level_set_event(values, length, verb): + """Generates `LevelSetEvent`; see _generate_sequence_event.""" + counts = combinatorics.uniform_non_negative_integers_with_sum( + len(values), length) + counts_dict = dict(list(zip(values, counts))) + event = probability.CountLevelSetEvent(counts_dict) + + shuffled_values = list(values) + random.shuffle(shuffled_values) + + counts_and_values = [ + '{} {}'.format(counts_dict[value], value) + for value in shuffled_values + if counts_dict[value] > 0 + ] + counts_and_values = _word_series(counts_and_values) + template = random.choice([ + '{verbing} {counts_and_values}', + ]) + verbing = _GERUNDS[verb] + event_description = template.format( + counts_and_values=counts_and_values, verbing=verbing) + return event, event_description + + +LetterBag = collections.namedtuple( + 'LetterBag', + ('weights', 'random_variable', 'letters_distinct', 'bag_contents')) + + +def _sample_letter_bag(is_train, min_total): + """Samples a "container of letters" and returns info on it.""" + while True: + num_distinct_letters = random.randint(1, _MAX_DISTINCT_LETTERS) + num_letters_total = random.randint( + max(num_distinct_letters, min_total), + min(_MAX_TOTAL_LETTERS, num_distinct_letters * _MAX_LETTER_REPEAT)) + letter_counts = combinatorics.uniform_positive_integers_with_sum( + num_distinct_letters, num_letters_total) + + # Test/train split. + if (is_train is None + or train_test_split.is_train(sorted(letter_counts)) == is_train): + break + + letters_distinct = random.sample(_LETTERS, num_distinct_letters) + weights = {i: 1 for i in range(num_letters_total)} + + letters_with_repetition = [] + for letter, count in zip(letters_distinct, letter_counts): + letters_with_repetition += [letter] * count + random.shuffle(letters_with_repetition) + + random_variable = probability.DiscreteRandomVariable( + {i: letter for i, letter in enumerate(letters_with_repetition)}) + + if random.choice([False, True]): + bag_contents = ''.join(letters_with_repetition) + else: + letters_and_counts = [ + '{}: {}'.format(letter, count) + for letter, count in zip(letters_distinct, letter_counts)] + bag_contents = '{' + ', '.join(letters_and_counts) + '}' + + return LetterBag( + weights=weights, + random_variable=random_variable, + letters_distinct=letters_distinct, + bag_contents=bag_contents) + + +def _swr_space(is_train, sample_range): + """Returns probability space for sampling without replacement.""" + num_sampled = random.randint(*sample_range) + sample = _sample_letter_bag(is_train=is_train, min_total=num_sampled) + + space = probability.SampleWithoutReplacementSpace(sample.weights, num_sampled) + + random_variable = probability.FiniteProductRandomVariable( + [sample.random_variable] * num_sampled) + + random_variable.description = ( + str(display.StringNumber(num_sampled)) + + ' caractéres são escolhidos sem reposição de ' + + sample.bag_contents) + + return sample.letters_distinct, space, random_variable + + +def _sample_without_replacement_probability_question( + is_train, event_fn, sample_range): + """Question for prob of some event when sampling without replacement.""" + def too_big(event_in_space): + if isinstance(event_in_space, probability.SequenceEvent): + size = len(event_in_space.all_sequences()) + else: + assert isinstance(event_in_space, probability.FiniteProductEvent) + size = np.prod([len(event.values) for event in event_in_space.events]) + return size > int(2e5) + + allow_trivial_prob = random.random() < _MAX_FRAC_TRIVIAL_PROB + + while True: + distinct_letters, space, random_variable = _swr_space( + is_train, sample_range) + + event, event_description = event_fn( + values=distinct_letters, length=space.n_samples, verb='escolher') + event_in_space = random_variable.inverse(event) + if too_big(event_in_space): + continue + answer = space.probability(event_in_space) + if answer not in [0, 1] or allow_trivial_prob: + break + + context = composition.Context() + + template = random.choice([ + '{random_variable_capitalize}. Qual é a probabilidade de(a) {event}?', + '{random_variable_capitalize}. Dá a probabilidade de(a) {event}.', + 'Qual é a probabilidade de(a) {event} quando {random_variable}?', + 'Calcula da probabilidade de(a) {event} quando {random_variable}.', + ]) + question = example.question( + context, + template, + random_variable=random_variable.description, + random_variable_capitalize=( + str(random_variable.description).capitalize()), + event=event_description) + return example.Problem(question, answer) + + +def swr_prob_sequence(is_train, sample_range): + """Probability of given sequence when sampling without replacement.""" + return _sample_without_replacement_probability_question( + is_train=is_train, event_fn=_sequence_event, sample_range=sample_range) + + +def swr_prob_level_set(is_train, sample_range): + """Probability of given level set when sampling without replacement.""" + return _sample_without_replacement_probability_question( + is_train=is_train, event_fn=_level_set_event, sample_range=sample_range) diff --git a/mathematics_dataset/mathematics_dataset/modules/train_test_split.py b/mathematics_dataset/mathematics_dataset/modules/train_test_split.py new file mode 100644 index 0000000000000000000000000000000000000000..e85d3d991a480d0e8ef6cddd31bd0ed49aff9d3a --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/modules/train_test_split.py @@ -0,0 +1,27 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Utility for train/test split based on hash value.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import hashlib + + +def is_train(value): + """Returns whether `value` should be used in a training question.""" + value_as_string = str(value).encode('utf-8') + return int(hashlib.md5(value_as_string).hexdigest(), 16) % 2 == 0 diff --git a/mathematics_dataset/mathematics_dataset/requires.txt b/mathematics_dataset/mathematics_dataset/requires.txt new file mode 100644 index 0000000000000000000000000000000000000000..ab0152c65b05ca59fe6c13c1e2ce42cc247ddce1 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/requires.txt @@ -0,0 +1,4 @@ +absl-py>=0.1.0 +numpy>=1.10 +six +sympy>=1.2 diff --git a/mathematics_dataset/mathematics_dataset/sample/__init__.py b/mathematics_dataset/mathematics_dataset/sample/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..d780829a1f5101333577a1ca9adcb960529213f1 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/sample/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/mathematics_dataset/mathematics_dataset/sample/arithmetic.py b/mathematics_dataset/mathematics_dataset/sample/arithmetic.py new file mode 100644 index 0000000000000000000000000000000000000000..d439387c7e986c5d8278d0bc19a269e243ac2cb6 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/sample/arithmetic.py @@ -0,0 +1,260 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Sample arithmetic expressions with a given value.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import collections +import math +import random + +# Dependency imports +from sample import number +from sample import ops +from util import combinatorics +import numpy as np +import six +from six.moves import zip +import sympy + + +class _SampleArgs(collections.namedtuple('SampleArgs', ('count', 'entropy'))): + """For sampling mathematical expressions.""" + + def peel(self, frac=1): + """Peels one (or `frac`) of an op's entropy.""" + entropy = frac * self.entropy / self.count + new_sample_args = _SampleArgs(self.count, self.entropy - entropy) + return entropy, new_sample_args + + def split(self, args): + """Splits the entropy and op counts up.""" + non_integer_count = sum(not arg.is_Integer for arg in args) + assert non_integer_count <= self.count - 1 + count_split = combinatorics.uniform_non_negative_integers_with_sum( + len(args), (self.count - 1) - non_integer_count) + for i, arg in enumerate(args): + if not arg.is_Integer: + count_split[i] += 1 + if all(count == 0 for count in count_split): + assert self.entropy == 0 + entropies = np.zeros(len(count_split)) + else: + entropies = ( + np.random.dirichlet(np.maximum(1e-9, count_split)) * self.entropy) + return [_SampleArgs(op_count, entropy) + for op_count, entropy in zip(count_split, entropies)] + + +def _add_sub_filter(value, sample_args): + return sample_args.count >= 2 or value.is_Integer + + +def _add_op(value, sample_args, rationals_allowed): + """Returns sampled args for `ops.Add`.""" + entropy, sample_args = sample_args.peel() + if rationals_allowed and sample_args.count >= 3: + x = number.integer_or_rational(entropy, True) + else: + x = number.integer(entropy, True) + if random.choice([False, True]): + op_args = [x, value - x] + else: + op_args = [value - x, x] + return ops.Add, op_args, sample_args + + +def _sub_op(value, sample_args, rationals_allowed): + """Returns sampled args for `ops.Sub`.""" + entropy, sample_args = sample_args.peel() + if rationals_allowed and sample_args.count >= 3: + x = number.integer_or_rational(entropy, True) + else: + x = number.integer(entropy, True) + if random.choice([False, True]): + op_args = [x, x - value] + else: + op_args = [value + x, x] + return ops.Sub, op_args, sample_args + + +def _entropy_of_factor_split(integer): + """Returns entropy (log base 10) of decomposing: integer = a * b.""" + assert integer.is_Integer + if integer == 0: + return 0 + # Gives dict of form {factor: multiplicity} + factors = sympy.factorint(integer) + return sum(math.log10(mult + 1) for mult in six.itervalues(factors)) + + +def _split_factors(integer): + """Randomly factors integer into product of two integers.""" + assert integer.is_Integer + if integer == 0: + return [1, 0] + # Gives dict of form {factor: multiplicity} + factors = sympy.factorint(integer) + left = sympy.Integer(1) + right = sympy.Integer(1) + for factor, mult in six.iteritems(factors): + left_mult = random.randint(0, mult) + right_mult = mult - left_mult + left *= factor ** left_mult + right *= factor ** right_mult + return left, right + + +def _mul_filter(value, sample_args): + if sample_args.count >= 2: + return True + if not value.is_Integer: + return False + return sample_args.entropy <= _entropy_of_factor_split(value) + + +def _mul_op(value, sample_args, rationals_allowed): + """Returns sampled args for `ops.Mul`.""" + if sample_args.count >= 3: + _, op_args, sample_args = _div_op(value, sample_args, rationals_allowed) + op_args = [op_args[0], sympy.Integer(1) / op_args[1]] + elif sample_args.count == 1: + entropy, sample_args = sample_args.peel() + assert _entropy_of_factor_split(value) >= entropy + op_args = _split_factors(value) + else: + assert sample_args.count == 2 + entropy, sample_args = sample_args.peel() + numer = sympy.numer(value) + denom = sympy.denom(value) + p1, p2 = _split_factors(numer) + entropy -= _entropy_of_factor_split(numer) + mult = number.integer(entropy, signed=True, min_abs=1, coprime_to=p1) + op_args = [p1 / (mult * denom), p2 * mult] + + if random.choice([False, True]): + op_args = list(reversed(op_args)) + + return ops.Mul, op_args, sample_args + + +def _div_filter(value, sample_args): + del value # unused + del sample_args # unused + return True + + +def _div_op(value, sample_args, rationals_allowed): + """Returns sampled args for `ops.Div`.""" + assert rationals_allowed # should be True if this function gets invoked + entropy, sample_args = sample_args.peel() + + numer = sympy.numer(value) + denom = sympy.denom(value) + + if sample_args.count == 1: + mult = number.integer(entropy, signed=True, min_abs=1) + op_args = [numer * mult, denom * mult] + elif sample_args.count == 2: + if numer == 0 or random.choice([False, True]): + x = number.integer(entropy, signed=True, min_abs=1, coprime_to=denom) + op_args = [sympy.Rational(x * numer, denom), x] + else: + x = number.integer(entropy, signed=True, min_abs=1, coprime_to=numer) + op_args = [x, sympy.Rational(x * denom, numer)] + else: + assert sample_args.count >= 3 + p2, p1 = _split_factors(numer) + q1, q2 = _split_factors(denom) + entropy -= _entropy_of_factor_split(numer) + _entropy_of_factor_split(denom) + entropy_r = random.uniform(0, entropy) + entropy_s = entropy - entropy_r + r = number.integer(entropy_r, signed=True, min_abs=1, coprime_to=q1*p2) + s = number.integer(entropy_s, signed=False, min_abs=1, coprime_to=p1*q2) + op_args = [sympy.Rational(r*p1, s*q1), sympy.Rational(r*q2, s*p2)] + + return ops.Div, op_args, sample_args + + +def _arithmetic(value, sample_args, add_sub, mul_div): + """Internal arithmetic thingy....""" + assert sample_args.count >= 0 + if sample_args.count == 0: + assert sample_args.entropy == 0 + return ops.Constant(value) + + allowed = [] + if add_sub and _add_sub_filter(value, sample_args): + allowed.append(_add_op) + allowed.append(_sub_op) + if mul_div and _mul_filter(value, sample_args): + allowed.append(_mul_op) + if mul_div and _div_filter(value, sample_args): + allowed.append(_div_op) + if not allowed: + raise ValueError( + 'No valid ops found, add_sub={} mul_div={} value={} sample_args={}' + .format(add_sub, mul_div, value, sample_args)) + choice = random.choice(allowed) + + op, args, sample_args = choice(value, sample_args, rationals_allowed=mul_div) + sample_args = sample_args.split(args) + child_expressions = [_arithmetic(arg, child_sample_arg, add_sub, mul_div) + for arg, child_sample_arg in zip(args, sample_args)] + + return op(*child_expressions) + + +def length_range_for_entropy(entropy): + """Returns length range to sample from for given entropy.""" + min_length = 3 + max_length = min_length + int(entropy / 2) + return min_length, max_length + + +def arithmetic(value, entropy, length=None, add_sub=True, mul_div=True): + """Generates an arithmetic expression with a given value. + + Args: + value: Target value (integer or rational). + entropy: Amount of randomness to use in generating expression. + length: Number of ops to use. If `None` then suitable length will be picked + based on entropy by sampling within the range + `length_range_for_entropy`. + add_sub: Whether to include addition and subtraction operations. + mul_div: Whether to include multiplication and division operations. + + Returns: + Instance of `ops.Op` containing expression. + """ + assert isinstance(entropy, float) + if length is None: + min_length, max_length = length_range_for_entropy(entropy) + length = random.randint(min_length, max_length) + # Some entropy used up in sampling the length. + entropy -= math.log10(max_length - min_length + 1) + else: + assert isinstance(length, int) + + # Entropy adjustment, because different binary trees (from sampling ops) can + # lead to the same expression. This is the correct value when we use just + # addition as the op, and is otherwise an an upper bound. + entropy += combinatorics.log_number_binary_trees(length) / math.log(10) + + value = sympy.sympify(value) + sample_args = _SampleArgs(length, entropy) + return _arithmetic(value, sample_args, add_sub, mul_div) diff --git a/mathematics_dataset/mathematics_dataset/sample/arithmetic_test.py b/mathematics_dataset/mathematics_dataset/sample/arithmetic_test.py new file mode 100644 index 0000000000000000000000000000000000000000..e19441f8989655223677bc7f8ccdbf73af85b2fd --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/sample/arithmetic_test.py @@ -0,0 +1,55 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Tests for mathematics_dataset.sample.arithmetic.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import random + +# Dependency imports +from absl.testing import absltest +from absl.testing import parameterized +from sample import arithmetic +from sample import number +from sample import ops +from six.moves import range +import sympy + + +class ArithmeticTest(parameterized.TestCase): + + def testArithmetic(self): + for _ in range(1000): + target = number.integer_or_rational(4, signed=True) + entropy = 8.0 + expression = arithmetic.arithmetic(target, entropy) + self.assertEqual(sympy.sympify(expression), target) + + def testArithmeticLength(self): + """Tests that the generated arithmetic expressions have given length.""" + for _ in range(1000): + target = number.integer_or_rational(4, signed=True) + entropy = 8.0 + length = random.randint(2, 10) + expression = arithmetic.arithmetic(target, entropy, length) + # Note: actual length is #ops = #numbers - 1. + actual_length = len(ops.number_constants(expression)) - 1 + self.assertEqual(actual_length, length) + + +if __name__ == '__main__': + absltest.main() diff --git a/mathematics_dataset/mathematics_dataset/sample/linear_system.py b/mathematics_dataset/mathematics_dataset/sample/linear_system.py new file mode 100644 index 0000000000000000000000000000000000000000..6e63307393975f9fc2e56a014d51035a8f61b028 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/sample/linear_system.py @@ -0,0 +1,144 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Generate linear systems with given set of solutions.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import random + +# Dependency imports +from sample import number +from sample import ops +from sample import polynomials +import numpy as np +from six.moves import range +import sympy + + +def _make_equals_zero_split(monomials): + """Returns an `ops.Eq` containing sum of monomials split on left and right.""" + left = [] + right = [] + for monomial in monomials: + if random.choice([False, True]): + left.append(monomial) + else: + right.append(ops.Neg(monomial)) + if not left: + left = [0] + if not right: + right = [0] + left = ops.Add(*left) + right = ops.Add(*right) + return ops.Eq(left, right) + + +def _is_trivial_in(matrix, variable): + """Returns true if matrix_ij == 0 for some i and all j != variable.""" + matrix = np.asarray(matrix) + assert matrix.ndim == 2 and matrix.shape[0] == matrix.shape[1] + size = matrix.shape[0] + if size == 1: + return False + for i in range(size): + all_zero = True + for j in range(size): + if j != variable and matrix[i, j] != 0: + all_zero = False + break + if all_zero: + return True + return False + + +def _invertible_matrix(degree, entropy, non_trivial_in): + """Generates random invertible matrix.""" + matrix_entropies = entropy * np.random.dirichlet(np.ones(degree * degree)) + matrix_entropies = np.reshape(matrix_entropies, [degree, degree]) + matrix_entropies = np.maximum(1, matrix_entropies) + + while True: + def gen(i, j): + return number.integer(matrix_entropies[i, j], True) + + matrix = [[gen(i, j) for i in range(degree)] for j in range(degree)] # pylint: disable=g-complex-comprehension + if non_trivial_in is not None and _is_trivial_in(matrix, non_trivial_in): + continue + if sympy.det(sympy.Matrix(matrix)) != 0: + break + + matrix = np.asarray(matrix).astype(int) + return matrix + + +def linear_system(variables, solutions, entropy, non_trivial_in=None, + length=None): + """Returns a linear system (set of equalities) with the given solutions. + + Args: + variables: List of variables. + solutions: List of solutions, of the same length as `variables`. + entropy: Float >= 0; the entropy used. + non_trivial_in: Optional integer corresponding to a variable for which the + solution shouldn't be "trivial". E.g., "solve a + b = 3, a = -2 for a" + is disallowed if `variables[non_trivial_in] == 'a'`. + length: Total number of terms appearing; if `None` then selected wisely. + + Returns: + List of `ops.Eq`. + """ + degree = len(variables) + assert degree == len(solutions) + + frac_entropy_matrix = random.uniform(1/3, 2/3) + matrix = _invertible_matrix( + degree, entropy * frac_entropy_matrix, non_trivial_in) + solutions = np.asarray(solutions) + constant = np.matmul(matrix, solutions.astype(int)) + flattened = np.concatenate([np.reshape(matrix, [degree * degree]), constant]) + is_zero = flattened == 0 + + if length is None: + min_length = np.count_nonzero(flattened) + 1 + max_length = max(min_length, 1 + int(degree * (1 + entropy / 2))) + length = random.randint(min_length, max_length) + + counts = polynomials.expanded_coefficient_counts( + length=length, is_zero=is_zero) + + entropies = (1 - frac_entropy_matrix) * entropy * np.random.dirichlet( + np.maximum(1e-9, counts - 1)) + + terms = [] + for i in range(len(flattened)): + coeffs = polynomials.integers_with_sum( + value=flattened[i], count=counts[i], entropy=entropies[i]) + terms.append(coeffs) + + matrix = terms[:degree*degree] + constant = terms[-degree:] + equations = [] + for row_index in range(degree): + monomials = [] + for col_index in range(degree): + for term in matrix[row_index * degree + col_index]: + monomials.append(polynomials.monomial(term, variables[col_index], 1)) + for term in constant[row_index]: + monomials.append(polynomials.monomial(-term, None, 0)) + equations.append(_make_equals_zero_split(monomials)) + + return equations diff --git a/mathematics_dataset/mathematics_dataset/sample/linear_system_test.py b/mathematics_dataset/mathematics_dataset/sample/linear_system_test.py new file mode 100644 index 0000000000000000000000000000000000000000..5f4d24593b4760b43731904875be82a31ef1f396 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/sample/linear_system_test.py @@ -0,0 +1,56 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Tests for mathematics_dataset.sample.linear_system.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import random + +# Dependency imports +from absl.testing import absltest +from absl.testing import parameterized +from sample import linear_system +from six.moves import range +import sympy + + +class ExpressionWithValueTest(parameterized.TestCase): + + def testIsTrivialIn(self): + self.assertEqual(linear_system._is_trivial_in([[1]], 0), False) + self.assertEqual(linear_system._is_trivial_in([[1, 2], [3, 4]], 0), False) + self.assertEqual(linear_system._is_trivial_in([[1, 2], [3, 0]], 0), True) + self.assertEqual(linear_system._is_trivial_in([[1, 2], [3, 0]], 1), False) + self.assertEqual(linear_system._is_trivial_in([[1, 2], [0, 3]], 0), False) + self.assertEqual(linear_system._is_trivial_in([[1, 2], [0, 3]], 1), True) + + @parameterized.parameters([1, 2, 3]) + def testLinearSystem(self, degree): + for _ in range(100): # test a few times + target = [random.randint(-100, 100) for _ in range(degree)] + variables = [sympy.Symbol(chr(ord('a') + i)) for i in range(degree)] + system = linear_system.linear_system( + variables=variables, + solutions=target, + entropy=10.0) + solved = sympy.solve(system, variables) + solved = [solved[symbol] for symbol in variables] + self.assertEqual(target, solved) + + +if __name__ == '__main__': + absltest.main() diff --git a/mathematics_dataset/mathematics_dataset/sample/number.py b/mathematics_dataset/mathematics_dataset/sample/number.py new file mode 100644 index 0000000000000000000000000000000000000000..5f83dff880cb94fd67b265c95fb13dfeabe3058b --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/sample/number.py @@ -0,0 +1,165 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Generate random integers and rationals with minimum guarantees on entropy.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import math +import random + +# Dependency imports +from util import display +import numpy as np +import six +import sympy + + +def _coprime_density(value): + """Returns float > 0; asymptotic density of integers coprime to `value`.""" + factors = sympy.factorint(value) + density = 1.0 + for prime in six.iterkeys(factors): + density *= 1 - 1 / prime + return density + + +def integer(entropy, signed, min_abs=0, coprime_to=1): + """Returns an integer from a set of size ceil(10**entropy). + + If `signed` is True, then includes negative integers, otherwise includes just + positive integers. + + Args: + entropy: Float >= 0. + signed: Boolean. Whether to also return negative numbers. + min_abs: Integer >= 0. The minimum absolute value. + coprime_to: Optional integer >= 1. The returned integer is guaranteed to be + coprime to `coprime_to`, with entropy still accounted for. + + Returns: + Integer. + """ + assert isinstance(min_abs, int) and not isinstance(min_abs, bool) + coprime_to = abs(coprime_to) + assert min_abs >= 0 + + max_ = math.pow(10, entropy) + max_ += min_abs + if coprime_to >= 2: + max_ = max_ / _coprime_density(coprime_to) + 1 + + if signed: + max_ = int(math.ceil(max_ / 2)) + range_ = [-max_, max_] + else: + max_ = int(math.ceil(max_)) + range_ = [min_abs, max_] + + while True: + value = random.randint(*range_) + if abs(value) >= min_abs and sympy.gcd(value, coprime_to) == 1: + break + + return sympy.Integer(value) + + +def non_integer_rational(entropy, signed): + """Similar args to `integer`. Entropy split between denom and numer.""" + numer_entropy = random.uniform(0, entropy) + denom_entropy = entropy - numer_entropy + numer = integer(numer_entropy, signed, min_abs=1) + denom = integer(denom_entropy, False, min_abs=2, coprime_to=numer) + return sympy.Rational(numer, denom) + + +def integer_or_rational(entropy, signed, min_abs=0): + """Returns a rational, with 50% probability of it being an integer.""" + if random.choice([False, True]): + return integer(entropy, signed, min_abs=min_abs) + else: + return non_integer_rational(entropy, signed) + + +def non_integer_decimal(entropy, signed): + """Returns a random decimal; integer divided by random power of ten. + + Guaranteed to be non-integer (i.e., numbers after the decimal point). + + Args: + entropy: Float. + signed: Boolean. Whether to also return negative numbers. + + Returns: + Non-integer decimal. + """ + while True: + base = integer(entropy, signed) + shift = random.randint(1, int(math.ceil(entropy))) + divisor = 10**shift + if base % divisor != 0: + return display.Decimal(sympy.Rational(base, divisor)) + + +def integer_or_decimal(entropy, signed): + """Returns integer or non-integer decimal; 50% probability of each.""" + if random.choice([False, True]): + # Represent it as a decimal so that arithmetic operations are supported: + return display.Decimal(integer(entropy, signed)) + else: + return non_integer_decimal(entropy, signed) + + +def entropy_of_value(value): + """Returns "min entropy" that would give probability of getting this value.""" + if isinstance(value, display.Decimal): + return entropy_of_value(sympy.numer(value)) + + if is_non_integer_rational(value): + numer = sympy.numer(value) + denom = sympy.denom(value) + return entropy_of_value(numer) + entropy_of_value(denom) + elif not is_integer(value): + raise ValueError('Unhandled value: {}'.format(value)) + + # Note: we sample integers in a range of size approx 10**entropy about zero, + # so assume that `abs(value)` is about half of the upper range. + return math.log10(5 * abs(value) + 1) + + +def is_integer(value): + return isinstance(value, (int, np.int64, np.int32, sympy.Integer)) + + +def is_positive_integer(value): + """Filter for: value is a strictly positive integer.""" + return is_integer(value) and value > 0 + + +def is_integer_or_rational(value): + return is_integer(value) or isinstance(value, sympy.Rational) + + +def is_integer_or_decimal(value): + return is_integer(value) or isinstance(value, display.Decimal) + + +def is_integer_or_rational_or_decimal(value): + return is_integer_or_rational(value) or is_integer_or_decimal(value) + + +def is_non_integer_rational(value): + return is_integer_or_rational(value) and not is_integer(value) diff --git a/mathematics_dataset/mathematics_dataset/sample/number_test.py b/mathematics_dataset/mathematics_dataset/sample/number_test.py new file mode 100644 index 0000000000000000000000000000000000000000..ab635e877206f1822d77e004e5b1941db313cd8f --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/sample/number_test.py @@ -0,0 +1,129 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Tests for mathematics_dataset.sample.number.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import random + +# Dependency imports +from absl.testing import absltest +from absl.testing import parameterized +from sample import number +from six.moves import range +import sympy + + +class NumberTest(parameterized.TestCase): + + def testCoprimeDensity(self): + self.assertEqual(number._coprime_density(1), 1.0) + self.assertEqual(number._coprime_density(2), 0.5) + self.assertLess(abs(number._coprime_density(3) - 2/3), 1e-6) + self.assertLess(abs(number._coprime_density(6) - 1/3), 1e-6) + + @parameterized.parameters(False, True) + def testInteger_allowZero(self, signed): + saw_zero = False + saw_nonzero = False + for _ in range(1000): + sample = number.integer(1, signed=signed) + if sample == 0: + saw_zero = True + else: + saw_nonzero = True + if saw_zero and saw_nonzero: + break + self.assertTrue(saw_zero) + self.assertTrue(saw_nonzero) + + def testNonIntegerRational(self): + for _ in range(1000): + entropy = random.uniform(0, 10) + signed = random.choice([False, True]) + sample = number.non_integer_rational(entropy, signed) + self.assertNotEqual(sympy.denom(sample), 1) + + @parameterized.parameters(False, True) + def testIntegerOrRational(self, signed): + # Tests we can call it. Do it a few times so both code paths get executed. + for _ in range(10): + number.integer_or_rational(2, signed) + + def testNonIntegerDecimal(self): + for _ in range(1000): + sample = number.non_integer_decimal(1, False) + self.assertNotEqual(sympy.denom(sample), 1) + self.assertLen(str(sample), 3) # should be of form "0.n" + self.assertGreater(sample, 0) # positive + + def testNonIntegerDecimal_size(self): + saw_bigger_one = False + saw_smaller_one = False + for _ in range(1000): + sample = number.non_integer_decimal(2, False) + if sample > 1: + saw_bigger_one = True + else: + saw_smaller_one = True + if saw_bigger_one and saw_smaller_one: + break + self.assertTrue(saw_bigger_one) + self.assertTrue(saw_smaller_one) + + @parameterized.parameters( + lambda: number.integer(0, True), + lambda: number.integer(1, True), + lambda: number.non_integer_rational(2, True), + lambda: number.non_integer_decimal(1, True)) + def testGenerate_signed(self, generator): + saw_positive = False + saw_negative = False + for _ in range(1000): + sample = generator() + saw_positive |= sample > 0 + saw_negative |= sample < 0 + if saw_positive and saw_negative: + break + + self.assertTrue(saw_positive) + self.assertTrue(saw_negative) + + @parameterized.parameters( + lambda: number.integer(2, False), + lambda: number.non_integer_rational(2, False)) + def testIntegerRational_distinctCount(self, generator): + seen = set() + for _ in range(3000): + seen.add(generator()) + self.assertGreaterEqual(len(seen), 10 ** 2) + + @parameterized.parameters(number.integer, number.non_integer_decimal) + def testEntropyOfValue(self, generator): + for entropy in [1, 2, 4, 8, 16]: + sum_entropy = 0.0 + count = 2000 + for _ in range(count): + value = generator(entropy, signed=True) + sum_entropy += number.entropy_of_value(value) + avg_entropy = sum_entropy / count + error = abs(entropy - avg_entropy) / entropy + self.assertLess(error, 0.2) + + +if __name__ == '__main__': + absltest.main() diff --git a/mathematics_dataset/mathematics_dataset/sample/ops.py b/mathematics_dataset/mathematics_dataset/sample/ops.py new file mode 100644 index 0000000000000000000000000000000000000000..33c9738d4eec81ee0e18830746149b413dacc403 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/sample/ops.py @@ -0,0 +1,451 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Mathematical operations used to build up expressions for printing. + +We can't use sympy because sympy will automatically simplify many types of +expressions, even with `evaluate=False` passed in. For example: + +* Mul(-2, -3, evaluate=False) gives -(-6), not (-2) x (-3). +* Add(2, 1, evaluate=False) gives 1 + 2, because the terms are sorted. + +As such, it's easier just to work with our own op classes that display precisely +as we created them. This also allows us to use custom symbols for the +expressions, such as the multiplication symbol. +""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import abc + +# Dependency imports +from absl import logging +from sample import number +from util import display +import numpy as np +import six +from six.moves import zip +import sympy + + +MUL_SYMBOL = '*' +DIV_SYMBOL = '/' +POW_SYMBOL = '**' +GT_SYMBOL = '>' +LT_SYMBOL = '<' +GE_SYMBOL = '>=' +LE_SYMBOL = '<=' +EQ_SYMBOL = '=' +NE_SYMBOL = '!=' + + +# Operator precedence levels. Used to insert brackets if necessary. +_EQ_PRECEDENCE = 0 +_CONSTANT_PRECEDENCE = 1 +_POW_PRECEDENCE = 2 +_SQRT_PRECEDENCE = 3 +_MUL_PRECEDENCE = 4 +_ADD_PRECEDENCE = 5 + + +def bracketed(child, parent, bracket_if_same_precedence): + """Returns string representation of `child`, possibly bracketed. + + Args: + child: Instance of `Op` or a valid value for `ConstantOp`. + parent: Instance of `Op`. Used to determine whether `child` needs to be + bracketed first before appearing in the parent op's expression. + bracket_if_same_precedence: Whether to bracket if the child has the same + operator precedence as the parent. + + Returns: + String representation of `child`. + """ + if not isinstance(child, Op): + child = Constant(child) + + child_precedence = child.precedence + parent_precedence = parent.precedence + if (parent_precedence > child_precedence + or (parent_precedence == child_precedence + and not bracket_if_same_precedence)): + return str(child) + else: + return '({})'.format(child) + + +def _flatten(iterable): + """Returns list.""" + if isinstance(iterable, (list, tuple)): + result = list(iterable) + else: + assert isinstance(iterable, dict) + keys = sorted(six.iterkeys(iterable)) + result = [iterable[key] for key in keys] + # Check we don't have any hierarchy in the structure (otherwise would need + # to use something recursive like tf.contrib.framework.nest.flatten). + for item in result: + assert not isinstance(item, (list, tuple, dict)) + return result + + +def _pack_sequence_as(example, flat): + if isinstance(example, list) or isinstance(example, tuple): + return flat + else: + assert isinstance(example, dict) + keys = sorted(six.iterkeys(example)) + return {key: value for key, value in zip(keys, flat)} + + +@six.add_metaclass(abc.ABCMeta) +class Op(object): + """An operation. + + This needs to support being transformed into sympy (and possibly in the future + other types such as an appropriately formatted string), when given the op + arguments. + """ + + def __init__(self, children): + """Initialize this `Op` base class. + + Args: + children: Iterable structure containing child ops. + """ + assert isinstance(children, (list, dict, tuple)) + flat_children = _flatten(children) + flat_children = [child if isinstance(child, Op) else Constant(child) + for child in flat_children] + children = _pack_sequence_as(children, flat_children) + self._children = children + + @property + def children(self): + """Returns iterable or dict over immediate children.""" + return self._children + + def descendants(self): + """Returns list of all descendants (self, children, grandchildren, etc).""" + descendants = [self] + flat_children = _flatten(self._children) + for child in flat_children: + descendants += child.descendants() + return descendants + + @abc.abstractmethod + def __str__(self): + """Returns a string format of this op.""" + + @abc.abstractmethod + def sympy(self): + """Returns the sympifcation of this op.""" + + def _sympy_(self): + """Convenience method to automatically sympify this object.""" + try: + return self.sympy() + except AttributeError as e: + # Note: we print this error here, before raising it again, because sympy + # will think `AttributeError` refers to this object not having a `_sympy_` + # method, rather than having it, which leads to otherwise confusing error + # messages. + logging.error( + 'Encountered attribute error while trying to sympify: %s', e) + raise e + + @abc.abstractproperty + def precedence(self): + """Returns the precedence (integer) of this op.""" + + +class Constant(Op): + """Returns a constant value; a nullary op.""" + + def __init__(self, value): + super(Constant, self).__init__([]) + if isinstance(value, six.integer_types): + value = sympy.Integer(value) + self._value = value + + def __str__(self): + return str(self._value) + + def sympy(self): + return self._value + + @property + def value(self): + return self._value + + @value.setter + def value(self, value): + self._value = value + + def _is_simple(self): + """Returns whether it's a simple number, rather than a division or neg.""" + if isinstance(self._value, sympy.Symbol): + return True + elif (isinstance(self._value, int) + or isinstance(self._value, sympy.Integer) + or isinstance(self._value, display.Decimal) + or isinstance(self._value, np.int64) + or isinstance(self._value, np.int32)): + return self._value >= 0 + elif isinstance(self._value, sympy.Rational): + return False + elif isinstance(self._value, sympy.Function): + return True + else: + raise ValueError('Unknown type {}'.format(type(self._value))) + + @property + def precedence(self): + if self._is_simple(): + return _CONSTANT_PRECEDENCE + else: + return _MUL_PRECEDENCE + + +class _SumLikeOp(Op): + """Abstract op for sum-like terms which may contain negative entries.""" + + @abc.abstractmethod + def expanded_signs_and_terms(self): + """Returns a list of arguments, plus any sub-arguments from sub-adds. + + E.g., if this op is `Add(Add(2, Neg(3)), Mul(4, 5), 1)`, then will return + `[(True, 2), (False, 3), (True, Mul(4, 5)), (True, 1)]` (the arguments of + the inner add have been extracted). + """ + + def __str__(self): + signs_and_terms = self.expanded_signs_and_terms() + if not signs_and_terms: + return '0' + for i, (sign, term) in enumerate(signs_and_terms): + if i == 0: + if sign: + expression = bracketed(term, self, True) + else: + expression = '-' + bracketed(term, self, True) + else: + if sign: + expression += ' + ' + bracketed(term, self, True) + else: + expression += ' - ' + bracketed(term, self, True) + return expression + + +class Identity(_SumLikeOp): + """The identity op (a unitary op).""" + + def __init__(self, input_): + super(Identity, self).__init__({'input': input_}) + + def expanded_signs_and_terms(self): + if isinstance(self.children['input'], _SumLikeOp): + return self.children['input'].expanded_signs_and_terms() + else: + return [(True, self.children['input'])] + + def __str__(self): + return str(self.children['input']) + + def sympy(self): + return self.children['input'].sympy() + + @property + def precedence(self): + return self.children['input'].precedence + + +class Neg(_SumLikeOp): + """Negation, a unary op. Also has special display when appearing in a sum.""" + + def __init__(self, arg): + super(Neg, self).__init__({'input': arg}) + + def expanded_signs_and_terms(self): + if isinstance(self.children['input'], _SumLikeOp): + inner_signs_and_terms = self.children['input'].expanded_signs_and_terms() + return [(not sign, term) for (sign, term) in inner_signs_and_terms] + else: + return [(False, self.children['input'])] + + def sympy(self): + return -sympy.sympify(self.children['input']) + + def inner(self): + return self.children['input'] + + @property + def precedence(self): + return _ADD_PRECEDENCE + + +class Add(_SumLikeOp): + """Addition.""" + + def __init__(self, *args): + super(Add, self).__init__(args) + + def expanded_signs_and_terms(self): + """Returns a list of arguments, plus any sub-arguments from sub-adds. + + E.g., if this op is `Add(Add(2, 3), Mul(4, 5), 1)`, then will return + `[2, 3, Mul(4, 5), 1]` (the arguments of the inner add have been extracted). + """ + expanded = [] + for arg in self.children: + if isinstance(arg, _SumLikeOp): + expanded += arg.expanded_signs_and_terms() + else: + expanded.append((True, arg)) + return expanded + + def sympy(self): + return sympy.Add(*[sympy.sympify(arg) for arg in self.children]) + + @property + def precedence(self): + return _ADD_PRECEDENCE + + +class Sub(Op): + """Subtraction.""" + + def __init__(self, left, right): + super(Sub, self).__init__({'left': left, 'right': right}) + + def __str__(self): + return (bracketed(self.children['left'], self, False) + ' - ' + + bracketed(self.children['right'], self, True)) + + def sympy(self): + return sympy.Add( + self.children['left'], sympy.Mul(-1, self.children['right'])) + + @property + def precedence(self): + return _ADD_PRECEDENCE + + +class Mul(Op): + """Multiplication.""" + + def __init__(self, *args): + super(Mul, self).__init__(args) + + def __str__(self): + if not self.children: + return '1' + else: + args = [bracketed(arg, self, False) for arg in self.children] + return MUL_SYMBOL.join(args) + + def sympy(self): + return sympy.Mul(*[sympy.sympify(arg) for arg in self.children]) + + @property + def precedence(self): + return _MUL_PRECEDENCE + + +class Div(Op): + """Division.""" + + def __init__(self, numer, denom): + super(Div, self).__init__({'numer': numer, 'denom': denom}) + + def __str__(self): + return u'{}{}{}'.format( + bracketed(self.children['numer'], self, True), DIV_SYMBOL, + bracketed(self.children['denom'], self, True)) + + def sympy(self): + return sympy.Mul( + self.children['numer'], sympy.Pow(self.children['denom'], -1)) + + @property + def precedence(self): + return _MUL_PRECEDENCE + + +class Pow(Op): + """Power a to the power b.""" + + def __init__(self, a, b): + super(Pow, self).__init__({'a': a, 'b': b}) + + def __str__(self): + return u'{}{}{}'.format( + bracketed(self.children['a'], self, True), POW_SYMBOL, + bracketed(self.children['b'], self, True)) + + def sympy(self): + return sympy.Pow( + sympy.sympify(self.children['a']), sympy.sympify(self.children['b'])) + + @property + def precedence(self): + return _POW_PRECEDENCE + + +class Sqrt(Op): + """Square root of a value.""" + + def __init__(self, a): + super(Sqrt, self).__init__({'a': a}) + + def __str__(self): + return 'sqrt({})'.format(self.children['a']) + + def sympy(self): + return sympy.sqrt(self.children['a']) + + @property + def precedence(self): + return _POW_PRECEDENCE + + +class Eq(Op): + """Equality.""" + + def __init__(self, left, right): + super(Eq, self).__init__({'left': left, 'right': right}) + + def __str__(self): + return '{} = {}'.format(self.children['left'], self.children['right']) + + def sympy(self): + return sympy.Eq(self.children['left'], self.children['right']) + + @property + def precedence(self): + return _EQ_PRECEDENCE + + +def number_constants(expressions): + """Returns list of integer, rational, decimal constants in the expressions.""" + if isinstance(expressions, Op): + expressions = [expressions] + descendants = [] + for expression in expressions: + descendants += expression.descendants() + candidate_constants = [op for op in descendants if isinstance(op, Constant)] + return [constant for constant in candidate_constants + if number.is_integer_or_rational_or_decimal(constant.value)] diff --git a/mathematics_dataset/mathematics_dataset/sample/ops_test.py b/mathematics_dataset/mathematics_dataset/sample/ops_test.py new file mode 100644 index 0000000000000000000000000000000000000000..64837dc09e562611dfc52730e83d67dadb0011ba --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/sample/ops_test.py @@ -0,0 +1,206 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Tests for mathematics_dataset.sample.ops.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +# Dependency imports +from absl.testing import absltest +from sample import ops +from six.moves import range +import sympy + + +class OpsTest(absltest.TestCase): + + def testNeg(self): + op = ops.Neg(2) + self.assertEqual(str(op), '-2') + self.assertEqual(op.sympy(), -2) + + op = ops.Add(ops.Neg(2), 3) + self.assertEqual(str(op), '-2 + 3') + self.assertEqual(op.sympy(), 1) + + op = ops.Add(3, ops.Neg(2)) + self.assertEqual(str(op), '3 - 2') + self.assertEqual(op.sympy(), 1) + + op = ops.Add(ops.Add(ops.Neg(2), 5), 3) + self.assertEqual(str(op), '-2 + 5 + 3') + self.assertEqual(op.sympy(), 6) + + op = ops.Add(3, ops.Add(ops.Identity(ops.Neg(2)), 5)) + self.assertEqual(str(op), '3 - 2 + 5') + self.assertEqual(op.sympy(), 6) + + op = ops.Add(3, ops.Add(2, ops.Neg(5))) + self.assertEqual(str(op), '3 + 2 - 5') + self.assertEqual(op.sympy(), 0) + + def testAdd(self): + add = ops.Add() + self.assertEqual(str(add), '0') + self.assertEqual(add.sympy(), 0) + + add = ops.Add(2, 3) + self.assertEqual(str(add), '2 + 3') + self.assertEqual(add.sympy(), 5) + + add = ops.Add(ops.Add(1, 2), 3) + self.assertEqual(str(add), '1 + 2 + 3') + self.assertEqual(add.sympy(), 6) + + def testSub(self): + sub = ops.Sub(2, 3) + self.assertEqual(str(sub), '2 - 3') + self.assertEqual(sub.sympy(), -1) + + sub = ops.Sub(ops.Sub(1, 2), 3) + self.assertEqual(str(sub), '1 - 2 - 3') + self.assertEqual(sub.sympy(), -4) + + sub = ops.Sub(1, ops.Sub(2, 3)) + self.assertEqual(str(sub), '1 - (2 - 3)') + self.assertEqual(sub.sympy(), 2) + + sub = ops.Sub(ops.Neg(1), 2) + self.assertEqual(str(sub), '-1 - 2') + self.assertEqual(sub.sympy(), -3) + + def testMul(self): + mul = ops.Mul() + self.assertEqual(str(mul), '1') + self.assertEqual(mul.sympy(), 1) + + mul = ops.Mul(2, 3) + self.assertEqual(str(mul), '2*3') + self.assertEqual(mul.sympy(), 6) + + mul = ops.Mul(ops.Identity(ops.Constant(-2)), 3) + self.assertEqual(str(mul), '-2*3') + self.assertEqual(mul.sympy(), -6) + + mul = ops.Mul(ops.Add(1, 2), 3) + self.assertEqual(str(mul), '(1 + 2)*3') + self.assertEqual(mul.sympy(), 9) + + mul = ops.Mul(ops.Mul(2, 3), 5) + self.assertEqual(str(mul), '2*3*5') + self.assertEqual(mul.sympy(), 30) + + # TODO(b/124038946): reconsider how we want brackets in these cases: +# mul = ops.Mul(ops.Div(2, 3), 5) +# self.assertEqual(str(mul), '(2/3)*5') +# self.assertEqual(mul.sympy(), sympy.Rational(10, 3)) +# +# mul = ops.Mul(sympy.Rational(2, 3), 5) +# self.assertEqual(str(mul), '(2/3)*5') +# self.assertEqual(mul.sympy(), sympy.Rational(10, 3)) + + def testDiv(self): + div = ops.Div(2, 3) + self.assertEqual(str(div), '2/3') + self.assertEqual(div.sympy(), sympy.Rational(2, 3)) + + div = ops.Div(2, sympy.Rational(4, 5)) + self.assertEqual(str(div), '2/(4/5)') + self.assertEqual(div.sympy(), sympy.Rational(5, 2)) + + div = ops.Div(1, ops.Div(2, 3)) + self.assertEqual(str(div), '1/(2/3)') + self.assertEqual(div.sympy(), sympy.Rational(3, 2)) + + div = ops.Div(ops.Div(2, 3), 4) + self.assertEqual(str(div), '(2/3)/4') + self.assertEqual(div.sympy(), sympy.Rational(1, 6)) + + div = ops.Div(2, ops.Mul(3, 4)) + self.assertEqual(str(div), '2/(3*4)') + + div = ops.Div(2, sympy.Function('f')(sympy.Symbol('x'))) + self.assertEqual(str(div), '2/f(x)') + + def testPow(self): + pow_ = ops.Pow(2, 3) + self.assertEqual(str(pow_), '2**3') + self.assertEqual(pow_.sympy(), 8) + + pow_ = ops.Pow(4, sympy.Rational(1, 2)) + self.assertEqual(str(pow_), '4**(1/2)') + self.assertEqual(pow_.sympy(), 2) + + pow_ = ops.Pow(sympy.Rational(1, 2), 3) + self.assertEqual(str(pow_), '(1/2)**3') + self.assertEqual(pow_.sympy(), 1/8) + + pow_ = ops.Pow(3, ops.Pow(2, 1)) + self.assertEqual(str(pow_), '3**(2**1)') + self.assertEqual(pow_.sympy(), 9) + + pow_ = ops.Pow(ops.Pow(2, 3), 4) + self.assertEqual(str(pow_), '(2**3)**4') + self.assertEqual(pow_.sympy(), 4096) + + pow_ = ops.Pow(-5, 2) + self.assertEqual(str(pow_), '(-5)**2') + self.assertEqual(pow_.sympy(), 25) + + def testEq(self): + op = ops.Eq(ops.Add(2, 3), 4) + self.assertEqual(str(op), '2 + 3 = 4') + self.assertEqual(op.sympy(), False) + + def testDescendants(self): + constants = [ops.Constant(i) for i in range(6)] + + # (1 + 2*3**4) / 5 - 6 + expression = ops.Sub( + ops.Div( + ops.Add( + constants[0], + ops.Mul( + constants[1], + ops.Pow( + constants[2], + constants[3]))), + constants[4]), + constants[5]) + descendants = expression.descendants() + descendants = ops._flatten(descendants) + + for constant in constants: + self.assertIn(constant, descendants) + self.assertEqual(descendants.count(constant), 1) + + # Also test top-level. + self.assertEqual(constants[0].descendants(), [constants[0]]) + + # Also general structure. + constant = ops.Constant(3) + expression = ops.Neg(constant) + self.assertEqual(set(expression.descendants()), set([constant, expression])) + + def testNumberConstants(self): + constant = ops.Constant(3) + expression = ops.Neg(constant) + constants = ops.number_constants([expression]) + self.assertEqual(constants, [constant]) + + +if __name__ == '__main__': + absltest.main() diff --git a/mathematics_dataset/mathematics_dataset/sample/polynomials.py b/mathematics_dataset/mathematics_dataset/sample/polynomials.py new file mode 100644 index 0000000000000000000000000000000000000000..09ee604b5ee133a31afd2402614a00c7bda297cf --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/sample/polynomials.py @@ -0,0 +1,601 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Generate polynomials with given values.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import math +import random + +# Dependency imports +from sample import number +from sample import ops +from util import combinatorics +import numpy as np +import six +from six.moves import range +from six.moves import zip +import sympy +from sympy.solvers.diophantine.diophantine import base_solution_linear as diophantine_solve_linear_2d + + +def expanded_coefficient_counts(length, is_zero): + """Generates list of integers for number of terms of given power. + + Args: + length: Integer >= `sum(is_zero)`. + is_zero: List of booleans. + + Returns: + List of non-negative integers of length `is_zero`, summing to `length`, + such that if `is_zero[i]` then `return_value[i] != 1`. + + Raises: + ValueError: If assignment not possible. + """ + if length == 1 and all(is_zero): + raise ValueError('length=1 and all zero') + + counts = np.asarray([0 if zero else 1 for zero in is_zero]) + extra_needed = (length - sum(counts)) + + if extra_needed < 0: + raise ValueError('length={} cannot handle is_zero={}' + .format(length, is_zero)) + + extra = combinatorics.uniform_non_negative_integers_with_sum( + count=len(is_zero), sum_=extra_needed) + counts += np.asarray(extra) + + # Tweak so that no zeros get "1". + while True: + bad_zeros = [ + i for i in range(len(is_zero)) if is_zero[i] and counts[i] == 1 + ] + if not bad_zeros: + break + take_from = random.choice(bad_zeros) + add_to = random.choice( + [i for i in range(len(is_zero)) if counts[i] >= 1 and i != take_from]) + counts[take_from] -= 1 + counts[add_to] += 1 + + return counts + + +def _split_value_equally(delta, count): + """Splits an integer or rational into roughly equal parts.""" + numer = sympy.numer(delta) + denom = sympy.denom(delta) + return [int(math.floor((numer + i) / count)) / denom for i in range(count)] + + +def integers_with_sum(value, count, entropy): + """Returns list of integers with a given sum. + + Args: + value: Target value. + count: Integer >= 1; the number of integers to use. + entropy: Entropy to use (in total). + + Returns: + List of numbers summing to `value`. + + Raises: + ValueError: If `value` is not an integer. + """ + # Special cases. + if count == 0: + assert value == 0 + assert entropy == 0 + return [] + if count == 1: + assert entropy == 0 + return [value] + + if not number.is_integer(value): + raise ValueError('value={} (type={}) is not an integer' + .format(value, type(value))) + + # Because e.g., (1, 1) and (2, 2) will both map to the same set of integers + # when we normalize to have sum equal to `value`. + entropy *= count / (count - 1) + + min_term_entropy = max( + 1, number.entropy_of_value(int(math.ceil(value/count)))) + term_entropies = entropy * np.random.dirichlet(np.ones(count)) + term_entropies = np.maximum(min_term_entropy, term_entropies) + + terms = [number.integer(term_entropy, signed=True) + for term_entropy in term_entropies] + + delta = value - sum(terms) + deltas = _split_value_equally(delta, count) + terms = [term + delta for term, delta in zip(terms, deltas)] + random.shuffle(terms) + return terms + + +def monomial(coefficient, variables, powers): + """Makes a simple monomial term.""" + if not isinstance(variables, (list, tuple)): + variables = [variables] + if not isinstance(powers, (list, tuple, np.ndarray)): + powers = [powers] + + terms = [] + + for variable, power in zip(variables, powers): + if power == 0: + continue + elif power == 1: + terms.append(variable) + else: + terms.append(ops.Pow(variable, power)) + + if (not terms + or isinstance(coefficient, sympy.Symbol) + or abs(coefficient) != 1): + if isinstance(coefficient, sympy.Symbol): + terms.insert(0, coefficient) + else: + terms.insert(0, abs(coefficient)) + + if len(terms) > 1: + term = ops.Mul(*terms) + else: + term = terms[0] + + if not isinstance(coefficient, sympy.Symbol) and coefficient < 0: + term = ops.Neg(term) + + return term + + +def sample_coefficients(degrees, entropy, min_non_zero=0, max_non_zero=None): + """Generates grid of coefficients with shape `degrees + 1`. + + This corresponds to univariate if degrees has length 1, otherwise + multivariate. + + Args: + degrees: List of integers containing max degrees of variables. + entropy: Float >= 0; entropy for generating entries. + min_non_zero: Optional integer >= 1; the minimum number of non-zero coeffs. + max_non_zero: Optional integer >= 1; the maximum number of non-zero coeffs. + + Returns: + NumPy int array of shape `degrees + 1`. + """ + if isinstance(degrees, int): + degrees = [degrees] + degrees = np.asarray(degrees) + + def random_index(): + return [random.randint(0, degrees[i]) for i in range(len(degrees))] + + indices = set() + # Ensure a variable of degree `degrees[i]` occurs for every axis i. + for i, degree in enumerate(degrees): + if degree > 0: + index = random_index() + index[i] = degree + indices.add(tuple(index)) + + abs_max_non_zero = np.prod(degrees + 1) + + min_non_zero = max(min_non_zero, 1, len(indices)) + if max_non_zero is None: + max_non_zero = min_non_zero + int(entropy/2) + + min_non_zero = min(min_non_zero, abs_max_non_zero) + max_non_zero = min(max_non_zero, abs_max_non_zero) + max_non_zero = max(min_non_zero, max_non_zero) + + num_non_zero = random.randint(min_non_zero, max_non_zero) + + while len(indices) < num_non_zero: + indices.add(tuple(random_index())) + + coeffs = np.zeros(degrees + 1, dtype=np.int64) + entropies = entropy * np.random.dirichlet(np.ones(num_non_zero)) + + for index, entry_entropy in zip(indices, entropies): + value = number.integer(entry_entropy, signed=True, min_abs=1) + coeffs.itemset(index, value) + + return coeffs + + +def expand_coefficients(coefficients, entropy, length=None): + """Expands coefficients to multiple terms that sum to each coefficient. + + Args: + coefficients: Array, such that `coefficients[i, j, ..., k]` is the + coefficient of x**i * y**j * ... * z**k. + entropy: Float >= 0; the entropy to use for generating extra randomness. + length: Number of terms that appear, e.g., 2x + 3 has two terms. If `None` + then a suitable length will be picked depending on the entropy + requested. + + Returns: + Numpy object array with the same shape as `coefficients`, containing lists. + """ + coefficients = np.asarray(coefficients) + shape = coefficients.shape + + expanded_coefficients = np.empty(shape, dtype=np.object_ ) + + min_length = np.count_nonzero(coefficients) + 2 + if length is None: + max_length = min_length + int(math.ceil(entropy) / 2) + length = random.randint(min_length, max_length) + if length < min_length: + length = min_length + + is_zero_flat = np.reshape(coefficients, [-1]) == 0 + counts = expanded_coefficient_counts(length, is_zero=is_zero_flat) + coeffs_entropy = entropy * np.random.dirichlet(np.maximum(1e-9, counts - 1)) + counts = np.reshape(counts, shape) + coeffs_entropy = np.reshape(coeffs_entropy, shape) + + indices = list(zip(*np.indices(shape).reshape([len(shape), -1]))) + for power in indices: + coeffs = integers_with_sum( + value=coefficients.item(power), + count=counts.item(power), + entropy=coeffs_entropy.item(power)) + expanded_coefficients.itemset(power, coeffs) + + return expanded_coefficients + + +def sample_expanded_coefficients(degrees, entropy, length=None): + """Convenience function: samples and expands coeffs, entropy split equally.""" + coefficients = sample_coefficients(degrees, entropy/2, max_non_zero=length) + return expand_coefficients(coefficients, entropy/2, length) + + +def coefficients_to_polynomial(coefficients, variables): + """Converts array of lists of coefficients to a polynomial.""" + coefficients = np.asarray(coefficients) + shape = coefficients.shape + + indices = list(zip(*np.indices(shape).reshape([len(shape), -1]))) + monomials = [] + for power in indices: + coeffs = coefficients.item(power) + if (number.is_integer_or_rational(coeffs) + or isinstance(coeffs, sympy.Symbol)): + coeffs = [coeffs] + elif not isinstance(coeffs, list): + raise ValueError('Unrecognized coeffs={} type={}' + .format(coeffs, type(coeffs))) + for coeff in coeffs: + monomials.append(monomial(coeff, variables, power)) + random.shuffle(monomials) + return ops.Add(*monomials) + + +def sample(variables, degrees, entropy, length=None): + coefficients = sample_expanded_coefficients(degrees, entropy, length) + return coefficients_to_polynomial(coefficients, variables) + + +def add_coefficients(coeffs1, coeffs2): + """Adds together two sets of coefficients over same set of variables.""" + coeffs1 = np.asarray(coeffs1) + coeffs2 = np.asarray(coeffs2) + + degrees1 = np.array(coeffs1.shape) + degrees2 = np.array(coeffs2.shape) + assert len(degrees1) == len(degrees2) + + extra1 = np.maximum(0, degrees2 - degrees1) + extra2 = np.maximum(0, degrees1 - degrees2) + + pad1 = [(0, extra) for extra in extra1] + pad2 = [(0, extra) for extra in extra2] + + coeffs1 = np.pad(coeffs1, pad1, 'constant', constant_values=0) + coeffs2 = np.pad(coeffs2, pad2, 'constant', constant_values=0) + + return coeffs1 + coeffs2 + + +def _random_factor(integer): + factors = sympy.factorint(integer) + result = 1 + for factor, power in six.iteritems(factors): + result *= factor ** random.randint(0, power) + return result + + +def coefficients_linear_split(coefficients, entropy): + """Finds two sets of coefficients and multipliers summing to `coefficients`. + + Given `coefficients` (an integer vector), will sample integers `a, b`, and + two sets of coefficients `coefficients_1, coefficients_2`, such that + `a * coefficients_1 + b * coefficients_2 == coefficients`. + + Args: + coefficients: Array of coefficients. + entropy: Float >= 0; the amount of randomness used to sample. + + Returns: + Tuple (a, b, coefficients_1, coefficients_2)`. + """ + coefficients = np.asarray(coefficients) + coefficients_shape = coefficients.shape + coefficients = np.reshape(coefficients, [-1]) + + entropy_a = max(1, random.uniform(0, entropy/3)) + entropy_b = max(1, random.uniform(0, entropy/3)) + entropy -= entropy_a + entropy_b + entropy_coefficients = entropy * np.random.dirichlet( + np.ones(len(coefficients))) + + # For each target coefficient z, we are required to solve the linear + # Diophantine equation a*x + b*y = c. Bezout's theorem: this has a solution if + # and only if gcd(a, b) divides c. + # Thus to be solvable for all coefficients, a and b must be chosen such that + # gcd(a, b) divides the gcd of the coefficients. + coefficients_gcd = sympy.gcd([i for i in coefficients]) + coefficients_gcd = max(1, abs(coefficients_gcd)) + + a = number.integer(entropy_a, signed=True, min_abs=1) + b = number.integer(entropy_b, signed=True, min_abs=1, coprime_to=a) + b *= _random_factor(coefficients_gcd) + if random.choice([False, True]): + a, b = b, a + + coefficients_1 = np.zeros(coefficients.shape, dtype=np.object_) + coefficients_2 = np.zeros(coefficients.shape, dtype=np.object_) + + for index, coefficient in enumerate(coefficients): + entropy_coeff = entropy_coefficients[index] + t = number.integer(entropy_coeff, signed=True) + x, y = diophantine_solve_linear_2d(c=coefficient, a=a, b=b, t=t) + coefficients_1[index] = x + coefficients_2[index] = y + + # Prevent all coefficients from being zero. + while np.all(coefficients_1 == 0) or np.all(coefficients_2 == 0): + index = random.randint(0, len(coefficients) - 1) + scale = random.choice([-1, 1]) + coefficients_1[index] += scale * b + coefficients_2[index] -= scale * a + + coefficients_1 = np.reshape(coefficients_1, coefficients_shape) + coefficients_2 = np.reshape(coefficients_2, coefficients_shape) + + return a, b, coefficients_1, coefficients_2 + + +def _degree_of_variable(polynomial, variable): + polynomial = sympy.sympify(polynomial).expand() + if polynomial.is_constant(): + return 0 + polynomial = sympy.poly(polynomial) + if variable not in polynomial.free_symbols: + return 0 + return polynomial.degree(variable) + + +def _sample_with_brackets(depth, variables, degrees, entropy, length, + force_brackets=True): + """Internal recursive function for: constructs a polynomial with brackets.""" + # To generate arbitrary polynomial recursively, can do one of: + # * add two polynomials, with at least one having brackets. + # * multiply two polynomials. + # * call `sample` (i.e., polynomial without brackets). + + if force_brackets: + length = max(2, length) + + if not force_brackets and (random.choice([False, True]) or length < 2): + return sample(variables, degrees, entropy, length) + + length_left = random.randint(1, length - 1) + length_right = length - length_left + entropy_left, entropy_right = entropy * np.random.dirichlet( + [length_left, length_right]) + + if random.choice([False, True]): + # Add two. Force brackets on at least one of the polynomials, and sample + # repeatedly until we don't get cancellation. + while True: + left = _sample_with_brackets( + depth + 1, variables, degrees, entropy_left, length_left, True) + right = _sample_with_brackets( + depth + 1, variables, degrees, entropy_right, length_right, False) + if random.choice([False, True]): + left, right = right, left + result = ops.Add(left, right) + all_ok = True + for variable, degree in zip(variables, degrees): + if _degree_of_variable(result, variable) != degree: + all_ok = False + break + if all_ok: + return result + else: + # Multiply two. + def sample_with_zero_check(degrees_, entropy_, length_): + while True: + result = _sample_with_brackets( + depth + 1, variables, degrees_, entropy_, length_, False) + if degrees_.sum() > 0 or not result.sympy().is_zero: + return result + degrees = np.asarray(degrees) + + def sample_degree(max_degree): + """Select in range [0, max_degree], biased away from ends.""" + if max_degree <= 1 or random.choice([False, True]): + return random.randint(0, max_degree) + return random.randint(1, max_degree - 1) + + degrees_left = np.array([sample_degree(degree) for degree in degrees]) + degrees_right = degrees - degrees_left + left = sample_with_zero_check(degrees_left, entropy_left, length_left) + right = sample_with_zero_check(degrees_right, entropy_right, length_right) + return ops.Mul(left, right) + + +def sample_with_brackets(variables, degrees, entropy, length=None): + """Constructs a polynomial with brackets. + + Args: + variables: List of variables to use. + degrees: Max degrees of variables. This function guarantees that these will + be obtained in the returned polynomial. + entropy: Float >= 0; the randomness to use in generating the polynomial. + length: Optional integer containing number of terms. If `None` then an + appropriate one will be generated depending on the entropy. + + Returns: + Instance of `ops.Op` containing the polynomial. + """ + if isinstance(degrees, int): + degrees = [degrees] + if not isinstance(variables, (list, tuple)): + variables = [variables] + + if length is None: + length = 3 + random.randint(0, int(entropy/2)) + + # Add on some entropy to compensate for different expressions generating the + # same apparent polynomial. + entropy += combinatorics.log_number_binary_trees(length) / math.log(10) + + return _sample_with_brackets(0, variables, degrees, entropy, length, True) + + +def sample_with_small_evaluation(variable, degree, max_abs_input, entropy): + """Generates a (canonically ordered) polynomial, with bounded evaluation. + + The coefficients are chosen to make use of the entropy, with the scaling + adjusted so that all give roughly the same contribution to the output of the + polynomial when the input is bounded in magnitude by `max_abs_input`. + + Args: + variable: Variable to use in polynomial. + degree: Degree of polynomial. + max_abs_input: Number >= 1; max absolute value of input. + entropy: Float; randomness for generating polynomial. + + Returns: + Instance of `ops.Add`. + """ + assert max_abs_input >= 1 + entropies = entropy * np.random.dirichlet(np.ones(degree + 1)) + coeffs = [] + + for power in range(degree + 1): + # This scaling guarantees that the terms give roughly equal contribution + # to the typical magnitude of the polynomial when |input| <= max_abs_input. + delta = 0.5 * (degree - 2 * power) * math.log10(max_abs_input) + power_entropy = entropies[power] + delta + min_abs = 1 if power == degree else 0 + coeff = number.integer(power_entropy, signed=True, min_abs=min_abs) + coeffs.append(coeff) + + terms = [monomial(coeff, variable, power) + for power, coeff in enumerate(coeffs)] + return ops.Add(*terms) + + +def sample_messy_power(variable, entropy): + """Returns unsimplified power expression like ((x**2)**3/x**4)**2/x**3.""" + if entropy <= 0: + return variable + + which = random.choice([1, 2, 3]) + + if which == 1: + exponent_entropy = min(2, entropy) + entropy -= exponent_entropy + exponent = number.integer_or_rational(exponent_entropy, signed=True) + left = sample_messy_power(variable, entropy) + return ops.Pow(left, exponent) + + entropy_left = entropy / 2 + if entropy_left < 1: + entropy_left = 0 + entropy_right = entropy - entropy_left + if random.choice([False, True]): + entropy_left, entropy_right = entropy_right, entropy_left + + left = sample_messy_power(variable, entropy_left) + right = sample_messy_power(variable, entropy_right) + if which == 2: + return ops.Mul(left, right) + else: + return ops.Div(left, right) + + +def trim(coefficients): + """Makes non-zero entry in the final slice along each axis.""" + coefficients = np.asarray(coefficients) + non_zero = np.not_equal(coefficients, 0) + ndim = coefficients.ndim + + for axis in range(ndim): + length = coefficients.shape[axis] + axis_complement = list(range(0, axis)) + list(range(axis + 1, ndim)) + non_zero_along_axis = np.any(non_zero, axis=tuple(axis_complement)) + + slice_to = 0 + for index in range(length - 1, -1, -1): + if non_zero_along_axis[index]: + slice_to = index + 1 + break + + if slice_to < length: + coefficients = coefficients.take(axis=axis, indices=list(range(slice_to))) + + return coefficients + + +def differentiate(coefficients, axis): + """Differentiate coefficients (corresponding to polynomial) along axis.""" + coefficients = np.asarray(coefficients) + indices = list(range(1, coefficients.shape[axis])) + coefficients = coefficients.take(axis=axis, indices=indices) + + broadcast_shape = np.ones(coefficients.ndim, dtype=np.int32) + broadcast_shape[axis] = len(indices) + broadcast = np.asarray(indices).reshape(broadcast_shape) + + result = broadcast * coefficients + return trim(result) + + +def integrate(coefficients, axis): + """Integrate coefficients (corresponding to polynomial) along axis.""" + coefficients = np.asarray(coefficients) + + length = coefficients.shape[axis] + broadcast_shape = np.ones(coefficients.ndim, dtype=np.int32) + broadcast_shape[axis] = length + powers = np.array([sympy.Integer(i) for i in range(1, length + 1)]) + powers = powers.reshape(broadcast_shape) + + result_unpadded = coefficients / powers + + pad = [(1 if i == axis else 0, 0) for i in range(coefficients.ndim)] + return np.pad(result_unpadded, pad, 'constant', constant_values=0) diff --git a/mathematics_dataset/mathematics_dataset/sample/polynomials_test.py b/mathematics_dataset/mathematics_dataset/sample/polynomials_test.py new file mode 100644 index 0000000000000000000000000000000000000000..c2879e1ecc47cf9cf26c5a34fe1f68b5a67e604a --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/sample/polynomials_test.py @@ -0,0 +1,162 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Tests for mathematics_dataset.sample.polynomials.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import random + +# Dependency imports +from absl.testing import parameterized +from sample import polynomials +import numpy as np +from six.moves import range +import sympy +import tensorflow as tf + + +class ExpressionWithValueTest(tf.test.TestCase, parameterized.TestCase): + + def testSplitValueEqually(self): + split = polynomials._split_value_equally(3, 2) + self.assertEqual(split, [1, 2]) + split = polynomials._split_value_equally(sympy.sympify('3/4'), 2) + self.assertEqual(split, [sympy.sympify('1/4'), sympy.sympify('1/2')]) + + def testIntegersWithSum(self): + value = 13 + count = 10 + terms = polynomials.integers_with_sum(value=value, count=count, entropy=4.0) + self.assertLen(terms, count) + self.assertEqual(sum(terms), value) + + def testMonomial(self): + x, y = sympy.symbols('x y') + self.assertEqual(str(polynomials.monomial(1, [x, y], [2, 3])), 'x**2*y**3') + # TODO(b/124038530): how handle rational coefficients; are they even used? + # self.assertEqual( + # str(polynomials.monomial(sympy.Rational(2, 3), [x], [1])), '2*x/3') + # self.assertEqual( + # str(polynomials.monomial(sympy.Rational(1, 3), [x], [1])), 'x/3') + self.assertEqual(str(polynomials.monomial(x, [y], [4])), 'x*y**4') + + def testExpandCoefficients(self): + for _ in range(10): + num_variables = np.random.randint(1, 4) + degrees = np.random.randint(0, 4, [num_variables]) + coefficients = np.random.randint(-3, 3, degrees + 1) + entropy = np.random.uniform(0, 10) + expanded = polynomials.expand_coefficients(coefficients, entropy) + collapsed = np.vectorize(sum)(expanded) + self.assertAllEqual(coefficients, collapsed) + + def testCoefficientsToPolynomial(self): + coeffs = [3, 2, 1] + x = sympy.Symbol('x') + polynomial = polynomials.coefficients_to_polynomial(coeffs, [x]) + polynomial = sympy.sympify(polynomial) + self.assertEqual(polynomial, x*x + 2*x + 3) + + def testUnivariate(self): + # Test generation for: x**2 + 2*x + 1 + x = sympy.Symbol('x') + coeffs = [1, 2, 3] + for _ in range(10): + expanded = polynomials.expand_coefficients(coeffs, 5.0) + polynomial = polynomials.coefficients_to_polynomial(expanded, [x]) + sympified = sympy.sympify(polynomial) + self.assertEqual(sympified, 1 + 2*x + 3*x*x) + + def testMultivariate(self): + # Test generation for: x**2 + 2*x*y + 3*y**2 - x + 5 + x, y = sympy.symbols('x y') + coeffs = [[5, 0, 3], [-1, 2, 0], [1, 0, 0]] + for _ in range(10): + expanded = polynomials.expand_coefficients(coeffs, 5.0, length=10) + polynomial = polynomials.coefficients_to_polynomial(expanded, [x, y]) + sympified = sympy.sympify(polynomial) + self.assertEqual(sympified, x*x + 2*x*y + 3*y*y - x + 5) + + def testAddCoefficients(self): + # Add x**2 + 2*y and 3*x + 4*y**3. + coeffs1 = [[0, 2], [0, 0], [1, 0]] + coeffs2 = [[0, 0, 0, 4], [3, 0, 0, 0]] + target = [[0, 2, 0, 4], [3, 0, 0, 0], [1, 0, 0, 0]] + actual = polynomials.add_coefficients(coeffs1, coeffs2) + self.assertAllEqual(target, actual) + + def testCoefficientsLinearSplit(self): + for degree in range(3): + for ndims in range(3): + for _ in range(10): + coefficients = np.random.randint(-5, 5, [degree + 1] * ndims) + entropy = random.uniform(1, 4) + c1, c2, coeffs1, coeffs2 = polynomials.coefficients_linear_split( + coefficients, entropy) + c1 = int(c1) + c2 = int(c2) + coeffs1 = np.asarray(coeffs1, dtype=np.int32) + coeffs2 = np.asarray(coeffs2, dtype=np.int32) + sum_ = c1 * coeffs1 + c2 * coeffs2 + self.assertAllEqual(sum_, coefficients) + + def testSampleWithBrackets(self): + x, y = sympy.symbols('x y') + for _ in range(100): + degrees = np.random.randint(1, 4, [2]) + entropy = random.uniform(0, 4) + polynomial = polynomials.sample_with_brackets( + variables=[x, y], degrees=degrees, entropy=entropy) + self.assertIn('(', str(polynomial)) + poly = sympy.poly(sympy.sympify(polynomial).expand()) + self.assertEqual(poly.degree(x), degrees[0]) + self.assertEqual(poly.degree(y), degrees[1]) + + def testTrim(self): + self.assertAllEqual(polynomials.trim([1]), [1]) + self.assertAllEqual(polynomials.trim([1, 0]), [1]) + self.assertAllEqual(polynomials.trim([0, 1]), [0, 1]) + self.assertAllEqual(polynomials.trim([0]), []) + self.assertAllEqual(polynomials.trim([0, 0]), []) + + def testDifferentiate_univariate(self): + coeffs = [5, 3, 2] + expected = [3, 4] + actual = polynomials.differentiate(coeffs, 0) + self.assertAllEqual(expected, actual) + + def testDifferentiate_multivariate(self): + coeffs = [[0, 3, 1], [5, 0, 0], [0, 2, 0]] + expected = [[5, 0], [0, 4]] + actual = polynomials.differentiate(coeffs, 0) + self.assertAllEqual(expected, actual) + + def testIntegrate_univariate(self): + coeffs = [5, 3, 2] + expected = [0, 5, sympy.Rational(3, 2), sympy.Rational(2, 3)] + actual = polynomials.integrate(coeffs, 0) + self.assertAllEqual(expected, actual) + + def testIntegrate_multivariate(self): + coeffs = [[0, 1], [1, 0]] + expected = [[0, 0, sympy.Rational(1, 2)], [0, 1, 0]] + actual = polynomials.integrate(coeffs, 1) + self.assertAllEqual(expected, actual) + + +if __name__ == '__main__': + tf.test.main() diff --git a/mathematics_dataset/mathematics_dataset/util/__init__.py b/mathematics_dataset/mathematics_dataset/util/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..d780829a1f5101333577a1ca9adcb960529213f1 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/util/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/mathematics_dataset/mathematics_dataset/util/combinatorics.py b/mathematics_dataset/mathematics_dataset/util/combinatorics.py new file mode 100644 index 0000000000000000000000000000000000000000..92eb8288622c3fd9b6f9516619674e1b7db1c082 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/util/combinatorics.py @@ -0,0 +1,58 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Combinatorics utility functions.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import math +import random + +# Dependency imports +from six.moves import range +from six.moves import zip + + +def uniform_positive_integers_with_sum(count, sum_): + """Returns list of size `count` of integers >= 1, summing to `sum_`.""" + assert sum_ >= 0 + if count > sum_: + raise ValueError('Cannot find {} numbers >= 1 with sum {}' + .format(count, sum_)) + if count == 0: + return [] + # Select `count - 1` numbers from {1, ..., sum_ - 1} + separators = random.sample(list(range(1, sum_)), count - 1) + separators = sorted(separators) + return [right - left + for left, right in zip([0] + separators, separators + [sum_])] + + +def uniform_non_negative_integers_with_sum(count, sum_): + """Returns list of size `count` of integers >= 0, summing to `sum_`.""" + positive = uniform_positive_integers_with_sum(count, sum_ + count) + return [i - 1 for i in positive] + + +def log_number_binary_trees(size): + """Returns (nat) log of number of binary trees with `size` internal nodes.""" + # This is equal to log of C_size, where C_n is the nth Catalan number. + assert isinstance(size, int) + assert size >= 0 + log = 0.0 + for k in range(2, size + 1): + log += math.log(size + k) - math.log(k) + return log diff --git a/mathematics_dataset/mathematics_dataset/util/combinatorics_test.py b/mathematics_dataset/mathematics_dataset/util/combinatorics_test.py new file mode 100644 index 0000000000000000000000000000000000000000..def98972e63b9e50c5c8cd7d07d7520b3c642046 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/util/combinatorics_test.py @@ -0,0 +1,64 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Tests mathematics_dataset.util.combinatorics.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import math + +# Dependency imports +from absl.testing import absltest +from util import combinatorics + + +class CombinatoricsTest(absltest.TestCase): + + def testPositiveIntegersWithSum(self): + result = combinatorics.uniform_positive_integers_with_sum(1, 1) + self.assertEqual(result, [1]) + result = combinatorics.uniform_positive_integers_with_sum(2, 2) + self.assertEqual(result, [1, 1]) + result = combinatorics.uniform_positive_integers_with_sum(1, 10) + self.assertEqual(sum(result), 10) + result = combinatorics.uniform_positive_integers_with_sum(2, 10) + self.assertEqual(sum(result), 10) + result = combinatorics.uniform_positive_integers_with_sum(0, 0) + self.assertEqual(result, []) + + def testNonNegativeIntegersWithSum(self): + result = combinatorics.uniform_non_negative_integers_with_sum(1, 0) + self.assertEqual(result, [0]) + result = combinatorics.uniform_non_negative_integers_with_sum(2, 0) + self.assertEqual(result, [0, 0]) + result = combinatorics.uniform_non_negative_integers_with_sum(3, 10) + self.assertEqual(sum(result), 10) + + def testLogNumberBinaryTrees(self): + self.assertAlmostEqual( + combinatorics.log_number_binary_trees(0), math.log(1)) + self.assertAlmostEqual( + combinatorics.log_number_binary_trees(1), math.log(1)) + self.assertAlmostEqual( + combinatorics.log_number_binary_trees(2), math.log(2)) + self.assertAlmostEqual( + combinatorics.log_number_binary_trees(3), math.log(5)) + self.assertAlmostEqual( + combinatorics.log_number_binary_trees(4), math.log(14)) + + +if __name__ == '__main__': + absltest.main() diff --git a/mathematics_dataset/mathematics_dataset/util/composition.py b/mathematics_dataset/mathematics_dataset/util/composition.py new file mode 100644 index 0000000000000000000000000000000000000000..27108d3f4235ee70ab41199b7242bb8fb927603f --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/util/composition.py @@ -0,0 +1,596 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""For performing module composition.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import collections +import random +import string + +# Dependency imports +from sample import number +from sample import ops +from sample import polynomials +from util import combinatorics +from util import display +import numpy as np +import six +from six.moves import range +from six.moves import zip +import sympy + + +# Allowed symbols. Don't allow "e", as sympy can hang when printing it as a +# function symbol (and it's reserved for exponent). +_ALLOWED_SYMBOLS = set(string.ascii_lowercase).difference(set(['e'])) + + +class Polynomial(collections.namedtuple('Polynomial', ('coefficients'))): + """Value wrapper for a polynomial function. + + Attributes: + coefficients: Numpy array of coefficients; see `polynomials.py`. + """ + + def __new__(cls, coefficients): + coefficients = np.asarray(coefficients) + return super(Polynomial, cls).__new__(cls, coefficients) + + +def is_polynomial(value): + return isinstance(value, Polynomial) + + +def is_integer_polynomial(value): + if not is_polynomial(value): + return False + coefficients = np.reshape(value.coefficients, [-1]) + return all(number.is_integer(coeff) for coeff in coefficients) + + +# List of pairs of `(filter, sampler)`, where `filter` is a function returning +# True if the sampler is valid for the given value, and `sampler` returns an +# `Entity`. +_FILTERS_AND_SAMPLERS = [] + + +def module(filter_): + """Returns a Decorator for a module function. + + The returned decorator adds the function to the library of known modules. + + Args: + filter_: Callable determining whether the module can handle a given value. + + Returns: + Decorator that adds the module function to the library. + """ + def decorator(module_fn): + """Decorates a module function.""" + _FILTERS_AND_SAMPLERS.append((filter_, module_fn)) + return module_fn + return decorator + + +class SampleArgs( + collections.namedtuple('SampleArgs', ('num_modules', 'entropy'))): + """For sampling mathematical entities / questions.""" + + def peel(self, frac=1): + """Peels one (or `frac`) of a module's entropy. + + In addition to a portion of the entropy, this returns a new `SampleArgs` + (since this object is immutable), which you should use when creating child + modules. + + Args: + frac: Float; proportion of module's entropy to take. + + Returns: + Triple `(entropy, new_sample_args)`, where `new_sample_args` is a new + `SampleArgs` with the entropy removed. + """ + entropy = frac * self.entropy / self.num_modules + new_sample_args = SampleArgs( + num_modules=self.num_modules, entropy=self.entropy - entropy) + return entropy, new_sample_args + + def split(self, count): + """Splits the entropy and module counts up. + + Args: + count: Integer >= 1; the split size. + + Returns: + List of `SampleArgs` of length `count`, to be passed to create child + entities. + + Raises: + ValueError: If it was not possible to use up all the entropy, for example, + all requested types were `WithValue`. + """ + num_child_modules = self.num_modules - 1 + + # Sample module counts at random + module_counts = combinatorics.uniform_non_negative_integers_with_sum( + count, num_child_modules) + + if num_child_modules == 0: + if self.entropy > 0: + raise ValueError('Unused entropy') + entropies = np.zeros(count) + else: + entropies = self.entropy * np.random.dirichlet( + np.maximum(1e-9, module_counts)) + + sample_args = [] + for i, num_modules in enumerate(module_counts): + child_sample_args = SampleArgs( + num_modules=num_modules, entropy=entropies[i]) + sample_args.append(child_sample_args) + + return sample_args + + +class PreSampleArgs( + collections.namedtuple( + 'PreSampleArgs', + ('min_modules', 'max_modules', 'min_entropy', 'max_entropy'))): + """Sample args before module count and entropy have been sampled.""" + + def __call__(self): + """Samples `SampleArgs`.""" + return SampleArgs( + num_modules=random.randint(self.min_modules, self.max_modules), + entropy=random.uniform(self.min_entropy, self.max_entropy)) + + def peel(self, *args, **kwargs): + sample_args = self() + return sample_args.peel(*args, **kwargs) + + def split(self, *args, **kwargs): + sample_args = self() + return sample_args.split(*args, **kwargs) + + +class FunctionHandle(object): + """Special handle to allow function composition. + + For example, suppose fn1 = f o g + fn2 = h + + and we want to display fn1(fn2(x)) = f(g(h(x))). This function basically just + stores the list of sympy functions. + """ + + def __init__(self, *function_entities): + """Initialize a `FunctionHandle`. + + Args: + *function_entities: List of function letters and `Entity`s representing + functions, to be composed. + """ + self._functions = [] + for fn in function_entities: + if isinstance(fn, str): + functions = [sympy.Function(fn)] + else: + assert isinstance(fn, Entity) + assert isinstance(fn.handle, FunctionHandle) + functions = fn.handle.functions + self._functions += functions + + def apply(self, *input_): + """Returns f(g(...(input)...)) where f, g, ... are the functions.""" + result = None + for function in reversed(self._functions): + if result is None: + result = function(*input_) + else: + result = function(result) + return result + + @property + def functions(self): + return self._functions + + def __str__(self): + raise ValueError('This should not be directly converted to a string') + + +def _polynomial_entity(value, context): + """Create a generic `Entity` describing a polynomial.""" + assert isinstance(value, Polynomial) + coefficients = np.asarray(value.coefficients) + num_variables = coefficients.ndim + variables = [sympy.Symbol(context.pop()) for _ in range(num_variables)] + function_symbol = context.pop() + handle = FunctionHandle(function_symbol) + handle_description = sympy.Function(function_symbol)(*variables) + + polynomial = polynomials.coefficients_to_polynomial(coefficients, variables) + polynomial = polynomial.sympy() + + return Entity( + context=context, + value=value, + expression=polynomial, + polynomial_variables=variables, + description='Seja {function} = {polynomial}.', + handle=handle, + function=handle_description, + polynomial=polynomial) + + +class Context(object): + """Keeps track of used symbols, and sampling of children. + + Each context is associated with an entity. Entities are constructed in a + tree-like fashion. + """ + + def __init__(self, relation_symbols=None): + """Initializes a `Context`. + + Args: + relation_symbols: Set of symbols used "externally": this means (with + reference to the tree in which this context sits) all symbols + occurring that aren't in this node or sub-nodes. + """ + if relation_symbols is None: + relation_symbols = set() + else: + assert isinstance(relation_symbols, set) + for symbol in relation_symbols: + assert isinstance(symbol, str) + + self._relation_symbols = relation_symbols + self._self_symbols = set() + self._child_symbols = set() + self._module_count = 1 + self._child_entities = [] + + @property + def relation_symbols(self): + return self._relation_symbols.copy() + + @property + def self_symbols(self): + return self._self_symbols.copy() + + @property + def child_symbols(self): + return self._child_symbols.copy() + + @property + def child_entities(self): + return self._child_entities[:] + + def pop(self): + """Returns an unused symbol (and keeps track of it being used).""" + allowed = (_ALLOWED_SYMBOLS + .difference(self._relation_symbols) + .difference(self._self_symbols) + .difference(self._child_symbols)) + if not allowed: + raise ValueError('Ran out of symbols') + symbol = random.choice(list(allowed)) + self._self_symbols.add(symbol) + return symbol + + def mark_used(self, symbol): + """Marks a given symbol as used.""" + assert isinstance(symbol, str) + if (symbol in self._relation_symbols + or symbol in self._self_symbols + or symbol in self._child_symbols): + raise ValueError('Symbol {} already used'.format(symbol)) + self._self_symbols.add(symbol) + + @property + def module_count(self): + """Returns the number of modules sampled.""" + return self._module_count + + def _sampler(self, value, sample_args): + """Returns a sampler appropriate for the given args. + + Args: + value: Target value. + sample_args: Instance of `SampleArgs` controlling entropy etc. + + Returns: + A sampler for producing entities. + + Raises: + ValueError: If no valid samplers were found. + """ + valid = [] + for filter_, sampler in _FILTERS_AND_SAMPLERS: + if filter_(value): + valid.append(sampler) + if not valid: + raise ValueError('No valid samplers found: value={} sample_args={}' + .format(value, sample_args)) + return random.choice(valid) + + def _value_entity(self, value, context): + if isinstance(value, (sympy.Integer, sympy.Rational, display.Decimal)): + return Entity(context=context, value=value, handle=value) + if isinstance(value, Polynomial): + return _polynomial_entity(value, context) + raise ValueError('Don\'t know how to handle value={} of type {}' + .format(value, type(value))) + + def sample(self, sample_args, values): + """Sample multiple entities. + + Args: + sample_args: Instance of `SampleArgs`. The min and max entropy + and module count will be split up betwene the various entities + sampled. + values: List of values to sample. + + Returns: + List of `Entity` of the same length as `types`. + + Raises: + RuntimeError: If one of the modules generates a non-`Entity`. + """ + # Can only sample children once. + assert self._module_count == 1 + assert not self._child_symbols + assert not self._child_entities + + if isinstance(sample_args, PreSampleArgs): + sample_args = sample_args() + sample_args_split = sample_args.split(len(values)) + + def all_symbols(): + return (self._relation_symbols + .union(self._self_symbols) + .union(self._child_symbols)) + + for value, child_sample_args in zip(values, sample_args_split): + if number.is_integer(value): + value = sympy.Integer(value) + + all_symbols_ = all_symbols() + context = Context(all_symbols_) + + if child_sample_args.num_modules == 0: + entity = self._value_entity(value, context) + else: + sampler = self._sampler(value, child_sample_args) + entity = sampler(value, child_sample_args, context) + if not isinstance(entity, Entity): + raise RuntimeError( + 'Expected entity, but got {} instead'.format(entity)) + if (not number.is_integer_or_rational_or_decimal(entity.value) + and not isinstance(entity.value, Polynomial)): + raise RuntimeError('sampler {} returned invalid value of type {}' + .format(sampler, type(entity.value))) + if ((number.is_integer_or_rational_or_decimal(value) + and entity.value != value) + or (isinstance(value, Polynomial) and not np.array_equal( + entity.value.coefficients, value.coefficients))): + raise RuntimeError( + 'entity values differ, sampler={} wanted={} got={}' + .format(sampler, value, entity.value)) + if child_sample_args.num_modules != context.module_count: + raise RuntimeError( + 'unused modules, value={} sample_args={} context.module_count={},' + ' sampler={}' + .format(value, child_sample_args, context.module_count, sampler)) + self._module_count += context.module_count + + self._child_entities.append(entity) + for symbol in context.self_symbols.union(context.child_symbols): + assert symbol not in all_symbols_ + self._child_symbols.add(symbol) + + return self._child_entities + + def sample_by_replacing_constants(self, sample_args, expressions): + """Replaces some of the constants with handles from other modules.""" + max_children = sample_args.num_modules - 1 + if max_children <= 0: + return + if isinstance(expressions, ops.Op): + expressions = [expressions] + constants = ops.number_constants(expressions) + if not constants: + raise ValueError('No constants to replace in {}' + .format([str(expr) for expr in expressions])) + + sample_count = random.randint(1, min(max_children, len(constants))) + constants = random.sample(constants, sample_count) + + values = [constant.value for constant in constants] + entities = self.sample(sample_args, values) + for constant, entity in zip(constants, entities): + constant.value = entity.handle + + +def expand_entities(context, **kwargs): + """Returns prefix description and updated `**kwargs`. + + Args: + context: Instance of `Context` containing all `Entity`s that occur. + **kwargs: Dictionary of key/value pairs, some of which are `Entity`s. + + Returns: + Pair `(child_description, new_kwargs)`. `child_description` is a description + of the entities contained in `kwargs`, and `new_kwargs` contains handles. + """ + kwargs = kwargs.copy() + entities = set(context.child_entities) + for key, maybe_entity in six.iteritems(kwargs): + if isinstance(maybe_entity, Entity): + entities.add(maybe_entity) + kwargs[key] = maybe_entity.handle + entities = list(entities) + random.shuffle(entities) + + child_descriptions = [] + for entity in entities: + child_descriptions.append(entity.child_description) + if not entity.expression_used: + child_descriptions.append(entity.description) + + child_description = ' '.join([s for s in child_descriptions if s]) + return child_description, kwargs + + +class Entity(object): + """An entity (e.g., representing an integer or function). + + Example usage: + + ``` + new_entity = Entity( + context=context, + value=17, + description='Let {self} be the gcd of {q} and {q}.' + p=p, q=q) + ``` + + Above, {self} will be replaced with a new symbol, to be used as the entity + handle. + """ + + def __init__(self, context, value, description='', handle=None, + expression=None, polynomial_variables=None, + **description_kwargs): + """Initializes an entity. + + Args: + context: Instance of `Context` keeping track of used symbols and child + entities (that may not explicitly occur in `description_kwargs`). + value: The value represented by this Entity. + description: String, describing this Entity. This can contain '{self}' as + a substring, in which case it will be substituted with a new handle + (and `context` must be non-None). + handle: Optional string/symbol that refers to this Entity. This must + always be provided if '{self}' does not occur in `description`. + expression: Optional string (or something that can be converted to a + string, like ops.Op or sympy.expr) representing the value of this + Entity, that can be used directly instead of using `handle`. + polynomial_variables: If `expression` provided, then for polynomial + entities, the variables used. + **description_kwargs: Dict of substitutions (including entities) for use + in `description`. + + Raises: + ValueError: If handle specified and '{self}' in description; or neither. + """ + self._value = value + + child_description, description_kwargs = expand_entities( + context, **description_kwargs) + + if '{self}' in description: + if handle is not None: + raise ValueError('Cannot specify handle if {self} in description') + handle = context.pop() + description_kwargs['self'] = handle + handle = sympy.var(handle) + else: + if handle is None: + raise ValueError('Must specify handle if {self} not in description') + if isinstance(handle, str): + handle = sympy.var(handle) + + if (isinstance(value, Polynomial) + and expression is not None + and polynomial_variables is None): + raise ValueError('Must provided polynomial_variables') + + self._child_description = child_description + self._description = description.format(**description_kwargs) + self._handle = handle + self._expression = expression + self._polynomial_variables = polynomial_variables + + # For checking that we don't use both the handle and the expression form of + # this entity. + self._handle_used = False + self._expression_used = False + + @property + def value(self): + """The actual value of the entity (e.g., sympy object).""" + return self._value + + @property + def child_description(self): + """A string describing the entities that this Entity relies on.""" + return self._child_description + + @property + def description(self): + """A string describing the entity.""" + assert not self._expression_used + self._handle_used = True + return self._description + + def has_expression(self): + """Returns whether there is an expression to use (instead of handle).""" + return self._expression is not None + + @property + def handle(self): + """A "handle", e.g., SymPy symbol or `function.CompositionHandle`.""" + assert not self._expression_used + self._handle_used = True + return self._handle + + @property + def expression(self): + """An expression representing the entity; possibly None. + + If this is used, then `description` does not need to get used. + + Returns: + String or None. + """ + assert not self._handle_used + self._expression_used = True + return self._expression + + @property + def polynomial_variables(self): + """For when `expression` is not None, and this entity is a polynomial.""" + return self._polynomial_variables + + @property + def expression_used(self): + """Returns true if expression instead of handle was used.""" + return self._expression_used + + @property + def expression_else_handle(self): + """Returns an expression if present, else the handle.""" + if self.has_expression(): + return self.expression + else: + return self.handle + + def __str__(self): + """Raises value error - should not attempt to convert to string directly.""" + raise ValueError('Should not convert Entity directly to string') diff --git a/mathematics_dataset/mathematics_dataset/util/composition_test.py b/mathematics_dataset/mathematics_dataset/util/composition_test.py new file mode 100644 index 0000000000000000000000000000000000000000..0d3e533bb8d718a5805600611a36cd2043e36599 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/util/composition_test.py @@ -0,0 +1,65 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Tests for mathematics_dataset.util.composition.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +# Dependency imports +from absl.testing import absltest +from util import composition +import sympy + + +class FunctionHandleTest(absltest.TestCase): + + def testApply(self): + handle = composition.FunctionHandle('f', 'g') + applied = handle.apply(*sympy.symbols('x y')) + self.assertEqual(str(applied), 'f(g(x, y))') + applied = handle.apply(sympy.symbols('x')) + self.assertEqual(str(applied), 'f(g(x))') + + +class ContextTest(absltest.TestCase): + + def testPeel(self): + sample_args = composition.SampleArgs(4, 3.0) + entropy, new_sample_args = sample_args.peel() + self.assertAlmostEqual(entropy, 0.75) + self.assertEqual(new_sample_args.num_modules, 4) + self.assertAlmostEqual(new_sample_args.entropy, 2.25) + + def testSplit(self): + sample_args = composition.SampleArgs(4, 5.0) + children = sample_args.split(2) + self.assertLen(children, 2) + self.assertEqual(sum([child.num_modules for child in children]), 3) + self.assertAlmostEqual(sum([child.entropy for child in children]), 5.0) + + +class EntityTest(absltest.TestCase): + + def testInit_valueErrorIfSelfAndHandle(self): + with self.assertRaisesRegex(self, ValueError, 'Cannot specify handle'): + composition.Entity(context=composition.Context(), + value=0, + description='Something with {self}. ', + handle='additional') + + +if __name__ == '__main__': + absltest.main() diff --git a/mathematics_dataset/mathematics_dataset/util/display.py b/mathematics_dataset/mathematics_dataset/util/display.py new file mode 100644 index 0000000000000000000000000000000000000000..0ab5b2e44356913752606a77d86e70824f1030d9 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/util/display.py @@ -0,0 +1,404 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Functionality for displaying expressions. + +SymPy provides a lot of functionality for displaying expressions, but it's +slightly too centered on being a symbolic maths engine to provides all our +needs. For example, it's impossible to display an unsimplified fraction like +3/6, or a decimal that isn't internally represented as a float and thus subject +to rounding. + +Also provides some other convenience such as converting numbers to words, and +displaying percentages (properly formatted). +""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import decimal + +# Dependency imports +import sympy + + +# For converting integers to words: +_INTEGER_LOW = [ + 'zero', 'um', 'dois', 'três', 'quatro', 'cinco', 'seis', 'sete', 'oito', + 'nove', 'dez', 'onze', 'doze', 'treze', 'quatorze', 'quinze', + 'dezasseis', 'dezassete', 'dezoito', 'dezanove' +] +_INTEGER_MID = [ + '', '', 'vinte', 'trinta', 'quarenta', 'cinquenta', 'sessenta', 'setenta', 'oitenta', + 'noventa' +] +_INTEGER_HIGH = [ + (int(1e12), 'bilião'), (int(1e9), 'milhar de milhão'), (int(1e6), 'milhão'), + (int(1e3), 'milhar'), (100, 'centena') +] + + +# For converting rationals to words: +_SINGULAR_DENOMINATORS = [ + '', '', 'metade', 'terço', 'quarto', 'quinto', 'sexto', 'sétimo', 'oitavo', + 'nono', 'dez avos', 'onze avos', 'onze avos', 'treze avos', 'quatorze avos', + 'quinze avos', 'dezasseis avos', 'dezassete avos', 'dezoito avos', 'dezanove avos', + 'vinte avos' +] +_PLURAL_DENOMINATORS = [ + '', '', 'metades', 'terços', 'quartos', 'quintos', 'sextos', 'sétimos', + 'oitavos', 'nonos', 'décimos', 'onze avos', 'doze avos', 'treze avos', + 'quatorze avos', 'quinze avos', 'dezasseis avos', 'dezassete avos', 'dezoito avos', + 'dezanove avos', 'vinte avos' +] + + +# For converting ordinals to words: +_ORDINALS = [ + 'zerésima', 'primeira', 'segunda', 'terceira', 'quarta', 'quinta', 'sexta', 'sétima', + 'oitava', 'nona', 'décima', 'décima primeira', 'décima segunda', 'décima terceira', + 'décima quarta', 'décima quinta', 'décima sexta', 'décima sétima', 'décima oitava', + 'décima nona', 'vigésima' +] + + +class Decimal(object): + """Display a value as a decimal.""" + + def __init__(self, value): + """Initializes a `Decimal`. + + Args: + value: (Sympy) value to display as a decimal. + + Raises: + ValueError: If `value` cannot be represented as a non-terminating decimal. + """ + self._value = sympy.Rational(value) + + numer = int(sympy.numer(self._value)) + denom = int(sympy.denom(self._value)) + + denom_factors = list(sympy.factorint(denom).keys()) + for factor in denom_factors: + if factor not in [2, 5]: + raise ValueError('Cannot represent {} as a non-recurring decimal.' + .format(value)) + self._decimal = decimal.Decimal(numer) / decimal.Decimal(denom) + + @property + def value(self): + """Returns the value as a `sympy.Rational` object.""" + return self._value + + def _sympy_(self): + return self._value + + def decimal_places(self): + """Returns the number of decimal places, e.g., 32 has 0 and 1.43 has 2.""" + if isinstance(self._decimal, int): + return 0 + elif isinstance(self._decimal, decimal.Decimal): + return -self._decimal.as_tuple().exponent + + def __str__(self): + sign, digits, exponent = self._decimal.as_tuple() + sign = '' if sign == 0 else '-' + + num_left_digits = len(digits) + exponent # number digits "before" point + + if num_left_digits > 0: + int_part = ''.join(str(digit) for digit in digits[:num_left_digits]) + else: + int_part = '0' + + if exponent < 0: + frac_part = '.' + if num_left_digits < 0: + frac_part += '0' * -num_left_digits + frac_part += ''.join(str(digit) for digit in digits[exponent:]) + else: + frac_part = '' + + return sign + int_part + frac_part + + def __add__(self, other): + if not isinstance(other, Decimal): + raise ValueError('Arithmetic support limited to other `Decimal`s.') + return Decimal(self.value + other.value) + + def __sub__(self, other): + if not isinstance(other, Decimal): + raise ValueError('Arithmetic support limited to other `Decimal`s.') + return Decimal(self.value - other.value) + + def __mul__(self, other): + if not isinstance(other, Decimal): + raise ValueError('Arithmetic support limited to other `Decimal`s.') + return Decimal(self.value * other.value) + + def __neg__(self): + return Decimal(-self.value) + + def round(self, ndigits=0): + """Returns a new `Decimal` rounded to this many decimal places.""" + scale = sympy.Integer(10 ** ndigits) + numer = sympy.numer(self.value) * scale + denom = sympy.denom(self.value) + return Decimal(int(round(numer / denom)) / scale) + + def __round__(self, ndigits): + return self.round(ndigits) + + def __int__(self): + """Returns conversion to integer if possible; TypeError if non-integer.""" + if self.decimal_places() == 0: + return int(self._decimal) + else: + raise TypeError('Cannot represent {} as an integer.'.format(str(self))) + + # NOTE: this is implemented in addition to `__cmp__` because SymPy does not + # support inequality comparison between sympy objects and objects that are not + # convertible to sympy objects (such as strings). + def __eq__(self, other): + return self.value == other + + # Python 2 comparison + def __cmp__(self, other): + if self.value == other: + return 0 + if self.value < other: + return -1 + return 1 + + # Python 3 comparison: + def __lt__(self, other): + return self.value < other + + def __le__(self, other): + return self.value <= other + + def __gt__(self, other): + return self.value > other + + def __ge__(self, other): + return self.value >= other + + +class Percentage(object): + """Container for a percentage.""" + + def __init__(self, value): + """Initializes a `Percentage`. + + Args: + value: Percentage as a fractional value. E.g., pass in + `sympy.Rational(2, 5)` to create the percentage "40%". + """ + self._value = value + + def _sympy_(self): + return self._value + + def __str__(self): + # Display percentages as decimals (not fractions). + value = Decimal(self._value * 100) + return str(value) + '%' + + +class NonSimpleRational(object): + """Container for rational a / b where allow gcd(a, b) > 1.""" + + def __init__(self, numer, denom): + self._numer = numer + self._denom = denom + + @property + def numer(self): + return self._numer + + @property + def denom(self): + return self._denom + + def __str__(self): + return '{}/{}'.format(self._numer, self._denom) + + +class StringNumber(object): + """A string representing a number, that can also be sympified.""" + + def __init__(self, value, join_number_words_with_hyphens=True): + """Initializes a `StringNumber`. + + Args: + value: An integer or rational. + join_number_words_with_hyphens: Whether to join the words in integers with + hyphens when describing as a string. + """ + self._join_number_words_with_hyphens = join_number_words_with_hyphens + self._sympy_value = sympy.sympify(value) + self._string = self._to_string(value) + + def _integer_to_words(self, integer): + """Converts an integer to a list of words.""" + if integer < 0: + raise ValueError('Cannot handle negative numbers.') + + if integer < 20: + return [_INTEGER_LOW[integer]] + + words = None + + if integer < 100: + tens, ones = divmod(integer, 10) + if ones > 0: + return [_INTEGER_MID[tens], _INTEGER_LOW[ones]] + else: + return [_INTEGER_MID[tens]] + + for value, word in _INTEGER_HIGH: + if integer >= value: + den, rem = divmod(integer, value) + words = self._integer_to_words(den) + [word] + if rem > 0: + if rem < 100: + words.append('and') + words += self._integer_to_words(rem) + return words + + def _rational_to_string(self, rational): + """Converts a rational to words, e.g., "two thirds".""" + numer = sympy.numer(rational) + denom = sympy.denom(rational) + + numer_words = self._to_string(numer) + + if denom == 1: + return numer_words + + if denom <= 0 or denom >= len(_PLURAL_DENOMINATORS): + raise ValueError('Unsupported denominator {}.'.format(denom)) + + if numer == 1: + denom_word = _SINGULAR_DENOMINATORS[denom] + else: + denom_word = _PLURAL_DENOMINATORS[denom] + + return '{} {}'.format(numer_words, denom_word) + + def _to_string(self, number): + """Converts an integer or rational to words.""" + if isinstance(number, sympy.Integer) or isinstance(number, int): + words = self._integer_to_words(number) + join_char = '-' if self._join_number_words_with_hyphens else ' ' + return join_char.join(words) + elif isinstance(number, sympy.Rational): + return self._rational_to_string(number) + else: + raise ValueError('Unable to handle number {} with type {}.' + .format(number, type(number))) + + def _sympy_(self): + return self._sympy_value + + def __str__(self): + return self._string + + +class StringOrdinal(object): + """A string representation of an ordinal, e.g., "first".""" + + def __init__(self, position): + """Initializes a `StringOrdinal`. + + Args: + position: An integer >= 0. + + Raises: + ValueError: If `position` is non-positive or out of range. + """ + if position < 0 or position >= len(_ORDINALS): + raise ValueError('Unsupported ordinal {}.'.format(position)) + self._string = _ORDINALS[position] + + def __str__(self): + return self._string + + +class NumberList(object): + """Contains a list of numbers, intended for display.""" + + def __init__(self, numbers): + self._numbers = numbers + + def __str__(self): + """Converts the list to a string. + + Returns: + Human readable string. + + Raises: + ValueError: if any of the strings contain a comma and thus would lead to + an ambigious representation. + """ + strings = [] + for number in self._numbers: + string = str(number) + if ',' in string: + raise ValueError('String representation of the list will be ambigious, ' + 'since term "{}" contains a comma.'.format(string)) + strings.append(string) + return ', '.join(strings) + + +class NumberInBase(object): + """Contains value, represented in a given base.""" + + def __init__(self, value, base): + """Initializes a `NumberInBase`. + + Args: + value: Positive or negative integer. + base: Integer in the range [2, 36]. + + Raises: + ValueError: If base is not in the range [2, 36] (since this is the limit + that can be represented by 10 numbers plus 26 letters). + """ + if not 2 <= base <= 36: + raise ValueError('base={} must be in the range [2, 36]'.format(base)) + self._value = value + self._base = base + + chars = [] + remainder = abs(value) + while True: + digit = remainder % base + char = str(digit) if digit <= 9 else chr(ord('a') + digit - 10) + chars.append(char) + remainder = int(remainder / base) + if remainder == 0: + break + if value < 0: + chars.append('-') + + self._str = ''.join(reversed(chars)) + + def __str__(self): + return self._str + + def _sympy_(self): + return self._value diff --git a/mathematics_dataset/mathematics_dataset/util/display_test.py b/mathematics_dataset/mathematics_dataset/util/display_test.py new file mode 100644 index 0000000000000000000000000000000000000000..6520655588a61631db6777c40b97a6d0b5d4c44b --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/util/display_test.py @@ -0,0 +1,207 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Tests for mathematics_dataset.util.display.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +# Dependency imports +from absl.testing import absltest +from util import display +import sympy + + +class DecimalTest(absltest.TestCase): + + def testBasic_integer(self): + decimal = display.Decimal(123) + self.assertEqual(str(decimal), '123') + self.assertEqual(sympy.sympify(decimal), sympy.Integer(123)) + self.assertEqual(decimal.decimal_places(), 0) + + def testBasic_ten(self): + decimal = display.Decimal(10) + self.assertEqual(str(decimal), '10') + self.assertEqual(sympy.sympify(decimal), sympy.Integer(10)) + self.assertEqual(decimal.decimal_places(), 0) + + def testBasic(self): + decimal = display.Decimal(sympy.Rational(123, 100)) + self.assertEqual(str(decimal), '1.23') + self.assertEqual(sympy.sympify(decimal), sympy.Rational(123, 100)) + self.assertEqual(decimal.decimal_places(), 2) + + def testStr(self): + self.assertEqual(str(display.Decimal(sympy.Rational(0, 10))), '0') + self.assertEqual(str(display.Decimal(sympy.Rational(-1, 10))), '-0.1') + self.assertEqual(str(display.Decimal(sympy.Rational(-11, 10))), '-1.1') + self.assertEqual(str(display.Decimal(sympy.Rational(11, 10))), '1.1') + self.assertEqual(str(display.Decimal(sympy.Rational(101, 1))), '101') + self.assertEqual( + str(display.Decimal(sympy.Rational(20171, 1000000))), '0.020171') + + def testStr_verySmall(self): + # Tests it doesn't display in "scientific" notation 1E-9. + decimal = display.Decimal(sympy.Rational(1, 1000000000)) + self.assertEqual(str(decimal), '0.000000001') + + def testAdd(self): + self.assertEqual((display.Decimal(2) + display.Decimal(3)).value, 5) + + def testSub(self): + self.assertEqual((display.Decimal(2) - display.Decimal(3)).value, -1) + + def testMul(self): + self.assertEqual((display.Decimal(2) * display.Decimal(3)).value, 6) + + def testRound(self): + decimal = display.Decimal(sympy.Rational(2675, 1000)) # 2.675 + self.assertEqual(sympy.sympify(decimal.round()), sympy.Integer(3)) + self.assertEqual(sympy.sympify(decimal.round(1)), sympy.Rational(27, 10)) + self.assertEqual(sympy.sympify(decimal.round(2)), sympy.Rational(268, 100)) + self.assertEqual(sympy.sympify(decimal.round(3)), + sympy.Rational(2675, 1000)) + + def testInt(self): + decimal = display.Decimal(123) + self.assertEqual(int(decimal), 123) + + def testInt_errorIfNonInt(self): + decimal = display.Decimal(sympy.Rational(1, 2)) + with self.assertRaisesRegex(self, TypeError, 'Cannot represent'): + int(decimal) + + def testComparison(self): + decimal = display.Decimal(sympy.Rational(-1, 2)) + # pylint: disable=g-generic-assert + self.assertFalse(decimal != -0.5) + self.assertTrue(decimal != 0) + self.assertFalse(decimal < -0.5) + self.assertTrue(decimal < 0) + self.assertTrue(decimal <= -0.5) + self.assertTrue(decimal <= 0) + self.assertFalse(decimal > -0.5) + self.assertTrue(decimal > -1) + self.assertTrue(decimal >= -0.5) + self.assertFalse(decimal >= 0) + self.assertFalse(decimal == 0) + self.assertTrue(decimal == -0.5) + + def testNegation(self): + decimal = display.Decimal(sympy.Rational(1, 2)) + decimal = -decimal + self.assertNotEqual(decimal, 0.5) + self.assertEqual(decimal, -0.5) + + +class PercentageTest(absltest.TestCase): + + def testPercentage(self): + percentage = display.Percentage(1.5) + self.assertEqual(str(percentage), '150%') + + percentage = display.Percentage(sympy.Rational(67, 100)) + self.assertEqual(str(percentage), '67%') + + percentage = display.Percentage(sympy.Rational(67, 1000)) + self.assertEqual(str(percentage), '6.7%') + + +class NonSimpleRationalTest(absltest.TestCase): + + def testBasic(self): + frac = display.NonSimpleRational(4, 6) + self.assertEqual(frac.numer, 4) + self.assertEqual(frac.denom, 6) + self.assertEqual(str(frac), '4/6') + + +class StringNumberTest(absltest.TestCase): + + def testIntegerToWords(self): + words = display.StringNumber(0) + self.assertEqual(str(words), 'zero') + self.assertEqual(sympy.sympify(words), 0) + + words = display.StringNumber(8) + self.assertEqual(str(words), 'eight') + self.assertEqual(sympy.sympify(words), 8) + + words = display.StringNumber(12) + self.assertEqual(str(words), 'twelve') + self.assertEqual(sympy.sympify(words), 12) + + words = display.StringNumber(30) + self.assertEqual(str(words), 'thirty') + self.assertEqual(sympy.sympify(words), 30) + + words = display.StringNumber(100) + self.assertEqual(str(words), 'one-hundred') + self.assertEqual(sympy.sympify(words), 100) + + words = display.StringNumber(103) + self.assertEqual(str(words), 'one-hundred-and-three') + self.assertEqual(sympy.sympify(words), 103) + + words = display.StringNumber(15439822) + self.assertEqual(str(words), 'fifteen-million-four-hundred-and-thirty-nine' + '-thousand-eight-hundred-and-twenty-two') + self.assertEqual(sympy.sympify(words), 15439822) + + def testRationalToWords(self): + words = display.StringNumber(sympy.Rational(2, 3)) + self.assertEqual(str(words), 'two thirds') + + +class StringOrdinalTest(absltest.TestCase): + + def testBasic(self): + ordinal = display.StringOrdinal(0) + self.assertEqual(str(ordinal), 'zeroth') + ordinal = display.StringOrdinal(10) + self.assertEqual(str(ordinal), 'tenth') + + def testCreate_errorIfNegative(self): + with self.assertRaisesRegex(self, ValueError, 'Unsupported ordinal'): + display.StringOrdinal(-1) + + +class NumberListTest(absltest.TestCase): + + def testBasic(self): + numbers = [2, 3, 1] + number_list = display.NumberList(numbers) + string = str(number_list) + self.assertEqual(string, '2, 3, 1') + + +class NumberInBaseTest(absltest.TestCase): + + def testBasic(self): + self.assertEqual(str(display.NumberInBase(1, 10)), '1') + self.assertEqual(str(display.NumberInBase(-1, 10)), '-1') + self.assertEqual(str(display.NumberInBase(1, 2)), '1') + self.assertEqual(str(display.NumberInBase(-1, 2)), '-1') + self.assertEqual(str(display.NumberInBase(2, 2)), '10') + self.assertEqual(str(display.NumberInBase(-2, 2)), '-10') + self.assertEqual(str(display.NumberInBase(10, 16)), 'a') + self.assertEqual(str(display.NumberInBase(16, 16)), '10') + self.assertEqual(str(display.NumberInBase(256, 16)), '100') + self.assertEqual(str(display.NumberInBase(-75483, 10)), '-75483') + + +if __name__ == '__main__': + absltest.main() diff --git a/mathematics_dataset/mathematics_dataset/util/probability.py b/mathematics_dataset/mathematics_dataset/util/probability.py new file mode 100644 index 0000000000000000000000000000000000000000..3016d0523306bebdd9671a104be8c6da51a61170 --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/util/probability.py @@ -0,0 +1,405 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Functionality for working with probability spaces and random variables. + +Basic recap of probability theory, and thus of classes in this file: + +* A probability space is a (finite or infinite) set Omega with a probability + measure defined on this. +* A random variable is a mapping from a probability space to another measure + space. +* An event is a measurable set in a sample space. + +For example, suppose a bag contains 3 balls: two red balls, and one white ball. +This could be represented by a discrete probability space of size 3 with +elements {1, 2, 3}, with equal measure assigned to all 3 elements; and a random +variable that maps 1->red, 2->red, and 3->white. Then the probability of drawing +a red ball is the measure in the probability space of the inverse under the +random variable mapping of {red}, i.e., of {1, 2}, which is 2/3. +""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import abc +import itertools + +# Dependency imports +import six +from six.moves import zip +import sympy + + +@six.add_metaclass(abc.ABCMeta) +class Event(object): + """Represents an event in a measure space.""" + + +@six.add_metaclass(abc.ABCMeta) +class ProbabilitySpace(object): + """Represents a probability space.""" + + @abc.abstractmethod + def probability(self, event): + """Returns the probability of an event.""" + + +@six.add_metaclass(abc.ABCMeta) +class RandomVariable(object): + """Random variable; a mapping from a probability space to a measure space.""" + + @abc.abstractmethod + def __call__(self, event): + """Maps an `_Event` in the probability space to one in the sample space.""" + + @abc.abstractmethod + def inverse(self, event): + """Maps event in the sample space back to the inverse in the prob. space.""" + + +class DiscreteEvent(Event): + """Set of discrete values.""" + + def __init__(self, values): + self._values = values + + @property + def values(self): + return self._values + + +class FiniteProductEvent(Event): + """Event consisting of cartesian product of events.""" + + def __init__(self, events): + """Initializes a `FiniteProductEvent`. + + Args: + events: Tuple of `Event`s; resulting event will be cartesian product of + these. + """ + self._events = events + + @property + def events(self): + return self._events + + def all_sequences(self): + """Returns iterator of sequences by selecting a single event in each coord. + + This assumes that every component event is an instance of `DiscreteEvent`. + + Returns: + Iterator over tuples of values. + + Raises: + ValueError: If one of the component events is not a `DiscreteEvent`. + """ + if not all(isinstance(event, DiscreteEvent) for event in self._events): + raise ValueError('Not all component events are DiscreteEvents') + values_list = [event.values for event in self._events] + return itertools.product(*values_list) + + +class CountLevelSetEvent(Event): + """Event of all sequences with fixed number of different values occurring.""" + + def __init__(self, counts): + """Initializes `CountLevelSetEvent`. + + E.g., to construct the event of getting two red balls and one green ball, + pass `counts = {red: 2, green: 1}`. (Then `all_sequences()` would return + `[(red, red, green), (red, green, red), (green, red, red)]`. + + Args: + counts: Dictionary mapping values to the number of times they occur in a + sequence. + """ + self._counts = counts + self._all_sequences = None + + @property + def counts(self): + return self._counts + + def all_sequences(self): + """Returns all sequences generated by this level set.""" + if self._all_sequences is None: + # Generate via dynamic programming. + cache = {} # dict mapping tuple -> list of tuples + labels = list(self._counts.keys()) + + def generate(counts): + """Returns list of tuples for given `counts` of labels.""" + if sum(counts) == 0: + return [()] + counts = tuple(counts) + if counts in cache: + return cache[counts] + generated = [] + for i, count in enumerate(counts): + if count == 0: + continue + counts_minus = list(counts) + counts_minus[i] -= 1 + counts_minus = tuple(counts_minus) + extensions = generate(counts_minus) + generated += [tuple([labels[i]] + list(extension)) + for extension in extensions] + cache[counts] = generated + return generated + + self._all_sequences = generate(list(self._counts.values())) + + return self._all_sequences + + +class SequenceEvent(Event): + """Collection of sequences.""" + + def __init__(self, sequences): + self._sequences = sequences + + def all_sequences(self): + return self._sequences + + +def normalize_weights(weights): + """Normalizes the weights (as sympy.Rational) in dictionary of weights.""" + weight_sum = sum(six.itervalues(weights)) + return { + i: sympy.Rational(weight, weight_sum) + for i, weight in six.iteritems(weights) + } + + +class DiscreteProbabilitySpace(ProbabilitySpace): + """Discrete probability space.""" + + def __init__(self, weights=None): + """Initializes an `DiscreteProbabilitySpace`. + + Args: + weights: Dictionary mapping values to relative probability of selecting + that value. This will be normalized. + """ + self._weights = normalize_weights(weights) + + def probability(self, event): + if isinstance(event, DiscreteEvent): + return sum(self._weights[value] + for value in event.values if value in self._weights) + else: + raise ValueError('Unhandled event type {}'.format(type(event))) + + @property + def weights(self): + """Returns dictionary of probability of each element.""" + return self._weights + + +class FiniteProductSpace(ProbabilitySpace): + """Finite cartesian product of probability spaces.""" + + def __init__(self, spaces): + """Initializes a `FiniteProductSpace`. + + Args: + spaces: List of `ProbabilitySpace`. + """ + self._spaces = spaces + + def all_spaces_equal(self): + return all([self._spaces[0] == space for space in self._spaces]) + + def probability(self, event): + # Specializations for optimization. + if isinstance(event, FiniteProductEvent): + assert len(self._spaces) == len(event.events) + return sympy.prod([ + space.probability(event_slice) + for space, event_slice in zip(self._spaces, event.events)]) + + if isinstance(event, CountLevelSetEvent) and self.all_spaces_equal(): + space = self._spaces[0] + counts = event.counts + probabilities = { + value: space.probability(DiscreteEvent({value})) + for value in six.iterkeys(counts) + } + + num_events = sum(six.itervalues(counts)) + assert num_events == len(self._spaces) + # Multinomial coefficient: + coeff = ( + sympy.factorial(num_events) / sympy.prod( + [sympy.factorial(i) for i in six.itervalues(counts)])) + return coeff * sympy.prod([ + pow(probabilities[value], counts[value]) + for value in six.iterkeys(counts) + ]) + + raise ValueError('Unhandled event type {}'.format(type(event))) + + @property + def spaces(self): + """Returns list of spaces.""" + return self._spaces + + +class SampleWithoutReplacementSpace(ProbabilitySpace): + """Probability space formed by sampling discrete space without replacement.""" + + def __init__(self, weights, n_samples): + """Initializes a `SampleWithoutReplacementSpace`. + + Args: + weights: Dictionary mapping values to relative probability of selecting + that value. This will be normalized. + n_samples: Number of samples to draw. + + Raises: + ValueError: If `n_samples > len(weights)`. + """ + if n_samples > len(weights): + raise ValueError('n_samples is more than number of discrete elements') + self._weights = normalize_weights(weights) + self._n_samples = n_samples + + @property + def n_samples(self): + """Number of samples to draw.""" + return self._n_samples + + def probability(self, event): + try: + all_sequences = event.all_sequences() + except AttributeError: + raise ValueError('Unhandled event type {}'.format(type(event))) + + probability_sum = 0 + for sequence in all_sequences: + if len(sequence) != len(set(sequence)): + continue # not all unique, so not "without replacement". + p_sequence = 1 + removed_prob = 0 + for i in sequence: + p = self._weights[i] if i in self._weights else 0 + if p == 0: + p_sequence = 0 + break + p_sequence *= p / (1 - removed_prob) + removed_prob += p + probability_sum += p_sequence + return probability_sum + + +class IdentityRandomVariable(RandomVariable): + """Identity map of a probability space.""" + + def __call__(self, event): + return event + + def inverse(self, event): + return event + + +class DiscreteRandomVariable(RandomVariable): + """Specialization to discrete random variable. + + This is simply a mapping from a discrete space to a discrete space (dictionary + lookup). + """ + + def __init__(self, mapping): + """Initializes `DiscreteRandomVariable` from `mapping` dict.""" + self._mapping = mapping + self._inverse = {} + for key, value in six.iteritems(mapping): + if value in self._inverse: + self._inverse[value].add(key) + else: + self._inverse[value] = set([key]) + + def __call__(self, event): + if isinstance(event, DiscreteEvent): + return DiscreteEvent({self._mapping[value] for value in event.values}) + else: + raise ValueError('Unhandled event type {}'.format(type(event))) + + def inverse(self, event): + if isinstance(event, DiscreteEvent): + set_ = set() + for value in event.values: + if value in self._inverse: + set_.update(self._inverse[value]) + return DiscreteEvent(set_) + else: + raise ValueError('Unhandled event type {}'.format(type(event))) + + +class FiniteProductRandomVariable(RandomVariable): + """Product random variable. + + This has the following semantics. Let this be X = (X_1, ..., X_n). Then + + X(w) = (X_1(w_1), ..., X_n(w_n)) + + (the sample space is assumed to be of sequence type). + """ + + def __init__(self, random_variables): + """Initializes a `FiniteProductRandomVariable`. + + Args: + random_variables: Tuple of `RandomVariable`. + """ + self._random_variables = random_variables + + def __call__(self, event): + if isinstance(event, FiniteProductEvent): + assert len(event.events) == len(self._random_variables) + zipped = list(zip(self._random_variables, event.events)) + return FiniteProductEvent( + [random_variable(sub_event) + for random_variable, sub_event in zipped]) + else: + raise ValueError('Unhandled event type {}'.format(type(event))) + + def inverse(self, event): + # Specialization for `FiniteProductEvent`; don't need to take all sequences. + if isinstance(event, FiniteProductEvent): + assert len(event.events) == len(self._random_variables) + zipped = list(zip(self._random_variables, event.events)) + return FiniteProductEvent(tuple( + random_variable.inverse(sub_event) + for random_variable, sub_event in zipped)) + + # Try fallback of mapping each sequence separately. + try: + all_sequences = event.all_sequences() + except AttributeError: + raise ValueError('Unhandled event type {}'.format(type(event))) + + mapped = set() + for sequence in all_sequences: + assert len(sequence) == len(self._random_variables) + zipped = list(zip(self._random_variables, sequence)) + mapped_sequence = FiniteProductEvent(tuple( + random_variable.inverse(DiscreteEvent({element})) + for random_variable, element in zipped)) + mapped.update(mapped_sequence.all_sequences()) + return SequenceEvent(mapped) diff --git a/mathematics_dataset/mathematics_dataset/util/probability_test.py b/mathematics_dataset/mathematics_dataset/util/probability_test.py new file mode 100644 index 0000000000000000000000000000000000000000..f474f05ee233631a05b60fbd062b25e33a0b698e --- /dev/null +++ b/mathematics_dataset/mathematics_dataset/util/probability_test.py @@ -0,0 +1,173 @@ +# Copyright 2018 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Tests for mathematics_dataset.util.probability.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +# Dependency imports +from absl.testing import absltest +from util import probability +import sympy + + +class FiniteProductEventTest(absltest.TestCase): + + def testAllSequences(self): + event = probability.FiniteProductEvent([probability.DiscreteEvent({1, 2}), + probability.DiscreteEvent({3})]) + all_sequences = [i for i in event.all_sequences()] + self.assertEqual(all_sequences, [(1, 3), (2, 3)]) + + +class CountLevelSetEventTest(absltest.TestCase): + + def testAllSequences(self): + event = probability.CountLevelSetEvent({'a': 2, 'b': 4, 'c': 1}) + all_sequences = event.all_sequences() + + # Number of sequences should be 7! / (4! * 2! * 1!) = 105. + self.assertLen(all_sequences, 105) + # They should all be unique. + self.assertEqual(len(all_sequences), len(set(all_sequences))) + # And check contains one correctly generated tuple. + self.assertIn(('a', 'b', 'c', 'b', 'b', 'a', 'b'), all_sequences) + + +class DiscreteProbabilitySpaceTest(absltest.TestCase): + + def testBasic(self): + space = probability.DiscreteProbabilitySpace({0: 1, 1: 2, 2: 3}) + p = space.probability(probability.DiscreteEvent([0])) + self.assertEqual(p, sympy.Rational(1, 6)) + p = space.probability(probability.DiscreteEvent([0, 1])) + self.assertEqual(p, sympy.Rational(1, 2)) + p = space.probability(probability.DiscreteEvent([0, 1, 2])) + self.assertEqual(p, 1) + p = space.probability(probability.DiscreteEvent([0, 1, 2, 3])) + self.assertEqual(p, 1) + p = space.probability(probability.DiscreteEvent([3])) + self.assertEqual(p, 0) + + +class FiniteProductSpaceTest(absltest.TestCase): + + def testProbability_FiniteProductEvent(self): + # 5 coin flips of a biased coin with heads prob = 1/3. + base_space = probability.DiscreteProbabilitySpace({'h': 1, 't': 2}) + space = probability.FiniteProductSpace([base_space] * 5) + + heads = probability.DiscreteEvent({'h'}) + tails = probability.DiscreteEvent({'t'}) + event = probability.FiniteProductEvent([heads, heads, tails, tails, heads]) + self.assertEqual(space.probability(event), sympy.Rational(4, 3**5)) + + def testProbability_CountLevelSetEvent(self): + base_space = probability.DiscreteProbabilitySpace({'a': 2, 'b': 3, 'c': 5}) + space = probability.FiniteProductSpace([base_space] * 12) + event = probability.CountLevelSetEvent({'a': 7, 'b': 2, 'c': 3}) + + # Probability should be (12 choose 7 2 3) * p(a)^7 p(b)^2 p(c)^3 + coeff = 7920 + p_a = sympy.Rational(1, 5) + p_b = sympy.Rational(3, 10) + p_c = sympy.Rational(1, 2) + self.assertEqual(space.probability(event), + coeff * pow(p_a, 7) * pow(p_b, 2) * pow(p_c, 3)) + + +class SampleWithoutReplacementSpaceTest(absltest.TestCase): + + def testBasic(self): + space = probability.SampleWithoutReplacementSpace({0: 1, 1: 1}, 2) + event_0_0 = probability.FiniteProductEvent( + [probability.DiscreteEvent({0}), probability.DiscreteEvent({0})]) + event_0_1 = probability.FiniteProductEvent( + [probability.DiscreteEvent({0}), probability.DiscreteEvent({1})]) + p_0_0 = space.probability(event_0_0) + p_0_1 = space.probability(event_0_1) + self.assertEqual(p_0_0, 0) + self.assertEqual(p_0_1, sympy.Rational(1, 2)) + + space = probability.SampleWithoutReplacementSpace({0: 1, 1: 0}, 1) + event_0 = probability.FiniteProductEvent([probability.DiscreteEvent({0})]) + event_1 = probability.FiniteProductEvent([probability.DiscreteEvent({1})]) + event_2 = probability.FiniteProductEvent([probability.DiscreteEvent({2})]) + p_0 = space.probability(event_0) + p_1 = space.probability(event_1) + p_2 = space.probability(event_2) + self.assertEqual(p_0, 1) + self.assertEqual(p_1, 0) + self.assertEqual(p_2, 0) + + +class DiscreteRandomVariableTest(absltest.TestCase): + + def testCall(self): + random_variable = probability.DiscreteRandomVariable({1: 1, 2: 3, 3: 4}) + forwards = random_variable(probability.DiscreteEvent({1, 3})) + self.assertEqual(forwards.values, {1, 4}) + + def testInverse(self): + random_variable = probability.DiscreteRandomVariable({1: 1, 2: 3, 3: 4}) + inverse = random_variable.inverse(probability.DiscreteEvent({1, 3})) + self.assertEqual(inverse.values, {1, 2}) + + random_variable = probability.DiscreteRandomVariable({1: 1, 2: 1}) + inverse = random_variable.inverse(probability.DiscreteEvent({1, 5})) + self.assertEqual(inverse.values, {1, 2}) + + +class FiniteProductRandomVariableTest(absltest.TestCase): + + def _random_variable(self): + rv1 = probability.DiscreteRandomVariable({1: 'a', 2: 'b', 3: 'c'}) + rv2 = probability.DiscreteRandomVariable({1: 'x', 2: 'y', 3: 'x'}) + return probability.FiniteProductRandomVariable((rv1, rv2)) + + def testCall_FiniteProductEvent(self): + rv = self._random_variable() + event1 = probability.DiscreteEvent({1, 2}) + event2 = probability.DiscreteEvent({1, 3}) + event = probability.FiniteProductEvent((event1, event2)) + result = rv(event) + self.assertIsInstance(result, probability.FiniteProductEvent) + self.assertLen(result.events, 2) + self.assertEqual(result.events[0].values, {'a', 'b'}) + self.assertEqual(result.events[1].values, {'x'}) + + def testInverse_FiniteProductEvent(self): + rv = self._random_variable() + event1 = probability.DiscreteEvent({'a', 'b'}) + event2 = probability.DiscreteEvent({'x'}) + event = probability.FiniteProductEvent((event1, event2)) + result = rv.inverse(event) + self.assertIsInstance(result, probability.FiniteProductEvent) + self.assertLen(result.events, 2) + self.assertEqual(result.events[0].values, {1, 2}) + self.assertEqual(result.events[1].values, {1, 3}) + + def testInverse_CountLevelSetEvent(self): + rv = self._random_variable() + event = probability.CountLevelSetEvent({'a': 1, 'x': 1}) + result = rv.inverse(event) + sequences = result.all_sequences() + self.assertLen(sequences, 2) + self.assertEqual(set(sequences), {(1, 1), (1, 3)}) + + +if __name__ == '__main__': + absltest.main() diff --git a/mathematics_dataset/setup.py b/mathematics_dataset/setup.py new file mode 100644 index 0000000000000000000000000000000000000000..150dd3f3599ea68a56767f1c669585a765e5d914 --- /dev/null +++ b/mathematics_dataset/setup.py @@ -0,0 +1,66 @@ +# Copyright 2019 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Module setuptools script.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +from setuptools import find_packages +from setuptools import setup + +description = """A synthetic dataset of school-level mathematics questions. + +This dataset code generates mathematical question and answer pairs, from a range +of question types (such as in arithmetic, algebra, probability, etc), at roughly +school-level difficulty. This is designed to test the mathematical learning and +reasoning skills of learning models. + +Original paper: Analysing Mathematical Reasoning Abilities of Neural Models +(Saxton, Grefenstette, Hill, Kohli) (https://openreview.net/pdf?id=H1gR5iR5FX). +""" + +setup( + name='mathematics_dataset', + version='1.0.1', + description='A synthetic dataset of school-level mathematics questions', + long_description=description, + author='DeepMind', + author_email='saxton@google.com', + license='Apache License, Version 2.0', + keywords='mathematics dataset', + url='https://github.com/deepmind/mathematics_dataset', + packages=find_packages(), + install_requires=[ + 'absl-py>=0.1.0', + 'numpy>=1.10', + 'six', + 'sympy>=1.2', + ], + classifiers=[ + 'Development Status :: 4 - Beta', + 'Environment :: Console', + 'Intended Audience :: Developers', + 'Intended Audience :: Science/Research', + 'License :: OSI Approved :: Apache Software License', + 'Operating System :: POSIX :: Linux', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Topic :: Scientific/Engineering :: Artificial Intelligence', + ], +)