├── .gitignore ├── .travis.yml ├── README.md ├── examples ├── .gitignore ├── tutorial_fxsdd_var_order.ipynb └── wmi_generate_100 │ ├── example_0.query │ ├── example_0.support │ ├── example_0.weights │ ├── example_1.query │ ├── example_1.support │ ├── example_1.weights │ ├── example_2.query │ ├── example_2.support │ ├── example_2.weights │ ├── example_3.query │ ├── example_3.support │ ├── example_3.weights │ ├── example_4.query │ ├── example_4.support │ ├── example_4.weights │ ├── example_5.query │ ├── example_5.support │ ├── example_5.weights │ ├── example_6.query │ ├── example_6.support │ ├── example_6.weights │ ├── example_7.query │ ├── example_7.support │ ├── example_7.weights │ ├── example_8.query │ ├── example_8.support │ └── example_8.weights ├── pywmi ├── __init__.py ├── __main__.py ├── convert.py ├── domain.py ├── engine.py ├── engines │ ├── __init__.py │ ├── adaptive_rejection.py │ ├── algebraic_backend.py │ ├── convex_integrator.py │ ├── latte_backend.py │ ├── mpwmi.py │ ├── pa.py │ ├── praise.py │ ├── pyxadd │ │ ├── __init__.py │ │ ├── algebra.py │ │ ├── core.py │ │ ├── decision.py │ │ ├── engine.py │ │ ├── leaf_transform.py │ │ ├── operation.py │ │ ├── reduce.py │ │ ├── resolve.py │ │ ├── view.py │ │ └── walk.py │ ├── rejection.py │ ├── xadd.py │ └── xsdd │ │ ├── __init__.py │ │ ├── draw.py │ │ ├── engine.py │ │ ├── engine_factorized.py │ │ ├── literals.py │ │ ├── piecewise.py │ │ ├── sdd_iterator.py │ │ ├── semiring.py │ │ ├── smt_to_sdd.py │ │ └── vtrees │ │ ├── __init__.py │ │ ├── int_tree.py │ │ ├── primal.py │ │ └── vtree.py ├── errors.py ├── export.py ├── install.py ├── log │ ├── integrate_106_d_a.dot │ ├── integrate_106_d_a.dot.png │ ├── integrate_107_d_b.dot │ ├── integrate_107_d_b.dot.png │ ├── integrate_113_d_x.dot │ ├── integrate_113_d_x.dot.png │ ├── integrate_19_d_x.dot │ ├── integrate_19_d_x.dot.png │ ├── integrate_35_d_a.dot │ ├── integrate_35_d_a.dot.png │ ├── integrate_44_d_x.dot │ ├── integrate_44_d_x.dot.png │ ├── integrate_53_d_x.dot │ ├── integrate_53_d_x.dot.png │ ├── integrate_9_d_a.dot │ └── integrate_9_d_a.dot.png ├── multimap.py ├── normalize_weight.py ├── parse.py ├── parser │ ├── __init__.py │ ├── minizinc │ │ ├── __init__.py │ │ ├── antlr │ │ │ ├── __init__.py │ │ │ ├── minizinc.interp │ │ │ ├── minizinc.tokens │ │ │ ├── minizincLexer.interp │ │ │ ├── minizincLexer.py │ │ │ ├── minizincLexer.tokens │ │ │ ├── minizincListener.py │ │ │ ├── minizincParser.py │ │ │ └── minizincVisitor.py │ │ ├── createParser.sh │ │ ├── minizinc.g4 │ │ ├── minizincErrorListener.py │ │ ├── minizincParser.py │ │ └── visitor.py │ └── smtlib │ │ ├── __init__.py │ │ ├── antlr │ │ ├── SMTLIBv2Lexer.interp │ │ ├── SMTLIBv2Lexer.py │ │ ├── SMTLIBv2Lexer.tokens │ │ ├── __init__.py │ │ ├── smtlib.interp │ │ ├── smtlib.tokens │ │ ├── smtlibLexer.interp │ │ ├── smtlibLexer.py │ │ ├── smtlibLexer.tokens │ │ ├── smtlibListener.py │ │ ├── smtlibParser.py │ │ └── smtlibVisitor.py │ │ ├── createParser.sh │ │ ├── smtlib.g4 │ │ ├── smtlibErrorListener.py │ │ ├── smtlibParser.py │ │ └── visitor.py ├── plot.py ├── sample.py ├── smt_check.py ├── smt_math.py ├── smt_print.py ├── smt_walk.py ├── temp.py ├── tests │ ├── __init__.py │ ├── examples.py │ ├── res │ │ ├── bug_z_negative │ │ │ ├── domain │ │ │ ├── renorm.support │ │ │ ├── vanilla.support │ │ │ └── vanilla.weight │ │ └── renorm_bug │ │ │ ├── domain.json │ │ │ ├── renorm_chi_0.support │ │ │ ├── renorm_chi_1.support │ │ │ ├── renorm_chi_2.support │ │ │ ├── renorm_chi_3.support │ │ │ ├── renorm_chi_4.support │ │ │ ├── vanilla.support │ │ │ └── vanilla.weight │ ├── running_example.py │ ├── test_adaptive.py │ ├── test_checking.py │ ├── test_domain.py │ ├── test_engine.py │ ├── test_install.py │ ├── test_mzn.py │ ├── test_pa.py │ ├── test_piecewise.py │ ├── test_plotting.py │ ├── test_praise.py │ ├── test_pyxadd.py │ ├── test_rejection.py │ ├── test_sample.py │ ├── test_smt_math.py │ ├── test_smt_to_sdd.py │ ├── test_xadd.py │ ├── test_xsdd.py │ └── transform │ │ └── test_positive_coefficients.py ├── transform │ ├── __init__.py │ ├── positive_coefficients.py │ └── smt_normalize.py └── weight_algebra │ ├── __init__.py │ └── psi │ ├── .gitignore │ ├── LICENSE │ ├── LICENSE_PSI │ ├── __init__.py │ ├── build │ ├── psilibrary-linux-x86_64-3.6 │ │ └── psipy.cpython-36m-x86_64-linux-gnu.so │ └── psilibrary-macosx-10.15-x86_64-3.7 │ │ └── psipy.cpython-37m-darwin.so │ ├── psipy │ ├── build_psi.py │ ├── psi │ │ ├── .gitignore │ │ ├── LICENSE │ │ ├── README.md │ │ ├── asymptotics.d │ │ ├── backend.d │ │ ├── build-release.sh │ │ ├── build.sh │ │ ├── context.d │ │ ├── declaration.d │ │ ├── dependencies-release.sh │ │ ├── dependencies.sh │ │ ├── dexpr.d │ │ ├── differentiation.d │ │ ├── distrib.d │ │ ├── dp.d │ │ ├── dparse.d │ │ ├── dutil.d │ │ ├── error.d │ │ ├── expression.d │ │ ├── hashtable.d │ │ ├── help.d │ │ ├── integration.d │ │ ├── lexer.d │ │ ├── library │ │ │ ├── prelude-nocheck.psi │ │ │ └── prelude.psi │ │ ├── limits.d │ │ ├── logo.png │ │ ├── notes.txt │ │ ├── options.d │ │ ├── parser.d │ │ ├── psi.d │ │ ├── r │ │ ├── r.ps1 │ │ ├── sample.d │ │ ├── samplefrom.d │ │ ├── scope_.d │ │ ├── semantic_.d │ │ ├── summarize.d │ │ ├── summation.d │ │ ├── symbolic.d │ │ ├── terminal.d │ │ ├── test │ │ │ ├── add_dice.psi │ │ │ ├── add_distinct_uniforms.psi │ │ │ ├── add_gauss.psi │ │ │ ├── add_gauss_uniform.psi │ │ │ ├── add_uniform.psi │ │ │ ├── add_uniform2.psi │ │ │ ├── add_uniform3.psi │ │ │ ├── add_uniform_with_counter.psi │ │ │ ├── add_uniform_with_counter_large.psi │ │ │ ├── annotateAssignmentLhs.psi │ │ │ ├── append.psi │ │ │ ├── append2.psi │ │ │ ├── approximate │ │ │ │ ├── scale4.psi │ │ │ │ ├── scale_kernel_simple2.psi │ │ │ │ ├── scale_kernel_simple_old.psi │ │ │ │ ├── sobel.psi │ │ │ │ ├── sum_const.psi │ │ │ │ ├── sumpareto.psi │ │ │ │ ├── sumsalary.psi │ │ │ │ ├── truncated │ │ │ │ │ ├── trunccexp.psi │ │ │ │ │ ├── truncexp.psi │ │ │ │ │ ├── truncgaus.psi │ │ │ │ │ ├── truncgaus1.psi │ │ │ │ │ ├── truncgaus2.psi │ │ │ │ │ ├── truncgaus3.psi │ │ │ │ │ ├── trunclaplace.psi │ │ │ │ │ ├── truncpareto.psi │ │ │ │ │ ├── truncpareto1.psi │ │ │ │ │ └── truncunif.psi │ │ │ │ └── uncertain_gpswalk.psi │ │ │ ├── array.psi │ │ │ ├── array2.psi │ │ │ ├── array3.psi │ │ │ ├── array4.psi │ │ │ ├── array5.psi │ │ │ ├── array6.psi │ │ │ ├── arrayAssignment.psi │ │ │ ├── arrayCellUpdate2D.psi │ │ │ ├── arrayDemo.psi │ │ │ ├── arrayExpectation.psi │ │ │ ├── arrayExpectation2.psi │ │ │ ├── arrayLength.psi │ │ │ ├── arrayLoop.psi │ │ │ ├── arrayMethodCall.psi │ │ │ ├── arrayNonInt.psi │ │ │ ├── arrayRandomLength.psi │ │ │ ├── assert.psi │ │ │ ├── badbernoulli.psi │ │ │ ├── baduniformint.psi │ │ │ ├── bernoulli_comp.psi │ │ │ ├── bernoulli_ite.psi │ │ │ ├── bertrand.psi │ │ │ ├── beta.psi │ │ │ ├── beta1.psi │ │ │ ├── beta_bernoulli.psi │ │ │ ├── binfsymex │ │ │ │ ├── compare.psi │ │ │ │ ├── compare_fixed.psi │ │ │ │ ├── ex1.psi │ │ │ │ ├── ex2.psi │ │ │ │ ├── ex3.psi │ │ │ │ ├── ex4.psi │ │ │ │ ├── ex5.psi │ │ │ │ ├── friends.psi │ │ │ │ └── students.psi │ │ │ ├── binomial.psi │ │ │ ├── binomial2.psi │ │ │ ├── birthday1.psi │ │ │ ├── birthday2.psi │ │ │ ├── birthday3.psi │ │ │ ├── bitwiseOps.psi │ │ │ ├── builtInOverride.psi │ │ │ ├── builtInOverride2.psi │ │ │ ├── builtInOverride3.psi │ │ │ ├── categorical.psi │ │ │ ├── categorical2.psi │ │ │ ├── categorical3.psi │ │ │ ├── categorical4.psi │ │ │ ├── cauchy.psi │ │ │ ├── ceilSmallX.psi │ │ │ ├── chiSquared.psi │ │ │ ├── chiSquared2.psi │ │ │ ├── chiSquared3.psi │ │ │ ├── chiSquared4.psi │ │ │ ├── cobserve.psi │ │ │ ├── coin_bias.psi │ │ │ ├── coin_bias_small.psi │ │ │ ├── coin_bias_small_nice.psi │ │ │ ├── coin_pattern.psi │ │ │ ├── colorado │ │ │ │ ├── beauquier-etal-3.psi │ │ │ │ ├── cav-example-1.psi │ │ │ │ ├── cav-example-2.psi │ │ │ │ ├── cav-example-3.psi │ │ │ │ ├── cav-example-4.psi │ │ │ │ ├── cav-example-5.psi │ │ │ │ ├── cav-example-6.psi │ │ │ │ ├── cav-example-7.psi │ │ │ │ ├── example-book-mod.psi │ │ │ │ ├── example-cart.psi │ │ │ │ ├── kidney.psi │ │ │ │ ├── probabilistic-program-benchmarks │ │ │ │ │ ├── beauquier-etal-3.imp │ │ │ │ │ ├── cav-example-1.imp │ │ │ │ │ ├── cav-example-2.imp │ │ │ │ │ ├── cav-example-3.imp │ │ │ │ │ ├── cav-example-4.imp │ │ │ │ │ ├── cav-example-5.imp │ │ │ │ │ ├── cav-example-6.imp │ │ │ │ │ ├── cav-example-7.imp │ │ │ │ │ ├── example-book-mod.imp │ │ │ │ │ ├── example-cart.imp │ │ │ │ │ ├── example-carton-5.imp │ │ │ │ │ ├── example-carton.imp │ │ │ │ │ ├── example-ckd-epi.imp │ │ │ │ │ ├── example-fig6.imp │ │ │ │ │ ├── example-fig7.imp │ │ │ │ │ ├── example-invPend.imp │ │ │ │ │ ├── example-loop-perf-1.imp │ │ │ │ │ ├── example-sprinkler.imp │ │ │ │ │ ├── example-vol.imp │ │ │ │ │ ├── example4-int.imp │ │ │ │ │ ├── example4.imp │ │ │ │ │ ├── example5.imp │ │ │ │ │ ├── framingham-hypten.imp │ │ │ │ │ ├── framingham.imp │ │ │ │ │ ├── herman.imp │ │ │ │ │ ├── israeli-jalfon-3.imp │ │ │ │ │ ├── israeli-jalfon-5.imp │ │ │ │ │ ├── triangle-mod.imp │ │ │ │ │ └── tug-of-war.imp │ │ │ │ └── script.sh │ │ │ ├── compare_gauss.psi │ │ │ ├── concat.psi │ │ │ ├── concat2.psi │ │ │ ├── condExponential.psi │ │ │ ├── constraints.psi │ │ │ ├── constructorReturn.psi │ │ │ ├── coupling │ │ │ │ ├── dynkin.psi │ │ │ │ └── randomwalk.psi │ │ │ ├── curriedDef.psi │ │ │ ├── datMethodCall.psi │ │ │ ├── datMethodCall2.psi │ │ │ ├── datMethodCall3.psi │ │ │ ├── datSingletonTuple.psi │ │ │ ├── data │ │ │ │ └── array │ │ │ │ │ └── array.csv │ │ │ ├── decl.psi │ │ │ ├── degbeta.psi │ │ │ ├── degcauchy.psi │ │ │ ├── degchisquared.psi │ │ │ ├── deggamma.psi │ │ │ ├── deglaplace.psi │ │ │ ├── degpoisson.psi │ │ │ ├── deguniform.psi │ │ │ ├── demo.psi │ │ │ ├── demo2.psi │ │ │ ├── demoArray.psi │ │ │ ├── dependence_example.psi │ │ │ ├── depindepgauss.psi │ │ │ ├── detcond.psi │ │ │ ├── dietest.psi │ │ │ ├── dirac.psi │ │ │ ├── diracObserve.psi │ │ │ ├── distributions.psi │ │ │ ├── div_gauss.psi │ │ │ ├── divbyzero.psi │ │ │ ├── divbyzero2.psi │ │ │ ├── divbyzero3.psi │ │ │ ├── divbyzero4.psi │ │ │ ├── divbyzero5.psi │ │ │ ├── divbyzero6.psi │ │ │ ├── divbyzero7.psi │ │ │ ├── divbyzero8.psi │ │ │ ├── division.psi │ │ │ ├── dollars.psi │ │ │ ├── effsampa │ │ │ │ ├── burglar_alarm.psi │ │ │ │ ├── grass_model.psi │ │ │ │ └── readme.txt │ │ │ ├── elseif.psi │ │ │ ├── emptyuniform.psi │ │ │ ├── explog.psi │ │ │ ├── explog2.psi │ │ │ ├── explog3.psi │ │ │ ├── explog4.psi │ │ │ ├── explog5.psi │ │ │ ├── exponential.psi │ │ │ ├── firstClassArray.psi │ │ │ ├── firstClassBuiltIns.psi │ │ │ ├── firstClassFunctions1.psi │ │ │ ├── firstClassFunctions2.psi │ │ │ ├── firstClassInfer.psi │ │ │ ├── firstClassPolymorphism.psi │ │ │ ├── floorCeil.psi │ │ │ ├── floor_continuous.psi │ │ │ ├── forLoop.psi │ │ │ ├── fose-icse │ │ │ │ ├── ex2.psi │ │ │ │ └── trueSkillFigure9.psi │ │ │ ├── fromMarginal.psi │ │ │ ├── fromMarginalMultiple.psi │ │ │ ├── fun │ │ │ │ ├── TODO.txt │ │ │ │ ├── addFun │ │ │ │ │ ├── max.psi │ │ │ │ │ ├── max_expectation.psi │ │ │ │ │ └── sum.psi │ │ │ │ ├── bayesPointMachine.psi │ │ │ │ ├── clickGraph.psi │ │ │ │ ├── clickGraphEq.psi │ │ │ │ ├── clinicalTrial.psi │ │ │ │ ├── coins.psi │ │ │ │ ├── conference.psi │ │ │ │ ├── count.txt │ │ │ │ ├── data │ │ │ │ │ ├── BPM │ │ │ │ │ │ ├── trainingFeatures1.csv │ │ │ │ │ │ ├── trainingFeatures2.csv │ │ │ │ │ │ ├── trainingFeatures3.csv │ │ │ │ │ │ └── trainingOutcomes.csv │ │ │ │ │ └── LearningGaussian │ │ │ │ │ │ ├── #data.csv# │ │ │ │ │ │ ├── data.csv │ │ │ │ │ │ └── generate.m │ │ │ │ ├── evidence │ │ │ │ │ ├── model1.psi │ │ │ │ │ └── model2.psi │ │ │ │ ├── learningGaussian.psi │ │ │ │ ├── linearRegression.psi │ │ │ │ ├── linearRegressionEquivalent.psi │ │ │ │ ├── mixtureOfGaussians.psi │ │ │ │ ├── murderMystery.psi │ │ │ │ ├── murderMysteryEq.psi │ │ │ │ ├── results.txt │ │ │ │ └── truncatedGaussian │ │ │ │ │ ├── truncatedGaussianA.psi │ │ │ │ │ └── truncatedGaussianB.psi │ │ │ ├── functionValues.psi │ │ │ ├── fwdRef.psi │ │ │ ├── gagandeep.psi │ │ │ ├── gamma.psi │ │ │ ├── gaussExpectation.psi │ │ │ ├── gauss_moments1.psi │ │ │ ├── gauss_moments2.psi │ │ │ ├── gauss_moments3.psi │ │ │ ├── gaussian-mixture.psi │ │ │ ├── generalarray.psi │ │ │ ├── genericArrayArg.psi │ │ │ ├── geometric.psi │ │ │ ├── geometric2.psi │ │ │ ├── geometric3.psi │ │ │ ├── geometric4.psi │ │ │ ├── geometric5.psi │ │ │ ├── geometric6.psi │ │ │ ├── geometric7.psi │ │ │ ├── geometric8.psi │ │ │ ├── geometricUniform.psi │ │ │ ├── global_constants.psi │ │ │ ├── gmm.psi │ │ │ ├── gossip-sub1.psi │ │ │ ├── gossip-sub2.psi │ │ │ ├── groups.psi │ │ │ ├── hmm.psi │ │ │ ├── if_real.psi │ │ │ ├── import1.psi │ │ │ ├── import2.psi │ │ │ ├── import3.psi │ │ │ ├── inferBernoulli.psi │ │ │ ├── inferError.psi │ │ │ ├── inferExpectation.psi │ │ │ ├── inferExpectation2.psi │ │ │ ├── inferSample.psi │ │ │ ├── inferThen.psi │ │ │ ├── inferUniform.psi │ │ │ ├── inferZeroProbObs.psi │ │ │ ├── inferZeroProbObs2.psi │ │ │ ├── infexpect.psi │ │ │ ├── integerDiv.psi │ │ │ ├── inverse.psi │ │ │ ├── invgamma.psi │ │ │ ├── irwhallperturb.psi │ │ │ ├── irwhallzero.psi │ │ │ ├── ite_error.psi │ │ │ ├── ite_missing_else.psi │ │ │ ├── kalman-inline.psi │ │ │ ├── kalman-multivariate.psi │ │ │ ├── kalman-running-predict.psi │ │ │ ├── kalman-running.psi │ │ │ ├── kalman.psi │ │ │ ├── lambda1.psi │ │ │ ├── lambda2-simple.psi │ │ │ ├── lambda2.psi │ │ │ ├── lambda3.psi │ │ │ ├── lambda4.psi │ │ │ ├── lambda5.psi │ │ │ ├── lambdaCrash.psi │ │ │ ├── lambdaIte.psi │ │ │ ├── laplace.psi │ │ │ ├── laplace2.psi │ │ │ ├── less_simple_trueskill.psi │ │ │ ├── lexer.psi │ │ │ ├── list.psi │ │ │ ├── logicalAssign.psi │ │ │ ├── logictest.psi │ │ │ ├── magicSquare.psi │ │ │ ├── manyAdds.psi │ │ │ ├── manyOrs.psi │ │ │ ├── manyOrsGaussian.psi │ │ │ ├── marg_test.psi │ │ │ ├── marginal.psi │ │ │ ├── methodCallError.psi │ │ │ ├── methodMultiRetVal.psi │ │ │ ├── method_expectation.psi │ │ │ ├── methods.psi │ │ │ ├── mod.psi │ │ │ ├── mod2.psi │ │ │ ├── model-big-small.psi │ │ │ ├── model-big-small2.psi │ │ │ ├── moebius.psi │ │ │ ├── more_or_less_simple_trueskill.psi │ │ │ ├── multUniAbsGaussExpectation.psi │ │ │ ├── multUniExpectation.psi │ │ │ ├── mult_bernoulli.psi │ │ │ ├── mult_gauss.psi │ │ │ ├── mult_gauss_uniform.psi │ │ │ ├── mult_uniform.psi │ │ │ ├── mult_uniform2.psi │ │ │ ├── mult_uniform3.psi │ │ │ ├── mult_uniform4.psi │ │ │ ├── mult_uniform5.psi │ │ │ ├── mult_uniform6.psi │ │ │ ├── mult_uniform_observe.psi │ │ │ ├── mult_uniform_observe2.psi │ │ │ ├── mult_uniform_test.psi │ │ │ ├── mult_uniformint.psi │ │ │ ├── mult_uniformint2.psi │ │ │ ├── multiret.psi │ │ │ ├── multiret2.psi │ │ │ ├── multiret3.psi │ │ │ ├── multiret4.psi │ │ │ ├── n_gauss.psi │ │ │ ├── n_if.psi │ │ │ ├── neg.psi │ │ │ ├── negBinomial.psi │ │ │ ├── negBinomial2.psi │ │ │ ├── negativeBoundsCheck.psi │ │ │ ├── negstddev.psi │ │ │ ├── neighbour.psi │ │ │ ├── neighbour_age.psi │ │ │ ├── neighbour_age_tuesday.psi │ │ │ ├── neighbour_both_bias.psi │ │ │ ├── neighbour_randomly_announce.psi │ │ │ ├── neighbour_tuesday.psi │ │ │ ├── nestedCall.psi │ │ │ ├── nestedDat.psi │ │ │ ├── nestedDat2.psi │ │ │ ├── nestedDat3.psi │ │ │ ├── nestedDat4.psi │ │ │ ├── nestedExpectation.psi │ │ │ ├── nestedFun.psi │ │ │ ├── nestedUniformInt.psi │ │ │ ├── nestedarray.psi │ │ │ ├── nocoerce.psi │ │ │ ├── nocoerce2.psi │ │ │ ├── nocoerce3.psi │ │ │ ├── nonlinear1.psi │ │ │ ├── nonlinear2.psi │ │ │ ├── nonlinear3.psi │ │ │ ├── observeGauss.psi │ │ │ ├── observea.psi │ │ │ ├── parameterShadowsLocalVariable.psi │ │ │ ├── parameterized.psi │ │ │ ├── parameterized2.psi │ │ │ ├── parameterized3.psi │ │ │ ├── paramzero.psi │ │ │ ├── parens.psi │ │ │ ├── pareto.psi │ │ │ ├── parseLambdaCondition.psi │ │ │ ├── parseLambdaCondition2.psi │ │ │ ├── perforation │ │ │ │ ├── bug.psi │ │ │ │ ├── minsum.psi │ │ │ │ ├── sum.psi │ │ │ │ └── sum2.psi │ │ │ ├── permutation3elem.psi │ │ │ ├── permutationLoop.psi │ │ │ ├── phantom.psi │ │ │ ├── pi.psi │ │ │ ├── piConstant.psi │ │ │ ├── piranha.psi │ │ │ ├── pointmass_comparison.psi │ │ │ ├── pointmass_comparison2.psi │ │ │ ├── pointmass_comparison3.psi │ │ │ ├── poisson.psi │ │ │ ├── polygon.psi │ │ │ ├── polymorphicDat.psi │ │ │ ├── polymorphicRecursion.psi │ │ │ ├── polymorphicTupleArgs.psi │ │ │ ├── polymorphicTupleRet.psi │ │ │ ├── polymorphism.psi │ │ │ ├── polymorphism1.psi │ │ │ ├── polymorphism2.psi │ │ │ ├── polymorphism3.psi │ │ │ ├── polymorphism4.psi │ │ │ ├── pow.psi │ │ │ ├── pow2.psi │ │ │ ├── pow3.psi │ │ │ ├── ppaml │ │ │ │ ├── birds.psi │ │ │ │ ├── coffee.psi │ │ │ │ ├── data.psi │ │ │ │ ├── demo32878723.psi │ │ │ │ ├── election.psi │ │ │ │ ├── one-flip.psi │ │ │ │ ├── simple-gaussians.psi │ │ │ │ └── trunc-poisson.psi │ │ │ ├── presentation-example-expectation.psi │ │ │ ├── presentation-example.psi │ │ │ ├── presentation-example2.psi │ │ │ ├── probmods │ │ │ │ └── ch06 │ │ │ │ │ ├── assembly2.psi │ │ │ │ │ ├── communication_game.psi │ │ │ │ │ ├── scalar_implicature.psi │ │ │ │ │ ├── social1.psi │ │ │ │ │ ├── social2.psi │ │ │ │ │ ├── social_epistemic1.psi │ │ │ │ │ ├── social_epistemic2.psi │ │ │ │ │ ├── social_epistemic3.psi │ │ │ │ │ ├── social_goal1.psi │ │ │ │ │ ├── social_goal2.psi │ │ │ │ │ ├── social_preferences1.psi │ │ │ │ │ └── social_preferences2.psi │ │ │ ├── product.psi │ │ │ ├── productTyRenaming.psi │ │ │ ├── r2 │ │ │ │ ├── Hiv.psi │ │ │ │ ├── burglarAlarm.psi │ │ │ │ ├── clinicalTrial.psi │ │ │ │ ├── coinBias.psi │ │ │ │ ├── coinBiasEquivalent.psi │ │ │ │ ├── coinBiasModified.psi │ │ │ │ ├── data │ │ │ │ │ ├── ClinicalTrial │ │ │ │ │ │ ├── dataControlGroup.csv │ │ │ │ │ │ ├── dataTreatedGroup.csv │ │ │ │ │ │ ├── extractHakaru.d │ │ │ │ │ │ └── hakaru.mpl │ │ │ │ │ ├── CoinBias │ │ │ │ │ │ └── tosses.csv │ │ │ │ │ ├── DigitRecognition │ │ │ │ │ │ ├── input.csv │ │ │ │ │ │ ├── nbParams.csv │ │ │ │ │ │ └── nbPrior.csv │ │ │ │ │ ├── DigitRecognitionEq │ │ │ │ │ │ ├── #hakaru.mpl# │ │ │ │ │ │ ├── extractHakaru.d │ │ │ │ │ │ ├── extractParams.d │ │ │ │ │ │ ├── hakaru.mpl │ │ │ │ │ │ ├── hakaru100.mpl │ │ │ │ │ │ ├── hakaru200.mpl │ │ │ │ │ │ ├── hakaru300.mpl │ │ │ │ │ │ ├── hakaru400.mpl │ │ │ │ │ │ ├── hakaru500.mpl │ │ │ │ │ │ ├── hakaru600.mpl │ │ │ │ │ │ ├── hakaru700.mpl │ │ │ │ │ │ ├── hakaruSmall.mpl │ │ │ │ │ │ ├── input.csv │ │ │ │ │ │ ├── nbParams.csv │ │ │ │ │ │ ├── nbParams1.csv │ │ │ │ │ │ ├── nbParams10.csv │ │ │ │ │ │ ├── nbParams2.csv │ │ │ │ │ │ ├── nbParams3.csv │ │ │ │ │ │ ├── nbParams4.csv │ │ │ │ │ │ ├── nbParams5.csv │ │ │ │ │ │ ├── nbParams6.csv │ │ │ │ │ │ ├── nbParams7.csv │ │ │ │ │ │ ├── nbParams8.csv │ │ │ │ │ │ ├── nbParams9.csv │ │ │ │ │ │ └── nbPrior.csv │ │ │ │ │ ├── Hiv │ │ │ │ │ │ ├── dataPerson.csv │ │ │ │ │ │ ├── dataTime.csv │ │ │ │ │ │ ├── dataY.csv │ │ │ │ │ │ └── numPersons.csv │ │ │ │ │ ├── LinearRegression │ │ │ │ │ │ ├── dataX.csv │ │ │ │ │ │ ├── dataX1.csv │ │ │ │ │ │ ├── dataY.csv │ │ │ │ │ │ └── dataY1.csv │ │ │ │ │ ├── TrueSkill_Simple │ │ │ │ │ │ ├── games.csv │ │ │ │ │ │ └── players.csv │ │ │ │ │ ├── survey │ │ │ │ │ │ ├── answer.csv │ │ │ │ │ │ ├── gender.csv │ │ │ │ │ │ ├── personGender.csv │ │ │ │ │ │ └── population.csv │ │ │ │ │ └── survey2 │ │ │ │ │ │ ├── answer.csv │ │ │ │ │ │ ├── gender.csv │ │ │ │ │ │ ├── personGender.csv │ │ │ │ │ │ └── population.csv │ │ │ │ ├── digitRecognition.psi │ │ │ │ ├── digitRecognitionEq.m │ │ │ │ ├── digitRecognitionEq.psi │ │ │ │ ├── grass.psi │ │ │ │ ├── hiv2.psi │ │ │ │ ├── linearRegression.psi │ │ │ │ ├── noisyOrModel.psi │ │ │ │ ├── surveyResultUnbias.psi │ │ │ │ ├── surveyResultUnbias2.psi │ │ │ │ ├── tmp.psi │ │ │ │ ├── trueSkillArray.psi │ │ │ │ ├── trueSkill_Simple.psi │ │ │ │ ├── twoCoins.psi │ │ │ │ └── twoCoinsTuple.psi │ │ │ ├── rayleigh.psi │ │ │ ├── renormalizeMarginal.psi │ │ │ ├── rep.psi │ │ │ ├── runtests.d │ │ │ ├── samplefrom.psi │ │ │ ├── samplefrom2.psi │ │ │ ├── scaleuniform.psi │ │ │ ├── shadowRelabel.psi │ │ │ ├── shadowRelabel2.psi │ │ │ ├── shortcut.psi │ │ │ ├── simple_trueskill.psi │ │ │ ├── simple_trueskill_like.psi │ │ │ ├── singletonTuples.psi │ │ │ ├── slice.psi │ │ │ ├── slice2.psi │ │ │ ├── square_constraint.psi │ │ │ ├── square_uniform.psi │ │ │ ├── studentt.psi │ │ │ ├── sum.psi │ │ │ ├── sum_truncgauss.psi │ │ │ ├── sumunif.psi │ │ │ ├── sve │ │ │ │ ├── competition.psi │ │ │ │ ├── data │ │ │ │ │ └── tracking │ │ │ │ │ │ ├── query1.csv │ │ │ │ │ │ ├── query2.csv │ │ │ │ │ │ ├── query3.csv │ │ │ │ │ │ ├── query4.csv │ │ │ │ │ │ ├── query5.csv │ │ │ │ │ │ ├── query6.csv │ │ │ │ │ │ ├── query_sasa.csv │ │ │ │ │ │ └── query_twohumps.csv │ │ │ │ ├── maple │ │ │ │ │ ├── radar │ │ │ │ │ │ └── query1.txt │ │ │ │ │ └── tracking │ │ │ │ │ │ ├── query0.txt │ │ │ │ │ │ ├── query1.txt │ │ │ │ │ │ ├── query2.txt │ │ │ │ │ │ ├── query3.txt │ │ │ │ │ │ ├── query4.txt │ │ │ │ │ │ ├── query5.txt │ │ │ │ │ │ └── query6.txt │ │ │ │ ├── mathematica │ │ │ │ │ ├── radar │ │ │ │ │ │ └── query1.txt │ │ │ │ │ └── tracking │ │ │ │ │ │ ├── query0.txt │ │ │ │ │ │ ├── query1.txt │ │ │ │ │ │ ├── query2.txt │ │ │ │ │ │ ├── query3.txt │ │ │ │ │ │ ├── query4.txt │ │ │ │ │ │ ├── query5.txt │ │ │ │ │ │ └── query6.txt │ │ │ │ ├── matlab │ │ │ │ │ ├── radar │ │ │ │ │ │ └── query1.txt │ │ │ │ │ └── tracking │ │ │ │ │ │ ├── query0.txt │ │ │ │ │ │ ├── query1.txt │ │ │ │ │ │ ├── query2.txt │ │ │ │ │ │ ├── query3.txt │ │ │ │ │ │ ├── query4.txt │ │ │ │ │ │ ├── query5.txt │ │ │ │ │ │ └── query6.txt │ │ │ │ ├── radar_query1.psi │ │ │ │ ├── radar_query2.psi │ │ │ │ ├── radar_query3.psi │ │ │ │ ├── radar_query4.psi │ │ │ │ ├── radar_query5.psi │ │ │ │ ├── tracking.psi │ │ │ │ ├── tracking_misunderstood.psi │ │ │ │ ├── tracking_orig.psi │ │ │ │ ├── tracking_query0.psi │ │ │ │ ├── tracking_query1.psi │ │ │ │ ├── tracking_query2.psi │ │ │ │ ├── tracking_query3.psi │ │ │ │ ├── tracking_query4.psi │ │ │ │ ├── tracking_query5.psi │ │ │ │ ├── tracking_query6.psi │ │ │ │ └── tracking_twohumps.psi │ │ │ ├── sve_sub.psi │ │ │ ├── swap.psi │ │ │ ├── swap2.psi │ │ │ ├── synopsis.psi │ │ │ ├── synthesis_counterexample.psi │ │ │ ├── testNonsense.psi │ │ │ ├── testSingletonTupleReturn.psi │ │ │ ├── testeqcheck.psi │ │ │ ├── timetotwo.psi │ │ │ ├── timetotwo2.psi │ │ │ ├── toplevelComma.psi │ │ │ ├── tree.psi │ │ │ ├── truefalse.psi │ │ │ ├── tt.psi │ │ │ ├── tt2.psi │ │ │ ├── tt2integrate.psi │ │ │ ├── tt3.psi │ │ │ ├── tt3integrate.psi │ │ │ ├── tt4.psi │ │ │ ├── tt5.psi │ │ │ ├── tt6.psi │ │ │ ├── tt7.psi │ │ │ ├── tt_ssa.psi │ │ │ ├── tt_ssa2.psi │ │ │ ├── tupleArgs.psi │ │ │ ├── tupleAssign.psi │ │ │ ├── tupleGauss.psi │ │ │ ├── tuplePolymorphism.psi │ │ │ ├── tupleRet.psi │ │ │ ├── tupleUniform.psi │ │ │ ├── tuples.psi │ │ │ ├── tuples2.psi │ │ │ ├── tuples3.psi │ │ │ ├── tuples4.psi │ │ │ ├── tuples5.psi │ │ │ ├── tuples6.psi │ │ │ ├── twoEnvelopes.psi │ │ │ ├── two_times_simple_trueskill.psi │ │ │ ├── uniOp.psi │ │ │ ├── uniTest.psi │ │ │ ├── uniformGaussMix.psi │ │ │ ├── uniformGaussMix2.psi │ │ │ ├── uniform_comparison.psi │ │ │ ├── uniform_multilinear1.psi │ │ │ ├── uniform_multilinear2.psi │ │ │ ├── uniform_nested.psi │ │ │ ├── uniform_nested2.psi │ │ │ ├── uniformint.psi │ │ │ ├── uniformint2.psi │ │ │ ├── uniformint_nested.psi │ │ │ ├── unitEarlyReturn.psi │ │ │ ├── weekend.psi │ │ │ ├── weibull.psi │ │ │ ├── while.psi │ │ │ ├── zero.psi │ │ │ ├── zeroprobif.psi │ │ │ ├── zeroprobif2.psi │ │ │ ├── zeroprobif3.psi │ │ │ ├── zeroprobif4.psi │ │ │ ├── zeroweightobs.psi │ │ │ ├── zeroweightobs2.psi │ │ │ ├── zeroweightobs3.psi │ │ │ ├── zeroweightobs4.psi │ │ │ ├── zeroweightobs5.psi │ │ │ ├── zeroweightobs6.psi │ │ │ └── zstddev.psi │ │ └── type.d │ └── psipy.d │ └── setup.py ├── setup.cfg ├── setup.py ├── testing.py └── testing2.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled python modules. 2 | *.pyc 3 | 4 | 5 | # Setuptools build folder. 6 | /build/ 7 | 8 | # Setuptools distribution folder. 9 | /dist/ 10 | 11 | # Python egg metadata, regenerated from source files by setuptools. 12 | /*.egg-info 13 | /.eggs/ 14 | 15 | /env/ 16 | /.idea/ 17 | 18 | # visual_studio 19 | ./.vs_* 20 | 21 | /log -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - '3.6' 4 | install: 5 | - pip install -e . 6 | script: 7 | - pytest 8 | -------------------------------------------------------------------------------- /examples/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weighted-model-integration/pywmi/727ba1b54579d276b33ab6b666bd3db70a719d39/examples/.gitignore -------------------------------------------------------------------------------- /examples/wmi_generate_100/example_0.query: -------------------------------------------------------------------------------- 1 | (set-logic QF_LRA) 2 | (declare-fun A_3 () Bool) 3 | (declare-fun x_0 () Real) 4 | (assert (and A_3 (< (* 10.0 x_0) 1.0))) 5 | (check-sat) 6 | -------------------------------------------------------------------------------- /examples/wmi_generate_100/example_0.support: -------------------------------------------------------------------------------- 1 | (set-logic QF_LRA) 2 | (declare-fun x_0 () Real) 3 | (declare-fun x_1 () Real) 4 | (declare-fun A_0 () Bool) 5 | (declare-fun A_2 () Bool) 6 | (declare-fun A_3 () Bool) 7 | (declare-fun A_4 () Bool) 8 | (assert (and (and (<= (- 64.0) x_0) (<= x_0 2.0)) (and (<= (- 27.0) x_1) (<= x_1 22.0)) (or (and (< (* (- 10.0) x_0) (- 6.0)) (<= (* 3.0 x_0) 1.0)) (or A_3 A_4)) (or (<= (+ (* (- 7.0) x_1) (* 10.0 x_0)) (- 3.0)) (or A_4 A_0)) (or true A_4) (or (and (< (+ (* 1.0 x_1) (* 7.0 x_0)) 2.0) (<= (+ (* (- 6.0) x_1) (* (- 4.0) x_0)) (- 9.0))) (or A_4 A_2)))) 9 | (check-sat) 10 | -------------------------------------------------------------------------------- /examples/wmi_generate_100/example_0.weights: -------------------------------------------------------------------------------- 1 | (set-logic QF_NRA) 2 | (declare-fun x_0 () Real) 3 | (declare-fun x_1 () Real) 4 | (declare-fun A_0 () Bool) 5 | (declare-fun A_1 () Bool) 6 | (declare-fun A_2 () Bool) 7 | (declare-fun A_3 () Bool) 8 | (declare-fun A_4 () Bool) 9 | (assert (* (ite A_0 (* (- 3.0) (pow x_1 1.0)) 1.0) (ite A_1 (* 3.0 (pow x_1 1.0)) 1.0) (ite A_2 (* 10.0 (pow x_0 1.0) (pow x_1 1.0)) 1.0) (ite A_3 (+ (* (- 10.0) (pow x_1 0.0) (pow x_0 0.0)) (* 8.0 (pow x_1 0.0)) (* (- 1.0) (pow x_0 0.0) (pow x_1 0.0))) 1.0) (ite A_4 (+ (* 8.0 (pow x_1 1.0)) (* 0.0 (pow x_1 0.0))) 1.0))) 10 | (check-sat) 11 | -------------------------------------------------------------------------------- /examples/wmi_generate_100/example_1.query: -------------------------------------------------------------------------------- 1 | (set-logic QF_LRA) 2 | (declare-fun A_3 () Bool) 3 | (declare-fun A_4 () Bool) 4 | (declare-fun x_1 () Real) 5 | (assert (or A_4 A_3 (< (* 2.0 x_1) 1.0))) 6 | (check-sat) 7 | -------------------------------------------------------------------------------- /examples/wmi_generate_100/example_1.support: -------------------------------------------------------------------------------- 1 | (set-logic QF_LRA) 2 | (declare-fun x_0 () Real) 3 | (declare-fun x_1 () Real) 4 | (declare-fun A_0 () Bool) 5 | (declare-fun A_1 () Bool) 6 | (declare-fun A_2 () Bool) 7 | (declare-fun A_3 () Bool) 8 | (assert (and (and (<= (- 86.0) x_0) (<= x_0 1.0)) (and (<= (- 72.0) x_1) (<= x_1 68.0)) (or (< (* (- 1.0) x_0) 10.0) (or A_1 A_2)) (or (< (* 8.0 x_1) (- 4.0)) A_2) (or (and (< (+ (* (- 10.0) x_1) (* (- 4.0) x_0)) (- 10.0)) (<= (+ (* (- 9.0) x_1) (* 8.0 x_0)) 9.0)) (or A_0 A_3)) (or (<= (+ (* 1.0 x_0) (* (- 5.0) x_1)) 8.0) (or A_0 A_3)))) 9 | (check-sat) 10 | -------------------------------------------------------------------------------- /examples/wmi_generate_100/example_2.query: -------------------------------------------------------------------------------- 1 | (set-logic QF_LRA) 2 | (declare-fun x_0 () Real) 3 | (declare-fun x_1 () Real) 4 | (assert (and (<= (+ (* (- 8.0) x_1) (* 2.0 x_0)) 6.0) (< (+ (* 1.0 x_0) (* 2.0 x_1)) 4.0) (<= (+ (* (- 2.0) x_1) (* 3.0 x_0)) (- 5.0)))) 5 | (check-sat) 6 | -------------------------------------------------------------------------------- /examples/wmi_generate_100/example_2.support: -------------------------------------------------------------------------------- 1 | (set-logic QF_LRA) 2 | (declare-fun x_0 () Real) 3 | (declare-fun x_1 () Real) 4 | (declare-fun A_0 () Bool) 5 | (declare-fun A_1 () Bool) 6 | (declare-fun A_2 () Bool) 7 | (declare-fun A_3 () Bool) 8 | (declare-fun A_6 () Bool) 9 | (assert (and (and (<= (- 28.0) x_0) (<= x_0 77.0)) (and (<= (- 27.0) x_1) (<= x_1 91.0)) (or true A_3) (or (and (< (* 0.0 x_0) (- 6.0)) (< (* 9.0 x_0) 7.0) (< (+ (* 7.0 x_0) (* 4.0 x_1)) (- 8.0))) (or A_1 A_2 A_6)) (or (< (* 1.0 x_1) 5.0) (or A_0 A_6)) (or true A_2) (or (< (* (- 1.0) x_1) (- 8.0)) A_0))) 10 | (check-sat) 11 | -------------------------------------------------------------------------------- /examples/wmi_generate_100/example_3.query: -------------------------------------------------------------------------------- 1 | (set-logic QF_LRA) 2 | (declare-fun A_5 () Bool) 3 | (declare-fun x_0 () Real) 4 | (declare-fun x_1 () Real) 5 | (assert (or (< (+ (* (- 5.0) x_1) (* (- 2.0) x_0)) 1.0) A_5 (<= (* 8.0 x_1) 1.0) A_5)) 6 | (check-sat) 7 | -------------------------------------------------------------------------------- /examples/wmi_generate_100/example_3.support: -------------------------------------------------------------------------------- 1 | (set-logic QF_LRA) 2 | (declare-fun A_3 () Bool) 3 | (declare-fun A_5 () Bool) 4 | (declare-fun x_0 () Real) 5 | (declare-fun x_1 () Real) 6 | (declare-fun A_2 () Bool) 7 | (assert (and (and (<= (- 6.0) x_0) (<= x_0 44.0)) (and (<= (- 30.0) x_1) (<= x_1 27.0)) (or true A_3) (or (< (* (- 9.0) x_1) 8.0) A_3) (or (and (<= (+ (* (- 1.0) x_1) (* 7.0 x_0)) 3.0) (< (* (- 9.0) x_0) (- 8.0))) (or A_3 A_2)) (or (< (* (- 1.0) x_0) (- 1.0)) (or A_5 A_3)) (or true A_2))) 8 | (check-sat) 9 | -------------------------------------------------------------------------------- /examples/wmi_generate_100/example_4.query: -------------------------------------------------------------------------------- 1 | (set-logic QF_LRA) 2 | (declare-fun x_1 () Real) 3 | (declare-fun x_2 () Real) 4 | (declare-fun A_0 () Bool) 5 | (assert (or A_0 (<= (+ (* (- 1.0) x_1) (* (- 1.0) x_2)) (- 6.0)))) 6 | (check-sat) 7 | -------------------------------------------------------------------------------- /examples/wmi_generate_100/example_4.support: -------------------------------------------------------------------------------- 1 | (set-logic QF_LRA) 2 | (declare-fun x_0 () Real) 3 | (declare-fun x_1 () Real) 4 | (declare-fun x_2 () Real) 5 | (declare-fun A_0 () Bool) 6 | (declare-fun A_1 () Bool) 7 | (declare-fun A_2 () Bool) 8 | (declare-fun A_3 () Bool) 9 | (declare-fun A_4 () Bool) 10 | (assert (and (and (<= (- 11.0) x_0) (<= x_0 10.0)) (and (<= (- 55.0) x_1) (<= x_1 27.0)) (and (<= (- 61.0) x_2) (<= x_2 72.0)) (or (<= (* 9.0 x_1) 7.0) A_3) (or (< (+ (* 1.0 x_1) (* (- 2.0) x_0) (* (- 10.0) x_2)) (- 9.0)) (or A_1 A_0)) (or (and (< (* (- 4.0) x_0) 8.0) (< (+ (* (- 8.0) x_2) (* 6.0 x_0) (* 8.0 x_1)) (- 2.0))) (or A_2 A_3 A_1)) (or true A_4))) 11 | (check-sat) 12 | -------------------------------------------------------------------------------- /examples/wmi_generate_100/example_5.query: -------------------------------------------------------------------------------- 1 | (set-logic QF_LRA) 2 | (declare-fun A_3 () Bool) 3 | (declare-fun x_0 () Real) 4 | (declare-fun x_1 () Real) 5 | (assert (not (or A_3 (<= (+ (* (- 1.0) x_0) (* 2.0 x_1)) (- 5.0))))) 6 | (check-sat) 7 | -------------------------------------------------------------------------------- /examples/wmi_generate_100/example_5.support: -------------------------------------------------------------------------------- 1 | (set-logic QF_LRA) 2 | (declare-fun x_0 () Real) 3 | (declare-fun x_1 () Real) 4 | (declare-fun A_0 () Bool) 5 | (declare-fun A_1 () Bool) 6 | (declare-fun A_2 () Bool) 7 | (declare-fun A_4 () Bool) 8 | (declare-fun A_5 () Bool) 9 | (assert (and (and (<= (- 9.0) x_0) (<= x_0 68.0)) (and (<= (- 28.0) x_1) (<= x_1 73.0)) (or (and (< (* (- 8.0) x_1) (- 3.0)) (< (+ (* 9.0 x_0) (* (- 4.0) x_1)) (- 3.0))) (or A_5 A_4)) (or (and (<= (+ (* (- 2.0) x_1) (* (- 3.0) x_0)) (- 3.0)) (<= (* 0.0 x_1) (- 6.0))) (or A_4 A_5 A_2)) (or true A_5) (or true A_4) (or (and (< (+ (* (- 7.0) x_0) (* 7.0 x_1)) 6.0) (<= (* (- 2.0) x_0) 4.0) (< (* 5.0 x_0) (- 1.0))) (or A_5 A_0 A_1)))) 10 | (check-sat) 11 | -------------------------------------------------------------------------------- /examples/wmi_generate_100/example_6.query: -------------------------------------------------------------------------------- 1 | (set-logic QF_LRA) 2 | (declare-fun x_0 () Real) 3 | (declare-fun A_0 () Bool) 4 | (assert (or A_0 (< (* (- 3.0) x_0) 2.0) A_0)) 5 | (check-sat) 6 | -------------------------------------------------------------------------------- /examples/wmi_generate_100/example_6.support: -------------------------------------------------------------------------------- 1 | (set-logic QF_LRA) 2 | (declare-fun x_0 () Real) 3 | (declare-fun x_1 () Real) 4 | (declare-fun A_0 () Bool) 5 | (declare-fun A_1 () Bool) 6 | (declare-fun A_2 () Bool) 7 | (declare-fun A_3 () Bool) 8 | (declare-fun A_4 () Bool) 9 | (assert (and (and (<= (- 5.0) x_0) (<= x_0 15.0)) (and (<= (- 62.0) x_1) (<= x_1 68.0)) (or (<= (* (- 5.0) x_0) 5.0) A_3) (or (< (* (- 10.0) x_1) (- 2.0)) (or A_1 A_3)) (or true A_1) (or (<= (* (- 10.0) x_0) 5.0) A_0) (or (< (+ (* 8.0 x_1) (* (- 10.0) x_0)) (- 10.0)) (or A_4 A_2)))) 10 | (check-sat) 11 | -------------------------------------------------------------------------------- /examples/wmi_generate_100/example_7.query: -------------------------------------------------------------------------------- 1 | (set-logic QF_LRA) 2 | (declare-fun x_0 () Real) 3 | (declare-fun x_1 () Real) 4 | (declare-fun x_2 () Real) 5 | (assert (and (< (* 0.0 x_2) 10.0) (< (+ (* 8.0 x_0) (* (- 4.0) x_2) (* (- 8.0) x_1)) (- 3.0)))) 6 | (check-sat) 7 | -------------------------------------------------------------------------------- /examples/wmi_generate_100/example_8.query: -------------------------------------------------------------------------------- 1 | (set-logic QF_LRA) 2 | (declare-fun x_0 () Real) 3 | (declare-fun A_5 () Bool) 4 | (declare-fun A_6 () Bool) 5 | (assert (or (<= (* (- 4.0) x_0) (- 5.0)) A_5 A_6)) 6 | (check-sat) 7 | -------------------------------------------------------------------------------- /examples/wmi_generate_100/example_8.support: -------------------------------------------------------------------------------- 1 | (set-logic QF_LRA) 2 | (declare-fun x_0 () Real) 3 | (declare-fun x_1 () Real) 4 | (declare-fun A_0 () Bool) 5 | (declare-fun A_1 () Bool) 6 | (declare-fun A_2 () Bool) 7 | (declare-fun A_3 () Bool) 8 | (declare-fun A_4 () Bool) 9 | (declare-fun A_6 () Bool) 10 | (assert (and (and (<= (- 65.0) x_0) (<= x_0 49.0)) (and (<= (- 80.0) x_1) (<= x_1 9.0)) (or (<= (* (- 1.0) x_1) 1.0) A_4) (or (and (< (* (- 6.0) x_0) (- 8.0)) (< (+ (* 0.0 x_0) (* 5.0 x_1)) 10.0)) (or A_2 A_4 A_1)) (or (< (* (- 7.0) x_0) (- 10.0)) A_0) (or (< (+ (* 8.0 x_1) (* 0.0 x_0)) 8.0) A_6) (or (<= (* 0.0 x_1) 7.0) (or A_3 A_1)))) 11 | (check-sat) 12 | -------------------------------------------------------------------------------- /pywmi/engines/pyxadd/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weighted-model-integration/pywmi/727ba1b54579d276b33ab6b666bd3db70a719d39/pywmi/engines/pyxadd/__init__.py -------------------------------------------------------------------------------- /pywmi/engines/xsdd/__init__.py: -------------------------------------------------------------------------------- 1 | from .engine import XsddEngine 2 | from .engine_factorized import FactorizedXsddEngine 3 | from .piecewise import PiecewiseFunction 4 | from .draw import sdd_to_png_file, sdd_to_dot_file 5 | from .semiring import Semiring, SddWalker, amc, walk 6 | -------------------------------------------------------------------------------- /pywmi/engines/xsdd/vtrees/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weighted-model-integration/pywmi/727ba1b54579d276b33ab6b666bd3db70a719d39/pywmi/engines/xsdd/vtrees/__init__.py -------------------------------------------------------------------------------- /pywmi/errors.py: -------------------------------------------------------------------------------- 1 | class InstallError(RuntimeError): 2 | pass 3 | 4 | 5 | class InfiniteVolumeError(RuntimeError): 6 | pass 7 | 8 | 9 | class ParsingFileError(RuntimeError): 10 | pass 11 | -------------------------------------------------------------------------------- /pywmi/log/integrate_106_d_a.dot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weighted-model-integration/pywmi/727ba1b54579d276b33ab6b666bd3db70a719d39/pywmi/log/integrate_106_d_a.dot.png -------------------------------------------------------------------------------- /pywmi/log/integrate_107_d_b.dot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weighted-model-integration/pywmi/727ba1b54579d276b33ab6b666bd3db70a719d39/pywmi/log/integrate_107_d_b.dot.png -------------------------------------------------------------------------------- /pywmi/log/integrate_113_d_x.dot: -------------------------------------------------------------------------------- 1 | digraph G { 2 | rankdir = TB; 3 | 113 [label="(x < 0)", shape=""] 4 | 113 -> 1 5 | 113 -> 112 [style=dashed] 6 | {rank = same; 113;} 7 | 1 [label="0", shape="box"] 8 | 110 [label="(-1*x < -0.5)", shape=""] 9 | 110 -> 108 10 | 110 -> 109 [style=dashed] 11 | {rank = same; 1; 110;} 12 | 112 [label="(x - 1*y < 0)", shape=""] 13 | 112 -> 111 14 | 112 -> 1 [style=dashed] 15 | {rank = same; 112;} 16 | 111 [label="(-1*y < -1)", shape=""] 17 | 111 -> 1 18 | 111 -> 110 [style=dashed] 19 | {rank = same; 111;} 20 | 108 [label="(1/10·y+1/2·x)·1/5·3/5+(1/10·y+1/2·x)·2/5·4/5", shape="box"] 21 | 109 [label="(1/10·x+7/10·y)·1/5·3/5+(1/10·x+7/10·y)·2/5·4/5", shape="box"] 22 | {rank = same; 108; 109;} 23 | } 24 | -------------------------------------------------------------------------------- /pywmi/log/integrate_113_d_x.dot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weighted-model-integration/pywmi/727ba1b54579d276b33ab6b666bd3db70a719d39/pywmi/log/integrate_113_d_x.dot.png -------------------------------------------------------------------------------- /pywmi/log/integrate_19_d_x.dot: -------------------------------------------------------------------------------- 1 | digraph G { 2 | rankdir = TB; 3 | 19 [label="(-1*x < -0.25)", shape=""] 4 | 19 -> 18 5 | 19 -> 1 [style=dashed] 6 | {rank = same; 19;} 7 | 18 [label="(-1*x < -0.75)", shape=""] 8 | 18 -> 1 9 | 18 -> 13 [style=dashed] 10 | {rank = same; 18;} 11 | 1 [label="0", shape="box"] 12 | 13 [label="1+x", shape="box"] 13 | {rank = same; 1; 13;} 14 | } 15 | -------------------------------------------------------------------------------- /pywmi/log/integrate_19_d_x.dot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weighted-model-integration/pywmi/727ba1b54579d276b33ab6b666bd3db70a719d39/pywmi/log/integrate_19_d_x.dot.png -------------------------------------------------------------------------------- /pywmi/log/integrate_35_d_a.dot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weighted-model-integration/pywmi/727ba1b54579d276b33ab6b666bd3db70a719d39/pywmi/log/integrate_35_d_a.dot.png -------------------------------------------------------------------------------- /pywmi/log/integrate_44_d_x.dot: -------------------------------------------------------------------------------- 1 | digraph G { 2 | rankdir = TB; 3 | 44 [label="(-1*x < -0.5)", shape=""] 4 | 44 -> 37 5 | 44 -> 43 [style=dashed] 6 | {rank = same; 44;} 7 | 37 [label="(-1*x < -1)", shape=""] 8 | 37 -> 1 9 | 37 -> 36 [style=dashed] 10 | 42 [label="(x < 0)", shape=""] 11 | 42 -> 1 12 | 42 -> 22 [style=dashed] 13 | {rank = same; 37; 42;} 14 | 43 [label="(-1*x < -0.2)", shape=""] 15 | 43 -> 37 16 | 43 -> 42 [style=dashed] 17 | {rank = same; 43;} 18 | 1 [label="0", shape="box"] 19 | 22 [label="3/10·x", shape="box"] 20 | 36 [label="3/10·x+7/10·x", shape="box"] 21 | {rank = same; 1; 22; 36;} 22 | } 23 | -------------------------------------------------------------------------------- /pywmi/log/integrate_44_d_x.dot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weighted-model-integration/pywmi/727ba1b54579d276b33ab6b666bd3db70a719d39/pywmi/log/integrate_44_d_x.dot.png -------------------------------------------------------------------------------- /pywmi/log/integrate_53_d_x.dot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weighted-model-integration/pywmi/727ba1b54579d276b33ab6b666bd3db70a719d39/pywmi/log/integrate_53_d_x.dot.png -------------------------------------------------------------------------------- /pywmi/log/integrate_9_d_a.dot: -------------------------------------------------------------------------------- 1 | digraph G { 2 | rankdir = TB; 3 | 9 [label="a", shape=""] 4 | 9 -> 4 5 | 9 -> 5 [style=dashed] 6 | {rank = same; 9;} 7 | 4 [label="3/10", shape="box"] 8 | 5 [label="7/10", shape="box"] 9 | {rank = same; 4; 5;} 10 | } 11 | -------------------------------------------------------------------------------- /pywmi/log/integrate_9_d_a.dot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weighted-model-integration/pywmi/727ba1b54579d276b33ab6b666bd3db70a719d39/pywmi/log/integrate_9_d_a.dot.png -------------------------------------------------------------------------------- /pywmi/normalize_weight.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weighted-model-integration/pywmi/727ba1b54579d276b33ab6b666bd3db70a719d39/pywmi/normalize_weight.py -------------------------------------------------------------------------------- /pywmi/parser/__init__.py: -------------------------------------------------------------------------------- 1 | from .minizinc import MinizincParser 2 | from .smtlib import SmtlibParser 3 | -------------------------------------------------------------------------------- /pywmi/parser/minizinc/__init__.py: -------------------------------------------------------------------------------- 1 | from .minizincParser import MinizincParser 2 | -------------------------------------------------------------------------------- /pywmi/parser/minizinc/antlr/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weighted-model-integration/pywmi/727ba1b54579d276b33ab6b666bd3db70a719d39/pywmi/parser/minizinc/antlr/__init__.py -------------------------------------------------------------------------------- /pywmi/parser/minizinc/createParser.sh: -------------------------------------------------------------------------------- 1 | java -Xmx500M -cp "/usr/local/lib/antlr-4.7.1-complete.jar:$CLASSPATH" org.antlr.v4.Tool -visitor -Dlanguage=Python3 -o antlr/ minizinc.g4 2 | -------------------------------------------------------------------------------- /pywmi/parser/minizinc/minizincErrorListener.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from .antlr.minizincParser import minizincParser 4 | from .antlr.minizincVisitor import minizincVisitor 5 | 6 | from antlr4 import * 7 | from antlr4.error.ErrorListener import * 8 | 9 | from pywmi.errors import ParsingFileError 10 | 11 | class MinizincErrorListener(ErrorListener): 12 | 13 | def syntaxError(self, recognizer, offendingSymbol, line, column, msg, e): 14 | raise ParsingFileError('Syntax error at line '+str(line)+', column '+str(column)+': '+msg) 15 | -------------------------------------------------------------------------------- /pywmi/parser/smtlib/__init__.py: -------------------------------------------------------------------------------- 1 | from .smtlibParser import SmtlibParser 2 | -------------------------------------------------------------------------------- /pywmi/parser/smtlib/antlr/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weighted-model-integration/pywmi/727ba1b54579d276b33ab6b666bd3db70a719d39/pywmi/parser/smtlib/antlr/__init__.py -------------------------------------------------------------------------------- /pywmi/parser/smtlib/createParser.sh: -------------------------------------------------------------------------------- 1 | java -Xmx500M -cp "/usr/local/lib/antlr-4.7.1-complete.jar:$CLASSPATH" org.antlr.v4.Tool -visitor -Dlanguage=Python3 -o antlr/ smtlib.g4 2 | -------------------------------------------------------------------------------- /pywmi/parser/smtlib/smtlibErrorListener.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from .antlr.smtlibParser import smtlibParser 4 | from .antlr.smtlibVisitor import smtlibVisitor 5 | 6 | from antlr4 import * 7 | from antlr4.error.ErrorListener import * 8 | 9 | from pywmi.errors import ParsingFileError 10 | 11 | class SmtlibErrorListener(ErrorListener): 12 | 13 | def syntaxError(self, recognizer, offendingSymbol, line, column, msg, e): 14 | raise ParsingFileError('Syntax error at line '+str(line)+', column '+str(column)+': '+msg) 15 | -------------------------------------------------------------------------------- /pywmi/tests/__init__.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | # we want to have pytest assert introspection in the helpers 4 | pytest.register_assert_rewrite('pywmi.tests.examples') 5 | -------------------------------------------------------------------------------- /pywmi/tests/res/bug_z_negative/domain: -------------------------------------------------------------------------------- 1 | {"var_domains": {"r0": [0.012071953237464905, 0.9935820597519394], "r1": [0.012550896131849898, 0.9821455383687209]}, "var_types": {"r0": "real", "r1": "real", "b0": "bool", "b1": "bool"}, "variables": ["b0", "b1", "r0", "r1"]} -------------------------------------------------------------------------------- /pywmi/tests/res/bug_z_negative/vanilla.support: -------------------------------------------------------------------------------- 1 | (set-logic QF_RDL) 2 | (declare-fun r0 () Real) 3 | (declare-fun r1 () Real) 4 | (assert (let ((.def_0 (<= r1 (/ 1094010116785893 1125899906842624)))) (let ((.def_1 (<= (/ 35059737994585 4503599627370496) r1))) (let ((.def_2 (and .def_1 .def_0))) (let ((.def_3 (<= r0 (/ 8744089220620803 9007199254740992)))) (let ((.def_4 (<= (/ 279425410672545 2251799813685248) r0))) (let ((.def_5 (and .def_4 .def_3))) (let ((.def_6 (and .def_5 .def_2))) .def_6)))))))) 5 | (check-sat) 6 | -------------------------------------------------------------------------------- /pywmi/tests/res/renorm_bug/domain.json: -------------------------------------------------------------------------------- 1 | {"variables": ["b0", "b1", "r0", "r1"], "var_types": {"r0": "real", "r1": "real", "b0": "bool", "b1": "bool"}, "var_domains": {"r0": [0.012071953237464905, 0.9935820597519394], "r1": [0.012550896131849898, 0.9821455383687209]}} -------------------------------------------------------------------------------- /pywmi/tests/res/renorm_bug/vanilla.support: -------------------------------------------------------------------------------- 1 | (set-logic QF_RDL) 2 | (declare-fun r0 () Real) 3 | (declare-fun r1 () Real) 4 | (assert (let ((.def_0 (<= r1 (/ 8846380561241933 9007199254740992)))) (let ((.def_1 (<= (/ 56524211142565 4503599627370496) r1))) (let ((.def_2 (and .def_1 .def_0))) (let ((.def_3 (<= r0 (/ 1118673948515211 1125899906842624)))) (let ((.def_4 (<= (/ 54367244101881 4503599627370496) r0))) (let ((.def_5 (and .def_4 .def_3))) (let ((.def_6 (and .def_5 .def_2))) .def_6)))))))) 5 | (check-sat) 6 | -------------------------------------------------------------------------------- /pywmi/tests/test_install.py: -------------------------------------------------------------------------------- 1 | def test_import_install(): 2 | # noinspection PyUnresolvedReferences 3 | from pywmi import install 4 | -------------------------------------------------------------------------------- /pywmi/tests/test_piecewise.py: -------------------------------------------------------------------------------- 1 | def test_piecewise(): 2 | pass -------------------------------------------------------------------------------- /pywmi/transform/__init__.py: -------------------------------------------------------------------------------- 1 | from .positive_coefficients import make_coefficients_positive 2 | from .smt_normalize import normalize_formula -------------------------------------------------------------------------------- /pywmi/transform/positive_coefficients.py: -------------------------------------------------------------------------------- 1 | from pysmt.fnode import FNode 2 | from pysmt.shortcuts import Real 3 | from pysmt.typing import REAL 4 | 5 | from pywmi.smt_walk import SmtIdentityWalker 6 | 7 | 8 | class PositiveCoefficientsWalker(SmtIdentityWalker): 9 | def walk_constant(self, value, v_type): 10 | if v_type == REAL: 11 | return Real(abs(value)) 12 | else: 13 | return SmtIdentityWalker.walk_constant(self, value, v_type) 14 | 15 | 16 | def make_coefficients_positive(formula: FNode) -> FNode: 17 | return PositiveCoefficientsWalker().walk_smt(formula) 18 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weighted-model-integration/pywmi/727ba1b54579d276b33ab6b666bd3db70a719d39/pywmi/weight_algebra/__init__.py -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/.gitignore: -------------------------------------------------------------------------------- 1 | build/* 2 | !build 3 | !build/psilibrary*/ 4 | build/psilibrary*/* 5 | !build/psilibrary*/*.so 6 | !build/psilibrary*/__init__.py 7 | 8 | 9 | psipy/linux 10 | psipy/darwin 11 | 12 | *.pyc 13 | __pycache__ -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2018, KU Leuven 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/build/psilibrary-linux-x86_64-3.6/psipy.cpython-36m-x86_64-linux-gnu.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weighted-model-integration/pywmi/727ba1b54579d276b33ab6b666bd3db70a719d39/pywmi/weight_algebra/psi/build/psilibrary-linux-x86_64-3.6/psipy.cpython-36m-x86_64-linux-gnu.so -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/build/psilibrary-macosx-10.15-x86_64-3.7/psipy.cpython-37m-darwin.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weighted-model-integration/pywmi/727ba1b54579d276b33ab6b666bd3db70a719d39/pywmi/weight_algebra/psi/build/psilibrary-macosx-10.15-x86_64-3.7/psipy.cpython-37m-darwin.so -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.o 3 | psi 4 | *.def 5 | *.log 6 | test/runtests 7 | test/misc 8 | */octave_workspace 9 | *~ 10 | **/tmp.prb 11 | *tmp.deleteme 12 | Cuba* 13 | *octave-workspace 14 | *.zip 15 | *.exe 16 | *.obj 17 | dmd* -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/build-release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | VERSION="1.16.0-beta2" 4 | 5 | if [[ "$OSTYPE" == "linux-gnu" ]]; then 6 | NAME="ldc2-$VERSION-linux-x86_64" 7 | elif [[ "$OSTYPE" == "darwin"* ]]; then 8 | NAME="ldc2-$VERSION-osx-x86_64" 9 | fi 10 | 11 | if [ -d $NAME ]; then 12 | LDMD="./$NAME/bin/ldmd2"; 13 | else 14 | LDMD="ldmd2" 15 | fi 16 | 17 | # release build 18 | # TODO: make sure tests run correctly with release build 19 | $LDMD -O -release -inline -boundscheck=off -J. -Jlibrary *.d -ofpsi 20 | # ldmd2 -O -release -inline -J. -Jlibrary *.d -ofllpsi 21 | 22 | if [ ! -f "test/runtests" ]; then 23 | $LDMD test/runtests.d -oftest/runtests 24 | fi 25 | 26 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [[ "$OSTYPE" == "linux-gnu" ]]; then 3 | BIN="linux/bin64" 4 | elif [[ "$OSTYPE" == "darwin"* ]]; then 5 | BIN="osx/bin" 6 | fi 7 | 8 | if [[ -d "dmd2" ]]; then 9 | DMD="./dmd2/$BIN/dmd" 10 | else 11 | DMD="dmd" 12 | fi 13 | 14 | # debug build 15 | $DMD -g -debug -J. -Jlibrary *.d -ofpsi 16 | 17 | if [ ! -f "test/runtests" ]; then 18 | $DMD test/runtests.d -oftest/runtests 19 | fi 20 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weighted-model-integration/pywmi/727ba1b54579d276b33ab6b666bd3db70a719d39/pywmi/weight_algebra/psi/psipy/psi/logo.png -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/r: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # debug build 3 | dmd -g -debug -J. -Jlibrary *.d -ofpsi -L-fuse-ld=gold && time ./psi $@ 4 | # dmd -release -inline -J. -O *.d -ofprob && time ./prob $@ 5 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/r.ps1: -------------------------------------------------------------------------------- 1 | $files = Resolve-Path *.d 2 | dmd -gc -debug -ofpsi "-J." $files 3 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/summarize.d: -------------------------------------------------------------------------------- 1 | import std.algorithm, std.array, std.conv; 2 | import declaration, type, error; 3 | 4 | string[] getSummary(FunctionDef fd,string[] entries){ 5 | return entries.map!(e=>getValue(fd,e)).array; 6 | } 7 | 8 | string getValue(FunctionDef fd,string property){ 9 | switch(property){ 10 | case "name": 11 | return fd.name.toString(); 12 | case "arg-arity": 13 | return fd.numArgs.to!string; 14 | case "ret-arity": 15 | return fd.numReturns.to!string; 16 | default: throw new Exception(text("summarize: unknown key '",property,"'")); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/add_dice.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | // (plot output) 3 | 4 | def abs(x){ 5 | return if x<0 { -x } else { x }; 6 | } 7 | 8 | def main(){ 9 | n := uniformInt(1,4); 10 | o := uniformInt(-2,2); 11 | c := if flip((o+3)/5){ 1/n }else {1/n^2}; 12 | x := 0; 13 | for i in [0..4){ if(i 2) { y = 0; } 7 | return y; 8 | } 9 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/approximate/truncated/truncgaus1.psi: -------------------------------------------------------------------------------- 1 | //skipped 2 | 3 | def main() { 4 | x := gauss(0,2); 5 | observe (x >= -10 && x <= 10); 6 | return x; 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/approximate/truncated/truncgaus2.psi: -------------------------------------------------------------------------------- 1 | //skipped 2 | 3 | def main() { 4 | x := truncatedGauss(0,2,-10.0,10.0); 5 | return x; 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/approximate/truncated/truncgaus3.psi: -------------------------------------------------------------------------------- 1 | //skipped 2 | 3 | def tg() { 4 | x := gauss(0,2); 5 | observe (x >= -10 && x <= 10); 6 | return x; 7 | } 8 | 9 | def main() { 10 | x1 := tg(); 11 | x2 := tg(); 12 | return x1 + x2; 13 | } 14 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/approximate/truncated/trunclaplace.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | 3 | 4 | def main() { 5 | assert(flip(0.999)); 6 | assert(flip(0.999)); 7 | assert(flip(0.999)); 8 | 9 | X := laplace(0, 0.2); observe(-0.5 <= X && X <= 0.5); 10 | Y := laplace(0, 0.2); observe(-0.5 <= Y && Y <= 0.5); 11 | Z := laplace(0, 0.2); observe(-0.5 <= Z && Z <= 0.5); 12 | 13 | return 0.25*(X+Y+Z); 14 | // return (X,Y); 15 | } 16 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/approximate/truncated/truncpareto.psi: -------------------------------------------------------------------------------- 1 | //skipped 2 | 3 | def main() { 4 | X := pareto(3,1); 5 | Y := pareto(3,1); 6 | //Z := pareto(3,1); 7 | return X + Y; 8 | } 9 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/approximate/truncated/truncpareto1.psi: -------------------------------------------------------------------------------- 1 | //skipped 2 | 3 | def df() { 4 | return pareto(3,1)-1; 5 | } 6 | 7 | def main(){ 8 | assert(flip(0.999)); 9 | assert(flip(0.999)); 10 | assert(flip(0.999)); 11 | 12 | x:=df(); 13 | y:=df(); 14 | z:=df(); 15 | 16 | v := 0.25*(x+y+z); 17 | 18 | return v; 19 | } 20 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/approximate/truncated/truncunif.psi: -------------------------------------------------------------------------------- 1 | //skipped 2 | 3 | def df() { 4 | return uniform(-0.5,0.5); 5 | } 6 | 7 | 8 | def main(){ 9 | assert(flip(0.999)); 10 | assert(flip(0.999)); 11 | assert(flip(0.999)); 12 | 13 | x:=df(); 14 | y:=df(); 15 | z:=df(); 16 | 17 | v := 0.25*(x+y+z); 18 | 19 | return v; 20 | } 21 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/array.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | a := readCSV("data/array/array.csv"); 3 | //observe(a.length==3); 4 | k := array(7); 5 | k[0]=3; 6 | k[1]=flip(0.5); 7 | // k[2]=Uniform(0,k[UniformInt(0,1)]); // TODO! 8 | r := k[0]+k[1]+k[2]+k[3]+a[0]+a[1]+a[2]; 9 | return r; // expected: 1/2·δ(10)[r]+1/2·δ(9)[r] 10 | } 11 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/array2.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := [[(1,2)],[(2,3)],[(3,4),(5,6)]]; 4 | return Expectation(x[uniformInt(0,1)][0][0]+x[2][uniformInt(0,1)][1]); // expected: δ(13/2)[r] 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/array3.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | 3 | def main(){ 4 | x := [1,2,3,4]; 5 | for i in [0..x.length){ 6 | x[i]-=1; 7 | } 8 | for i in [0..x.length){ 9 | x[x[i]]=i+1; 10 | if flip(1/2){ 11 | x[x[i]]-=1; 12 | } 13 | } 14 | return (x[0]+x[1]+x[2]+x[3]); // expected: 3/16·δ(0)[-r₁+9]+δ(0)[-r₁+10]·⅟16+δ(0)[-r₁+6]·⅟16+δ(0)[-r₁+7]·⅟8+δ(0)[-r₁+8]·⅟4 15 | } 16 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/array4.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | n := 2; 3 | x := [0]; 4 | x[0] = beta(1,1); 5 | return x; // expected: ∫dξ₁[-1+ξ₁≤0]·[-ξ₁≤0]·δ([ξ₂ ↦ ξ₁] (1))[x] 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/array5.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | // TODO: simplify better 3 | 4 | def main(){ 5 | a := [[0],[0]]; 6 | for i in [0..a.length){ a[i]=[0,0]; } 7 | for i in [0..a.length){ 8 | for j in [0..a[i].length){ 9 | a[i][j]=uniform(0,1); 10 | } 11 | } 12 | return a; // expected: ∫dξ₁(∫dξ₂(∫dξ₃(∫dξ₄[-1+ξ₄≤0]·[-ξ₄≤0]·δ_a[[ξ₅ ↦ ([ξ₆ ↦ [-ξ₆+1=0]·ξ₁+[-ξ₆+1≠0]·[ξ₆=0]·ξ₂] (2))·[-ξ₅+1=0]+([ξ₆ ↦ [-ξ₆+1=0]·ξ₃+[-ξ₆+1≠0]·[ξ₆=0]·ξ₄] (2))·[-ξ₅+1≠0]·[ξ₅=0]] (2)])·[-1+ξ₃≤0]·[-ξ₃≤0])·[-1+ξ₂≤0]·[-ξ₂≤0])·[-1+ξ₁≤0]·[-ξ₁≤0] 13 | } 14 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/array6.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | a:=[1,2]; 3 | a[flip(1/2)]+=1; 4 | assert(a[0]<=2); 5 | return; // expected: 1 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/arrayAssignment.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | a := [[1,2,3],[2,3,4],[5,6,7]]; 4 | a[uniformInt(0,2)][uniformInt(0,2)]+=flip(1/2); 5 | assert(a[0][0]<=2); 6 | p := Expectation(a[0][0]==2); 7 | return p; // expected: δ(1/18)[p] 8 | } 9 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/arrayCellUpdate2D.psi: -------------------------------------------------------------------------------- 1 | 2 | dat Cell{ 3 | c: ℝ; 4 | def Cell(c: ℝ){ 5 | this.c=c; 6 | } 7 | } 8 | 9 | def main(){ 10 | cells := array(1,array(1,Cell(0))); 11 | cells[0][0] = Cell(1); 12 | for flow in [0..2){ 13 | cells[0][0].c -= uniform(0,1); 14 | } 15 | return cells[0][0].c; // expected: ((-c+1)·[-c≤0]·[c≠0]+[c≠0]·[c≤0]·c+[c≤0])·[-1+-c≤0]·[-1+c≤0] 16 | } 17 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/arrayDemo.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | 3 | def main(){ 4 | //a := [flip(1/2),flip(1/2),flip(1/2),flip(1/2),flip(1/2),flip(1/2),flip(1/2)]; 5 | //return a; 6 | return (flip(1/2),flip(1/2),flip(1/2),flip(1/2),flip(1/2),flip(1/2),flip(1/2)); // expected: TODO: (1/2·δ(0)[r₁]+1/2·δ(1)[r₁])·(1/2·δ(0)[r₂]+1/2·δ(1)[r₂])·(1/2·δ(0)[r₃]+1/2·δ(1)[r₃])·(1/2·δ(0)[r₄]+1/2·δ(1)[r₄])·(1/2·δ(0)[r₅]+1/2·δ(1)[r₅])·(1/2·δ(0)[r₆]+1/2·δ(1)[r₆])·(1/2·δ(0)[r₇]+1/2·δ(1)[r₇]) 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/arrayExpectation.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := [0,1]; 3 | return Expectation(x[uniformInt(0,1)]); // expected: δ(1/2)[r] 4 | } 5 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/arrayExpectation2.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := [1,2]; 4 | k := 1; 5 | l := Expectation(x[uniformInt(0,1)]); 6 | return (k,l); // expected: δ(1)[k]·δ(3/2)[l] 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/arrayLength.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | return array(uniformInt(1,4)/2,0); // expected: 1/4·δ([ξ₁ ↦ 0] (1))[r]+1/4·δ([ξ₁ ↦ 0] (2))[r] 4 | } 5 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/arrayLoop.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | a := array(11); 3 | r := 0; 4 | for i in [0..5){ a[i]=i+1; } 5 | for i in [0..5){ r+=a[i]; } 6 | x := flip(1/2); 7 | r += x; 8 | b := array(r-x); 9 | return r; // expected: 1/2·δ(15)[r]+1/2·δ(16)[r] 10 | } 11 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/arrayMethodCall.psi: -------------------------------------------------------------------------------- 1 | dat Cell{ 2 | x : ℝ; 3 | def Cell(x : ℝ){ 4 | this.x = x; 5 | } 6 | def inc(i){ 7 | x = x + i; 8 | } 9 | } 10 | 11 | def main(){ 12 | a := [Cell(0),Cell(10)]; 13 | for i in [0..2){ 14 | a[uniformInt(0,1)].inc(1); 15 | } 16 | return a[0]; // expected: 1/2·δ({.x ↦ 1})[a₀]+1/4·δ({.x ↦ 0})[a₀]+1/4·δ({.x ↦ 2})[a₀] 17 | } 18 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/arrayNonInt.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | a := [1]; 3 | return a[1/2]; // expected: 0 4 | } 5 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/arrayRandomLength.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | a := if flip(1/4) { [1,2,3] } else { [1,2] }; 3 | return a[uniformInt(0,2)]; // expected: 1/12·δ(3)[aᵢ]+1/3·δ(1)[aᵢ]+1/3·δ(2)[aᵢ] 4 | } 5 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/assert.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | assert(flip(1/3)); 3 | return (); // expected: 1/3 4 | } 5 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/badbernoulli.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := uniform(-1,2); 3 | y := flip(x); 4 | return y; // expected: 1/6·δ(0)[y]+1/6·δ(1)[y] 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/baduniformint.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := uniformInt(0,-1); 3 | return; // expected: 0 4 | } 5 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/bernoulli_comp.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := bernoulli(1/2); 3 | y := x<=1; 4 | z := x<1; 5 | return (y,z); // expected: 1/2·δ(0)[z]·δ(1)[y]+1/2·δ(1)[y]·δ(1)[z] 6 | // TODO: maybe it makes sense to manipulate this in factorized form; certainly it should be returned that way 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/bernoulli_ite.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := bernoulli(1/2); 3 | y := if x { x } else { bernoulli(1/2); }; 4 | return y; // expected: 1/4·δ(0)[y]+3/4·δ(1)[y] 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/bertrand.psi: -------------------------------------------------------------------------------- 1 | // TODO: formulate in terms of multi-dimensional arrays 2 | 3 | def main(){ 4 | whichBox := uniformInt(1,3); 5 | isRed := if whichBox==1 { 1 } else { if whichBox==2 { 0 } else { flip(1/2); } }; 6 | observe(isRed); 7 | return whichBox; // expected: 1/3·δ(3)[whichBox]+2/3·δ(1)[whichBox] 8 | } 9 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/beta.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | r := beta(1/2,2); 3 | return r; // expected: (-3/4·r+3/4)·[-1+r≤0]·[-r≤0]·⅟√̅r 4 | } 5 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/beta1.psi: -------------------------------------------------------------------------------- 1 | //skipped 2 | 3 | def main() { // ~1 minute 4 | 5 | x := beta(2.0,2.0); 6 | y := x; 7 | 8 | x2 := beta(2.0,2.0); 9 | 10 | y = y + x2; 11 | 12 | x3 := beta(2.0,2.0); 13 | y = y + x3; 14 | 15 | x4 := beta(2.0,2.0); 16 | y = y + x4; 17 | 18 | return 0.001*y; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/binfsymex/compare.psi: -------------------------------------------------------------------------------- 1 | // Compare benchmark. Partially supported. 2 | // This is buggy: it does not actually compute whether a <= b. 3 | // TODO: Original code uses arrays, this should be rewritten. 4 | 5 | def main(){ // compare 6 | r := true; 7 | //s := true; 8 | // n := 100, TODO: allow 9 | repeat 100{ 10 | a := flip(1/2); 11 | b := flip(1/2); 12 | //r = r && (a <= b); 13 | r = a <= b || a == b && r; 14 | //s = b < a || a == b && r; 15 | //r = r*(a+b); 16 | //r = r*a; 17 | } 18 | return r; // expected: 1/4·δ(0)[r]+3/4·δ(1)[r] 19 | } 20 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/binfsymex/compare_fixed.psi: -------------------------------------------------------------------------------- 1 | // Compare benchmark. What was probably intended. 2 | // (Original code uses arrays, this should be rewritten.) 3 | // TODO: why is this so slow? (Try n=100). 4 | 5 | def main(){ // compare 6 | r := true; 7 | x := true; 8 | n := 10; 9 | repeat n{ 10 | a := flip(1/2); 11 | b := flip(1/2); 12 | if(x && a != b){ 13 | r = a 0 { return true ; } 10 | days[bday] += 1; 11 | } 12 | return false; // expected: 19/49·δ(1)[r]+30/49·δ(0)[r] 13 | } 14 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/birthday3.psi: -------------------------------------------------------------------------------- 1 | // By: Everett Hildenbrandth 2 | 3 | def main() { 4 | d := 7; 5 | p := 3; 6 | days := array(d,0); 7 | for i in [0..p) { 8 | bday := uniformInt(0,d-1); 9 | if days[bday] > 0 { return true ; } 10 | days[bday] = 1; 11 | } 12 | return false; // expected: 19/49·δ(1)[r]+30/49·δ(0)[r] 13 | } 14 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/bitwiseOps.psi: -------------------------------------------------------------------------------- 1 | 2 | def swap(a,b){ 3 | x:=a,y:=b; 4 | x xorb= y; 5 | y xorb= x; 6 | x xorb= y; 7 | return (x,y); 8 | } 9 | 10 | def main(){ 11 | x := 5 ⊕ 3; 12 | y := 2134678 | 1287122; 13 | z := 2134678 & 1287122; 14 | w := 5; 15 | w ⊕= 5; 16 | assert(!w); 17 | return (x,y,z,swap(x,y),~0); // expected: δ(-1)[r₂]·δ(33426)[z]·δ(3388374)[y]·δ(6)[x]·δ(y,6)[r₁] 18 | } 19 | 20 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/builtInOverride.psi: -------------------------------------------------------------------------------- 1 | 2 | dat Distribution[a]{ 3 | x: a; 4 | def Distribution(x: a){ 5 | this.x=x; 6 | } 7 | } 8 | 9 | def sample[a](d: Distribution[a]){ 10 | return d.x; 11 | } 12 | 13 | def main(){ 14 | x := Distribution(4); 15 | k := ()=>sample(x); 16 | array := 4; 17 | return k()+array; // expected: δ(8)[r] 18 | } 19 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/builtInOverride2.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | array := (a,b)=>(a,b); 4 | return array(3,0); // expected: δ(0)[r₂]·δ(3)[r₁] 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/builtInOverride3.psi: -------------------------------------------------------------------------------- 1 | // compilation errors 2 | 3 | dat Distribution[a]{ 4 | x: a; 5 | def Distribution(x: a){ 6 | this.x=x; 7 | } 8 | } 9 | 10 | def main(){ 11 | x := Distribution(4); 12 | k := ()=>sample(x); // error 13 | return k(); 14 | } 15 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/categorical.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | a := [0,0,0]; 4 | k := uniformInt(1,3); 5 | for i in [0..3) { a[i] = flip((i+1)/3)/k; } 6 | x := categorical(a); 7 | return x; // expected: 31/162·δ(2)[x]+7/162·δ(0)[x]+8/81·δ(1)[x] 8 | } 9 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/categorical2.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := [0.2,0.3,0.5]; 3 | return categorical(x); // expected: 1/2·δ(2)[r]+1/5·δ(0)[r]+3/10·δ(1)[r] 4 | } 5 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/categorical3.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | a := [flip(1/3)/3,flip(2/3)/3,1/3]; 4 | x := categorical(a); 5 | return x; // expected: 2/27·δ(0)[x]+2/27·δ(1)[x]+2/27·δ(2)[x] 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/categorical4.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := categorical([1/2,1/2]); 4 | a := [[0.5,0.4,0.1],[0.3,0.7]]; 5 | y := categorical(a[x]); 6 | return y; // expected: 1/20·δ(2)[y]+11/20·δ(1)[y]+2/5·δ(0)[y] 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/cauchy.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | return cauchy(1,2); // expected: [∫dξ₁⅟(-1/2·ξ₁·π+1/4·ξ₁²·π+5/4·π)≠0]·⅟((∫dξ₁⅟(-1/2·ξ₁·π+1/4·ξ₁²·π+5/4·π))·1/4·r²·π+(∫dξ₁⅟(-1/2·ξ₁·π+1/4·ξ₁²·π+5/4·π))·5/4·π+-(∫dξ₁⅟(-1/2·ξ₁·π+1/4·ξ₁²·π+5/4·π))·r·π·1/2) 4 | // TODO: evaluate normalization constant 5 | // TODO: simplify (1/2)/(1/2·x+1/4) 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/ceilSmallX.psi: -------------------------------------------------------------------------------- 1 | def ceilSmallX(x){ 2 | r := 0; 3 | for i in [0..4){ 4 | if x>r { r += 1; } 5 | } 6 | return r; 7 | } 8 | 9 | def main(){ 10 | r := ceilSmallX(2.3); 11 | return r; // expected: δ(3)[r] 12 | } 13 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/chiSquared.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := gauss(0,1); 4 | return x^2; // expected: [-r≤0]·[r≠0]·[∫dξ₁[-ξ₁≤0]·[ξ₁≠0]·⅟e^(1/2·ξ₁)·⅟√̅ξ̅₁≠0]·⅟(∫dξ₁[-ξ₁≤0]·[ξ₁≠0]·⅟e^(1/2·ξ₁)·⅟√̅ξ̅₁)·⅟e^(1/2·r)·⅟√̅r 5 | // TODO: prove that normalization constant is 1. 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/chiSquared2.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(k){ 3 | return expectation(ChiSquared(k)); // expected: TODO: δ(0)[-r₁+k] 4 | } 5 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/chiSquared3.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | return chiSquared(2); // expected: 1/2·[-r≤0]·⅟e^(1/2·r) 3 | } 4 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/chiSquared4.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | return gauss(0,1)^2+gauss(0,1)^2; // expected: TODO: 1/2·[-r₁≤0]·⅟e^(1/2·r₁) 3 | } 4 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/cobserve.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := uniform(0,1); 4 | y := uniform(x,2*x); 5 | cobserve(y,2/3); 6 | return x; // expected: [-2/3+x≤0]·[-x+1/3≤0]·⅟log(2)·⅟x 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/coin_bias_small.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | p := uniform(0,1); 3 | x1 := flip(p); 4 | observe(x1==1); 5 | x2 := flip(p); 6 | observe(x2==1); 7 | x3 := flip(p); 8 | observe(x3==1); 9 | x4 := flip(p); 10 | observe(x4==1); 11 | x5 := flip(p); 12 | observe(x5==0); 13 | return p; // expected: (-30·p⁵+30·p⁴)·[-1+p≤0]·[-p≤0] 14 | } 15 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/coin_bias_small_nice.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | p := uniform(0,1); 3 | r := [1,1,0,1,0]; 4 | for i in [0..r.length){ 5 | observe(flip(p)==r[i]); 6 | } 7 | return p; // expected: (-120·p⁴+60·p³+60·p⁵)·[-1+p≤0]·[-p≤0] 8 | } 9 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/colorado/cav-example-2.psi: -------------------------------------------------------------------------------- 1 | // skipped: this has unbounded loops 2 | 3 | def main(){ 4 | h:=0; 5 | t:=10; 6 | //while h<=t{ 7 | repeat 6{if(h<=t){ 8 | flip_guard := uniform(0,1); 9 | if flip_guard <= 1/2{ 10 | h+=uniform(0,10); 11 | } 12 | t = t+1; 13 | }} 14 | r := h-t; 15 | // estimateProb(r > 1); 16 | //p := r>1; 17 | //p := h<=t; 18 | return r; 19 | } 20 | 21 | /*h = 0.0; 22 | t = 10.0; 23 | while (h <= t) do 24 | flip_guard = unifReal(0.0, 1.0); 25 | if (flip_guard <= 0.5) 26 | then 27 | h = h + unifReal(0.0, 10.0) 28 | end; 29 | t = t + 1.0 30 | end; 31 | estimateProb(h-t > 1.0)*/ 32 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/colorado/cav-example-7.psi: -------------------------------------------------------------------------------- 1 | // skipped: this contains unbounded loops 2 | 3 | def main(){ 4 | count := 0; 5 | i := 1; 6 | //while(i < 5) { 7 | repeat 10{ if i < 5 { 8 | count = count + 1; 9 | flip_guard1 := uniform(0, 1); 10 | if (flip_guard1 <= 1-i/5){ 11 | i = i + 1; 12 | } 13 | }} 14 | return count; 15 | /*estimateProb(count <= 0); 16 | estimateProb(count <= 10); 17 | estimateProb(count <= 25); 18 | estimateProb(count <= 50); 19 | estimateProb(count <= 100); 20 | estimateProb(count <= 250); 21 | estimateProb(count <= 500); 22 | estimateProb(count <= 1000)*/ 23 | } 24 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/colorado/probabilistic-program-benchmarks/cav-example-1.imp: -------------------------------------------------------------------------------- 1 | x = 0.0; 2 | N = 500; 3 | i = 0; 4 | while (i < N) do 5 | x = x + unifReal(0.0,1.0); 6 | i = i + 1 7 | end; 8 | estimateProb(x <= 0.0); 9 | estimateProb(x <= 50.0); 10 | estimateProb(x <= 100.0); 11 | estimateProb(x <= 150.0); 12 | estimateProb(x <= 200.0); 13 | estimateProb(x <= 250.0); 14 | estimateProb(x <= 300.0); 15 | estimateProb(x <= 350.0); 16 | estimateProb(x <= 400.0); 17 | estimateProb(x <= 450.0); 18 | estimateProb(x <= 500.0) 19 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/colorado/probabilistic-program-benchmarks/cav-example-2.imp: -------------------------------------------------------------------------------- 1 | h = 0.0; 2 | t = 10.0; 3 | while (h <= t) do 4 | flip_guard = unifReal(0.0, 1.0); 5 | if (flip_guard <= 0.5) 6 | then 7 | h = h + unifReal(0.0, 10.0) 8 | end; 9 | t = t + 1.0 10 | end; 11 | estimateProb(h-t > 1.0) 12 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/colorado/probabilistic-program-benchmarks/cav-example-4.imp: -------------------------------------------------------------------------------- 1 | x = 0; 2 | guard = -1.0; 3 | guard = unifReal(0.0, 1.0); 4 | while (guard >= 0.5) do 5 | x = x + 1; 6 | guard = unifReal(0.0, 1.0) 7 | end; 8 | estimateProb(x <= 0); 9 | estimateProb(x <= 1); 10 | estimateProb(x <= 2); 11 | estimateProb(x <= 3); 12 | estimateProb(x <= 4); 13 | estimateProb(x <= 5); 14 | estimateProb(x <= 6); 15 | estimateProb(x <= 7); 16 | estimateProb(x <= 8); 17 | estimateProb(x <= 9); 18 | estimateProb(x <= 10); 19 | estimateProb(x <= 12); 20 | estimateProb(x <= 14); 21 | estimateProb(x <= 16); 22 | estimateProb(x <= 18); 23 | estimateProb(x <= 20) 24 | 25 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/colorado/probabilistic-program-benchmarks/cav-example-7.imp: -------------------------------------------------------------------------------- 1 | count = 0; 2 | i = 1.0; 3 | while (i < 5.0) do 4 | count = count + 1; 5 | flip_guard1 = unifReal(0.0, 1.0); 6 | if (flip_guard1 <= 1.0 - 0.2*i) 7 | then 8 | i = i + 1.0 9 | end 10 | end; 11 | estimateProb(count <= 0); 12 | estimateProb(count <= 10); 13 | estimateProb(count <= 25); 14 | estimateProb(count <= 50); 15 | estimateProb(count <= 100); 16 | estimateProb(count <= 250); 17 | estimateProb(count <= 500); 18 | estimateProb(count <= 1000) 19 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/colorado/probabilistic-program-benchmarks/example-fig6.imp: -------------------------------------------------------------------------------- 1 | x = unifReal(-1.0,3.0); 2 | c = 0; 3 | while (x <= 4.0) do 4 | x = x + unifReal(-1.0,3.0); 5 | c = c + unifInt(0,2) 6 | end; 7 | estimateProb(c <= 8); 8 | estimateProb(c <= 7); 9 | estimateProb(c <= 6); 10 | estimateProb(c <= 5); 11 | estimateProb(c <= 4); 12 | estimateProb(c <= 3); 13 | estimateProb(c <= 2); 14 | estimateProb(c <= 1) 15 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/colorado/probabilistic-program-benchmarks/example-fig7.imp: -------------------------------------------------------------------------------- 1 | x = 2.0; 2 | lnX = 1.0; 3 | y = unifReal(0.,1.); 4 | while( y < 0.5) do 5 | y = unifReal(0.,1.); 6 | x = x * 2.0; 7 | lnX = lnX + 1.0 8 | end; 9 | estimateProb( x <= 1000.0) 10 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/colorado/probabilistic-program-benchmarks/example4-int.imp: -------------------------------------------------------------------------------- 1 | x = unifInt(-10;10); 2 | y = unifInt(-5;5); 3 | 4 | if (x+y <= 4) then y = y+5 end; 5 | if (x+y >= 3) then x = x + 1 end; 6 | estimateProb(x+y > 10); 7 | estimateProb(x+y > 11); 8 | estimateProb(x+y > 12); 9 | estimateProb(x+y > 13); 10 | estimateProb(x+y > 14); 11 | estimateProb(x+y > 15); 12 | estimateProb(x+y > 16) 13 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/colorado/probabilistic-program-benchmarks/example4.imp: -------------------------------------------------------------------------------- 1 | x = unifReal(-10;10); 2 | y = unifReal(-5;5); 3 | 4 | if (x+y < 4.0) then y = y+5.0 end; 5 | if (x+y >= 3.0) then x = y + 1.0 end; 6 | estimateProb(x+y > 10.); 7 | estimateProb(x+y > 11.); 8 | estimateProb(x+y > 12.); 9 | estimateProb(x+y > 13.); 10 | estimateProb(x+y > 14.); 11 | estimateProb(x+y > 15.); 12 | estimateProb(x+y > 16.) 13 | 14 | 15 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/colorado/probabilistic-program-benchmarks/example5.imp: -------------------------------------------------------------------------------- 1 | x = unifReal(-10.0,10.0); 2 | y = unifReal(-5.0,5.0); 3 | z = unifReal(-100.0,100.0); 4 | 5 | if (x+y+z <= 3.0) then 6 | x = x + 1.; 7 | y = y+1.; 8 | z= z+1. 9 | end; 10 | estimateProb(x+y > z+10.) 11 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/colorado/script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | for i in {1..10}; do cat cav-example-1.prb | sed "s/repeat X/repeat $i/" > tmp.prb && time ../../prob tmp.prb; rm tmp.prb; done 3 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/compare_gauss.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | //x := gauss(0,1); 3 | //y := x<0; 4 | 5 | a := gauss(0,1); 6 | b := gauss(0,1); 7 | c := a < b; 8 | return c; // expected: 1/2·δ(0)[c]+1/2·δ(1)[c] 9 | } 10 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/concat.psi: -------------------------------------------------------------------------------- 1 | def main(a: ℝ[],b: ℝ[],c: ℝ[]){ 2 | assert(((a~b)~c).length==(a~(b~c)).length); 3 | return; // expected: 1 4 | } 5 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/concat2.psi: -------------------------------------------------------------------------------- 1 | dat Cell{ x : ℝ; } 2 | def main(a : Cell[]){ 3 | return ([]:Cell[])~a~([]:Cell[]); // expected: δ(a)[r] 4 | } 5 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/condExponential.psi: -------------------------------------------------------------------------------- 1 | // https://www.quora.com/If-X-and-Y-are-independent-exponential-random-variables-with-parameter-1-What-is-E-X+Y-2-X-1-Y-1 2 | 3 | def main(){ 4 | (x,y) := (exponential(1),exponential(1)); 5 | observe(x>1&&y>1); 6 | return Expectation((x+y)^2); // expected: δ(18)[r] 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/constructorReturn.psi: -------------------------------------------------------------------------------- 1 | 2 | dat Foo{ 3 | x:R; 4 | def Foo(){ 5 | x = 2; 6 | return this; 7 | } 8 | } 9 | 10 | def main(){ 11 | return Foo(); // expected: δ({.x ↦ 2})[r] 12 | } 13 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/curriedDef.psi: -------------------------------------------------------------------------------- 1 | 2 | def k(x:ℝ)(y:ℝ)=>x; 3 | 4 | def main(){ 5 | f := k(3); 6 | g := ((x:ℝ)(y:ℝ)=>x)(3); 7 | return f(2)==g(3); // expected: δ(1)[r] 8 | } 9 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/datMethodCall.psi: -------------------------------------------------------------------------------- 1 | dat Counter{ 2 | x:ℝ; 3 | def Counter(){ 4 | this.x = 0; 5 | } 6 | def foo(){ 7 | this.x += 1; 8 | return (); 9 | } 10 | } 11 | 12 | def main(){ 13 | c := Counter(); 14 | for i in [0..10){ 15 | if flip(1/2){ c.foo(); } 16 | } 17 | return c; // expected: 1/1024·δ({.x ↦ 0})[c]+1/1024·δ({.x ↦ 10})[c]+105/512·δ({.x ↦ 4})[c]+105/512·δ({.x ↦ 6})[c]+15/128·δ({.x ↦ 3})[c]+15/128·δ({.x ↦ 7})[c]+45/1024·δ({.x ↦ 2})[c]+45/1024·δ({.x ↦ 8})[c]+5/512·δ({.x ↦ 1})[c]+5/512·δ({.x ↦ 9})[c]+63/256·δ({.x ↦ 5})[c] 18 | } 19 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/datMethodCall2.psi: -------------------------------------------------------------------------------- 1 | dat GaussCounter{ 2 | x:ℝ; 3 | def GaussCounter(){ 4 | this.x = 0; 5 | } 6 | def foo(){ 7 | this.x += gauss(0,1); 8 | return (); 9 | } 10 | } 11 | 12 | def main(){ 13 | c := GaussCounter(); 14 | for i in [0..2){ 15 | c.foo(); 16 | } 17 | return c; // expected: TODO: simplify this better 18 | } 19 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/datMethodCall3.psi: -------------------------------------------------------------------------------- 1 | dat Filter{ 2 | x: ℝ , v: ℝ, a: ℝ; 3 | def Filter(x: ℝ,v: ℝ, a: ℝ){ 4 | (this.x,this.v,this.a) = (x,v,a); 5 | } 6 | def update(t: ℝ){ 7 | } 8 | } 9 | 10 | 11 | def main(){ 12 | //data := readCSV("data/kalman.csv"); 13 | data := [1,3,6,10,15,13,12]; 14 | filter := Filter(0,0,0); 15 | filter.update(1); 16 | return filter; // expected: δ({.x ↦ 0,.a ↦ 0,.v ↦ 0})[filter] 17 | } 18 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/datSingletonTuple.psi: -------------------------------------------------------------------------------- 1 | 2 | dat Foo{ 3 | x: ℝ; 4 | def Foo(x){ 5 | this.x=x; 6 | } 7 | def foo(){ 8 | return (x,); 9 | } 10 | def bar(){ 11 | return x; 12 | } 13 | } 14 | 15 | def main(){ 16 | f := Foo(2); 17 | k := f.foo()[0]; 18 | f.x = 3; 19 | l := f.bar(); 20 | return (k,l); // expected: δ(2)[k]·δ(3)[l] 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/data/array/array.csv: -------------------------------------------------------------------------------- 1 | 1,2,3 -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/decl.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | // compilation errors 3 | 4 | def foo(x){ 5 | return x; 6 | } 7 | 8 | def main(y: ℝ × ℝ × ℝ × 𝟙):𝟙{ 9 | y = (1,2,3,()); 10 | x:=(3,2,1,()); //y:=2; 11 | x=y; 12 | x=foo(2):ℝ; 13 | (x,y) = (y,x); 14 | f := Filter(1,2,3); 15 | f := 3; 16 | a := array(3); 17 | a[0]=2; 18 | z := a.length; 19 | w := if 2 { 3 }else { array(4) }; 20 | (aa,bb) := (3,4); 21 | xx:=main(y); 22 | return (xx,a[2],aa,bb); 23 | } 24 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/degbeta.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | p := beta(0,0); 3 | observe(flip(p)); 4 | return (p,beta(0,0),beta(1,0),beta(0,1)); // expected: (1/2·δ(0)[r₁]+1/2·δ(1)[r₁])·(δ(0)[p]+δ(1)[p])·[-1+p≤0]·[-p≤0]·p·δ(0)[r₃]·δ(1)[r₂] 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/degcauchy.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | return cauchy(7.34,0); // expected: δ(367/50)[r] 3 | } 4 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/degchisquared.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | return chiSquared(0); // expected: δ(0)[r] 3 | } 4 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/deggamma.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | return gamma(0,1); // expected: δ(0)[r] 3 | } 4 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/deglaplace.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | return laplace(123,0); // expected: δ(123)[r] 4 | } 5 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/degpoisson.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | return poisson(0); // expected: δ(0)[r] 3 | // (if an event happens with rate 0, it happens zero times in any interval) 4 | } 5 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/deguniform.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := uniform(0,0); 3 | return x; // expected: δ(0)[x] 4 | } 5 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/demo.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | //x := 1; 4 | //x += Bernoulli(1/3); 5 | // x += UniformInt(1,10); 6 | x := gauss(0,1); 7 | y := x; 8 | if y<0 { x=3; } 9 | return x; // expected: 1/2·δ(3)[x]+[-x≤0]·⅟e^(1/2·x²)·⅟√̅2·⅟√̅π 10 | } 11 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/demo2.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := flip(1/2); 3 | y := x*x; 4 | return y; // expected: 1/2·δ(0)[y]+1/2·δ(1)[y] 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/demoArray.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | a := [(1,2)]; 3 | return a[1/2][0]; // expected: 0 4 | } 5 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/dependence_example.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := gauss(0,10); 4 | y := gauss(0,10); 5 | a := x < y; 6 | b := x < y; 7 | c := a == b; 8 | c = c^100000000^2*100000002^2^2^2; 9 | return c; // expected: δ(100000032000004800000448000029120001397760051251201464320032947200585728008200192089456640745472004587520019660800052428800065536)[c] 10 | } 11 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/depindepgauss.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | // TODO: make this example illustrate the difference between adding independent and fully dependent gaussians 3 | 4 | def main(){ 5 | x := gauss(0,1); 6 | y := gauss(0,1); 7 | z := x+z; // error 8 | return z; 9 | } 10 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/detcond.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x:=1; 3 | x=x+1; 4 | y:=3; 5 | if y>x { y-=x; } 6 | return y; // expected: δ(1)[y] 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/dirac.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | return dirac(3); // expected: δ(3)[r] 4 | } 5 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/diracObserve.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | d := Dirac(1); 3 | return (){ 4 | a := sample(d); 5 | observe(a==1); 6 | }; // expected: δ(λξ₁. Λξ₂. δ(val())[ξ₂])[r] 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/distributions.psi: -------------------------------------------------------------------------------- 1 | 2 | 3 | def main(){ 4 | x := Dirac(5); 5 | y := expectation(Categorical([1/2,1/3,1/6])); 6 | z := expectation(Gauss(3,4)); 7 | w := sample(Dirac([1,2,3]))[2]; 8 | y = sample(Dirac(y)); 9 | return (x,y,z,w); // expected: δ(2/3)[y]·δ(3)[w]·δ(3·⅟2^(3/2)·√̅8)[z]·δ(Λξ₁. δ(val(5))[ξ₁])[x] 10 | // TODO: simplify ⅟2^(3/2)·√8̅ to 1. 11 | } 12 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/div_gauss.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | X := gauss(0,1); 4 | Y := gauss(0,1); 5 | return X/Y; // expected: [∫dξ₁⅟(1/2·ξ₁²·π+1/2·π)≠0]·⅟((∫dξ₁⅟(1/2·ξ₁²·π+1/2·π))·1/2·r²·π+(∫dξ₁⅟(1/2·ξ₁²·π+1/2·π))·1/2·π) 6 | // TODO: evaluate normalization constant 7 | // TODO: simplify better 8 | } 9 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/divbyzero.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := 3; 4 | y := uniformInt(-3,3); 5 | z := 0; 6 | if flip(1/2){ 7 | z = x/y; 8 | }else{ 9 | z = 2; 10 | } 11 | return (); // expected: 13/14 12 | } 13 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/divbyzero2.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := 3; 3 | y := uniformInt(-3,3); 4 | z := 0; 5 | w := flip(1/2); 6 | repeat 2{ 7 | if flip(1/2){ 8 | z = x/y; 9 | }else{ 10 | z = 2; 11 | } 12 | } 13 | return; // expected: 25/28 14 | } 15 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/divbyzero3.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := 3; 3 | z := 0; 4 | repeat 2{ 5 | if flip(1/2){ 6 | z = x/0; 7 | }else{ 8 | z = 2; 9 | } 10 | } 11 | return (); // expected: 1/4 12 | } 13 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/divbyzero5.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := 3; 3 | z := 0; 4 | repeat 2{ 5 | y := uniformInt(-3,3); 6 | if flip(1/2){ 7 | z = x/y; 8 | }else{ 9 | z = 2; 10 | } 11 | } 12 | return; // expected: 169/196 13 | } 14 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/divbyzero6.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := gauss(0,1); 3 | y := gauss(0,1); 4 | z := x/y; 5 | return; // expected: 1 6 | // (the important thing is that the zero-probability division by zero isn't reported) 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/divbyzero7.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := uniform(-1,1); 3 | y := uniform(-1,1); 4 | z := x/y; 5 | return z; // expected: 1/4·[z=0]+1/8·[-1+-⅟z≠0]·[-1+-⅟z≤0]·[-1+⅟z≤0]·[z≠0]·[z≤0]·⅟z²+1/8·[-1+-⅟z≠0]·[1+⅟z≤0]·[z≠0]·[z≤0]+1/8·[-1+-⅟z≤0]·[-1+⅟z≤0]·[-z≤0]·[-⅟z+1≠0]·[z≠0]·⅟z²+1/8·[-1+-⅟z≤0]·[-1+⅟z≤0]·[z≠0]·⅟z²+1/8·[-z≤0]·[-⅟z+1≠0]·[-⅟z+1≤0]·[z≠0]+1/8·[-z≤0]·[-⅟z+1≤0]·[z≠0]+1/8·[1+⅟z≤0]·[z≠0]·[z≤0] 6 | // TODO: get rid of the case split on [z=0]. 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/divbyzero8.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := 1; 3 | y := uniform(-1,1); 4 | z := x/y; 5 | return (); // expected: 1 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/division.psi: -------------------------------------------------------------------------------- 1 | def main(){ // divide 2 | x := uniform(0,1); 3 | y := uniform(-1,1); 4 | z := x/y; 5 | return (); // expected: 1 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/dollars.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | // https://www.quora.com/If-you-randomly-distribute-13-dollars-among-4-people-what-is-the-expected-difference-between-the-highest-and-lowest-amounts-of-money-received-by-individuals 3 | 4 | def main(){ 5 | d := 3; // 13 6 | p := 2; // 4 7 | m := array(p,0); 8 | for i in [0..d){ 9 | m[uniformInt(0,p-1)]+=1; 10 | } 11 | min := 14; 12 | max := -1; 13 | for i in [0..p){ 14 | if m[i] < min { min = m[i]; } 15 | if m[i] > max { max = m[i]; } 16 | } 17 | r := max-min; 18 | return r; 19 | } 20 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/effsampa/burglar_alarm.psi: -------------------------------------------------------------------------------- 1 | // Benchmark 2. 2 | 3 | def main(){ 4 | earthquake := flip(1/10000); 5 | burglary := flip(1/1000); 6 | alarm := earthquake || burglary; 7 | phoneWorking := flip(if earthquake { 7/10 } else { 99/100 }); 8 | maryWakes := flip(if alarm { if earthquake { 8/10 } else { 6/10 } } else { 2/10 }); 9 | called := maryWakes && phoneWorking; 10 | observe(called); 11 | return burglary; // expected: 2969983/992160802·δ(1)[burglary]+989190819/992160802·δ(0)[burglary] 12 | } 13 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/effsampa/grass_model.psi: -------------------------------------------------------------------------------- 1 | // Benchmark 1. (Quite common in the literature) 2 | 3 | def main(){ 4 | cloudy := flip(1/2); 5 | rain := flip(if cloudy { 4/5 } else { 1/5 }); 6 | sprinkler := flip(if cloudy { 1/10 } else { 1/2 }); 7 | wet_roof := flip(7/10) && rain; 8 | wet_grass := flip(9/10) && rain || flip(9/10) && sprinkler; 9 | observe(wet_grass); 10 | return rain; // expected: (1000/6471+1000/719·[rain=0])·(21/100·δ(0)[rain]+9/100·δ(1)[rain])·(27/100+63/100·[rain=0]+63/100·[rain≠0])+500/719·δ(1)[rain] 11 | // TODO: simplify to 210/719·δ(0)[rain]+509/719·δ(1)[rain] 12 | } 13 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/effsampa/readme.txt: -------------------------------------------------------------------------------- 1 | Missing benchmarks: 2 | Noisy OR 3 | Red Light Game 4 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/elseif.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := 0; 3 | if flip(1/2){ x = 1; } 4 | else if flip(1/2){ x = 2; } 5 | else { x = 3; } 6 | return x; // expected: 1/2·δ(1)[x]+1/4·δ(2)[x]+1/4·δ(3)[x] 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/emptyuniform.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := uniformInt(-1,5); 3 | y := uniform(x,2*x); 4 | return y; // expected: 1/14·[-4+y≤0]·[-y+2≤0]+1/21·[-6+y≤0]·[-y+3≤0]+1/28·[-8+y≤0]·[-y+4≤0]+1/35·[-10+y≤0]·[-y+5≤0]+1/7·[-2+y≤0]·[-y+1≤0]+1/7·δ(0)[y] 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/explog.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x:=exp(1)^100; 3 | return log(exp(2*log(x)))+log(2)+exp(0.5); // expected: δ(200+log(2)+√̅e)[r] 4 | } 5 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/explog2.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := uniform(0,exp(10)); 3 | return log(x); // expected: [-e¹⁰+e^r≤0]·e^(-10+r) 4 | // TODO: simplify Iverson bracket 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/explog3.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := uniform(0,log(10)); 3 | return exp(x); // expected: [-log(10)+log(r)≤0]·[-r+1≤0]·⅟log(10)·⅟r 4 | // TODO: simplify [-log(10)+log(r)≤0] to [-10+r≤0] 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/explog4.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := uniform(0,1); 3 | return 2^x; // expected: [-1+log(r)·⅟log(2)≤0]·[-r+1≤0]·⅟log(2)·⅟r 4 | } 5 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/explog5.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | 3 | def main(){ 4 | x := uniform(0,log(10)/log(2)); 5 | return 2^x; // expected: TODO: simplify this better / faster 6 | // TODO: simplify e^(log(2)+log(5)) to 10. 7 | // TODO: simplify constant Iverson brackets. 8 | } 9 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/exponential.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := exponential(3); 3 | y := x > 1/3; 4 | return y; // expected: (-⅟e+1)·δ(0)[y]+δ(1)[y]·⅟e 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/firstClassArray.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | a := array; 4 | b := array[ℝ]; 5 | assert(b(2,3)[0]==3); 6 | return (a(3,0)[0],a(4,[1,2])[0][0],a(4,[1,2])[1][1]); // expected: δ(0)[r₁]·δ(1)[r₂]·δ(2)[r₃] 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/firstClassBuiltIns.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | f := if (()=>flip)()(1/2) { bernoulli } else { exponential }; 4 | return f(1/2); // expected: 1/4·[-r≤0]·⅟e^(1/2·r)+1/4·δ(0)[r]+1/4·δ(1)[r] 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/firstClassFunctions1.psi: -------------------------------------------------------------------------------- 1 | 2 | def foo(x){ 3 | assert(flip(99/100)); 4 | return x; 5 | } 6 | def bar(x){ 7 | assert(0); 8 | return 2*x; 9 | } 10 | 11 | def main(){ 12 | x:=if flip(1/2) { foo } else { bar }; 13 | y:=x(2); 14 | return y; // expected: 99/200·δ(2)[y] 15 | } 16 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/firstClassFunctions2.psi: -------------------------------------------------------------------------------- 1 | 2 | dat Foo{ 3 | x: ℝ; 4 | def Foo(x){ 5 | this.x=x; 6 | } 7 | def foo(){ 8 | return x; 9 | } 10 | } 11 | 12 | def main(){ 13 | k := 1338; 14 | k += flip(1/2); 15 | def foo(){ 16 | return k; 17 | } 18 | x := foo; // captured by value 19 | y := Foo(1337); 20 | y.x += flip(1/2); 21 | z := y.foo; // captured by value 22 | k = 0; 23 | y.x = 0; // hence these assignments are not visible 24 | return (x(),z()); // expected: (1/2·δ(1337)[r₂]+1/2·δ(1338)[r₂])·(1/2·δ(1338)[r₁]+1/2·δ(1339)[r₁]) 25 | // TODO: keep in factored form 26 | } 27 | 28 | 29 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/firstClassInfer.psi: -------------------------------------------------------------------------------- 1 | 2 | def Dirac[a](x:a):Distribution[a]{ // TODO: make built-in 3 | return infer(()=>x); 4 | } 5 | 6 | def main(){ 7 | k := if flip(1/2) { infer } else { [a](f:𝟙 → a)=>Dirac(f()) }; 8 | return k(()=>flip(1/2)); // expected: 1/2·δ(Λξ₁. 1/2·δ(val(0))[ξ₁]+1/2·δ(val(1))[ξ₁])[r]+1/4·δ(Λξ₁. δ(val(0))[ξ₁])[r]+1/4·δ(Λξ₁. δ(val(1))[ξ₁])[r] 9 | } 10 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/firstClassPolymorphism.psi: -------------------------------------------------------------------------------- 1 | 2 | def id[b](x:b)⇒x; 3 | 4 | def main(){ 5 | f := id: Π[a:*]. a→ a; 6 | g := id: Pi[a:*]. a→ a; 7 | h := id: Π[a:*](x:a). a; 8 | i := id: Pi[a:*](x:a). a; 9 | j := ([a:*,b:*]=>id[a×b]): Π[c:*,d:*](x:c,y:d). c×d; 10 | k := ([a:*,b:*]=>id[a×b]): Pi[c:*,d:*](x:c,y:d). c×d; 11 | l := f[Π[a:*]. a]; 12 | def crash[a:*]: a{ assert(0); } 13 | // return f(g(h(i(j(k(l(crash),0),1))))); // expected: δ(1)[r₂]·δ(λξ₁. Λξ₂. δ(⊥)[ξ₂],0)[r₁] 14 | return l(crash); // expected: δ(λξ₁. Λξ₂. δ(⊥)[ξ₂])[r] 15 | } 16 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/floorCeil.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := floor(uniformInt(1,5)/2); 4 | y := ceil(uniformInt(1,5)/2); 5 | return (x,y); // expected: (1/5·δ(0)[x]+2/5·δ(1)[x]+2/5·δ(2)[x])·(1/5·δ(3)[y]+2/5·δ(1)[y]+2/5·δ(2)[y]) 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/floor_continuous.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | return floor(exponential(1))==0; // expected: TODO: (-⅟e+1)·δ(0)[-r₁+1]+δ(0)[-r₁]·⅟e 3 | } 4 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/forLoop.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | i := 0; 3 | for j in [1..10) { i += j; } 4 | return i; // expected: δ(45)[i] 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/fose-icse/ex2.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | count := 0; 4 | c1 := flip(1/2); 5 | c2 := flip(1/2); 6 | if c1 { count += 1; } 7 | if c2 { count += 1; } 8 | observe(c1 || c2); 9 | return count; // expected: 1/3·δ(2)[count]+2/3·δ(1)[count] 10 | } 11 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/fromMarginal.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := flip(1/2); 3 | y := flip(1/2); 4 | z := sample(Marginal(x+y)); 5 | z = z-x-y; 6 | return z; // expected: 1/16·δ(-2)[z]+1/16·δ(2)[z]+1/4·δ(-1)[z]+1/4·δ(1)[z]+3/8·δ(0)[z] 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/fromMarginalMultiple.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := flip(1/2); 3 | y := flip(1/2); 4 | z := x+y; 5 | (h,k) := sample(Marginal(x,z)); 6 | return (x-h,k-z); // expected: 1/16·δ(-1)[r₁]·δ(0)[r₂]+1/16·δ(-1)[r₁]·δ(2)[r₂]+1/16·δ(-2)[r₂]·δ(1)[r₁]+1/16·δ(0)[r₂]·δ(1)[r₁]+1/4·δ(0)[r₁]·δ(0)[r₂]+1/8·δ(-1)[r₁]·δ(1)[r₂]+1/8·δ(-1)[r₂]·δ(0)[r₁]+1/8·δ(-1)[r₂]·δ(1)[r₁]+1/8·δ(0)[r₁]·δ(1)[r₂] 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/fun/TODO.txt: -------------------------------------------------------------------------------- 1 | mixtureOfGaussians 2 | bayesPointMachine 3 | trueSkill 4 | conference 5 | LDA 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/fun/addFun/max.psi: -------------------------------------------------------------------------------- 1 | def max(a,b){ 2 | r := if a > b { a } else { b }; 3 | return r; 4 | } 5 | 6 | def main(){ 7 | x := gauss(0,1); 8 | y := gauss(0,1); 9 | r := max(x,y); 10 | return r; // expected: (d/dx)⁻¹[e^(-x²)](r·⅟√̅2)·⅟e^(1/2·r²)·⅟π·√̅2 11 | } 12 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/fun/addFun/max_expectation.psi: -------------------------------------------------------------------------------- 1 | def max(a,b){ 2 | r := if a > b { a } else { b }; 3 | return r; 4 | } 5 | 6 | def main(){ 7 | x := gauss(0,1); 8 | y := gauss(0,1); 9 | r := Expectation(max(x,y)); 10 | return r; // expected: δ((∫dξ₁(d/dx)⁻¹[e^(-x²)](ξ₁·⅟√̅2)·ξ₁·⅟e^(1/2·ξ₁²))·⅟π·⅟√̅2+1/2·⅟√̅π)[r] 11 | // TODO: δ(⅟√π̅)[r] // (mathematica is able to determine this.) 12 | } 13 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/fun/addFun/sum.psi: -------------------------------------------------------------------------------- 1 | // TODO: passing arrays to methods 2 | // TODO: array literals 3 | 4 | def main(){ 5 | x := array(3); 6 | for i in [0..3){ x[i] = gauss(0,1); } 7 | // ind := [1,0,1]; 8 | ind := array(3); 9 | ind[0]=1; ind[1]=0; ind[2]=1; 10 | r := 0; 11 | for i in [0..3){ 12 | if ind[i] { r += x[i]; } 13 | } 14 | return r; // expected: 1/2·⅟e^(1/4·r²)·⅟√̅π 15 | } 16 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/fun/coins.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | c1 := flip(1/2); 3 | c2 := flip(1/2); 4 | bothHeads := c1 && c2; 5 | observe(bothHeads == 0); 6 | return (c1,c2,bothHeads); // expected: (1/2·δ(0)[c1]+1/2·δ(1)[c1])·(1/2·δ(0)[c2]+1/2·δ(1)[c2])·(4/3·[c1=0]+4/3·[c1≠0]·[c2=0])·δ(0)[bothHeads] 7 | // TODO: simplify more 8 | } 9 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/fun/count.txt: -------------------------------------------------------------------------------- 1 | 2 | D : |||| 3 | 4 | C : 5 | 6 | DC: || 7 | 8 | C0: 9 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/fun/data/BPM/trainingFeatures1.csv: -------------------------------------------------------------------------------- 1 | 63,16,28,55,22,20 -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/fun/data/BPM/trainingFeatures2.csv: -------------------------------------------------------------------------------- 1 | 38,23,40,27,18,40 -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/fun/data/BPM/trainingFeatures3.csv: -------------------------------------------------------------------------------- 1 | 1,1,1,1,1,1 -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/fun/data/BPM/trainingOutcomes.csv: -------------------------------------------------------------------------------- 1 | 1,0,1,1,0,0 -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/fun/data/LearningGaussian/generate.m: -------------------------------------------------------------------------------- 1 | data = normrnd(0,100,1,100); 2 | csvwrite('data.csv',data); 3 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/fun/evidence/model1.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | evidence := flip(1/2); 3 | if evidence { 4 | coin := flip(1/2); 5 | observe(coin); 6 | } 7 | return evidence; // expected: 1/3·δ(1)[evidence]+2/3·δ(0)[evidence] 8 | } 9 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/fun/evidence/model2.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | evidence := flip(1/2); 4 | coin := 0; 5 | if evidence { 6 | coin1 := flip(1/2); 7 | observe(coin1); 8 | coin = coin1; 9 | }else{ 10 | coin = flip(1/2); 11 | } 12 | return coin; // expected: 1/3·δ(0)[coin]+2/3·δ(1)[coin] 13 | } 14 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/fun/learningGaussian.psi: -------------------------------------------------------------------------------- 1 | // skipped: sample size too large 2 | // TODO: passing arrays 3 | 4 | def main(){ 5 | n := 100; 6 | gaussianData := readCSV("data/LearningGaussian/data.csv"); 7 | //assert(n==gaussianData.length); 8 | 9 | mean := gauss(0,100); 10 | prec := gamma(1,1); 11 | for i in [0..n){ 12 | x := gaussianData[i]; 13 | y := gauss(mean,prec); 14 | cobserve(y,x); 15 | } 16 | //return (mean,prec); 17 | return Expectation(mean); 18 | } 19 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/fun/linearRegression.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | 3 | def main(){ 4 | a := gauss(0,1); 5 | b := gauss(5,0.3^0.5); 6 | invNoise := gamma(1,1); 7 | 8 | // TODO: just use one set of concrete data here 9 | aTrue := gauss(0,1); 10 | bTrue := gauss(5,0.3^0.5); 11 | invNoiseTrue := gamma(1,1); 12 | n := 10; 13 | data := array(n); 14 | for i in [1..n]{ 15 | data[i-1]=gauss(aTrue*i+bTrue,invNoiseTrue); 16 | } 17 | 18 | for i in [1..n]{ 19 | cobserve(data[i-1],gauss(a*i+b,invNoise)); 20 | } 21 | return (a,b,invNoise); // TODO 22 | } 23 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/fun/linearRegressionEquivalent.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | 3 | def main(){ 4 | a := gauss(0,1); 5 | b := gauss(5,0.3^0.5); 6 | invNoise := gamma(1,1); 7 | 8 | // TODO: just use one set of concrete data here 9 | aTrue := gauss(0,1); 10 | bTrue := gauss(5,0.3^0.5); 11 | invNoiseTrue := gamma(1,1); 12 | n := 10; 13 | for i in [1..n]{ 14 | cobserve(gauss(aTrue*i+bTrue,invNoiseTrue),gauss(a*i+b,invNoise)); 15 | } 16 | return (a,b,invNoise); 17 | } 18 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/fun/mixtureOfGaussians.psi: -------------------------------------------------------------------------------- 1 | // skipped: sample size too large 2 | // TODO: improve method calls 3 | // TODO: allow returning arrays 4 | // TODO: dirichlet distribution 5 | 6 | 7 | def main(){ 8 | p := array(2); 9 | p[0]=1;p[1]=1; 10 | weights := dirichlet(p);// Dirichlet([1,1]); 11 | 12 | } 13 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/fun/murderMystery.psi: -------------------------------------------------------------------------------- 1 | // skipped: need multiple return values 2 | 3 | def mystery(b){ 4 | aliceDunnit := flip(0.3); 5 | withGun := if aliceDunnit { flip(0.03) } else { flip(0.8) }; 6 | return (aliceDunnit,withGun); 7 | } 8 | 9 | def gunFoundAtScene(gunFound){ 10 | (aliceDunnit, withGun) := mystery(true); 11 | observe(withGun == gunFound); 12 | return aliceDunnit; 13 | } 14 | 15 | def main(){ 16 | posterior := gunFoundAtScene(true); 17 | return posterior; // expected: 560·δ(0)[posterior]·⅟569+9·δ(0)[-posterior+1]·⅟569 18 | } 19 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/fun/murderMysteryEq.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | gunFound := true; 4 | aliceDunnit := flip(0.3); 5 | withGun := if aliceDunnit { flip(0.03) } else { flip(0.8) }; 6 | observe(withGun == gunFound); 7 | posterior := aliceDunnit; 8 | return posterior; // expected: 560/569·δ(0)[posterior]+9/569·δ(1)[posterior] 9 | } 10 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/fun/truncatedGaussian/truncatedGaussianA.psi: -------------------------------------------------------------------------------- 1 | // TODO: array literals 2 | // TODO: returning arrays 3 | 4 | def main(){ 5 | //a := [0,0.1,1.0] 6 | a := array(3); 7 | a[0]=0; a[1]=0.1; a[2]=1; 8 | result := array(3); 9 | for i in [0..3){ 10 | result[i] = gauss(0,1); 11 | } 12 | for i in [0..3){ 13 | observe(a[i] > result[i]); 14 | } 15 | return (result[0],result[1],result[2]); // expected: [-1+result₂≤0]·[-1/10+result₁≤0]·[-result₁+1/10≠0]·[-result₂+1≠0]·[result₀≠0]·[result₀≤0]·e^(-1/2·result₀²+-1/2·result₁²+-1/2·result₂²)·⅟(d/dx)⁻¹[e^(-x²)](1/10·⅟√̅2)·⅟(d/dx)⁻¹[e^(-x²)](⅟√̅2)·⅟√̅2·⅟√̅π 16 | } 17 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/fun/truncatedGaussian/truncatedGaussianB.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | a := [0,0.1,1.0]; 4 | y := gauss(0,1); 5 | result := array(3); 6 | for i in [0..3){ 7 | result[i] = y; 8 | } 9 | for i in [0..3){ 10 | observe(a[i] > result[i]); 11 | } 12 | return (result[0],result[1],result[2]); // expected: [result₂≠0]·[result₂≤0]·δ(0)[-result₀+result₁]·δ(0)[-result₂+result₁]·⅟e^(1/2·result₂²)·⅟√̅π·√̅2 13 | } 14 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/functionValues.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | 3 | dat Dat{ 4 | x: ℝ; 5 | def Dat(x){ this.x=x; } 6 | def query(){ 7 | return x; 8 | } 9 | } 10 | 11 | def main(){ 12 | d := Dat(4); 13 | y := d.query; 14 | return y; 15 | } 16 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/fwdRef.psi: -------------------------------------------------------------------------------- 1 | 2 | dat A{ 3 | b: B[]; 4 | def A(b: B[]){ 5 | this.b=b; 6 | } 7 | } 8 | dat B{ 9 | a: A[]; 10 | def B(a: A[]){ 11 | this.a=a; 12 | } 13 | } 14 | 15 | def main(){ 16 | a := A([B([A([]:B[]),A([B([]:A[]),B([]:A[])])]),B([]:A[])]); 17 | return a.b[0].a[0].b; // expected: δ([])[b] 18 | } 19 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/gagandeep.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | // Gagandeep: "My friend put wine on her computer, and it stopped working." 3 | gagandeepMeansLinuxWine := bernoulli(9/10); 4 | computerStopsWorking := if gagandeepMeansLinuxWine { bernoulli(1/1000) } else { bernoulli(9/10); }; 5 | observe(computerStopsWorking); 6 | return gagandeepMeansLinuxWine; // expected: 1/101·δ(1)[gagandeepMeansLinuxWine]+100/101·δ(0)[gagandeepMeansLinuxWine] 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/gamma.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | r := gamma(9,1/2); 3 | return r; // expected: 1/20643840·[-r≤0]·r⁸·⅟e^(1/2·r) 4 | } 5 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/gaussExpectation.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := gauss(1398/89,4/3); 3 | return Expectation(x); // expected: δ(1398/89)[r] 4 | } 5 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/gauss_moments1.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | // TODO: make fast 3 | 4 | 5 | def Variance(x:Distribution[ℝ]){ 6 | //return expectation(then((x)=>x^2)(x))-expectation(x)^2; // TODO: make this work 7 | return Expectation(sample(x)^2)-Expectation(sample(x))^2; 8 | } 9 | 10 | def main(){ 11 | mu := 12; 12 | nu := 36; 13 | g := infer(()=>gauss(mu,nu)); 14 | //g := Uniform(0,1); 15 | mu' := Expectation(sample(g)); 16 | nu' := Variance(g); 17 | nu'' := Expectation(sample(g)^2)-Expectation(sample(g))^2; 18 | assert(nu' == nu''); 19 | return (); // expected: 1 20 | } 21 | 22 | def then[a,b](f: a→ b)(d: Distribution[a])=>infer(()=>f(sample(d))); 23 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/gauss_moments2.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := gauss(0,1); 4 | return Expectation(x^2); // expected: δ(1)[r] 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/gauss_moments3.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := gauss(0,1); 4 | return Expectation(x^6); // expected: δ(15)[r] 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/gaussian-mixture.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | tau := 1; 4 | sigma := 1; 5 | mu1 := gauss(0,tau^2); 6 | mu2 := gauss(0,tau^2); 7 | 8 | x1 := if flip(1/3) { gauss(mu1, sigma) } else { gauss(mu2, sigma) }; 9 | x2 := if flip(1/3) { gauss(mu1, sigma) } else { gauss(mu2, sigma) }; 10 | return (x1,x2); // expected: 1/9·e^(-1/4·x1²+-1/4·x2²)·⅟π+5/18·e^(-1/3·x1²+-1/3·x2²+1/3·x1·x2)·⅟π·⅟√̅3 11 | } 12 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/generalarray.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := ([] : R[]); // declare empty array of real numbers 3 | y := x ~ [1]; // y is the concatenation of x with [1] 4 | 5 | z := array(uniformInt(1,3),[1,2,3]); // declare array of arrays of random size, initialized with [1,2,3] 6 | return (x,y,z); // expected: (1/3·δ([ξ₁ ↦ [ξ₂ ↦ 2·[-ξ₂+1=0]+3·[-ξ₂+2=0]+[ξ₂=0]] (3)] (1))[z]+1/3·δ([ξ₁ ↦ [ξ₂ ↦ 2·[-ξ₂+1=0]+3·[-ξ₂+2=0]+[ξ₂=0]] (3)] (2))[z]+1/3·δ([ξ₁ ↦ [ξ₂ ↦ 2·[-ξ₂+1=0]+3·[-ξ₂+2=0]+[ξ₂=0]] (3)] (3))[z])·δ([])[x]·δ([ξ₁ ↦ 1] (1))[y] 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/genericArrayArg.psi: -------------------------------------------------------------------------------- 1 | 2 | def id[a](x:a)⇒x; 3 | def id_arr[a](x:a[])⇒id[a[]](x); 4 | 5 | def main(){ 6 | return; // expected: 1 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/geometric.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x:=geometric(1/3); 4 | observe(x<=10); 5 | return x; // expected: (∑_ξ₁(2/3)^ξ₁·[-ξ₁≤0]·δ(ξ₁)[x])·59049/175099·[-10+x≤0] 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/geometric2.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(p){ 3 | x:=geometric(p); 4 | observe(x<=10); 5 | return Expectation(x); // expected: [-1+p≤0]·[-11·p¹¹+-165·p⁹+-330·p⁵+-462·p⁷+-55·p³+11·p²+165·p⁴+330·p⁸+462·p⁶+55·p¹⁰+p¹²≠0]·[-p≤0]·δ(0)[((-495·p⁴+-495·p⁸+-66·p²+-66·p¹⁰+-924·p⁶+-p¹²+11·p+12·p¹¹+220·p³+220·p⁹+792·p⁵+792·p⁷)·⅟p²+-11·⅟p+-121·p⁹+-1815·p⁷+-3630·p³+-5082·p⁵+-605·p+11·p¹⁰+121+1815·p²+3630·p⁶+5082·p⁴+605·p⁸)·p²·⅟(-11·p¹¹+-165·p⁹+-330·p⁵+-462·p⁷+-55·p³+11·p²+165·p⁴+330·p⁸+462·p⁶+55·p¹⁰+p¹²)+-r] 6 | // TODO: simplify better 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/geometric3.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | return expectation(Geometric(1/2)); // expected: δ(1)[r] 4 | // TODO: discrete antiderivative for 2ⁱ·i 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/geometric4.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := geometric(1/2); 4 | y := geometric(1/2); 5 | return x = y; // expected: 1/3·δ(1)[r]+2/3·δ(0)[r] 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/geometric5.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := geometric(1/2); 3 | y := geometric(1/2); 4 | assert(x ≠ 2 ∧ y ≠ 3); 5 | return x = y; // expected: 241/768·δ(1)[r]+389/768·δ(0)[r] 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/geometric6.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := geometric(1/2); 4 | y := geometric(1/2); 5 | return x+1==y; // expected: 1/6·δ(1)[r]+5/6·δ(0)[r] 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/geometric7.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | return expectation(Geometric(1/10)); // expected: δ(9)[r] 3 | } 4 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/geometric8.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := geometric(1/2); 3 | return Expectation(x^2); // expected: δ(3)[r] 4 | } 5 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/geometricUniform.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | n := geometric(1/4); 4 | m := uniform(0,n); 5 | return Expectation(m); // expected: δ(3/2)[r] 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/global_constants.psi: -------------------------------------------------------------------------------- 1 | 2 | x := 2; 3 | y := x+3; 4 | z := [1,2,3]; 5 | w := z~[4,5,6]; 6 | 7 | def foo(){ 8 | r := 0; 9 | for i in [0..x){ 10 | r += 4+i; 11 | } 12 | return r; 13 | } 14 | 15 | def main(){ 16 | return (w[y],foo()); // expected: δ(6)[r₁]·δ(9)[r₂] 17 | } 18 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/gossip-sub1.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | N := 2; numSteps := 1; 4 | infected := array(N,0); 5 | infected[0] = 1; 6 | infected[1] = flip(1/2); 7 | newInfected := infected; 8 | if true{ 9 | which := uniformInt(0,N-1); 10 | newInfected[which] = 1; 11 | } 12 | return newInfected[1]; // expected: 1/4·δ(0)[newInfected₁]+3/4·δ(1)[newInfected₁] 13 | } 14 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/if_real.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := uniformInt(-1,1); 3 | r := 1; 4 | if x { r = 2; } 5 | return r; // expected: 1/3·δ(1)[r]+2/3·δ(2)[r] 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/import1.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | 3 | def foo() ⇒ uniform(0,1); 4 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/import2.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | 3 | def bar() ⇒ foo()+foo(); 4 | import import1; 5 | 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/import3.psi: -------------------------------------------------------------------------------- 1 | import import1,import2; 2 | 3 | def main(){ 4 | return foo()*bar(); // expected: (-2·[-2+r≤0]·[-r+1≠0]·[-r+1≤0]·log(r)+-2·[-2+r≤0]·[r≠0]+-[-1+r≤0]·[r≠0]·r+2·[-1+r≤0]·[r≠0]+2·[-2+r≤0]·log(2)+[-2+r≤0]·[-r+1≠0]·[-r+1≤0]·r)·[-r≤0] 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/inferBernoulli.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | return infer(()=>bernoulli(1/2)); // expected: δ(Λξ₁. 1/2·δ(val(0))[ξ₁]+1/2·δ(val(1))[ξ₁])[r] 3 | } 4 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/inferError.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | y := infer((){ assert(0); }); 3 | return y; // expected: δ(Λξ₁. δ(⊥)[ξ₁])[y] 4 | } 5 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/inferExpectation.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | p := gauss(0,1); 4 | k := infer(()=>flip(p)); 5 | return expectation(k); // expected: [-1+r≤0]·[-r≤0]·⅟e^(1/2·r²)·⅟√̅2·⅟√̅π 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/inferExpectation2.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | // TODO: make shape of result deterministic 3 | // TODO: solve integrals 4 | 5 | def then[a,b](d: Distribution[a],f: a→ b){ 6 | return infer(()=>f(sample(d))); 7 | } 8 | 9 | def variance(d: Distribution[ℝ]){ 10 | return expectation(then(d,(x)=>x^2))-expectation(d)^2; 11 | } 12 | 13 | def main(){ 14 | k := infer(()=>gauss(2,3)); 15 | d := variance(then(k,(x)=>x+sample(k))); 16 | (a,b,c) := 17 | (expectation(k), 18 | variance(k), 19 | variance(then(k,(x)=>x+x))); 20 | return (a,b,c,d); // expected: δ(0)[-a+2]·δ(0)[-b+3]·δ(0)[-c+12]·δ(0)[-d+6] 21 | } 22 | 23 | /+def main(a,b){ 24 | return expectation(infer(()=>gauss(a,b))); 25 | }+/ 26 | 27 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/inferSample.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := flip(1/2); 3 | y := infer(()=>x+flip(1/2)); 4 | return (sample(y),sample(y)); // expected: (1/2·δ(-1)[-r₂+r₁]+1/2·δ(0)[-r₂+r₁])·(1/4·δ(1)[r₂]+1/4·δ(2)[r₂])+(1/2·δ(1)[-r₂+r₁]+1/2·δ(r₂)[r₁])·(1/4·δ(0)[r₂]+1/4·δ(1)[r₂]) 5 | // TODO: keep in factored form 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/inferThen.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | // TODO: make shape of output deterministic 3 | 4 | def main(){ 5 | x := flip(1/2); 6 | y := infer(()=>x+1); 7 | k := then((x)=>(x,x+flip(1/2)))(y); 8 | return (sample(then((a,b)=>a+b)(k)),sample(k)[0]); // expected: (δ(0)[-1+-2·r₂+r₁]·⅟2+δ(0)[-2·r₂+r₁]·⅟2)·(δ(0)[-r₂+1]·⅟2+δ(0)[-r₂+2]·⅟2) 9 | //return (sample(then((x:ℝ×ℝ)=>x[0]+x[1])(k)),sample(k)[0]); 10 | } 11 | 12 | def then[a,b](f: a→ b)(d: Distribution[a])=>infer(()=>f(sample(d))); 13 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/inferUniform.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | return infer(()=>uniform(0,1)); // expected: δ(Λξ₁. ∫dξ₂[-1+ξ₂≤0]·[-ξ₂≤0]·δ(val(ξ₂))[ξ₁])[r] 3 | } 4 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/inferZeroProbObs.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := flip(1/2); 4 | y := infer((){ observe(x == flip(1/2)+1); return x; }); 5 | return sample(y); // expected: (1/2·[-r+1=0]+1/2·[-r+2=0])·(1/2·δ(0)[r]+1/2·δ(1)[r])·(2·[-r+1=0]+2·[-r+2=0])·([-r+1=0]+[-r+2=0]) 6 | // TODO: simplify better 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/inferZeroProbObs2.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := flip(1/2); 4 | d := Dirac(); 5 | y := andThen((){ observe(x == flip(1/2)+1); return x; })(d); 6 | return sample(y); // expected: (1/2·[-r+1=0]+1/2·[-r+2=0])·(1/2·δ(0)[r]+1/2·δ(1)[r])·(2·[-r+1=0]+2·[-r+2=0])·([-r+1=0]+[-r+2=0]) 7 | // TODO: simplify better 8 | } 9 | 10 | def andThen[a,b](f: a→ b)(d: Distribution[a])=>infer(()=>f(sample(d))); 11 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/infexpect.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := gauss(gauss(3,1),1); 4 | return Expectation(x); // expected: δ(3)[r] 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/integerDiv.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | k := uniformInt(-10,10); 4 | x := if k == 0 { 0 } else { 10 div k }; 5 | y := uniform(0,100); 6 | y div= 10; 7 | return (x,y); // expected: (1/1050·δ(2)[x]+1/2100·δ(-1)[x]+1/2100·δ(-10)[x]+1/2100·δ(-3)[x]+1/2100·δ(-4)[x]+1/2100·δ(-5)[x]+1/2100·δ(0)[x]+1/2100·δ(10)[x]+1/2100·δ(3)[x]+1/2100·δ(5)[x]+1/420·δ(-2)[x]+1/420·δ(1)[x])·(∫dξ₁[-100+ξ₁≤0]·[-ξ₁≤0]·δ(0)[-y+⌊1/10·ξ₁⌋]) 8 | // TODO: better simplification 9 | } 10 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/inverse.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := uniform(1,2); 3 | y := 1/x; 4 | return y; // expected: [-2+⅟y≤0]·[-⅟y+1≤0]·[y≠0]·⅟y² 5 | // TODO: linearize to get [y+-1≤0]·[-2·y+1≤0]·⅟y² 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/invgamma.psi: -------------------------------------------------------------------------------- 1 | 2 | def main() { 3 | X := gamma(1,1); 4 | Z := 1/X; 5 | return Z; // expected: [-Z≤0]·[Z≠0]·[∫dξ₁[-ξ₁≤0]·[ξ₁≠0]·⅟e^(⅟ξ₁)·⅟ξ₁²≠0]·⅟(∫dξ₁[-ξ₁≤0]·[ξ₁≠0]·⅟e^(⅟ξ₁)·⅟ξ₁²)·⅟Z²·⅟e^(⅟Z) 6 | // TODO: compute normalization constant 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/irwhallperturb.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := uniform(0,1) + uniform(0,1); 3 | eps := 10^(-10); 4 | observe(x==0+eps || x==2-eps); 5 | if x < 1 { x = x - eps } else { x = x + eps } 6 | return x; // expected: TODO: δ(0)[-x+2]·⅟2+δ(0)[-x]·⅟2 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/irwhallzero.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := uniform(0,1) + uniform(0,1); 3 | observe(x==1 || x==2); 4 | return x; // expected: TODO: δ(0)[-x+2]·⅟2+δ(0)[x]·⅟2 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/ite_error.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := flip(1/2); 3 | if x { 4 | assert(x); 5 | observe(x); 6 | }else{ 7 | assert(!x); 8 | observe(!x); 9 | } 10 | 11 | y := if x { 1/x } else { 1/(1-x) }; 12 | z := 0; 13 | if x { z = 1/x; } else { z=1/(1-x); } 14 | 15 | w := if x { flip(1/2) } else { flip(1/3) }; 16 | return (y,z,w); // expected: 5/12·δ(1)[w]·δ(1)[y]·δ(1)[z]+7/12·δ(0)[w]·δ(1)[y]·δ(1)[z] 17 | } 18 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/ite_missing_else.psi: -------------------------------------------------------------------------------- 1 | // compilation errors 2 | 3 | def main(){ 4 | x := flip(1/2); 5 | y := if x { 2 }; // error 6 | return y; 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/kalman-inline.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | // TODO: performance currently depends critically on marginalization order, fix this 3 | 4 | dat Filter{ 5 | x: ℝ , v: ℝ, a: ℝ; 6 | def Filter(x: ℝ,v: ℝ, a: ℝ){ 7 | (this.x,this.v,this.a) = (x,v,a); 8 | } 9 | } 10 | 11 | 12 | def main(){ 13 | data := [1,3,6,10,15]; 14 | filter := Filter(0,0,0); 15 | for i in [0..data.length){ 16 | t := 1; 17 | filter.x += t*filter.v; 18 | filter.v += t*filter.a; 19 | filter.a += t*gauss(0,1); 20 | o := filter.x + t*gauss(0,1); 21 | cobserve(o,data[i]); 22 | } 23 | return filter.x; // expected: e^(-488601·⅟3382+-89·x²·⅟152+699·x·⅟38)·⅟√1̅5̅2̅·⅟√π̅·√8̅9̅ 24 | } 25 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/lambda1.psi: -------------------------------------------------------------------------------- 1 | 2 | dat Foo{ 3 | def Foo(){} 4 | def foo(){} 5 | } 6 | 7 | def foo(t){ 8 | return t; 9 | } 10 | 11 | def main(){ 12 | x := flip(1/2); 13 | q := foo; 14 | f := Foo(); 15 | r := f.foo; 16 | y := (z:ℝ) => x+z+q(z); 17 | def bar(k){ 18 | return (x-y(2))*k; 19 | } 20 | z := bar; 21 | return z(2); // expected: δ(-8)[r] 22 | } 23 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/lambda2-simple.psi: -------------------------------------------------------------------------------- 1 | 2 | def map(lambda: 𝟙→ ℝ){ 3 | a := [lambda()]; 4 | r₁ := [lambda()]~a; 5 | return r₁; 6 | } 7 | 8 | def main(){ 9 | r:=map(()=>flip(1/2)); 10 | return r[0]+r[1]; // expected: 1/2·δ(1)[r]+1/4·δ(0)[r]+1/4·δ(2)[r] 11 | } 12 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/lambda2.psi: -------------------------------------------------------------------------------- 1 | 2 | arrayLength := 3; // TODO: make unnecessary 3 | 4 | def map(lambda: ℝ → ℝ){ 5 | return (arr: ℝ[]){ 6 | result := []; 7 | for i in [0..arrayLength){ 8 | result ~= [lambda(arr[i])]; 9 | } 10 | return result; 11 | } 12 | } 13 | 14 | def all(lambda: ℝ → ℝ){ 15 | return (arr: ℝ[]){ 16 | result := 1; 17 | for i in [0..arrayLength){ 18 | result &&= lambda(arr[i]); 19 | } 20 | return result; 21 | } 22 | } 23 | 24 | def main(){ 25 | g := map(flip); 26 | a := [1/2,1/3,1/4]; 27 | h := (x)=>x!=0; 28 | return all(h)(g(a)); // expected: 1/24·δ(1)[r]+23/24·δ(0)[r] 29 | } 30 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/lambda3.psi: -------------------------------------------------------------------------------- 1 | 2 | def foo(x){ 3 | return ()=>x; 4 | } 5 | 6 | def main(){ 7 | f := foo(1337); 8 | return f(); // expected: δ(1337)[r] 9 | } 10 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/lambda4.psi: -------------------------------------------------------------------------------- 1 | def call(f: ℝ → ℝ → ℝ) ⇒ f(1)(2); 2 | def main(){ 3 | return call((x)⇒ (y) ⇒ x+y); // expected: δ(3)[r] 4 | } 5 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/lambda5.psi: -------------------------------------------------------------------------------- 1 | 2 | def ret(arg: ℝ) ⇒ (k: ℝ → ℝ) ⇒ k(arg); 3 | def bind(me: (ℝ → ℝ) → ℝ, f: ℝ → (ℝ → ℝ)→ ℝ) ⇒ 4 | (k: ℝ → ℝ) ⇒ me((r:ℝ) ⇒ f(r)(k)); 5 | def callCC(f: (ℝ → (ℝ → ℝ) → ℝ) × ℝ → (ℝ → ℝ) →ℝ,arg: ℝ) ⇒ 6 | (k: ℝ → ℝ) ⇒ f(((a:ℝ)⇒(_:ℝ → ℝ)⇒k(a)),arg)(k); 7 | 8 | def main(){ 9 | y := flip(1/2); 10 | def f(cont: ℝ → (ℝ → ℝ) → ℝ, x: ℝ){ 11 | return bind(if x<3 { cont(x) } else { ret(y) }, (a: ℝ)⇒ cont(x+a)); 12 | } 13 | assert(callCC(f,1)((x) ⇒ x)==1); 14 | cont := (x:ℝ) ⇒ (g:ℝ → ℝ) ⇒ g(x); 15 | assert(f(cont,1)((x)=>x)==2); 16 | return callCC(f,3-flip(1/2))((x) ⇒ x); // expected: 1/2·δ(2)[r]+1/4·δ(3)[r]+1/4·δ(4)[r] 17 | } 18 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/lambdaCrash.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | f:=(){assert(0);}; 4 | return f(); // expected: 0 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/lambdaIte.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x:=(x)=>(x){assert(flip(1/2));}; 4 | y:=(){assert(0);}; 5 | return if flip(1/3) { x(1)(2); } else { y(); }; // expected: 1/6 6 | } 7 | 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/laplace.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x1 := laplace(0,1); 4 | observe(x1 < 1); 5 | return x1; // expected: (1/2·[-x1≤0]·⅟e^x1+1/2·[x1≠0]·[x1≤0]·e^x1)·[-1+x1≤0]·[-x1+1≠0]·[-⅟e+2≠0]·⅟(-1/2·⅟e+1) 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/laplace2.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x1 := laplace(-10,1); 4 | observe(x1 < 1); 5 | return x1; // expected: (1/2·[-10+-x1≠0]·[10+x1≤0]·e^(10+x1)+1/2·[-10+-x1≤0]·e^(-10+-x1))·[-1+x1≤0]·[-x1+1≠0]·[-⅟e¹¹+2≠0]·⅟(-1/2·⅟e¹¹+1) 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/lexer.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | r := 1000000000000000000000000000; 3 | s := r+0.5; 4 | return s; // expected: δ(2000000000000000000000000001/2)[s] 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/list.psi: -------------------------------------------------------------------------------- 1 | dat List{ 2 | head: ℝ; 3 | tail: List; 4 | def List(h:ℝ,t:List){ 5 | this.head = h; 6 | this.tail = t; 7 | } 8 | } 9 | 10 | def main(null:List){ 11 | x := List(1,null); 12 | for i in [2..20){ 13 | x = List(i,x); 14 | } 15 | return x; // expected: δ({.head ↦ 19,.tail ↦ {.head ↦ 18,.tail ↦ {.head ↦ 17,.tail ↦ {.head ↦ 16,.tail ↦ {.head ↦ 15,.tail ↦ {.head ↦ 14,.tail ↦ {.head ↦ 13,.tail ↦ {.head ↦ 12,.tail ↦ {.head ↦ 11,.tail ↦ {.head ↦ 10,.tail ↦ {.head ↦ 9,.tail ↦ {.head ↦ 8,.tail ↦ {.head ↦ 7,.tail ↦ {.head ↦ 6,.tail ↦ {.head ↦ 5,.tail ↦ {.head ↦ 4,.tail ↦ {.head ↦ 3,.tail ↦ {.head ↦ 2,.tail ↦ {.head ↦ 1,.tail ↦ null}}}}}}}}}}}}}}}}}}})[x] 16 | } 17 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/logicalAssign.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | a := 1; 4 | a &&= 2; 5 | b := 0; 6 | b ||= 2; 7 | c := 2; 8 | c ||= 0; 9 | return (a,b,c); // expected: δ(1)[a]·δ(1)[b]·δ(1)[c] 10 | } 11 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/manyAdds.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x₁ := gauss(0,1); 4 | x₂ := gauss(0,1); 5 | x₃ := gauss(0,1); 6 | x₄ := gauss(0,1); 7 | x₅ := gauss(0,1); 8 | x₆ := gauss(0,1); 9 | x₇ := x₁+x₂; 10 | x₈ := x₃+x₄; 11 | x₉ := x₆+x₇; 12 | return x₁+2*x₂+3*x₃+4*x₄+5*x₅+6*x₆+7*x₇+8*x₈+9*x₉; // expected: 1/4·⅟e^(1/2256·r²)·⅟√̅1̅4̅1·⅟√̅π 13 | } 14 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/manyOrs.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | 3 | def main(){ 4 | x₁ := uniform(0,2); 5 | x₂ := uniform(0,2); 6 | x₃ := uniform(0,2); 7 | x₄ := uniform(0,2); 8 | x₅ := uniform(0,2); 9 | x₆ := uniform(0,2); 10 | x₇ := x₁+x₂; 11 | x₈ := x₃+x₄; 12 | x₉ := x₆+x₇; 13 | return x₁>1||x₂>1||x₃>1||x₄>1||x₅>1||x₆>1||x₇>1||x₈>1||x₉>1; 14 | } 15 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/manyOrsGaussian.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | 3 | def main(){ 4 | x₁ := gauss(0,1); 5 | x₂ := gauss(0,1); 6 | x₃ := gauss(0,1); 7 | x₄ := gauss(0,1); 8 | x₅ := gauss(0,1); 9 | x₆ := gauss(0,1); 10 | x₇ := x₁+x₂; 11 | x₈ := x₃+x₄; 12 | x₉ := x₆+x₇; 13 | return x₁>1||x₂>1||x₃>1||x₄>1||x₅>1||x₆>1||x₇>1||x₈>1||x₉>1; 14 | } 15 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/marg_test.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := 0; 4 | if flip(1/2){ x=1; } 5 | return x; // expected: 1/2·δ(0)[x]+1/2·δ(1)[x] 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/marginal.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := flip(1/2); 4 | k := Marginal(x); 5 | return (x,sample(k),sample(k),expectation(k)); // expected: (1/2·δ(0)[r₁]+1/2·δ(1)[r₁])·(1/2·δ(0)[r₂]+1/2·δ(1)[r₂])·(1/2·δ(0)[x]+1/2·δ(1)[x])·δ(1/2)[r₃] 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/methodCallError.psi: -------------------------------------------------------------------------------- 1 | def foo(x){ 2 | r := 1/x; 3 | return r; 4 | } 5 | 6 | def main(){ 7 | x := 1/uniformInt(-1,1); 8 | r := foo(uniformInt(-1,1)); 9 | return x; // expected: 2/9·δ(-1)[x]+2/9·δ(1)[x] 10 | } 11 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/methodMultiRetVal.psi: -------------------------------------------------------------------------------- 1 | def Swapped(a,b){ 2 | return (b,a); 3 | } 4 | 5 | def main(){ 6 | (x,y) := Swapped(1,2); 7 | return (x,y); // expected: δ(1)[y]·δ(2)[x] 8 | } 9 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/method_expectation.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | // this does not work anymore 3 | // TODO: update once higher-order inference is in 4 | 5 | def foo(a){ 6 | r:=Expectation(a); 7 | observe(a==1); 8 | return r; 9 | } 10 | 11 | def main(){ 12 | x:=flip(1/2); 13 | r:=foo(x); 14 | observe(x==1); 15 | return (r,x); // expected: 2·δ(0)[-2·r+1]·δ(0)[-x+1] 16 | } 17 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/methods.psi: -------------------------------------------------------------------------------- 1 | def sum(a,b){ 2 | r := a+b; 3 | return r; 4 | } 5 | 6 | def product(a,b){ 7 | r := a*b; 8 | return r; 9 | } 10 | 11 | def main(){ 12 | k := uniform(0,1); 13 | r := sum(1,2); 14 | r += product(r,r); 15 | return (r,k); // expected: [-1+k≤0]·[-k≤0]·δ(12)[r] 16 | } 17 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/mod.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := uniformInt(1,5); 4 | return x % 2; // expected: 2/5·δ(0)[r]+3/5·δ(1)[r] 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/mod2.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | return ((-5)%3,5%-3,5%3); // expected: δ(-1)[r₂]·δ(1)[r₁]·δ(2)[r₃] 4 | } 5 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/moebius.psi: -------------------------------------------------------------------------------- 1 | def main_(){ 2 | x := uniform(0,1); 3 | y := (2*x+1)/(3*x+2); 4 | return y; // expected: ([((-12·y+6)·⅟(-3·y+2)+-3)·⅟((-3+6·y)·⅟(-3·y+2)+2)²+2·⅟((-3+6·y)·⅟(-3·y+2)+2)≠0]·[((-12·y+6)·⅟(-3·y+2)+-3)·⅟((-3+6·y)·⅟(-3·y+2)+2)²+2·⅟((-3+6·y)·⅟(-3·y+2)+2)≤0]·⅟(((-6+12·y)·⅟(-3·y+2)+3)·⅟((-3+6·y)·⅟(-3·y+2)+2)²+-2·⅟((-3+6·y)·⅟(-3·y+2)+2))+[((-6+12·y)·⅟(-3·y+2)+3)·⅟((-3+6·y)·⅟(-3·y+2)+2)²+-2·⅟((-3+6·y)·⅟(-3·y+2)+2)≤0]·⅟(((-12·y+6)·⅟(-3·y+2)+-3)·⅟((-3+6·y)·⅟(-3·y+2)+2)²+2·⅟((-3+6·y)·⅟(-3·y+2)+2)))·[(-1+2·y)·⅟(-3·y+2)+-1≤0]·[-7·y+2+6·y²≤0]·[-y+2/3≠0] 5 | // TODO: simplify better 6 | // TODO: evaluate normalization constant 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/multUniAbsGaussExpectation.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := uniform(0,1); 3 | y := uniform(0,1); 4 | z := abs(gauss(0,1)); 5 | return Expectation(x*y*z); // expected: δ(⅟2^(3/2)·⅟√̅π)[r] 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/multUniExpectation.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := uniform(0,1); 4 | y := uniform(0,1); 5 | return Expectation(x*y); // expected: δ(1/4)[r] 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/mult_bernoulli.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | a := bernoulli(1/2); 4 | b := bernoulli(1/3); 5 | c := a*b; 6 | return (a,c); // expected: (1/2·δ(0)[a]+1/2·δ(1)[a])·(1/3·δ(0)[-a+c]+2/3·δ(0)[c]) 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/mult_gauss.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := gauss(0,1); 4 | y := gauss(0,1); 5 | z := x*y; 6 | return z; // expected: (∫dξ₁(-1/2·[ξ₁≤0]·⅟ξ₁+1/2·[-ξ₁≤0]·⅟ξ₁)·[ξ₁≠0]·e^(-1/2·z²·⅟ξ₁²+-1/2·ξ₁²))·⅟π 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/mult_gauss_uniform.psi: -------------------------------------------------------------------------------- 1 | def main() { 2 | x := gauss(0,1); 3 | y := uniform(0,1); 4 | return x*y; // expected: (∫dξ₁[-1+ξ₁≤0]·[-ξ₁≤0]·[ξ₁≠0]·⅟e^(1/2·r²·⅟ξ₁²)·⅟ξ₁)·⅟√̅2·⅟√̅π 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/mult_uniform.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := uniform(0,1); 3 | y := uniform(0,1); 4 | z := x*y; 5 | return z; // expected: -[-1+z≤0]·[-z≤0]·[z≠0]·log(z) 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/mult_uniform2.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := uniform(0,1); 3 | y := uniform(0,1); 4 | z := uniform(0,1); 5 | w := x*y*z; 6 | return w; // expected: 1/2·[-1+w≤0]·[-w≤0]·[w≠0]·log(w)² 7 | // TODO: confirm that this is correct 8 | } 9 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/mult_uniform3.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | r := 1; 3 | repeat 4{ 4 | r *= uniform(0,1); 5 | } 6 | return r; // expected: -1/6·[-1+r≤0]·[-r≤0]·[r≠0]·log(r)³ 7 | // TODO: confirm that this is correct 8 | } 9 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/mult_uniform4.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | r := 1; 3 | repeat 3{ 4 | k := uniform(0,1); 5 | r *= k; 6 | } 7 | p := r > 1/2; 8 | return p; // expected: (-1/2·log(2)+-1/4·log(2)²+1/2)·δ(1)[p]+(1/2+1/2·log(2)+1/4·log(2)²)·δ(0)[p] 9 | // TODO: confirm using an experiment that this is correct 10 | } 11 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/mult_uniform5.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | r1 := 1; 3 | r2 := 1; 4 | repeat 3{ 5 | k := uniform(0,1); 6 | r1 *= k; 7 | r2 *= uniform(0,1); 8 | } 9 | return (r1,r2); // expected: 1/4·[-1+r1≤0]·[-1+r2≤0]·[-r1≤0]·[-r2≤0]·[r1≠0]·[r2≠0]·log(r1)²·log(r2)² 10 | // TODO: confirm that this is correct 11 | } 12 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/mult_uniform6.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | a := uniform(0,1); 3 | b := uniform(-1,0); 4 | c := a*b; 5 | return c; // expected: -[-1+-c≤0]·[c≠0]·[c≤0]·log(-c) 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/mult_uniform_test.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | 3 | def k(a,b){ 4 | x := uniform(0,1); 5 | y := uniform(0,1); 6 | z := x*y; 7 | assert(zb); 8 | return; // expected: TODO: something with linearized constraints, comparable to ∫dξ₁(-∫dξ₂(∫dξ₃[-ξ₁+ξ₃≤0]·q(ξ₃,ξ₂,γ⃗))·[-ξ₁+ξ₂≤0]·[-ξ₂+ξ₁≠0]+-∫dξ₂∫dξ₃[-ξ₃+ξ₁≠0]·[-ξ₃+ξ₁≤0]·q(ξ₃,ξ₂,γ⃗))·[-1+ξ₁≤0]·[-ξ₁≤0]·[ξ₁≠0]·log(ξ₁) 9 | } 10 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/mult_uniformint.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := uniformInt(0,2); 3 | y := uniformInt(0,2); 4 | z := x*y; 5 | return z; // expected: 1/9·δ(1)[z]+1/9·δ(4)[z]+2/9·δ(2)[z]+5/9·δ(0)[z] 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/mult_uniformint2.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := uniformInt(0,2); 4 | y := uniformInt(0,x); 5 | z := x*y; 6 | return z; // expected: 1/6·δ(1)[z]+1/9·δ(2)[z]+1/9·δ(4)[z]+11/18·δ(0)[z] 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/multiret.psi: -------------------------------------------------------------------------------- 1 | 2 | def p(x,y){ 3 | if x == y{ 4 | return x; 5 | }else{ 6 | return y; 7 | } 8 | } 9 | 10 | def main(){ 11 | assert(p(0,0)==0); 12 | assert(p(0,1)==1); 13 | assert(p(1,0)==0); 14 | assert(p(1,1)==1); 15 | return (); // expected: 1 16 | } 17 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/multiret2.psi: -------------------------------------------------------------------------------- 1 | 2 | def find(haystack: ℝ[], needle){ 3 | for i in [0..3/+haystack.length+/){ // TODO: symbolic loops 4 | if haystack[i] == needle{ 5 | return i; 6 | } 7 | } 8 | return -1; 9 | } 10 | 11 | def main(){ 12 | a:=array(3,0); 13 | for i in [0..a.length){ 14 | a[i] = uniformInt(-1,1); 15 | } 16 | return find(a,0); // expected: 1/3·δ(0)[r]+2/9·δ(1)[r]+4/27·δ(2)[r]+8/27·δ(-1)[r] 17 | } 18 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/multiret3.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := flip(1/2); 4 | if x == 0{ 5 | return 0; 6 | } 7 | if x == 1{ 8 | return 1; // expected: 1/2·δ(0)[r]+1/2·δ(1)[r] 9 | } 10 | assert(0); 11 | } 12 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/multiret4.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | if flip(1/2){ assert(0); return 0; } 3 | return 1; // expected: 1/2·δ(1)[r] 4 | } 5 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/n_if.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := uniformInt(1,10); 3 | i := 1; 4 | y := 0; 5 | repeat 5{ 6 | if flip(1/2) && x == i { 7 | y = y + 1; 8 | } 9 | i = i + flip(1/2); 10 | } 11 | return y; // expected: 1/5120·δ(5)[y]+19/512·δ(2)[y]+23/2560·δ(3)[y]+4153/5120·δ(0)[y]+721/5120·δ(1)[y]+9/5120·δ(4)[y] 12 | } 13 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/neg.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := 1; 3 | r := 0.0; 4 | if !x==r { r=1; } else { r=2; } 5 | return r; // expected: δ(1)[r] 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/negBinomial.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | p := uniform(0,1); 4 | a := expectation(NegBinomial(1,p)); 5 | b := expectation(Geometric(p)); 6 | assert(a!=b); 7 | return (); // expected: 0 8 | } 9 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/negBinomial2.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | return expectation(infer((){ 4 | p := uniform(0,1); 5 | x := negBinomial(2,p); 6 | observe(x<=10); // TODO: make work in unbounded case 7 | return x; 8 | })); // expected: δ(300533/152460)[r] 9 | } 10 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/negativeBoundsCheck.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | a := array(100,0); 4 | return a[-1]; // expected: 0 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/negstddev.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := gauss(0,1); 3 | y := gauss(0,x); 4 | return y; // expected: (∫dξ₁[-ξ₁≤0]·[ξ₁≠0]·e^(-1/2·y²·⅟ξ₁+-1/2·ξ₁²)·⅟√̅ξ̅₁)·1/2·⅟π 5 | // TODO: better simplification (?) 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/neighbour.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | isGirl1 := flip(1/2); 4 | isGirl2 := flip(1/2); 5 | observe(isGirl1 || isGirl2); 6 | bothAreGirls := isGirl1 && isGirl2; 7 | return bothAreGirls; // expected: 1/3·δ(1)[bothAreGirls]+2/3·δ(0)[bothAreGirls] 8 | } 9 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/neighbour_age.psi: -------------------------------------------------------------------------------- 1 | // TODO: why so slow? 2 | 3 | def main(){ 4 | isGirl1 := flip(1/2); 5 | age1 := uniform(1,30); 6 | isGirl2 := bernoulli(1/2); 7 | age2 := uniform(1,30); 8 | if age1 > age2 { 9 | observe(isGirl1); 10 | }else{ 11 | observe(isGirl2); 12 | } 13 | bothAreGirls := isGirl1 && isGirl2; 14 | return bothAreGirls; // expected: 1/2·δ(0)[bothAreGirls]+1/2·δ(1)[bothAreGirls] 15 | } 16 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/neighbour_age_tuesday.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | isGirl1 := flip(1 / 2); 3 | age1 := uniform(1,30); 4 | bornOnATuesday1 := flip(1 / 7); 5 | isGirl2 := flip(1 / 2); 6 | age2 := uniform(1,30); 7 | bornOnATuesday2 := flip(1 / 7); 8 | if age1 > age2 { 9 | observe(isGirl1 && bornOnATuesday1); 10 | } else { 11 | observe(isGirl2 && bornOnATuesday1); 12 | } 13 | bothAreGirls := isGirl1 && isGirl2; 14 | return bothAreGirls; // expected: 1/2·δ(0)[bothAreGirls]+1/2·δ(1)[bothAreGirls] 15 | // TODO: why is this so unreasonably slow? 16 | } 17 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/neighbour_both_bias.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | bias := 4 / 5; 4 | isGirl1 := flip(1 / 2); 5 | isGirl2 := flip(1 / 2); 6 | isGirlAnnounce := -1; 7 | if flip(bias){ 8 | isGirlAnnounce = if flip(1/2) { isGirl1 } else { isGirl2 }; 9 | }else{ 10 | isGirlAnnounce = isGirl1 || isGirl2; 11 | } 12 | observe(isGirlAnnounce); 13 | bothAreGirls := isGirl1 && isGirl2; 14 | return bothAreGirls; // expected: 5/11·δ(1)[bothAreGirls]+6/11·δ(0)[bothAreGirls] 15 | } 16 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/neighbour_randomly_announce.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | isGirl1 := flip(1 / 2); 4 | isGirl2 := flip(1 / 2); 5 | isGirlAnnounce := -1; 6 | if flip(1 / 2){ 7 | isGirlAnnounce = isGirl1; 8 | }else{ 9 | isGirlAnnounce = isGirl2; 10 | } 11 | observe(isGirlAnnounce); 12 | bothAreGirls := isGirl1 && isGirl2; 13 | return bothAreGirls; // expected: 1/2·δ(0)[bothAreGirls]+1/2·δ(1)[bothAreGirls] 14 | } 15 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/neighbour_tuesday.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | isGirl1 := flip(1/2); 4 | bornOnATuesday1 := flip(1/7); 5 | isGirl2 := flip(1/2); 6 | bornOnATuesday2 := flip(1/7); 7 | observe(isGirl1 && bornOnATuesday1 || 8 | isGirl2 && bornOnATuesday2); 9 | bothAreGirls := isGirl1 && isGirl2; 10 | return bothAreGirls; // expected: 13/27·δ(1)[bothAreGirls]+14/27·δ(0)[bothAreGirls] 11 | } 12 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/nestedCall.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | def fun(){ 3 | return 2; 4 | } 5 | if 1 != 0{ 6 | return fun(); // expected: δ(2)[r] 7 | } 8 | assert(0); 9 | } 10 | 11 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/nestedDat.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := flip(1/2); 4 | y := flip(1/3); 5 | dat Foo{ 6 | dat Bar{ 7 | a : ℝ; 8 | b : ℝ; 9 | def Bar(z: ℝ){ 10 | a = x; 11 | b = z; 12 | } 13 | } 14 | b: Bar; 15 | def Foo(){ 16 | b = Bar(y); 17 | } 18 | def foo(){ 19 | return b.b; 20 | } 21 | def bar(){ 22 | return b.a; 23 | } 24 | } 25 | k := Foo().bar(); 26 | l := Foo().foo(); 27 | return (k,l); // expected: (1/2·δ(0)[k]+1/2·δ(1)[k])·(1/3·δ(1)[l]+2/3·δ(0)[l]) 28 | } 29 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/nestedDat2.psi: -------------------------------------------------------------------------------- 1 | 2 | dat Foo{ 3 | x: ℝ; 4 | def Foo(x: ℝ){ 5 | this.x=x; 6 | } 7 | def foo(){ 8 | def bar(){ 9 | return x; 10 | } 11 | return bar(); 12 | } 13 | } 14 | 15 | def main(){ 16 | f := Foo(2); 17 | return f.foo(); // expected: δ(2)[r] 18 | } 19 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/nestedDat3.psi: -------------------------------------------------------------------------------- 1 | 2 | 3 | def main(){ 4 | x := 2; 5 | dat Foo{ 6 | dat Bar{ 7 | k: ℝ; 8 | def Bar(){ 9 | k = x; 10 | } 11 | } 12 | b: Bar; 13 | def Foo(){ 14 | this.b = Bar(); 15 | } 16 | } 17 | f := Foo(); 18 | return f; // expected: δ({.b ↦ {.k ↦ 2,.`outer' ↦ {.`outer ↦ {.x ↦ 2}}},.`outer ↦ {.x ↦ 2}})[f] 19 | } 20 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/nestedDat4.psi: -------------------------------------------------------------------------------- 1 | 2 | dat Foo{ 3 | x: ℝ; 4 | def Foo(x){ 5 | this.x = x; 6 | } 7 | dat Bar{ 8 | y: ℝ; 9 | def Bar(){ 10 | y = x; 11 | } 12 | } 13 | } 14 | 15 | def main(){ 16 | return Foo(3).Bar(); // expected: δ({.y ↦ 3,.`outer ↦ {.x ↦ 3}})[r] 17 | } 18 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/nestedExpectation.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | // this does not work anymore 3 | // TODO: Update once higher-order inference is in. 4 | 5 | def foo(x){ 6 | return Expectation(x); 7 | } 8 | 9 | def bar(y){ 10 | return foo(y); 11 | } 12 | 13 | 14 | def main(){ 15 | return bar(flip(1/3)); // expected: 3·δ(0)[-3·r₁+1] 16 | } 17 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/nestedFun.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := flip(1/2); 4 | y := flip(1/2); 5 | def foo(){ 6 | def bar(){ 7 | return x; 8 | } 9 | def baz(){ 10 | return y-bar(); 11 | } 12 | return bar()+baz(); 13 | } 14 | return foo(); // expected: 1/2·δ(0)[r]+1/2·δ(1)[r] 15 | } 16 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/nestedUniformInt.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := uniformInt(0,2); 3 | y := uniformInt(0,x); 4 | return (x,y); // expected: (1/3·δ(0)[x]+1/3·δ(1)[x]+1/3·δ(2)[x])·(∑_ξ₁[-x+ξ₁≤0]·[-ξ₁≤0]·δ(ξ₁)[y])·[-⌊x⌋≤0]·⅟(1+⌊x⌋) 5 | // TODO: get rid of the ∑ 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/nestedarray.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | a:=[[0],[0]]; 3 | a[0][0]=uniform(0,1); 4 | return a; // expected: ∫dξ₁[-1+ξ₁≤0]·[-ξ₁≤0]·δ([ξ₂ ↦ ([ξ₃ ↦ 0] (1))·[-ξ₂+1=0]+([ξ₃ ↦ ξ₁] (1))·[ξ₂=0]] (2))[a] 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/nocoerce.psi: -------------------------------------------------------------------------------- 1 | // compilation error 2 | 3 | def coerce[b][a](x:a){ 4 | def foo[a]=>x; 5 | return foo[b]; 6 | } 7 | 8 | def main(){ 9 | x := coerce[ℝ[]](3); 10 | return x[0]; 11 | } 12 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/nocoerce2.psi: -------------------------------------------------------------------------------- 1 | // compilation errors 2 | 3 | def coerce[b][a'](x:a'){ 4 | a := 3; 5 | def foo[a]=>x; 6 | def bar[a']=>x; 7 | k := foo; 8 | k = bar; 9 | return foo[b]; 10 | } 11 | 12 | def main(){ 13 | x := coerce[ℝ[]](3); 14 | return x[0]; 15 | } 16 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/nocoerce3.psi: -------------------------------------------------------------------------------- 1 | // compilation error 2 | 3 | a:=3; 4 | def coerce[b][a](x:a){ 5 | def foo[a']=>x; 6 | return foo[b]; 7 | } 8 | 9 | def main(){ 10 | x := coerce[R[]](3); 11 | return x[0]; 12 | } 13 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/nonlinear1.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := uniform(0,1); 4 | y := x*(x+1); 5 | return y; // expected: [-1/4+-y≠0]·[-1/4+-y≤0]·[-3+√̅1̅+̅4̅·̅y≤0]·[-√̅1̅+̅4̅·̅y+1≤0]·⅟√̅1̅+̅4̅·̅y 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/nonlinear2.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := uniform(0,1); 3 | y := x*(x+1)*(x+2); 4 | return y; // expected: TODO: figure this out 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/nonlinear3.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := uniform(0,1); 3 | y := 1/(x*(x+1)); 4 | return y; // expected: TODO: figure this out 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/observeGauss.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | 3 | def doIt(a,b,mu0){ 4 | // a = 1; b = 2; mu0 = 1; 5 | tau := gamma(a,b); 6 | mu := gauss(mu0,mu0*tau); 7 | x1 := gauss(mu,tau); 8 | //x2 := Gauss(mu,tau); 9 | //observe(x1>x2); 10 | observe(x1<0); 11 | return x1; // expected: TODO: fix 12 | } 13 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/observea.psi: -------------------------------------------------------------------------------- 1 | def p(a){ 2 | x := flip(1/2); 3 | observe(x == a); 4 | return x; 5 | } 6 | 7 | def main(){ 8 | y := flip(1/2); 9 | r := p(y); 10 | return r; // expected: 1/2·δ(0)[r]+1/2·δ(1)[r] 11 | // TODO: improve simplification 12 | } 13 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/parameterShadowsLocalVariable.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := uniform(0,1); 3 | def foo(x){ return x; } 4 | return foo(x); // expected: [-1+r≤0]·[-r≤0] 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/parameterized.psi: -------------------------------------------------------------------------------- 1 | def main(arg1,arg2){ 2 | observe(arg1==arg2); 3 | return (arg1,arg2); // expected: [-arg2'+arg1'=0]·δ(0)[-arg1'+arg1]·δ(0)[-arg2'+arg2] 4 | } 5 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/parameterized2.psi: -------------------------------------------------------------------------------- 1 | def main(arg1,arg2){ 2 | if(arg1 != arg2){ 3 | observe(arg1 == arg2); 4 | } 5 | return; // expected: [-arg2+arg1=0] 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/parameterized3.psi: -------------------------------------------------------------------------------- 1 | def main(arg1,arg2){ 2 | if(arg1 != arg2){ 3 | observe(arg1 != arg2); 4 | } 5 | return; // expected: 1 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/paramzero.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(a){ 3 | x := gauss(a,1); 4 | y := x - x; 5 | return y; // expected: δ(0)[y] 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/parens.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | // TODO: make fast 3 | 4 | def main(){ 5 | N := 6; 6 | x := array(N,0); 7 | for i in [0..N){ 8 | x[i] = flip(1/2); 9 | } 10 | ok := 1; 11 | cur := 0; 12 | for i in [0..N){ 13 | if x[i] == 0{ 14 | cur+=1; 15 | }else{ 16 | cur-=1; 17 | if cur<0{ ok = 0; } 18 | } 19 | } 20 | if cur != 0 { ok = 0; } 21 | return ok; // expected: 5/64·δ(0)[-ok+1]+59/64·δ(0)[ok] 22 | /+observe(ok); 23 | return x[1]; // expected: 2·δ(0)[-r₁+1]·⅟5+3·δ(0)[-r₁]·⅟5+/ 24 | } 25 | 26 | /+ 27 | The five sequences are: 28 | 29 | ((())) 30 | (()()) 31 | (())() 32 | ()(()) 33 | ()()() 34 | +/ 35 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/pareto.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | return pareto(3,0.1); // expected: 3/1000·[-r+1/10≤0]·⅟r⁴ 4 | } 5 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/parseLambdaCondition.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | if (x){ return x; }(2)==2{ return 1; } 4 | return 0; // expected: δ(1)[r] 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/parseLambdaCondition2.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | if((x)=>x)(2){ return 1; } 4 | return 0; // expected: δ(1)[r] 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/perforation/sum.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | // TODO: assume? 3 | 4 | def main(){ 5 | s := 0; 6 | sis := 0; 7 | skip := 0; 8 | n := 10; 9 | m := 0; 10 | for i in [0..n) { 11 | x := gauss(0,1); 12 | s = s + x; 13 | 14 | if skip == 0 { 15 | sis = sis + x; 16 | skip = 1 - skip; 17 | m = m + 1; 18 | } 19 | } 20 | 21 | //assume(m > 0); 22 | sis = sis * n * (n-m) / m; 23 | 24 | 25 | res := sis - s; 26 | if res < 0 { res = 0 - res; } 27 | //return res; 28 | return Expectation(res); 29 | } 30 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/permutationLoop.psi: -------------------------------------------------------------------------------- 1 | // TODO: make this fast for reasonable n, for example n≤10, certainly n=3 2 | // ideally n can be a parameter to main 3 | 4 | def main(){ 5 | n := 2; 6 | p := array(n); 7 | for i in [0..n){ p[i] = uniformInt(0,2); } // TODO: support n here 8 | f := array(n); 9 | for i in [0..n){ 10 | for j in [0..n){ 11 | if p[j]==i { f[i] = 1; } 12 | } 13 | } 14 | for i in [0..n){ observe(f[i]); } 15 | for i in [0..n-1){ observe(p[i]==i+1); } 16 | return p[n-1]; // expected: δ(0)[pᵢ] 17 | } 18 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/phantom.psi: -------------------------------------------------------------------------------- 1 | dat Phantom[a]{ 2 | def Phantom(){} 3 | } 4 | 5 | def phantom[a]: Phantom[a]{ 6 | return Phantom[a](); 7 | } 8 | 9 | def main(): Phantom[ℝ]×Phantom[ℝ×ℝ]{ 10 | return (phantom[ℝ],phantom[ℝ×ℝ]); // expected: δ({})[r₁]·δ({})[r₂] 11 | } 12 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/pi.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := uniform(-1,1); 4 | y := uniform(-1,1); 5 | z := x^2 + y^2 <= 1; 6 | return z; // expected: TODO: δ(0)[z]·(1+-π·⅟4)+1/4·δ(1)[z]·π 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/piConstant.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | return π; // expected: δ(π)[r] 4 | } 5 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/piranha.psi: -------------------------------------------------------------------------------- 1 | // Simple example from Joost-Pieter Katoen's talk 2 | // TODO: arrays / tuples 3 | 4 | def main(){ 5 | a := flip(1/2); // 1 -- piranha 6 | b := 1; // add piranha 7 | r := if flip(1/2) { a } else { b }; 8 | observe(r); 9 | return a; // expected: 1/3·δ(0)[a]+2/3·δ(1)[a] 10 | } 11 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/pointmass_comparison.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := uniform(0,1); 4 | if x > 1/2 { 5 | x = 1/2; 6 | } 7 | z := x <= 1/2; 8 | return z; // expected: δ(1)[z] 9 | } 10 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/pointmass_comparison2.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := uniform(0,1); 4 | if x < 1/2 { 5 | x = 1; 6 | } 7 | z := x >= 1; 8 | return z; // expected: 1/2·δ(0)[z]+1/2·δ(1)[z] 9 | } 10 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/pointmass_comparison3.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := uniform(0,1); 4 | if x < 1/2 { 5 | x = 1; 6 | } 7 | z := x > 1; 8 | return z; // expected: δ(0)[z] 9 | } 10 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/poisson.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := poisson(2); 3 | return x; // expected: (∑_ξ₁2^ξ₁·[-ξ₁≤0]·δ(ξ₁)[x]·⅟(∫dξ₂[-ξ₂≤0]·ξ₂^ξ₁·⅟e^ξ₂))·[∑_ξ₁2^ξ₁·[-ξ₁≤0]·⅟(∫dξ₂[-ξ₂≤0]·ξ₂^ξ₁·⅟e^ξ₂)≠0]·⅟(∑_ξ₁2^ξ₁·[-ξ₁≤0]·⅟(∫dξ₂[-ξ₂≤0]·ξ₂^ξ₁·⅟e^ξ₂)) 4 | // TODO: evaluate normalization constant 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/polygon.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x₁ := uniform(-1000,1000); 4 | x₂ := uniform(-1000,1000); 5 | observe((1 <= x₁) & (x₁ <= 3) & (4 <= x₂) & (x₂ <= 8)); 6 | y₁ := 10*x₁+20*x₂; 7 | y₂ := 30*x₁+40*x₂; 8 | return (y₁,y₂); // expected: 1/1600·[-160+-y₂+3·y₁≤0]·[-2·y₁+-30+y₂≤0]·[-3·y₁+80+y₂≤0]·[-y₂+10+2·y₁≤0] 9 | } 10 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/polymorphicDat.psi: -------------------------------------------------------------------------------- 1 | 2 | dat Cell[a]{ 3 | x: a; 4 | def Cell(x: a){ 5 | this.x = x; 6 | } 7 | def map[b](f:a→b)=>Cell(f(x)); 8 | } 9 | 10 | def main(){ 11 | a := Cell([2]); 12 | b := Cell(1); 13 | c := b.map((x)=>[3*x]); 14 | return ([Cell(b.x).map((x)=>x).x][0],a.x[0],c.x[0]); // expected: δ(1)[r]·δ(2)[x₀₁]·δ(3)[x₀₂] 15 | } 16 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/polymorphicRecursion.psi: -------------------------------------------------------------------------------- 1 | def rec[a](f: 𝟙→ a):ℝ{ 2 | return rec(f); 3 | } 4 | 5 | def main(){ 6 | return; // expected: 1 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/polymorphicTupleRet.psi: -------------------------------------------------------------------------------- 1 | def f()=>(1,2); 2 | def call[b](x:𝟙 → b)=>x(); 3 | def main(){ 4 | xs:=call[ℝ×ℝ](f); 5 | return xs; // expected: δ(1)[xs₁]·δ(2)[xs₂] 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/polymorphism.psi: -------------------------------------------------------------------------------- 1 | 2 | // def foo[a, (+): a×a → a](x:a)(y:a)(z:a) ⇒ x+y+z; // TODO: something like this 3 | 4 | def main(){ 5 | x := 1 ⊕ 4; 6 | return x; // expected: δ(5)[x] 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/polymorphism1.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | // TODO: fix nondeterminism 3 | 4 | def id1[a](x:a)=>x; 5 | def id2[a]=>(x:a)=>x; 6 | 7 | def main(){ 8 | f := (x:ℝ)⇒x; 9 | x := 0; 10 | //k := ℝ→ℝ; 11 | def id3[a,b,c](x:a → b,y:a,z:c){ return x(y); } 12 | xs:=id3[ℝ,(ℝ×ℝ),𝟙]((x:ℝ)=>(x+1,231),2,()); 13 | k := [a](x:a)=>x; 14 | return (id1(1),id2[ℝ](2),k(3)); // expected: δ(0)[-r₁+1]·δ(0)[-r₂+2]·δ(0)[-r₃+3] 15 | //k := (a × b); 16 | //return 2 → 3; 17 | } 18 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/polymorphism2.psi: -------------------------------------------------------------------------------- 1 | 2 | def id[a](x:a)=>x; 3 | 4 | def main(){ 5 | x:=2; 6 | return id(()=>x)()+id(3); // expected: δ(5)[r] 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/polymorphism3.psi: -------------------------------------------------------------------------------- 1 | 2 | arrayLength := 3; // TODO: make unnecessary 3 | 4 | def map[a,b](lambda: a → b){ 5 | return (arr: a[]){ 6 | result := ([]:b[]); 7 | for i in [0..arrayLength){ 8 | result ~= [lambda(arr[i])]; 9 | } 10 | return result; 11 | } 12 | } 13 | 14 | def cat2[a](x:a[]){ 15 | return x~x; 16 | } 17 | 18 | def main(){ 19 | r:=map((x)=>x+1)([1,2,3]); 20 | t:=map((x:ℝ×ℝ[])=>x[1]~[x[0]])([(0,r),(1,r),(2,r)]); 21 | s:=cat2([1,2]); 22 | return (r[0],r[1],r[2],t[0][3],t[1][3],s[0],s[1],s[2],s[3]); // expected: δ(0)[t₀₃]·δ(1)[s₀]·δ(1)[s₂]·δ(1)[t₁₃]·δ(2)[r₀]·δ(2)[s₁]·δ(2)[s₃]·δ(3)[r₁]·δ(4)[r₂] 23 | } 24 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/polymorphism4.psi: -------------------------------------------------------------------------------- 1 | 2 | def foo[a,b](x:a×b){ 3 | return x[0]; 4 | } 5 | 6 | 7 | def main(){ 8 | return foo((2,[3,4])); // expected: δ(2)[r] 9 | } 10 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/pow.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := uniformInt(-2,2); 4 | y := uniformInt(-2,2); 5 | return x^y; // expected: 1/25·δ(-1/2)[r]+1/25·δ(-2)[r]+1/25·δ(1/2)[r]+1/25·δ(2)[r]+11/25·δ(1)[r]+2/25·δ(-1)[r]+2/25·δ(0)[r]+2/25·δ(1/4)[r]+2/25·δ(4)[r] 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/pow2.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := -1; 4 | y := uniform(-1,1); 5 | return x^y; // expected: (∫dξ₁[-1+-ξ₁≤0]·[-1+ξ₁≤0]·[-⌊ξ₁⌋+ξ₁=0]·δ(0)[(-1)^ξ₁+-r])·1/2·⅟((∫dξ₁[-1+-ξ₁≤0]·[-1+ξ₁≤0]·[-⌊ξ₁⌋+ξ₁=0])·1/2+(∫dξ₁[-1+-ξ₁≤0]·[-1+ξ₁≤0]·[-⌊ξ₁⌋+ξ₁≠0])·1/2) 6 | // TODO: solve (the probability that y is an integer is 0.) 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/pow3.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := flip(1/2); 4 | y := flip(1/2); 5 | return 0^(x-y); // expected: 1/2·δ(1)[r]+1/4·δ(0)[r] 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/ppaml/birds.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | 3 | def main(x){ 4 | female := flip(0.49); 5 | length := if female { gauss(89,0.2); } else { gauss(92,0.2); }; 6 | cobserve(length,x); 7 | assert(!female); 8 | return length; 9 | } 10 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/ppaml/coffee.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | 3 | def main(){ 4 | x := gauss(22,10); 5 | z := gauss(x,1); 6 | cobserve(z,25); 7 | //return Expectation(x); // TODO 8 | return Expectation(x); 9 | } 10 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/ppaml/data.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | 3 | def main(){ 4 | k := 1; 5 | n := 15; 6 | p := beta(0.01,0.1)*20000+30000; 7 | //observe(Binomial(p,n)==k); // TODO: Binomial 8 | return p; 9 | } 10 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/ppaml/demo32878723.psi: -------------------------------------------------------------------------------- 1 | def max(x,y){ 2 | return if x>y { x } else { y }; 3 | } 4 | 5 | def main(){ 6 | x := gauss(0,1); 7 | y := uniform(0,1); 8 | //observe(x>=0); 9 | //cobserve(x,3); 10 | /*x := uniform(0,1); 11 | y := uniform(0,1); 12 | observe(y==0||x==y);*/ 13 | return max(x,y); // expected: (([-1+r≤0]·r+[-r+1≠0]·[-r+1≤0])·[-r≤0]·⅟e^(1/2·r²)·⅟√̅2+(d/dx)⁻¹[e^(-x²)](r·⅟√̅2)·[-1+r≤0]·[-r≤0])·⅟√̅π 14 | } 15 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/ppaml/election.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | // TODO: get rid of the huge terms and possibly the integral 3 | 4 | def main(){ 5 | p0:=1+276; 6 | p1:=1+304; 7 | p := beta(p0,p1); 8 | n:=2400000; 9 | np:=n*p; 10 | clintonVotes := gauss(np,np*(1-p)); 11 | return clintonVotes>n/2; 12 | } 13 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/ppaml/one-flip.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | bias := uniform(0,1); 4 | bias2 := bias^(1/2); // designed to thwart exact inference 5 | //bias2 := bias^2; 6 | outcome := 1; 7 | observe(flip(bias2) == outcome); 8 | //return Expectation(bias2); // expected: 5·δ(0)[-5·r₁+3] 9 | return bias2; // expected: 3·[-1+bias2²≤0]·[-1+bias2≤0]·[-bias2≤0]·bias2² 10 | //return Bernoulli(bias2); 11 | } 12 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/ppaml/simple-gaussians.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | m := gauss(0,5^(1/2)); 4 | s := 3^(1/2); 5 | cobserve(gauss(m,s),9); 6 | cobserve(gauss(m,s),8); 7 | return (m,uniform(0,1)); // expected: [-1+r≤0]·[-r≤0]·e^(-1/2·m²·⅟√̅5+-289/3·⅟(2·⅟√̅5+4·⅟√̅3)+-m²·⅟√̅3+17·m·⅟√̅3)·√̅1̅/̅2̅·̅⅟̅π̅·̅⅟̅√̅̅5̅+̅⅟̅π̅·̅⅟̅√̅̅3 8 | } 9 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/presentation-example-expectation.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | 3 | def max(a,b){ 4 | r := a; 5 | if b > r { r = b; } 6 | return r; 7 | } 8 | 9 | def main(){ 10 | x := uniform(0,1); 11 | y := gauss(0,1); 12 | z := uniform(0,1); 13 | r := max(x,max(y,z)); 14 | observe(x < 0.75); 15 | if flip(1/2){ assert(r < 0.9); } 16 | return Expectation(r + uniformInt(1,3)); 17 | } 18 | 19 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/presentation-example.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | 3 | def max(a,b){ 4 | r := a; 5 | if b > r { r = b; } 6 | return r; 7 | } 8 | 9 | def main(){ 10 | x := uniform(0,1); 11 | y := gauss(0,1); 12 | z := uniform(0,1); 13 | r := max(x,max(y,z)); 14 | observe(x < 0.75); 15 | if flip(1/2) 16 | { assert(r < 0.9); } 17 | return r + uniformInt(1,3); 18 | } 19 | 20 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/presentation-example2.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := uniform(0,1); 4 | y := bernoulli(1/2); 5 | if y{ 6 | x *= x; 7 | }else{ 8 | z := uniform(0,1); 9 | x += z; 10 | } 11 | return x; // expected: (-1/2·[-x+1≤0]·x+1/2·[-1+x≤0]·[-x+1≠0]·x+[-x+1≤0])·[-2+x≤0]·[-x≤0]+1/4·[-1+√̅x≤0]·[-x≤0]·[x≠0]·⅟√̅x 12 | } 13 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/product.psi: -------------------------------------------------------------------------------- 1 | 2 | def product(a,b){ 3 | r := a*b; 4 | return r; // expected: δ(0)[-r+a·b] 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/productTyRenaming.psi: -------------------------------------------------------------------------------- 1 | def main[τ](x: τ):τ{ 2 | def bar(k: Π[τ:*]. Π(x:τ). τ)⇒k[ℝ](3); 3 | return x; // expected: δ(λξ₁. Λξ₂. δ(val(ξ₁))[ξ₂])[r] 4 | } 5 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/r2/coinBias.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | 3 | def main(){ 4 | observedResults := readCSV("data/CoinBias/tosses.csv"); 5 | bias := beta(2, 5); 6 | tossResults := array(5); 7 | assert(observedResults.length == tossResults.length); 8 | for i in [0..5) { tossResults[i] = flip(bias); } 9 | // observe(tossResults == observedResults); // TODO 10 | for i in [0..5) { observe(tossResults[i] == observedResults[i]); } 11 | //return bias; // expected: (-2·bias+1+bias²)·(-9240·bias+-9240·bias³+13860·bias²+2310+2310·bias⁴)·[-1+bias≤0]·[-bias≤0]·bias⁴ 12 | return bias; 13 | // TODO: better simplification 14 | } 15 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/r2/coinBiasModified.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | 3 | def main(){ 4 | observedResults := readCSV("data/CoinBias/tosses.csv"); 5 | //bias := Beta(2, 5); 6 | bias := gauss(0.5,1); 7 | observe(-1<=bias && bias<=1); 8 | tossResults := array(5); 9 | assert(observedResults.length == tossResults.length); 10 | for i in [0..5) { tossResults[i] = flip(bias); } 11 | // observe(tossResults == observedResults); // TODO 12 | for i in [0..5) { observe(tossResults[i] == observedResults[i]); } 13 | //return bias; // expected: (-2·bias+1+bias²)·(-9240·bias+-9240·bias³+13860·bias²+2310+2310·bias⁴)·[-1+bias≤0]·[-bias≤0]·bias⁴ 14 | return bias; 15 | // TODO: better simplification 16 | } 17 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/r2/data/CoinBias/tosses.csv: -------------------------------------------------------------------------------- 1 | 1,1,0,1,0 -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/r2/data/DigitRecognition/nbPrior.csv: -------------------------------------------------------------------------------- 1 | 0.098717,0.11237,0.0993,0.10218,0.097367,0.09035,0.098633,0.10442,0.097517,0.09915 -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/r2/data/DigitRecognitionEq/extractParams.d: -------------------------------------------------------------------------------- 1 | import std.stdio, std.file, std.conv; 2 | 3 | void main(){ 4 | auto fin=File("nbParams.csv","r"); 5 | foreach(i;1..11) File(text("nbParams",i,".csv"),"w").writeln(fin.readln()); 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/r2/data/DigitRecognitionEq/nbPrior.csv: -------------------------------------------------------------------------------- 1 | 0.098717,0.11237,0.0993,0.10218,0.097367,0.09035,0.098633,0.10442,0.097517,0.09915 -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/r2/data/Hiv/numPersons.csv: -------------------------------------------------------------------------------- 1 | 84 -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/r2/data/TrueSkill_Simple/games.csv: -------------------------------------------------------------------------------- 1 | 0,1,1 2 | 1,2,1 3 | 0,2,1 -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/r2/data/TrueSkill_Simple/players.csv: -------------------------------------------------------------------------------- 1 | 0,1,2 -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/r2/data/survey/answer.csv: -------------------------------------------------------------------------------- 1 | 1,0,1,1,1 -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/r2/data/survey/gender.csv: -------------------------------------------------------------------------------- 1 | 0,1 -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/r2/data/survey/personGender.csv: -------------------------------------------------------------------------------- 1 | 0,1,0,0,1 -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/r2/data/survey/population.csv: -------------------------------------------------------------------------------- 1 | 3141,2718 -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/r2/data/survey2/answer.csv: -------------------------------------------------------------------------------- 1 | 1,0,1,1,0 -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/r2/data/survey2/gender.csv: -------------------------------------------------------------------------------- 1 | 0,1 -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/r2/data/survey2/personGender.csv: -------------------------------------------------------------------------------- 1 | 0,1,0,1,0 -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/r2/data/survey2/population.csv: -------------------------------------------------------------------------------- 1 | 1000,2000 2 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/r2/digitRecognition.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | // data too large, 2D-Arrays not supported 3 | 4 | def main(){ 5 | dataPrior := readCSV("data/DigitRecognition/nbPrior.csv"); 6 | dataParams := readCSV("data/DigitRecognition/nbParams.csv"); 7 | dataX := readCSV("data/DigitRecognition/input.csv"); 8 | probs := array(10); 9 | for i in [0..10){ probs[i] = dataPrior[i]; } 10 | x := array(dataX.length); 11 | y := categorical(probs); 12 | for i in [0..dataX.length){ 13 | x[i] = flip(dataParams[y,i]); 14 | observe(x[i] == dataX[i]); 15 | } 16 | return y; 17 | } 18 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/r2/grass.psi: -------------------------------------------------------------------------------- 1 | def main(){ // didItRain 2 | cloudy := flip(0.5); 3 | rain := 0; sprinkler := 0; 4 | 5 | if (cloudy){ 6 | rain = flip(0.8); 7 | sprinkler = flip(0.1); 8 | }else{ 9 | rain = flip(0.2); 10 | sprinkler = flip(0.5); 11 | } 12 | 13 | temp1 := flip(0.7); 14 | wetRoof := temp1 && rain; 15 | temp2 := flip(0.9); 16 | temp3 := flip(0.9); 17 | wetGrass := temp2 && rain || temp3 && sprinkler; 18 | 19 | observe(wetGrass); 20 | //return rain; // TODO: better simplification for this query? 21 | return Expectation(rain); // expected: δ(509/719)[r] 22 | // TODO: better simplification? 23 | } 24 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/r2/twoCoins.psi: -------------------------------------------------------------------------------- 1 | def main(){ // bothHeads 2 | firstCoin := flip(1/2); 3 | secondCoin := flip(1/2); 4 | bothHeads := firstCoin && secondCoin; 5 | observe(bothHeads == 0); 6 | firstCoin = Expectation(firstCoin); 7 | secondCoin = Expectation(secondCoin); 8 | return (firstCoin,secondCoin); // expected: δ(1/3)[firstCoin]·δ(1/3)[secondCoin] 9 | } 10 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/r2/twoCoinsTuple.psi: -------------------------------------------------------------------------------- 1 | def main(){ // bothHeads 2 | firstCoin := flip(1/2); 3 | secondCoin := flip(1/2); 4 | bothHeads := firstCoin && secondCoin; 5 | observe(bothHeads == 0); 6 | return (firstCoin,secondCoin); // expected: (1/2·δ(0)[secondCoin]+1/2·δ(1)[secondCoin])·(2/3·δ(0)[firstCoin]+2/3·δ(1)[firstCoin])·([firstCoin=0]+[firstCoin≠0]·[secondCoin=0]) 7 | // TODO: simplify more 8 | } 9 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/rayleigh.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x:= rayleigh(10); 4 | return x; // expected: 1/10·[-x≤0]·x·⅟e^(1/20·x²) 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/renormalizeMarginal.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | observe(flip(1/2)); 3 | return expectation(Marginal(uniform(0,1))); // expected: δ(1/2)[r] 4 | } 5 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/rep.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := 0;//Gauss(0,1) + Gauss(1,1); 3 | //repeat 3{ x += Bernoulli(1/2); } 4 | //repeat 100 { x+=1; } 5 | //repeat 100{ x += Bernoulli(1/2); } 6 | repeat 10{ x += flip(1/2); } 7 | //repeat 100 { x*=2; } 8 | //x += Bernoulli(1/2); 9 | return x; // expected: 1/1024·δ(0)[x]+1/1024·δ(10)[x]+105/512·δ(4)[x]+105/512·δ(6)[x]+15/128·δ(3)[x]+15/128·δ(7)[x]+45/1024·δ(2)[x]+45/1024·δ(8)[x]+5/512·δ(1)[x]+5/512·δ(9)[x]+63/256·δ(5)[x] 10 | } 11 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/samplefrom.psi: -------------------------------------------------------------------------------- 1 | 2 | def nice(y){ 3 | x := sampleFrom("(x;y) => [-y<=x]*[x<=y]*x^2",y); 4 | return x; 5 | } 6 | 7 | def main(){ 8 | x := nice(3); 9 | y := nice(4); 10 | return x+y; // expected: (-1/23040·[-1+-r≠0]·[-1+-r≤0]·r⁵+-1/6·[-r+1≤0]·r+-27/512·[-1+-r≠0]·[-1+-r≤0]·r+1/23040·[-1+r≤0]·[-r+1≠0]·r⁵+1/36·[-r+1≤0]·r²+1/36·[1+r≤0]·r²+1/6·[1+r≤0]·r+27/512·[-1+r≤0]·[-r+1≠0]·r+3/256·[-1+-r≠0]·[-1+-r≤0]·r²+3/256·[-1+r≤0]·[-r+1≠0]·r²+4/15·[-r+1≤0]+4/15·[1+r≤0]+81/1280·[-1+-r≠0]·[-1+-r≤0]+81/1280·[-1+r≤0]·[-r+1≠0])·[-7+-r≤0]·[-7+r≤0] 11 | } 12 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/scaleuniform.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := uniform(0,1); 3 | k := 2; 4 | y := k*x; 5 | return y; // expected: 1/2·[-2+y≤0]·[-y≤0] 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/shadowRelabel.psi: -------------------------------------------------------------------------------- 1 | 2 | def foo[a](x: a){ 3 | def bar[a](y:a)=>(x,y); 4 | return bar([1]); 5 | } 6 | 7 | def main(){ 8 | r:=foo(2); 9 | assert(r[0]==2 && r[1][0]==1); 10 | return; // expected: 1 11 | } 12 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/shadowRelabel2.psi: -------------------------------------------------------------------------------- 1 | def foo(){ 2 | def foo(){ 3 | def foo()=>2; 4 | return foo(); 5 | } 6 | return foo(); 7 | } 8 | 9 | def main(){ 10 | return foo(); // expected: δ(2)[r] 11 | } 12 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/shortcut.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := uniformInt(-1,1); 4 | y := if 1/x!=1 || x == 0 { 1 } else { 0 }; 5 | return y; // expected: 1/3·δ(0)[y]+1/3·δ(1)[y] 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/simple_trueskill.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | skill1 := gauss(100,10); 4 | skill2 := gauss(100,10); 5 | perf1 := gauss(skill1,15); 6 | perf2 := gauss(skill2,15); 7 | observe(perf1 > perf2); 8 | return (skill1,skill2); // expected: TODO: simplify better 9 | //p := skill1 > skill2; 10 | //return p; 11 | } 12 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/simple_trueskill_like.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | a := gauss(100,15); 4 | b := gauss(100,15); 5 | c := a > b; 6 | return c; // expected: 1/2·δ(0)[c]+1/2·δ(1)[c] 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/singletonTuples.psi: -------------------------------------------------------------------------------- 1 | 2 | def foo(){ 3 | return (1,); 4 | } 5 | def main(){ 6 | x := foo(); 7 | return (x[0],(2,)); // expected: δ(1)[x₀]·δ(2,)[r] 8 | } 9 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/slice2.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | a := [1,2,3,4]; 4 | r := a[2..3]; 5 | return r; // expected: δ([ξ₁ ↦ 3] (1))[r] 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/square_constraint.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := uniform(-2,2); 3 | if x^2 > 1 { x+=1; } 4 | return x; // expected: 1/4·[-1+-x≤0]·[-3+x≤0]·[-x²+2·x≠0]·[-x²+2·x≤0]+1/4·[-1+x²≤0]·[-2+-x≤0]·[-2+x≤0] 5 | // TODO: linearize the constraints? 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/square_uniform.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := uniform(0,1); 4 | y := x^2; 5 | return y; // expected: 1/2·[-1+√̅y≤0]·[-y≤0]·[y≠0]·⅟√̅y 6 | // TODO: get rid of the square root in the bracket 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/studentt.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := studentT(2); 4 | return x; // expected: ⅟(1+1/2·x²)^(3/2)·⅟(∫dξ₁⅟(1+1/2·ξ₁²)^(3/2)) 5 | // TODO: evaluate normalization constant? 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/sum.psi: -------------------------------------------------------------------------------- 1 | def sum(a,b){ 2 | r := a + b; 3 | return r; // expected: δ(0)[-r+a+b] 4 | } 5 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/sum_truncgauss.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | // http://math.stackexchange.com/questions/831714/sum-of-two-truncated-gaussian 3 | 4 | def tg(μ,σ,a,b){ 5 | x := gauss(μ,σ^2); 6 | observe (x >= a && x <= b); 7 | return x; 8 | } 9 | 10 | def main() { 11 | return tg(5,2,5,8)+tg(1,4,7,9); // expected: TODO: determine normalization 12 | } 13 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/sumunif.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | 3 | def main() { 4 | val := 0; 5 | for j in [0..8) { val = val + uniform(0,j); } 6 | return val; 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/sve/data/tracking/query1.csv: -------------------------------------------------------------------------------- 1 | 5,6 -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/sve/data/tracking/query2.csv: -------------------------------------------------------------------------------- 1 | 5,8 -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/sve/data/tracking/query3.csv: -------------------------------------------------------------------------------- 1 | 3,5,8 -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/sve/data/tracking/query4.csv: -------------------------------------------------------------------------------- 1 | 5,5,6 -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/sve/data/tracking/query5.csv: -------------------------------------------------------------------------------- 1 | 3,5,8,4 -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/sve/data/tracking/query6.csv: -------------------------------------------------------------------------------- 1 | 4,5,5,6 -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/sve/data/tracking/query_sasa.csv: -------------------------------------------------------------------------------- 1 | 5.0,8.0,6.0,7.1,5.5,10.0,6.4,7.5,8.0,8.1 -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/sve/data/tracking/query_twohumps.csv: -------------------------------------------------------------------------------- 1 | 3,3,3,3,9,9,9,9 -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/sve/maple/tracking/query0.txt: -------------------------------------------------------------------------------- 1 | p(d) = limit(1/10*piecewise((-10)+d 0 { x } else { -x }); 5 | return b; // expected: δ(1)[b] 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/toplevelComma.psi: -------------------------------------------------------------------------------- 1 | 2 | x := 1, y := 2; 3 | 4 | def main(){ 5 | return (x,y); // expected: δ(1)[r₁]·δ(2)[r₂] 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/tree.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | // TODO 3 | 4 | dat Tree{ 5 | value: ℝ; 6 | children: Tree[]; 7 | def Tree(value: ℝ,children: Tree[]){ 8 | this.value=value; 9 | this.children=children; 10 | } 11 | def sum(): ℝ{ // TODO 12 | s := 0; 13 | for i in [0..children.length){ 14 | s += children[i].sum(); 15 | } 16 | return s; 17 | } 18 | } 19 | 20 | def main(){ 21 | λ := ([]: Tree[]); 22 | //μ : Tree[] := []; // TODO 23 | ε := Tree(3,λ); 24 | return Tree(1,[ε,Tree(2,[ε,ε])]).sum(); 25 | } 26 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/truefalse.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | r := true; 3 | if true { r = false } 4 | return r; // expected: δ(0)[r] 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/tt.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := uniform(1,10); 3 | //x := UniformInt(1,10); 4 | if x<7 { x+=1; } 5 | /*repeat 10 { 6 | x+=Bernoulli(1/2); 7 | }*/ 8 | return x; // expected: 1/9·[-10+x≤0]·[-x+7≤0]+1/9·[-8+x≤0]·[-x+2≤0]·[-x+8≠0] 9 | } 10 | 11 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/tt2.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x:=1; 3 | x=x+1; 4 | y:=gauss(x,x); 5 | if y>x { y-=x; } 6 | return y; // expected: 1/2·[-2+y≤0]·e^(-1+-1/4·y²+y)·⅟√̅π+1/2·[-y≤0]·[y≠0]·⅟e^(1/4·y²)·⅟√̅π 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/tt2integrate.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x:=1; 3 | x=x+1; 4 | y:=gauss(x,x); 5 | if y>x { y-=x; } 6 | return; // expected: 1 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/tt3.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := gauss(0,1); 3 | y := 0; 4 | if x > 0 { 5 | y = x; 6 | } else { 7 | y = -x; 8 | } 9 | return y; // expected: [-y≤0]·[y≠0]·⅟e^(1/2·y²)·⅟√̅2·⅟√̅π+[-y≤0]·⅟e^(1/2·y²)·⅟√̅2·⅟√̅π 10 | } 11 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/tt3integrate.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := gauss(0,1); 3 | y := 0; 4 | if x > 0 { 5 | y = x; 6 | } else { 7 | y = -x; 8 | } 9 | return; // expected: 1 10 | } 11 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/tt4.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := uniform(0,5); 3 | y := x*x; 4 | return y; // expected: TODO: [-y≤0]·[-25+y≤0]·⅟10·⅟√y̅ 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/tt5.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := uniform(0,5); 3 | y := 0; 4 | if x < 2 { 5 | y = x*x; 6 | }else{ 7 | y = 3; 8 | } 9 | y += x; 10 | return y; // expected: TODO: simplify better 11 | } 12 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/tt6.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := uniform(0,2); 3 | y := 2*x; 4 | return y; // expected: 1/4·[-4+y≤0]·[-y≤0] 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/tt7.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | count := 0; 4 | c1 := flip(1/2); 5 | c2 := flip(1/2); 6 | if c1 { count += 1; } 7 | if c2 { count *= 2; } 8 | observe(c1 && c2); 9 | return count; // expected: δ(2)[count] 10 | } 11 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/tt_ssa2.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x₁ := gauss(0,1); 3 | x₂ := gauss(1,1); 4 | x₃ := gauss(x₁,x₂); 5 | return (x₁,x₂,x₃); // expected: (1/2·[x₂=0]·δ(x₁)[x₃]·⅟π+[x₂≠0]·e^((-1/2·x₁²+-1/2·x₃²+x₁·x₃)·⅟x₂)·⅟2^(3/2)·⅟π^(3/2)·⅟√̅x̅₂)·[-x₂≤0]·e^(-1/2+-1/2·x₁²+-1/2·x₂²+x₂) 6 | //return (x₁,x₂); 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/tupleAssign.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | (x,y,z,w) := (1,2,3,4); 4 | (x,(y,z))[1] = (z,y); 5 | (x,y) = (y,x); 6 | return (x,y,z,w); // expected: δ(1)[y]·δ(2)[z]·δ(3)[x]·δ(4)[w] 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/tupleGauss.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := (gauss(0,1)+gauss(0,1),); 3 | return (x,); // expected: TODO: simplify 4 | } 5 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/tuplePolymorphism.psi: -------------------------------------------------------------------------------- 1 | def id[a](x:a)=>x; 2 | 3 | def main(){ 4 | return (id(),id(3),id(1,[2])); // expected: δ()[r₁]·δ(1,[ξ₁ ↦ 2] (1))[r₃]·δ(3)[r₂] 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/tupleRet.psi: -------------------------------------------------------------------------------- 1 | def a()=>(1,2); 2 | def b()=>a(); 3 | def main(){ 4 | c:=b(); 5 | return c; // expected: δ(1)[c₁]·δ(2)[c₂] 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/tupleUniform.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | a := uniform(0,1); b := uniform(0,1); 3 | x := (a+b,a-b); 4 | return x; // expected: 1/2·[-2+-x₂+x₁≤0]·[-2+x₁+x₂≤0]·[-x₁+-x₂≤0]·[-x₁+x₂≤0] 5 | // TODO: canonicalize intermediate results better, e.g. for ∫dξ₁(∫dξ₂[-1+ξ₂≤0]·[-ξ₂≤0]·δ_x[(ξ₁+ξ₂,-ξ₁+ξ₂)])·[-1+ξ₁≤0]·[-ξ₁≤0] 6 | // E.g. ∫dξ₁∫dξ₂[-1+ξ₁+ξ₂≤0]·[-1+ξ₂≤0]·[-ξ₁+-ξ₂≤0]·[-ξ₂≤0]·δ_x[(2·ξ₂+ξ₁,ξ₁)] 7 | // is another representation of the same distribution 8 | } 9 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/tuples.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | y := (1,2,3); 4 | x := if flip(1/2) { (1,2,y[0]) } else { (2,3,y[2]); }; 5 | return if flip(1/3) { x[0] } else { x[1] }; // expected: 1/2·δ(2)[r]+1/3·δ(3)[r]+1/6·δ(1)[r] 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/tuples2.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := (uniform(0,1),uniform(0,1)); 3 | return x; // expected: [-1+x₁≤0]·[-1+x₂≤0]·[-x₁≤0]·[-x₂≤0] 4 | } 5 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/tuples3.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := (uniform(0,1),uniform(0,1)); 3 | y := (x[0],x[1]); 4 | t := (x[0]-y[0],x[1]-y[1]); 5 | assert(t[0]==-t[1]); 6 | return (); // expected: 1 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/tuples4.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := (uniform(0,1),uniform(0,1)); 3 | y := (x[1],x[0]); 4 | t := (x[0]-y[0],x[1]-y[1]); 5 | assert(t[0]==-t[1]); 6 | return (); // expected: 1 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/tuples5.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := (uniform(0,1),uniform(0,1)); 4 | y := if flip(1/2) { (x[0],x[1]) } else { (x[1],x[0]) }; 5 | t := (x[0]-y[0],x[1]-y[1]); 6 | assert(t[0]==-t[1]); 7 | return (); // expected: 1 8 | } 9 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/tuples6.psi: -------------------------------------------------------------------------------- 1 | def foo(a,b){ 2 | return ((a,b),(b,a)); 3 | } 4 | def main(){ 5 | k:=foo(1,2)[1]; 6 | k[0]+=3; 7 | k[1]+=k[0]; 8 | return k; // expected: δ(5)[k₁]·δ(6)[k₂] 9 | } 10 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/twoEnvelopes.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | // https://en.wikipedia.org/wiki/Two_envelopes_problem 3 | 4 | def main(){ 5 | envelopes := array(2); 6 | for i in [0..2) { envelopes[i] = uniform(0,1); } 7 | observe(envelopes[0] == 2*envelopes[1]);// || (envelopes[1] == 2*envelopes[0])); 8 | //which := UniformInt(0,1); 9 | //switch := envelopes[which] < envelopes[1-which];// TODO 10 | //switch := envelopes[0] > envelopes[1]; 11 | return 1; 12 | } 13 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/uniOp.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := 0; 4 | x = 1 ≤ 1; 5 | assert(x); 6 | x = 1 = 1; 7 | assert(x); 8 | x ← 1 = 1; 9 | (a,b) := (1,2); 10 | (a,b) ← (b,a); 11 | assert(a=2 ∧ b=1); 12 | assert(¬(⊥ ∨ ⊥)); 13 | assert(⊤ ∨ ⊥); 14 | a ∨= 1; 15 | a ∧= 7; 16 | a ∨← 1; 17 | a ∧← 7; 18 | a +← 3; 19 | return 2·a; // expected: δ(12)[r] 20 | } 21 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/uniTest.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | μ := 3; 4 | return -μ; // expected: δ(-3)[r] 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/uniformGaussMix.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := uniform(0,1); 3 | y := 0; 4 | if x>1/2{ 5 | y = gauss(0,1); 6 | x -= 2; 7 | }else{ 8 | y = uniform(2,3); 9 | } 10 | if x > y{ y -= 3; } 11 | return y; // expected: ((-1+3/2·[9/2+y≤0])·⅟√̅2·⅟√̅π+(-3·⅟√̅2·⅟√̅π+-y·⅟√̅2·⅟√̅π)·[-9/2+-y≠0]·[-9/2+-y≤0])·[4+y≤0]·e^(-1/2·y²+-3·y+-9/2)+(-[-1+-y≠0]·[-1+-y≤0]+3/2+[1+y≤0]·y)·[-3/2+-y≤0]·⅟e^(1/2·y²)·⅟√̅2·⅟√̅π+1/2·[-3+y≤0]·[-y+2≤0] 12 | } 13 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/uniformGaussMix2.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | 3 | def main(){ 4 | x := uniform(0,1); 5 | y := 0; 6 | if x>1/2{ 7 | y = gauss(0,1); 8 | x -= 2; 9 | }else{ 10 | y = uniform(2,3); 11 | } 12 | if x > y{ y -= 3; } 13 | return x+y; // TODO: why integral remaining? 14 | } 15 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/uniform_comparison.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := uniform(0,1); 4 | y := x > 1 || x < 0; 5 | return y; // expected: δ(0)[y] 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/uniform_multilinear1.psi: -------------------------------------------------------------------------------- 1 | 2 | def mains(){ 3 | x := uniform(0,1); 4 | y := uniform(0,1); 5 | k := uniform(0,1); 6 | a := x*y+k; 7 | return a; // expected: ((-1+a)·[-a+1≠0]·[-a+1≤0]·log(-1+a)+-[-1+a≤0]·[a≠0]·a·log(a)+-[-a+1≠0]·[-a+1≤0]·a+2·[-a+1≠0]·[-a+1≤0]+[-1+a≤0]·a)·[-2+a≤0]·[-a≤0] 8 | // TODO: compute normalization constant 9 | // TODO: pdf does not need factor [a≠0]. 10 | } 11 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/uniform_multilinear2.psi: -------------------------------------------------------------------------------- 1 | // skipped 2 | 3 | def mains(){ 4 | x := uniform(0,1); 5 | y := uniform(0,1); 6 | z := uniform(0,1); 7 | w := uniform(0,1); 8 | k := uniform(0,1); 9 | a := x*y+z*w+k; 10 | return a; 11 | } 12 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/uniform_nested.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | a := uniform(0,1); 3 | b := uniform(0,a); 4 | return b; // expected: -[-1+b≤0]·[-b≤0]·[b≠0]·log(b) 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/uniform_nested2.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | a := uniform(0,1); 4 | b := uniform(0,a); 5 | c := uniform(0,b); 6 | d := uniform(0,c); 7 | return d; // expected: -1/6·[-1+d≤0]·[-d≤0]·[d≠0]·log(d)³ 8 | } 9 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/uniformint.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := uniformInt(0,10); 3 | x += x; 4 | return x; // expected: 1/11·δ(0)[x]+1/11·δ(10)[x]+1/11·δ(12)[x]+1/11·δ(14)[x]+1/11·δ(16)[x]+1/11·δ(18)[x]+1/11·δ(2)[x]+1/11·δ(20)[x]+1/11·δ(4)[x]+1/11·δ(6)[x]+1/11·δ(8)[x] 5 | 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/uniformint_nested.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | a := uniformInt(0,10); 4 | b := uniformInt(0,a); 5 | return b; // expected: 1/121·δ(10)[b]+15797/304920·δ(6)[b]+1691/43560·δ(7)[b]+20417/304920·δ(5)[b]+21/1210·δ(9)[b]+25961/304920·δ(4)[b]+299/10890·δ(8)[b]+32891/304920·δ(3)[b]+42131/304920·δ(2)[b]+55991/304920·δ(1)[b]+83711/304920·δ(0)[b] 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/unitEarlyReturn.psi: -------------------------------------------------------------------------------- 1 | 2 | def foo(){ 3 | if flip(1/2){ 4 | return; 5 | } 6 | } 7 | 8 | def main(){ 9 | foo(); 10 | return; // expected: 1 11 | } 12 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/weibull.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := weibull(1,1/2); 4 | y := weibull(1,5); 5 | return (x,y); // expected: [-x≤0]·[-y≤0]·[∫dξ₁[-ξ₁≤0]·ξ₁⁴·⅟e^(ξ₁⁵)≠0]·[∫dξ₁[-ξ₁≤0]·⅟e^√̅ξ̅₁·⅟√̅ξ̅₁≠0]·e^(-y⁵+-√̅x)·y⁴·⅟(∫dξ₁[-ξ₁≤0]·ξ₁⁴·⅟e^(ξ₁⁵))·⅟(∫dξ₁[-ξ₁≤0]·⅟e^√̅ξ̅₁·⅟√̅ξ̅₁)·⅟√̅x 6 | // TODO: evaluate normalization constant 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/while.psi: -------------------------------------------------------------------------------- 1 | // compilation error 2 | 3 | def main(){ 4 | x := 0; 5 | while x<3{ x+=1 } 6 | return x; // expected: TODO: δ(0)[-x+3] 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/zero.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(a) { 3 | x := a; 4 | y := x - x; 5 | return y; // expected: δ(0)[y] 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/zeroprobif.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := gauss(0,1); 3 | y := gauss(0,1); 4 | if x { 5 | observe(!y); 6 | } 7 | if y { 8 | observe(!x); 9 | } 10 | return (x,y); // expected: TODO: figure this out 11 | } 12 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/zeroprobif2.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := gauss(0,1); 3 | if x { observe(0); } 4 | return x; // expected: TODO: δ(0)[x] 5 | } 6 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/zeroprobif3.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := gauss(0,1); 4 | y := gauss(0,1); 5 | z := 0; 6 | if x==0 { 7 | if y == 0 { 8 | z=1; 9 | } 10 | } 11 | observe(!x && !y); 12 | return z; // expected: TODO: δ(0)[-z+1] 13 | } 14 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/zeroprobif4.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := gauss(0,1); 4 | z := 0; 5 | obs := 1; 6 | if x == 0 { 7 | y := gauss(0,1); 8 | if y == 0 { 9 | z = 1; 10 | } 11 | obs = y == 0; 12 | } 13 | observe(!x && obs); 14 | return z; // expected: TODO: δ(0)[-z+1] 15 | } 16 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/zeroweightobs.psi: -------------------------------------------------------------------------------- 1 | 2 | def main(){ 3 | x := gauss(0,1); 4 | observe(x==0); 5 | return x; // expected: TODO: δ(0)[-x] 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/zeroweightobs2.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := uniform(0,1); 3 | y := uniform(0,1); 4 | z := uniform(0,1); 5 | //observe(x==y || x+y+z==1 || x == 1 && y == 1); 6 | observe(x==y || x+y+z==1 || x == 1); 7 | return x; // expected: TODO: ((-x+1)·([x≠0]+[x≤0])·[-1+x≤0]·[-x≤0]·√3̅+[-1+x≤0]·[-x≤0]·√2̅+[-x+1=0]·⅟2·√5̅+δ(0)[-x+1])·⅟(1+⅟2·√3̅+√2̅) 8 | } 9 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/zeroweightobs3.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := gauss(0,1); 3 | observe(x==1 || x==-1); 4 | return x; // expected: TODO: (δ(0)[-1+-x]·⅟√2̅·⅟√e̅·⅟√π̅+δ(0)[-x+1]·⅟√2̅·⅟√e̅·⅟√π̅)·⅟√2̅·√e̅·√π̅ 5 | // TODO: simplify better 6 | } 7 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/zeroweightobs4.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := gauss(0,1); 3 | y := uniformInt(0,1); 4 | observe(x==y || x==-y); 5 | return x; // expected: TODO: (δ(0)[-1+-x]·⅟2·⅟√2̅·⅟√e̅·⅟√π̅+δ(0)[-x+1]·⅟2·⅟√2̅·⅟√e̅·⅟√π̅+δ(0)[-x]·⅟2·⅟√2̅·⅟√π̅)·⅟(⅟2·⅟√2̅·⅟√π̅+⅟√2̅·⅟√e̅·⅟√π̅) 6 | // TODO: simplify better 7 | } 8 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/zeroweightobs5.psi: -------------------------------------------------------------------------------- 1 | // skipped: very illustrative, but output quite large 2 | 3 | def main(){ 4 | x := gauss(0,1); 5 | y := uniformInt(-100,100)/20; 6 | cobserve(x,y); 7 | return x; // expected: 8 | } 9 | -------------------------------------------------------------------------------- /pywmi/weight_algebra/psi/psipy/psi/test/zstddev.psi: -------------------------------------------------------------------------------- 1 | def main(){ 2 | x := gauss(0,0); 3 | return x; // expected: δ(0)[x] 4 | } 5 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [aliases] 2 | test=pytest 3 | --------------------------------------------------------------------------------