Package Exports
- math-practice
- math-practice/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (math-practice) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
数学练习解析
提供数学算术问题解析服务,对输入的数学问题提供不同的答题提示。
解题方法类型
- 口算 oral:直接提供算术结果
- 脱式计算 working:展示算术计算的逐步算术过程
- 竖式计算 vertical: 使用竖式计算展现计算过程
技术标准
- 使用TS开发,类型定义清晰
- 模块化、模块关系清晰
模块结构
- working/src/types.ts:核心类型定义(Step、CalculationResult、StrategyModule 等)
- working/src/parser.ts:表达式标准化与词法解析工具
- working/src/addition.ts|subtraction.ts|multiplication.ts|division.ts:整数四则运算策略实现
- working/src/decimal.ts|fraction.ts:小数与分数专用策略
- working/src/mixed.ts:混合运算(先乘除后加减)流程
- working/src/engine.ts:策略编排与统一对外接口
- working/src/index.ts:导出入口
核心算法
- 策略优先级:分数 → 小数 → 除法 → 乘法 → 加法 → 减法 → 混合运算
- 加法策略涵盖颠倒数求和、基准数加法、拆补凑整、分组凑整、连续自然数求和等
- 减法策略包含退位检测、分段减法与减整补差法
- 乘法策略支持平移乘法、凑整配对、近百数乘法、乘以 11 等速算技巧
- 除法策略覆盖除数拆分、拆整相除,以及除以 5/25/125 的换算
- 分数策略保持分数形式输出,并在每步过程中化简
- 混合策略根据“先乘除后加减”生成中间步骤
使用方式
- 安装依赖并构建
pnpm install pnpm build
- 在代码中引入并使用默认计算引擎
import { defaultEngine } from './working/src'; const result = defaultEngine.generate('36 + 63'); console.log(result.steps);
测试
- 在 packages/math-practice/test 目录下编写 Jest 测试用例
- 运行
pnpm test执行全部测试