Skip to content

Normal cdf + copy args in smooth canonicalizer#178

Merged
dance858 merged 7 commits intomasterfrom
normal_cdf
Mar 17, 2026
Merged

Normal cdf + copy args in smooth canonicalizer#178
dance858 merged 7 commits intomasterfrom
normal_cdf

Conversation

@dance858
Copy link
Collaborator

@dance858 dance858 commented Mar 15, 2026

This PR adds the normal cdf as an atom. It also fixes a subtle error that was raised when we called a smooth full domain atom on a division, like exp(1/x).

@dance858
Copy link
Collaborator Author

@PTNobel

Parth, what do you think about the name "normal_cdf"?

@PTNobel
Copy link
Member

PTNobel commented Mar 16, 2026

MATLAB uses normcdf and SciPy uses norm.cdf and torch uses normal.cdf and JAX uses norm.cdf

Fortran used cdf_normal, R uses ??? pnorm ???

My soft preference is to call it normcdf to match log_normcdf, but as long as we don't use what R does I'm happy.

https://www.mathworks.com/help/stats/normcdf.html
https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.norm.html
https://r02pro.github.io/normal-distribution.html

@dance858
Copy link
Collaborator Author

MATLAB uses normcdf and SciPy uses norm.cdf and torch uses normal.cdf and JAX uses norm.cdf

Fortran used cdf_normal, R uses ??? pnorm ???

My soft preference is to call it normcdf to match log_normcdf, but as long as we don't use what R does I'm happy.

https://www.mathworks.com/help/stats/normcdf.html https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.norm.html https://r02pro.github.io/normal-distribution.html

Haha great! I'll call it normcdf then.

@github-actions
Copy link

Benchmarks that have stayed the same:

   before           after         ratio
 [e6df2dda]       [805a30b0]
     15.2±0ms         16.6±0ms     1.09  simple_QP_benchmarks.ParametrizedQPBenchmark.time_compile_problem
      1.57±0s          1.70±0s     1.08  tv_inpainting.TvInpainting.time_compile_problem
      727±0ms          754±0ms     1.04  simple_QP_benchmarks.LeastSquares.time_compile_problem
      133±0ms          137±0ms     1.03  high_dim_convex_plasticity.ConvexPlasticity.time_compile_problem
      226±0ms          232±0ms     1.03  gini_portfolio.Murray.time_compile_problem
      278±0ms          284±0ms     1.02  slow_pruning_1668_benchmark.SlowPruningBenchmark.time_compile_problem
      4.48±0s          4.58±0s     1.02  svm_l1_regularization.SVMWithL1Regularization.time_compile_problem
      10.1±0s          10.3±0s     1.02  simple_LP_benchmarks.SimpleLPBenchmark.time_compile_problem
      1.05±0s          1.07±0s     1.02  gini_portfolio.Cajas.time_compile_problem
      1.77±0s          1.79±0s     1.01  simple_QP_benchmarks.UnconstrainedQP.time_compile_problem
      875±0ms          885±0ms     1.01  simple_LP_benchmarks.SimpleScalarParametrizedLPBenchmark.time_compile_problem
      713±0ms          716±0ms     1.00  matrix_stuffing.ConeMatrixStuffingBench.time_compile_problem
      285±0ms          286±0ms     1.00  matrix_stuffing.ParamSmallMatrixStuffing.time_compile_problem
      315±0ms          317±0ms     1.00  gini_portfolio.Yitzhaki.time_compile_problem
     42.0±0ms         42.1±0ms     1.00  matrix_stuffing.SmallMatrixStuffing.time_compile_problem
      238±0ms          237±0ms     1.00  simple_QP_benchmarks.SimpleQPBenchmark.time_compile_problem
      2.98±0s          2.98±0s     1.00  quantum_hilbert_matrix.QuantumHilbertMatrix.time_compile_problem
     14.6±0ms         14.5±0ms     1.00  simple_LP_benchmarks.SimpleFullyParametrizedLPBenchmark.time_compile_problem
      20.8±0s          20.6±0s     0.99  sdp_segfault_1132_benchmark.SDPSegfault1132Benchmark.time_compile_problem
      5.16±0s          5.10±0s     0.99  optimal_advertising.OptimalAdvertising.time_compile_problem
      3.98±0s          3.93±0s     0.99  huber_regression.HuberRegression.time_compile_problem
      536±0ms          529±0ms     0.99  semidefinite_programming.SemidefiniteProgramming.time_compile_problem
      12.8±0s          12.4±0s     0.98  finance.CVaRBenchmark.time_compile_problem
      1.02±0s          990±0ms     0.97  finance.FactorCovarianceModel.time_compile_problem
      1.46±0s          1.41±0s     0.96  matrix_stuffing.ParamConeMatrixStuffing.time_compile_problem

def smooth_full_domain_canon(expr, args):
if isinstance(args[0], Variable):
return expr, []
return expr.copy([args[0]]), []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a comment about this in the PR title? After that I think its good to merge.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also we should ensure that all full domain atoms have only one argument (since it indexes with 0), but this should be fine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they always have one argument, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that was part of the contract of being a full domain function and the multiargs had different requirements

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we wanted to be safe we could just pass args directly tho!

@dance858 dance858 changed the title [Ready for review] Normal cdf Normal cdf + copy args in smooth canonicalized Mar 17, 2026
@dance858 dance858 changed the title Normal cdf + copy args in smooth canonicalized Normal cdf + copy args in smooth canonicalizer Mar 17, 2026
@dance858 dance858 merged commit 74006e5 into master Mar 17, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants