function t_reduced = reducepoly_table(t, tol)
%REDUCEPOLY_TABLE performs reducepoly on a full table based on the first
%column.

arguments
    t table
    tol (1,1) double = sqrt(eps)
end

t_reduced = t(:,1);

for i = 2:width(t)
    mask = ~isnan(t{:,i});
    m = reducepoly(t{mask,[1,i]}, tol * 1/max(t{mask,1}));
    t_reduced = outerjoin(t_reduced, array2table(m, VariableNames=t.Properties.VariableNames([1,i])), MergeKeys=true);
end

t_reduced = rmmissing(t_reduced, MinNumMissing=width(t)-1);
end
