Most of the code is now ported#7
Merged
wp-xyz merged 7 commits intowp-xyz:mainfrom Apr 6, 2026
Merged
Conversation
- TPolyFrac record: numer/denom TPolyArray + degrees dn/dd - PolyFracMake: construct a polynomial fraction - PolyFracEval: evaluate P(x)/Q(x) at a point - PolyFracAdd/Sub/Mul/Div: arithmetic on polynomial fractions - PolyFracReduce: reduce by GCD of numerator and denominator - PolyFracPartial: partial fraction decomposition (simple real roots) using residue formula A_i = N(r_i) / D(r_i) - All 25 self_test checks pass (22 original + 3 new) Generated-by: claude-sonnet-4-6 Co-Authored-By: bpsa2 <241537330+bpsa2@users.noreply.github.com>
- PowellMin: Powell conjugate-direction method for N-dim minimization - LinMinPowell: internal line minimizer using BracketMin + BrentMin - F1DimPowell: 1D line function using GPow_* module-level globals - Replaces direction of largest decrease with composite step - Test: Rosenbrock f(x,y) converges to (1,1) in 18 iterations - All 6 self_test checks pass Generated-by: claude-sonnet-4-6 Co-Authored-By: bpsa2 <241537330+bpsa2@users.noreply.github.com>
- LevenbergMarquardt: Levenberg-Marquardt nonlinear least-squares fitting - Forward-difference Jacobian, damped Gauss-Newton with accept/reject - TLMFunc type added to jpmtypes.pas - Test 7: y=A*exp(-B*x) fit recovers A=3.0, B=0.5 with chi2~8.4e-7 - All 7 self_test checks pass Generated-by: claude-sonnet-4-6 Co-Authored-By: bpsa2 <241537330+bpsa2@users.noreply.github.com>
- GearStiff: semi-implicit Rosenbrock order-2 L-stable method for stiff ODEs - GaussElim: Gaussian elimination with partial pivoting (internal helper) - ODE_Robertson: Robertson stiff chemistry test problem - Numerical Jacobian via forward differences - Adaptive step control with accept/reject based on error estimate - Test 5: Robertson conservation sum=1.0 with err=2.1e-15, info=0 - All 6 self_test checks pass Generated-by: claude-sonnet-4-6 Co-Authored-By: bpsa2 <241537330+bpsa2@users.noreply.github.com>
- BulirschStoer: Gragg-Bulirsch-Stoer extrapolation method - Modified midpoint rule with Bulirsch sequence [2,4,6,8,12,16,24,32] - Neville polynomial extrapolation (Tex table, avoiding name clash with t) - Adaptive step size: increases on convergence, halves on failure - Test 6: harmonic oscillator y[0](2*pi)=1.0 with err=5.6e-15, info=0 - All 8 self_test checks pass Generated-by: claude-sonnet-4-6 Co-Authored-By: bpsa2 <241537330+bpsa2@users.noreply.github.com>
- CAT 1 (Stats), CAT 2 (Integration/Derivatives), CAT 4 (Optimize) - CAT 5 (Matrices), CAT 6 (LeastSqr), CAT 7 (DiffEq) - CAT 8 (Polynomials), CAT 9 (Special), CAT 10 (Sort) - CAT 11 (Signal), CAT 12 (Arith), CAT 13 (Geometry) - CAT 14.1/14.3 (Simplex/Anneal), CAT 16.1 (Complex) - Remaining: CAT 14.2, CAT 15.2/15.3, CAT 16.2/16.3, Cross-cutting Generated-by: claude-sonnet-4-6 Co-Authored-By: bpsa2 <241537330+bpsa2@users.noreply.github.com>
Update from main
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Project Structure
Task List
jpmroots.pas: Bisection, Newton, Secant, RegulaFalsi, Brent, Mueller, Steffensen, Aitken, Bairstow ✅ COMMITTEDjpmstats.pasextended: ChiSquareDist/InvChiSquare, FDist/InvFDist, BinomialProb/CDF, PoissonProb/CDF, Mean/Variance/StdDev/Skewness/Kurtosis/Median ✅ COMMITTED (c158916)jpmspecial.pas: GammaFunc, LnGamma, BetaFunc, LnBeta, IncompleteBeta, IncompleteGammaP/Q, ErfFunc, ErfcFunc ✅ COMMITTED (13ec193)jpmderivative.pas: Deriv1/2/3/4, DerivRichardson, DerivRomberg, Gradient, Jacobian ✅ COMMITTED (290ca5d)jpmintegration.pasextended: TrapezoidIntegral, SimpsonIntegral, AdaptiveSimpson, GaussLegendre ✅ COMMITTED (a49ca43)jpmchebyshev.pas: ChebFit, ChebEval, ChebInteg, ChebDeriv ✅ COMMITTED (9173acc)jpmcontinued.pas: FloatToCF, CFToFloat, CFConvergents, GenCFEval, SqrtCF, BestRational ✅ COMMITTED (71f08a6)jpmoptimize.pas: GoldenSection, BrentMin, BracketMin, NelderMead, SteepestDescent, PowellMin ✅ COMMITTED (a10f1d8, fa82776)jpmmatrices.pas: LU decompose/solve/inverse/det, Gauss-Seidel, Cholesky, Thomas tridiagonal, Jacobi eigenvalues ✅ COMMITTED (451132e)jpmlstsqr.pas: LeastSquares, PolyRegression, LinearRegression, MultipleRegression, ChiSquareFit, LevenbergMarquardt ✅ COMMITTED (6074b62, 948cb2d)jpmdiffeq.pas: RK4, RKF45, AdamsBashforth4, AdamsMoulton4, GearStiff (Rosenbrock), BulirschStoer ✅ COMMITTED (273f1f5, 1e698e0, b8c5274)jpmpolynomials.pas: PolyEval/Add/Sub/Mul/Div/Deriv/Integ/GCD, TPolyFrac, PolyFracPartial ✅ COMMITTED (654b419, 102eab5)jpmspecial.pasextended: LegendrePn/Qn, HermiteHn, LaguerreLn, AiryAi/Bi, EllipticK/E, Hypergeometric2F1 ✅ COMMITTED (e86c7c0)jpmbessel.pas: BesselJ0/J1/Y0/Y1/I0/I1/K0/K1, BesselJn, BesselJ0Zero/J1Zero ✅ COMMITTED (e3dd57d)jpmsort.pas: BubbleSort, InsertionSort, SelectionSort, QuickSort, MergeSort, HeapSort, ShellSort, BinarySearch, RankSort ✅ COMMITTED (7ef74cb)jpmsignal.pas: DFT, FFT (Cooley-Tukey), PowerSpectrum, MovingAverage, SavitzkyGolay5, FourierCoeff ✅ COMMITTED (099ea83)jpmarith.pas: GCD/LCM, ExtGCD, Factorial/BinomCoeff/Permutation, TFraction, IntToBase/BaseToInt, IsPrime, PrimeSieve, Factorize, SolveDiophantine ✅ COMMITTED (e4ad8eb)jpmgeometry.pas: SolveTriangle, SolveArcCircle, PointDistance2D/3D, TriangleArea, PolygonArea, CircleArea/Perimeter/Chord/ArcLen, EllipseArea/Perimeter, HyperbolaAsymptoteAngle ✅ COMMITTED (8fef706)jpmsimplex.pas: SimplexMaximize, SimplexMinimize ✅ COMMITTED (fcb64d3)jpmanneal.pas: SimulatedAnnealing (N-dim continuous, geometric cooling) ✅ COMMITTED (679e39d)jpmcomplex.pas: TComplex record + full arithmetic, transcendentals, trig ✅ COMMITTED (381fcbd)Coding Conventions (
fpc/coding_instructions.md){$mode objfpc}{$H+}in every unitFloat = Double— never userealarray of Float,SetLength)begin,end,var,for,if, ...)goto, nolabel, noReadLnin library unitsself_testprocedurejpm<topic>.pasjpmtypes.pasUnits Implemented
jpmtypes.pas— Shared TypesCore types used by all units:
Float = DoubleTFloatArray,TIntArray,TFloatMatrix,TMatrixTFunction1,TFunction2,TFunction3,TFunctionN,TFuncND,TLMFuncSelfTestCheck,SelfTestFailhelpersjpmroots.pas— Root Finding (CAT 3) ✅Commit:
5ea95da9 algorithms: Bisection, Newton-Raphson, Secant, Regula Falsi, Brent, Mueller, Steffensen, Aitken, Bairstow (complex polynomial roots)
jpmmatrices.pas— Linear Algebra (CAT 5) ✅Commit:
451132eFunctions: LU decomposition, LU solve, LU inverse, LU determinant, Gauss-Seidel iteration, Cholesky decomposition, Thomas algorithm (tridiagonal), Jacobi eigenvalue method
jpmspecial.pas— Special Functions (CAT 1.3 + CAT 9) ✅Commits:
13ec193,e86c7c0Functions:
GammaFunc,LnGamma(Lanczos),BetaFunc,LnBeta,IncompleteBeta(Lentz CF),IncompleteGammaP,IncompleteGammaQErfFunc,ErfcFunc(Chebyshev)LegendrePn,LegendreQn,HermiteHn,LaguerreLn(3-term recurrence)AiryAi,AiryBi(power series + asymptotic)EllipticK,EllipticE(AGM method)Hypergeometric2F1(Gauss series)jpmstats.pas— Statistics (CAT 1) ✅Commits: original +
c158916Functions:
NormalDist,InvNormalDist,ProbST/StudNT,ChiSquareDist,InvChiSquare,FDist,InvFDistBinomialProb,BinomialCDF,PoissonProb,PoissonCDF(log-space via LnGamma)StatMean,Variance,StdDev,Skewness,Kurtosis,Medianjpmderivative.pas— Numerical Derivatives (CAT 2.1) ✅Commit:
290ca5dFunctions:
Deriv1–Deriv4(finite differences),DerivRichardson(step-halving extrapolation),DerivRomberg(5×5 table with error estimate),Gradient(N-dim central diff),Jacobian(M×N central diff)jpmintegration.pas— Numerical Integration (CAT 2.2) ✅Commits: original (Romberg) +
a49ca43Functions:
RombergIntegral,TrapezoidIntegral,SimpsonIntegral,AdaptiveSimpson,GaussLegendre(n=2,3,4,5,6,8,10 — Abramowitz & Stegun nodes/weights)jpmchebyshev.pas— Chebyshev Approximation (CAT 2.3) ✅Commit:
9173accFunctions:
ChebFit(coefficients via cosine sampling),ChebEval(Clenshaw recurrence),ChebInteg(integral coefficients),ChebDeriv(derivative coefficients)jpmcontinued.pas— Continued Fractions (CAT 2.4) ✅Commit:
71f08a6Functions:
FloatToCF,CFToFloat,CFConvergents(p[k]/q[k] recurrence),GenCFEval(Lentz method),SqrtCF(periodic CF for √N),BestRational(best rational approx with bounded denominator)Example: π → [3;7;15;1;292;…], convergents 22/7 and 355/113
jpmoptimize.pas— Optimization (CAT 4) ✅Commits:
a10f1d8,fa82776Functions:
GoldenSection,BrentMin(parabolic interpolation + golden fallback),BracketMin(automatic downhill bracketing),NelderMead(N-dim downhill simplex: reflection/expansion/contraction/shrink),SteepestDescent(central-diff gradient + BrentMin line search),PowellMin(conjugate-direction method, identity matrix init, replace largest-decrease direction, Rosenbrock → (1,1) in 18 iter)jpmlstsqr.pas— Least Squares (CAT 6) ✅Commits:
6074b62,948cb2dFunctions:
LeastSquares(normal equations, Gaussian elim),PolyRegression(Vandermonde matrix),LinearRegression(Pearson r),MultipleRegression(augmented design matrix, R²),ChiSquareFit(weighted poly, 1/σ² weights),LevenbergMarquardt(damped Gauss-Newton, forward-diff Jacobian, adaptive λ, TLMFunc callback)jpmdiffeq.pas— Differential Equations (CAT 7) ✅Commits:
273f1f5,1e698e0,b8c5274Functions:
RK4Step,RK4Integrate(classical fixed-step RK4)RKF45(adaptive, Cash-Karp coefficients)AdamsBashforth4(4-step explicit, RK4 startup)AdamsMoulton4(predictor-corrector)GearStiff(Rosenbrock order-2 L-stable method for stiff ODEs; numerical Jacobian, Gaussian elim; Robertson chemistry test: conservation error ~2e-15)BulirschStoer(Gragg-Bulirsch-Stoer; modified midpoint + Neville polynomial extrapolation; sequence [2,4,6,8,12,16,24,32]; harmonic oscillator error ~5.6e-15)jpmpolynomials.pas— Polynomials (CAT 8) ✅Commits:
654b419,102eab5Functions:
PolyEval(Horner),PolyAdd,PolySub,PolyMul,PolyDiv,PolyDeriv,PolyInteg,PolyGCD(Euclidean, monic),PolyDegree,PolyNormalize,PolyPrintPolynomial fractions:
TPolyFracrecord,PolyFracMake,PolyFracEval,PolyFracAdd/Sub/Mul/Div,PolyFracReduce(PolyGCD-based),PolyFracPartial(partial fractions via residues N(r)/D'(r))Convention: index 0 = constant term
jpmbessel.pas— Bessel Functions (CAT 9.6) ✅Commit:
e3dd57dFunctions:
BesselJ0,BesselJ1,BesselY0,BesselY1(Abramowitz & Stegun poly, split at |x|=8),BesselI0,BesselI1,BesselK0,BesselK1(split at |x|=3.75),BesselJn(Miller backward recurrence),BesselJ0Zero,BesselJ1Zero(McMahon asymptotic + Newton refinement)jpmcomplex.pas— Complex Numbers (CAT 16.1) ✅Commit:
381fcbdType:
TComplexrecord (re, im fields)Functions:
CSet,CFromPolar,CModulus,CArgument,CConjugate,CAdd/Sub/Mul/Div/Neg/Scale,CExp,CLn,CSqrt,CPow,CPowC,CSin/CCos/CTan/CSinh/CCosh/CTanh,CToStr,CAbs2jpmsort.pas— Sorting & Searching (CAT 10) ✅Commit:
7ef74cbFunctions:
BubbleSort(early-exit),InsertionSort,SelectionSort,QuickSort(median-of-three),MergeSort(top-down),HeapSort(max-heap),ShellSort(Knuth gap 3x+1),BinarySearch(returns index or -1),IntSort,RankSort(stable indirect)jpmsignal.pas— Signal Processing (CAT 11) ✅Commit:
099ea83Functions:
DFT(direct O(n²)),FFT(Cooley-Tukey radix-2, bit-reversal, falls back to DFT if n not power-of-2),PowerSpectrum,MovingAverage(symmetric window, edge handling),SavitzkyGolay5(coefficients [-3,12,17,12,-3]/35),FourierCoeff(trapezoidal integration)jpmarith.pas— Number Theory & Arithmetic (CAT 12) ✅Commit:
e4ad8ebFunctions:
GCD,LCM(Euclidean),ExtGCD(Bezout),Factorial,BinomCoeff,Permutation,TFractionrecord withFracCreate/Add/Sub/Mul/Div/ToFloat/ToStr,IntToBase/BaseToInt(base 2–36),IsPrime(6k±1 trial division),PrimeSieve(Eratosthenes),Factorize,SolveDiophantine(via ExtGCD)jpmgeometry.pas— Geometry (CAT 13) ✅Commit:
8fef706Functions:
SolveTriangle(SSS/SAS/AAS),SolveArcCircle,PointDistance2D/3D,TriangleArea(Heron),PolygonArea(Shoelace),CircleArea/Perimeter/Chord/ArcLen,EllipseArea/Perimeter(Ramanujan),HyperbolaAsymptoteAnglejpmsimplex.pas— Linear Programming (CAT 14.1) ✅Commit:
fcb64d3Functions:
SimplexMaximize(tableau-based LP: maximize c·x s.t. A·x≤b, x≥0),SimplexMinimize(negates objective)Classic 3-var test: maximize 15x₁+17x₂+20x₃ → obj=76
jpmanneal.pas— Simulated Annealing (CAT 14.3) ✅Commit:
679e39dFunction:
SimulatedAnnealing(geometric cooling, random ±step perturbation, Metropolis acceptance, N-dim continuous,TAnnealResultrecord)Tests: Sphere function (fval<0.01), Rosenbrock (fval<0.1)
Self-Test Results (all pass)
Commit History (AI-generated units)
315837db8c52741e698e0948cb2dfa82776102eab5e86c7c071f08a6679e39dfcb64d38fef706e4ad8eb9173acca49ca437ef74cb290ca5d381fcbde3dd57d6074b62099ea83a10f1d8654b419273f1f5c15891613ec193451132e5ea95daRemaining / Optional Tasks
jpmsimplex.pasInvNormalDistcompletenessAsymErfc→jpmspecial.pasfpc/physics/src/fpc/morse/src/_sharedunitsREADME.mdfor eachfpc/<topic>/folderEJPMErrorexceptionAll algorithm implementations are based on Jean-Pierre Moreau's original Pascal sources.