计算机科学 ›› 2026, Vol. 53 ›› Issue (10): 384-395.doi: 10.11896/jsjkx.250700009

• 计算机软件 • 上一篇    下一篇

ExprRL:基于强化学习的浮点表达式精度优化方法

梁军达, 王磊, 张旭林, 牛梦锦, 郜振琦   

  1. 中原工学院网络空间安全学院 郑州 450007
  • 收稿日期:2025-07-01 修回日期:2025-12-13 发布日期:2026-10-13
  • 通讯作者: 王磊(wl1167@163.com)
  • 作者简介:(dadadaguai@foxmail.com)
  • 基金资助:
    基于高性能计算的基础数学库软件研发(22001742)

ExprRL:Method for Optimizing Floating-point Expression Accuracy Based on ReinforcementLearning

LIANG Junda, WANG Lei, ZHANG Xulin, NIU Mengjin, GAO Zhenqi   

  1. School of Cyberspace Security,Zhongyuan University of Technology,Zhengzhou 450007, China
  • Received:2025-07-01 Revised:2025-12-13 Online:2026-10-13
  • About author:LIANG Junda,born in 1999,postgra-duate,is a student member of CCF(No.R7609G).His main research interests include high performance computing and code security.
    WANG Lei,born in 1977,professor,is a member of CCF(No.12516M).His main research interests include research and development of high performance computingand domestic independent and controlable basic software.
  • Supported by:
    Research and Development of Basic Mathematical Library Software Based on High-Performance Computing(22001742).

摘要: 随着数值计算领域的快速发展,浮点程序的精度优化已成为提升计算可靠性的关键问题。传统方法如混合精度优化、近似正确舍入误差、误差检测与修复及表达式优化重写等,虽然取得了一定进展,但仍面临搜索空间庞大、优化效率低下、依赖专家经验等局限性。为了解决这些问题,提出了一种基于强化学习的浮点表达式自适应优化方法,并实现了表达式优化工具ExprRL,通过结合强化学习与动态精度优化经验库,实现了高效且自适应的精度优化。ExprRL采用Tree-LSTM模型计算表达式的符号、结构和语义特征嵌入向量,并通过余弦相似度检索匹配经验库中的优化策略,加速优化过程;若匹配失败,则启动强化学习模块,将表达式优化问题建模为马尔可夫决策过程,通过Q-learning算法探索最优重写动作序列,并动态更新至经验库中。实验选取FPBench标准数据集中的31个表达式作为测试集,结果表明经过ExprRL优化后,平均ulp误差降低41.42%,最大ulp误差降低46.92%,ExprRL性能优于传统精度优化工具Herbie和exprAuto。

关键词: 浮点运算, 精度优化, 强化学习, 经验库, 相似度匹配

Abstract: With the rapid development of numerical computing,precision optimization of floating-point programs has become a key issue in improving computational reliability.While traditional approaches,such as mixed-precision optimization,approximate rounding error correction,error detection and repair,and expression optimization rewriting,have achieved some progress,they still face limitations such as a large search space,low optimization efficiency,and reliance on expert experience.To address these issues,this paper proposes a reinforcement learning-based adaptive optimization method for floating-point expressions and implements an expression optimization tool,ExprRL.By combining reinforcement learning with a dynamic precision optimization experience library,ExprRL achieves efficient and adaptive precision optimization.ExprRL uses a Tree-LSTM model to compute embedding vectors of the symbolic,structural,and semantic features of expressions.It then uses cosine similarity to retrieve and match optimization strategies in the experience library to accelerate the optimization process.If a match fails,a reinforcement learning module is initiated,modeling the expression optimization problem as a Markov decision process.A Q-learning algorithm is used to explore the optimal rewriting action sequence and dynamically updates it to the experience library.Experiment selects 31 expressions from the FPBench standard dataset as the test set.Experimental results show that after ExprRL optimization,the average ulp error is reduced by 41.42%,and the maximum ulp error is reduced by 46.92%,which is better than traditional precision optimization tools Herbie and exprAuto.

Key words: Floating-point arithmetic, Precision optimization, Reinforcement learning, Experience repository, Similarity matching

中图分类号: 

  • TP311
[1] ZOU D,GU Y,SHI Y,et al.Oracle-free repair synthesis for floating-point programs[J].Proceedings of the ACM on Programming Languages,2022,6(OOPSLA2):957-985.
[2] FOUSSE L,HANROT G,LEFÈVRE V,et al.MPFR:A multiple-precision binary floating-point library with correct rounding[J].ACM Transactions on Mathematical Software,2007,33(2):1-15.
[3] ZURAS D,COWLISHAW M,AIKEN A,et al.IEEE Standard for Floating-Point Arithmetic[S].IEEE Std 754-2008.
[4] GOLDBER G,DAVI D.What every computer scientist shouldknow about floating-point arithmetic[J].ACM Computing Surveys,1991,23(1):5-48.
[5] ASHOK P,CHATTERJEE K,DACA P,et al.Value Iteration for Long-run Average Reward in Markov Decision Processes[C]//LNCS.Cham:Springer,2017:201-221.
[6] CHAPMAN D,KAELBLING L P.Input Generalization in Delayed Reinforcement Learning:An Algorithm and Performance Comparisons[C]//Proceedings of the 12th International Joint Conference on Artificial Intelligence-Volume 2.1991.
[7] JANG B,KIM M,HARERIMANA G,et al.Q-learning Algo-rithms:A Comprehensive Classification and Applications[J].IEEE Access,2019,7:133653-133667.
[8] YI J,JIALU F,TIANYOU C,et al.Data-Driven Flotation Industrial Process Operational OptimalControl Based on Reinforcement Learning[J].IEEE Transactions on Industrial Informatics,2018,14(5):1974-1989.
[9] KHAN G S,HERRMANN G,LEWIS L F,et al.Reinforcement learning and optimal adaptive control:An overview and implementation examples[J].Annual Reviews in Control,2012,36(1):42-59.
[10] MOERLAND T M,BROEKENS J,JONKER C M.Emotion in Reinforcement Learning Agents and Robots:A Survey[J].Machine Learning,2017,107(2):1-38.
[11] YU Z,CAO R,TANG Q,et al.Order Matters:Semantic-AwareNeural Networks for Binary Code Similarity Detection[C]//Association for the Advancement of Artificial Intelligence.2020:1145-1152.
[12] LI T,WANG J.Binary code similarity detection based on attention mechanism and Child-Sum Tree-LSTM[J].Cybersecurity and Data Governance,2023,42(11):8-14,34.
[13] ZHAO G,HUANG J.DeepSim:deep learning code functionalsimilarity[C]//Proceedings of the 2018 26th ACM Joint Meeting on European Software Engineering Conference and Symposium on the Foundations of Software Engineering.2018:141-151.
[14] CHOWDHARY S,NAGARAKATTE S.Fast shadow execution for debugging numerical errors using error free transformations[J].Proceedings of the ACM on Programming Languages.2022,6(OOPSLA2):1845-1872.
[15] YI X,CHEN L,MAO X,et al.Efficient automated repair of high floating-point errors in numerical libraries[J].Proceedings of the ACM on Programming Languages,2019,3(POPL):1-29.
[16] HOU M,GUO S Z,WANG P J,et al.Mixed precision optimization method based on sensitivity[J].Journal of Information Engineering University,2022,23(6):718-723.
[17] HAO J G,ZHOU B,XU J C,et al.Mixed precision optimization method using multi-precision basis functions[J].Journal of Information Engineering University,2024,25(6):703-709.
[18] ARZELIER D,BREHARD F,JOLDES M.Exchange Algorithm for Evaluation and Approximation Error-Optimized Polynomials[C]//2019 IEEE 26th Symposium on Computer Arithmetic,IEEE,2019.
[19] AANJANEYA M,LIM J P,NAGARAKATTE S.Progressive polynomial approximations for fast correctly rounded math libraries[C]//Proceedings of the 43rd ACM SIGPLAN International Conference on Programming Language Design and Implementation.2022:552-565.
[20] LIM J P,NAGARAKATTE S.High performance correctlyrounded math libraries for 32-bit floating point representations[C]//Proceedings of the 42nd ACM SIGPLAN International Conference on Programming Language Design and Implementation.2021:359-374.
[21] PANCHEKHA P,SANCHEZ-STERN A,WILCOX J R,et al.Automatically improving accuracy for floating point expressions[J].ACM Sigplan Notices,2015,50(6):1-11.
[22] WANG X,WANG H,SU Z,et al.Global optimization of numerical programs via prioritized stochastic algebraic transformations[C]//2019 IEEE/ACM 41st International Conference on Software Engineering(ICSE).IEEE,2019:1131-1141.
[23] DAMOUCHE N,MARTEL M.Salsa:An Automatic Tool toImprove the Numerical Accuracy of Programs[C]//AFM@ NFM.2017:63-76.
[24] WANG Y Z,WANG L,XU F J,et al.Floating point program precision defect repair method based on program rewriting[J].Journal of Computer Applications,2023,43(S1):177-181.
[25] HAO J W,YANG H R,XIA Y Y,et al.Floating-point expression precision optimization method based on multi-type calculation rewriting[J].Computer Science,2024,51(4):86-94.
[26] LI Z,DONG X X,HUANG C C,et al.Floating-point expression design space exploration method based on heuristic search[J].Computer Applications,2020,40(9):2665-2669.
[27] XIAO A X,ZHANG S X,TANG E Y,et al.An empirical library-guided floating-point programoptimization acceleration strategy [J].Chinese Journal of Computers,2022,45(9):2014-2028.
[28] XIAO Y,AHMED N K.A Graph-Based Learning Framework for Compiler Loop Auto-Vectorization[J].Intelligent Computing,2025,4:0113.
[29] LI J,ZHENG Q.Reinforcement Learning for Automated Pragma-Based Loop Optimization[C]//2025 IEEE 8th Information Technology and Mechatronics Engineering Conference(ITOEC).IEEE,2025:1643-1647.
[30] WEI A,SURESH T,TAN H,et al.Improving Assembly Code Performance with Large Language Models via Reinforcement Learning[J].arXiv:2505.11480,2025.
Viewed
Full text


Abstract

Cited

  Shared   
  Discussed   
No Suggested Reading articles found!