# Precision in Graph methods

It appears that GraphDistance, GraphDistanceMatrix, FindShortestPath, etc. all work with Machine Precision. I don't see an option for WorkingPrecision. Please tell me that's not the case!

The overview introduction to Graphs & Networks says

Graphs are first-class citizens in the Wolfram Language; they can be used as input and output and they are deeply integrated into the rest of the Wolfram Language.

Has arbitrary precision been omitted from this deep integration? Or have I just missed something?

Example: Inputs have explicit precision 80

m = GraphDistanceMatrix[
CompleteGraph[3, DirectedEdges -> True,
EdgeWeight -> {0.008416639999999999538493611339617928024381399154663085937580.,
0.000339746999999999998217509178388695545436348766088485717773437580.,
0.00596406599999999963851449180651798087637871503829956054687580.,
0.00011414700000000000334413746694295355155190918594598770141601562580.,
0.008647247999999999740206035880873969290405511856079101562580.,
0.003799601000000000106809894262482885096687823534011840820312580.},
EdgeLabels -> "EdgeWeight",
VertexLabels -> "Name"
]
]



Outputs look like machine precision numbers:

{{0., 0.00413935, 0.000339747},
{0.00596407, 0., 0.000114147},
{0.00864725, 0.0037996, 0.}}


GraphDistance only involves comparisons and additions. It seems to me that incorporating arbitrary precision would be a small step with great value.

• I am no expert in Mathematica's graph functionality but, if I had to guess, I'd say that this might be a limitation of whatever external library is used under the hood to implement this functionality. Commented Dec 17, 2021 at 3:55
• Some graph metrics can use exact numbers and arbitrary precision numbers, some cannot. As you yourself show, this is not the case for shortest paths. While it could be implemented, it does not seem to be (note that if it were, it would come with a performance impact; in order to retain the current performance, they'd possibly need to keep two separate implementations, a fast machine precision one and a slow exact one). Commented Dec 17, 2021 at 16:30
• I am just curious: what is the application for which you need shortest paths with higher than machine precision? Commented Dec 17, 2021 at 16:31
• Szabolcs, yes, I understand the tradeoff between speed and precision (and memory). That balance is managed so nicely in tools like NDSolve and Minimize. I'm trying to solve a Brownian drift control problem. Proving optimality of the solution requires high precision -- often WorkingPrecision greater than 100. To construct the functions proving optimality requires Column Generation: Maximize (an LP) yields dual variables that translate to edge weights for ShortestPath that identifies new columns to add to the optimization. NDSolve was brilliant in getting the solution. Now I need the proof. Commented Dec 18, 2021 at 14:20

This will do for my purposes. It employs the precision of the weights themselves. Basic, but fast enough.

graphDistanceMatrix[graph_]:=
Module[{distances},
With[{edges = EdgeList[graph],
vertices = VertexList[graph]},