├── project ├── build.properties └── plugins.sbt ├── daisy_logo.jpg ├── lib ├── mpfr_java-1.4.jar ├── mpfr_java-1.4-osx64.jar └── mpfr_java-1.4-linux64.jar ├── omelette ├── install.sh ├── Cargo.toml └── src │ └── context.rs ├── .gitignore ├── .gitmodules ├── output ├── README └── compileScript.sh ├── testcases ├── relative │ ├── SummationSingle.scala │ ├── Summation.scala │ ├── smallranges │ │ ├── Sqrt.scala │ │ ├── Doppler.scala │ │ ├── Sine.scala │ │ ├── InvertedPendulum.scala │ │ ├── JetEngine.scala │ │ ├── Himmilbeau.scala │ │ ├── RigidBody.scala │ │ ├── Turbine.scala │ │ ├── Bsplines.scala │ │ └── Kepler.scala │ ├── wideranges │ │ ├── Sqrt.scala │ │ ├── Doppler.scala │ │ ├── Sine.scala │ │ ├── InvertedPendulum.scala │ │ ├── JetEngine.scala │ │ ├── Himmilbeau.scala │ │ ├── RigidBody.scala │ │ ├── Turbine.scala │ │ ├── Bsplines.scala │ │ └── Kepler.scala │ ├── Sqrt.scala │ ├── DopplerSingle.scala │ ├── Doppler.scala │ ├── RigidBodySingle.scala │ ├── BallBeamSingle.scala │ ├── InvertedPendulum.scala │ ├── Sine.scala │ ├── InvertedPendulumSingle.scala │ ├── TurbineSingle.scala │ ├── Himmilbeau.scala │ ├── HimmilbeauSingle.scala │ ├── JetEngine.scala │ ├── RigidBody.scala │ ├── JetEngineSingle.scala │ ├── Turbine.scala │ ├── BicycleSingle.scala │ ├── Bsplines.scala │ ├── TimesPlusReal.scala │ ├── Kepler.scala │ └── KeplerSingle.scala ├── fpbench │ ├── exp1x.scala │ ├── nonlin1.scala │ ├── exp1x_32.scala │ ├── bspline3.scala │ ├── intro_example.scala │ ├── exp1x_log.scala │ ├── i6.scala │ ├── i4.scala │ ├── logexp.scala │ ├── nmse_example_3_7.scala │ ├── sqrt_add.scala │ ├── x_by_xy.scala │ ├── nmse_example_3_4.scala │ ├── nmse_example_3_5.scala │ ├── nmse_example_3_1.scala │ ├── nmse_example_3_9.scala │ ├── nmse_problem_3_4_1.scala │ ├── nmse_section_3_11.scala │ ├── test05_nonlin1_test2.scala │ ├── nmse_problem_3_3_6.scala │ ├── nmse_problem_3_3_7.scala │ ├── hypot.scala │ ├── i4modified.scala │ ├── nmse_example_3_10.scala │ ├── nmse_problem_3_3_1.scala │ ├── nmse_problem_3_4_5.scala │ ├── floudas.scala │ ├── nmse_example_3_6.scala │ ├── sineOrder3.scala │ ├── test03_nonlin2.scala │ ├── hypot32.scala │ ├── nmse_problem_3_4_3.scala │ ├── nmse_example_3_8.scala │ ├── nmse_problem_3_4_4.scala │ ├── verhulst.scala │ ├── nmse_section_3_5.scala │ ├── nmse_problem_3_3_3.scala │ ├── nmse_example_3_3.scala │ ├── nmse_problem_3_3_2.scala │ ├── nmse_problem_3_3_5.scala │ ├── nonlin2.scala │ ├── sqroot.scala │ ├── predatorPrey.scala │ ├── test05_nonlin1_r4.scala │ ├── carthesianToPolar_radius.scala │ ├── sec4_example.scala │ ├── complex_sine_cosine.scala │ ├── sine.scala │ ├── cav10.scala │ ├── floudas3.scala │ ├── complex_square_root.scala │ ├── rigidBody1.scala │ ├── turbine2.scala │ ├── squareRoot3.scala │ ├── himmilbeau.scala │ ├── triangle.scala │ ├── doppler1.scala │ ├── doppler2.scala │ ├── doppler3.scala │ ├── squareRoot3Invalid.scala │ ├── test06_sums4_sum1.scala │ ├── test06_sums4_sum2.scala │ ├── turbine1.scala │ ├── turbine3.scala │ ├── carthesianToPolar_theta.scala │ ├── rigidBody2.scala │ ├── nmse_problem_3_4_2.scala │ ├── sum.scala │ ├── nmse_p42_negative.scala │ ├── nmse_p42_positive.scala │ ├── polarToCarthesian_x.scala │ ├── polarToCarthesian_y.scala │ ├── nmse_problem_3_2_1_negative.scala │ ├── nmse_problem_3_2_1_positive.scala │ ├── test01_sum3.scala │ ├── triangle1.scala │ ├── triangle2.scala │ ├── triangle3.scala │ ├── sphere.scala │ ├── triangle4.scala │ ├── triangle5.scala │ ├── triangle6.scala │ ├── triangle7.scala │ ├── triangle8.scala │ ├── triangle9.scala │ ├── triangle10.scala │ ├── triangle11.scala │ ├── triangle12.scala │ ├── carbonGas.scala │ ├── floudas2.scala │ ├── kepler1.scala │ ├── sine_newton.scala │ ├── kepler0.scala │ ├── rump_with_pow.scala │ ├── test02_sum8.scala │ ├── delta4.scala │ ├── jacobisMethodX1.scala │ ├── jacobisMethodX2.scala │ ├── jacobisMethodX3.scala │ ├── jacobisMethodX4.scala │ ├── newtonRaphson.scala │ ├── rump_from_C.scala │ ├── pendulum.scala │ ├── rump_revisited.scala │ ├── jetEngine.scala │ ├── jetEngineModified.scala │ ├── kepler2.scala │ ├── matrixDeterminant.scala │ ├── matrixDeterminant2.scala │ ├── matrixDeterminant2modified.scala │ ├── triangleSorted.scala │ ├── delta.scala │ ├── pid.scala │ ├── azimuth.scala │ ├── n_body.scala │ ├── n_bodyXmodified.scala │ ├── n_bodyZmodified.scala │ ├── runge_kutta_4.scala │ ├── floudas1.scala │ ├── test04_dqmom9.scala │ ├── smartRoot.scala │ ├── instantaneousCurrent.scala │ ├── hartman3.scala │ └── hartman6.scala ├── misc │ ├── Sqrt.scala │ ├── Sine.scala │ ├── TranscendentalsInlined.scala │ └── Transcendentals.scala ├── modular │ ├── unittests │ │ ├── TestReuseSaved.scala │ │ ├── LiteralsTest.scala │ │ ├── paperExample1.scala │ │ ├── LiteralsTest2.scala │ │ ├── FunctionAsArgExample.scala │ │ ├── multipleFuncCallInOne.scala │ │ ├── paperExample2.scala │ │ ├── SimpleNested.scala │ │ ├── UltimateUnitTest.scala │ │ └── Bsplines_Test.scala │ └── keyfloat │ │ ├── matrix2 │ │ └── matrix2.scala │ │ └── rotation │ │ └── rotation.scala ├── rosa │ ├── Doppler.scala │ ├── DopplerInlined.scala │ ├── JetEngine.scala │ ├── JetEngineInlined.scala │ ├── RigidBody.scala │ ├── Turbine.scala │ ├── Science.scala │ ├── Bsplines.scala │ └── Triangle.scala ├── ints │ ├── intSanity.scala │ ├── rigidBody1.scala │ ├── turbine2.scala │ ├── doppler1.scala │ ├── doppler2.scala │ ├── doppler3.scala │ ├── himmilbeau.scala │ ├── turbine1.scala │ ├── turbine3.scala │ ├── rigidBody2.scala │ ├── carbonGas.scala │ ├── kepler1.scala │ ├── kepler0.scala │ ├── delta4.scala │ ├── jetEngine.scala │ ├── kepler2.scala │ ├── matrixDeterminant.scala │ ├── delta.scala │ └── floudas1.scala ├── control │ ├── BallBeam.scala │ ├── InvertedPendulum.scala │ ├── JetEngine.scala │ ├── RigidBody.scala │ ├── Taylor.scala │ ├── Bicycle.scala │ ├── DCMotor.scala │ ├── Pitch.scala │ ├── Misc.scala │ ├── InvertedPendulum4.scala │ └── Traincar1.scala ├── real2float │ ├── Himmilbeau.scala │ └── Kepler.scala └── mixed-precision │ ├── Bsplines0.scala │ ├── Bsplines1.scala │ ├── Bsplines2.scala │ └── Sqrt.scala ├── src ├── main │ └── scala │ │ └── daisy │ │ ├── daisy.scala │ │ ├── utils │ │ ├── DaisyFatalError.scala │ │ ├── UniqueCounter.scala │ │ ├── Pipeline.scala │ │ ├── CachingMap.scala │ │ ├── Timer.scala │ │ ├── Bijection.scala │ │ └── DebugSection.scala │ │ ├── tools │ │ ├── Exceptions.scala │ │ ├── RangeArithmetic.scala │ │ └── MonotonicityPhase.scala │ │ ├── solvers │ │ ├── Exceptions.scala │ │ └── Z3Solver.scala │ │ ├── frontend │ │ ├── DaisyExtraction.scala │ │ ├── CExtractionPhase.scala │ │ └── ScalaCompiler.scala │ │ ├── analysis │ │ ├── ModularContext.scala │ │ └── Sampler.scala │ │ ├── lang │ │ └── TypeOps.scala │ │ └── transform │ │ └── PowTransformerPhase.scala └── test │ └── resources │ └── AbsErrorRegressionJetEngine.scala ├── scripts ├── analysis_ints.sh ├── metalibm │ ├── time_all.sh │ ├── timedata_processing.py │ ├── elem_overhead_timing.sh │ └── metalibm_timing.sh ├── analysis_ds2l.sh ├── analysis_dataflow_IA_AA.sh ├── analysis_dataflow_z3_AA.sh ├── analysis_taylor.sh ├── analysis_subdivision_IA_AA.sh ├── optimization_rewriting.sh ├── analysis_fixed_codegen.sh ├── analysis_dynamic.sh ├── analysis_modular.sh └── optimization_mixed-tuning_rewriting.sh ├── regression └── reference │ ├── tuning_results.csv │ ├── modular_results.csv │ ├── rewriting_results.csv │ └── dataflow_z3_AA_results.csv ├── LEON_LICENSE └── library └── Real.scala /project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=1.4.7 2 | -------------------------------------------------------------------------------- /daisy_logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/malyzajko/daisy/HEAD/daisy_logo.jpg -------------------------------------------------------------------------------- /lib/mpfr_java-1.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/malyzajko/daisy/HEAD/lib/mpfr_java-1.4.jar -------------------------------------------------------------------------------- /lib/mpfr_java-1.4-osx64.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/malyzajko/daisy/HEAD/lib/mpfr_java-1.4-osx64.jar -------------------------------------------------------------------------------- /lib/mpfr_java-1.4-linux64.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/malyzajko/daisy/HEAD/lib/mpfr_java-1.4-linux64.jar -------------------------------------------------------------------------------- /omelette/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | cargo build -r && cp ./target/release/omelette ../lib/omelette 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_STORE 2 | output/*.scala 3 | output/*.csv 4 | target/ 5 | project/project/ 6 | project/target/ 7 | *.log 8 | /daisy 9 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "metalibm-for-daisy"] 2 | path = metalibm-for-daisy 3 | url = https://gitlab.mpi-sws.org/eva/metalibm-for-daisy.git 4 | -------------------------------------------------------------------------------- /output/README: -------------------------------------------------------------------------------- 1 | This directory will contain generated scala code from daisy. 2 | Filenames will be the same as your input files. 3 | Files are generated with the "--printToFile" flag. 4 | -------------------------------------------------------------------------------- /output/compileScript.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash --posix 2 | 3 | # name of generated file (without suffix) 4 | name=$1 5 | 6 | cd output/ 7 | g++ -Winline -O2 -fPIC -c ${name}.c ${name}_benchmark.c 8 | g++ -o ${name}_exe ${name}.o ${name}_benchmark.o -lm 9 | -------------------------------------------------------------------------------- /project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0") 2 | //addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.3.3") 3 | 4 | resolvers += "sonatype-releases" at "https://oss.sonatype.org/content/repositories/releases/" 5 | -------------------------------------------------------------------------------- /testcases/relative/SummationSingle.scala: -------------------------------------------------------------------------------- 1 | 2 | 3 | import daisy.lang._ 4 | import Real._ 5 | 6 | 7 | object SummationSingle { 8 | 9 | def summ(u: Real): Real = { 10 | require(0.0 <= u && u <= 10) 11 | 12 | u + u 13 | 14 | } 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/scala/daisy/daisy.scala: -------------------------------------------------------------------------------- 1 | // Copyright 2017 MPI-SWS, Saarbruecken, Germany 2 | 3 | import scala.collection.immutable.Seq 4 | 5 | package object daisy { 6 | 7 | type PathCond = Seq[lang.Trees.Expr] 8 | val emptyPath = Seq[lang.Trees.Expr]() 9 | 10 | } 11 | -------------------------------------------------------------------------------- /testcases/fpbench/exp1x.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object exp1x { 6 | 7 | 8 | def exp1x(x: Real): Real = { 9 | require(((0.01 <= x) && (x <= 0.5))) 10 | ((exp(x) - 1.0) / x) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/nonlin1.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object nonlin1 { 6 | 7 | 8 | def nonlin1(z: Real): Real = { 9 | require(((0.0 <= z) && (z <= 999.0))) 10 | (z / (z + 1.0)) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/exp1x_32.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object exp1x_32 { 6 | 7 | 8 | def exp1x_32(x: Real): Real = { 9 | require(((0.01 <= x) && (x <= 0.5))) 10 | ((exp(x) - 1.0) / x) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/relative/Summation.scala: -------------------------------------------------------------------------------- 1 | 2 | 3 | import daisy.lang._ 4 | import Real._ 5 | 6 | 7 | object Summation { 8 | 9 | def summ(u: Real, v: Real): Real = { // 10 | require(2.0 <= u && u <= 10 && 1 <= v && v <= 10)// 11 | 12 | u + u * u 13 | 14 | } 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /testcases/fpbench/bspline3.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object bspline3 { 6 | 7 | 8 | def bspline3(u: Real): Real = { 9 | require(((0.0 <= u) && (u <= 1.0))) 10 | (-(((u * u) * u)) / 6.0) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/misc/Sqrt.scala: -------------------------------------------------------------------------------- 1 | 2 | 3 | import daisy.lang._ 4 | import Real._ 5 | 6 | 7 | object SqrtApproximations { 8 | 9 | 10 | def sqroot(x: Real): Real = { 11 | require(x >= 0.0 && x < 10.0) 12 | 1.0 + 0.5*x - 0.125*x*x + 0.0625*x*x*x - 0.0390625*x*x*x*x 13 | } 14 | 15 | 16 | } -------------------------------------------------------------------------------- /testcases/fpbench/intro_example.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object intro_example { 6 | 7 | 8 | def intro_example(t: Real): Real = { 9 | require(((0.0 <= t) && (t <= 999.0))) 10 | (t / (t + 1.0)) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/exp1x_log.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object exp1x_log { 6 | 7 | 8 | def exp1x_log(x: Real): Real = { 9 | require(((0.01 <= x) && (x <= 0.5))) 10 | ((exp(x) - 1.0) / log(exp(x))) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/i6.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object i6 { 6 | 7 | 8 | def i6(x: Real, y: Real): Real = { 9 | require(((0.1 <= x) && (x <= 10.0) && (-5.0 <= y) && (y <= 5.0))) 10 | sin((x * y)) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /scripts/analysis_ints.sh: -------------------------------------------------------------------------------- 1 | 2 | sbt compile 3 | 4 | if [ ! -e daisy ]; then 5 | sbt script 6 | fi 7 | 8 | # run Daisy on each testfile 9 | for file in testcases/ints/*.scala; do 10 | echo "*******" 11 | echo ${file} 12 | time ./daisy --silent --results-csv=ints_real_analysis.csv ${file} 13 | 14 | done -------------------------------------------------------------------------------- /testcases/fpbench/i4.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object i4 { 6 | 7 | 8 | def i4(x: Real, y: Real): Real = { 9 | require(((0.1 <= x) && (x <= 10.0) && (-5.0 <= y) && (y <= 5.0))) 10 | sqrt((x + (y * y))) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/logexp.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object logexp { 6 | 7 | 8 | def logexp(x: Real): Real = { 9 | require(((-8.0 <= x) && (x <= 8.0))) 10 | val e: Real = exp(x) 11 | log((1.0 + e)) 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /testcases/fpbench/nmse_example_3_7.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object nmse_example_3_7 { 6 | 7 | 8 | def nmse_example_3_7(x: Real): Real = { 9 | require(((x >= -10.0) && (x <= 10.0))) 10 | (exp(x) - 1.0) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/sqrt_add.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object sqrt_add { 6 | 7 | 8 | def sqrt_add(x: Real): Real = { 9 | require(((1.0 <= x) && (x <= 1000.0))) 10 | (1.0 / (sqrt((x + 1.0)) + sqrt(x))) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/x_by_xy.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object x_by_xy { 6 | 7 | 8 | def x_by_xy(x: Real, y: Real): Real = { 9 | require(((1.0 <= x) && (x <= 4.0) && (1.0 <= y) && (y <= 4.0))) 10 | (x / (x + y)) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/relative/smallranges/Sqrt.scala: -------------------------------------------------------------------------------- 1 | 2 | import daisy.lang._ 3 | import Real._ 4 | 5 | 6 | object Sqrt { 7 | 8 | 9 | def sqroot(x: Real): Real = { 10 | require(x >= 0.0 && x < 1) // FPTaylor uses [ 0; 1 ] 11 | 1.0 + 0.5*x - 0.125*x*x + 0.0625*x*x*x - 0.0390625*x*x*x*x 12 | } 13 | 14 | 15 | } -------------------------------------------------------------------------------- /testcases/relative/wideranges/Sqrt.scala: -------------------------------------------------------------------------------- 1 | 2 | import daisy.lang._ 3 | import Real._ 4 | 5 | 6 | object Sqrt { 7 | 8 | 9 | def sqroot(x: Real): Real = { 10 | require(x >= 0.0 && x < 1.925) // FPTaylor uses [ 0; 1 ] 11 | 1.0 + 0.5*x - 0.125*x*x + 0.0625*x*x*x - 0.0390625*x*x*x*x 12 | } 13 | 14 | 15 | } -------------------------------------------------------------------------------- /testcases/fpbench/nmse_example_3_4.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object nmse_example_3_4 { 6 | 7 | 8 | def nmse_example_3_4(x: Real): Real = { 9 | require(((x >= 0.1) && (x <= 3.0))) 10 | ((1.0 - cos(x)) / sin(x)) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/nmse_example_3_5.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object nmse_example_3_5 { 6 | 7 | 8 | def nmse_example_3_5(N: Real): Real = { 9 | require(((N >= -1.0) && (N <= 1.0))) 10 | (atan((N + 1.0)) - atan(N)) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/nmse_example_3_1.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object nmse_example_3_1 { 6 | 7 | 8 | def nmse_example_3_1(x: Real): Real = { 9 | require(((x >= 0.001) && (x <= 10.0))) 10 | (sqrt((x + 1.0)) - sqrt(x)) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/nmse_example_3_9.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object nmse_example_3_9 { 6 | 7 | 8 | def nmse_example_3_9(x: Real): Real = { 9 | require(((x >= 0.001) && (x <= 1.5))) 10 | ((1.0 / x) - (1.0 / tan(x))) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/nmse_problem_3_4_1.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object nmse_problem_3_4_1 { 6 | 7 | 8 | def nmse_problem_3_4_1(x: Real): Real = { 9 | require(((x >= 0.1) && (x <= 10.0))) 10 | ((1.0 - cos(x)) / (x * x)) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/nmse_section_3_11.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object nmse_section_3_11 { 6 | 7 | 8 | def nmse_section_3_11(x: Real): Real = { 9 | require(((x >= 0.1) && (x <= 10.0))) 10 | (exp(x) / (exp(x) - 1.0)) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/test05_nonlin1_test2.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object test05_nonlin1_test2 { 6 | 7 | 8 | def test05_nonlin1_test2(x: Real): Real = { 9 | require(((1.00001 < x) && (x < 2.0))) 10 | (1.0 / (x + 1.0)) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/relative/Sqrt.scala: -------------------------------------------------------------------------------- 1 | 2 | 3 | import daisy.lang._ 4 | import Real._ 5 | 6 | 7 | object SqrtApproximations { 8 | 9 | 10 | def sqroot(x: Real): Real = { 11 | require(x >= 0.0 && x < 10.0) // FPTaylor uses [ 0; 1 ] 12 | 1.0 + 0.5*x - 0.125*x*x + 0.0625*x*x*x - 0.0390625*x*x*x*x 13 | } 14 | 15 | 16 | } -------------------------------------------------------------------------------- /testcases/fpbench/nmse_problem_3_3_6.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object nmse_problem_3_3_6 { 6 | 7 | 8 | def nmse_problem_3_3_6(N: Real): Real = { 9 | require(((N >= 0.0001) && (N <= 10.0))) 10 | (log((N + 1.0)) - log(N)) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/nmse_problem_3_3_7.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object nmse_problem_3_3_7 { 6 | 7 | 8 | def nmse_problem_3_3_7(x: Real): Real = { 9 | require(((x >= -10.0) && (x <= 10.0))) 10 | ((exp(x) - 2.0) + exp(-(x))) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/hypot.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object hypot { 6 | 7 | 8 | def hypot(x1: Real, x2: Real): Real = { 9 | require(((1.0 <= x1) && (x1 <= 100.0) && (1.0 <= x2) && (x2 <= 100.0))) 10 | sqrt(((x1 * x1) + (x2 * x2))) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/i4modified.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object i4modified { 6 | 7 | 8 | def i4modified(x: Real, y: Real): Real = { 9 | require(((0.1 <= x) && (x <= 10.0) && (0.0 <= y) && (y <= 5.0))) 10 | sqrt((x + (y * y))) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/nmse_example_3_10.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object nmse_example_3_10 { 6 | 7 | 8 | def nmse_example_3_10(x: Real): Real = { 9 | require(((0.001 < x) && (x < 0.9999))) 10 | (log((1.0 - x)) / log((1.0 + x))) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/nmse_problem_3_3_1.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object nmse_problem_3_3_1 { 6 | 7 | 8 | def nmse_problem_3_3_1(x: Real): Real = { 9 | require(((x >= 0.001) && (x <= 1.5))) 10 | ((1.0 / (x + 1.0)) - (1.0 / x)) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/nmse_problem_3_4_5.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object nmse_problem_3_4_5 { 6 | 7 | 8 | def nmse_problem_3_4_5(x: Real): Real = { 9 | require(((x >= 0.0001) && (x <= 10.0))) 10 | ((x - sin(x)) / (x - tan(x))) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/floudas.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object floudas { 6 | 7 | 8 | def floudas(x1: Real, x2: Real): Real = { 9 | require(((0.0 <= x1) && (x1 <= 2.0) && (0.0 <= x2) && (x2 <= 3.0) && ((x1 + x2) <= 2.0))) 10 | (x1 + x2) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/nmse_example_3_6.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object nmse_example_3_6 { 6 | 7 | 8 | def nmse_example_3_6(x: Real): Real = { 9 | require(((x >= 0.001) && (x <= 10.0))) 10 | ((1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)))) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/sineOrder3.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object sineOrder3 { 6 | 7 | 8 | def sineOrder3(x: Real): Real = { 9 | require(((-2.0 < x) && (x < 2.0))) 10 | ((0.954929658551372 * x) - (0.12900613773279798 * ((x * x) * x))) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/test03_nonlin2.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object test03_nonlin2 { 6 | 7 | 8 | def test03_nonlin2(x: Real, y: Real): Real = { 9 | require(((0.0 < x) && (x < 1.0) && (-1.0 < y) && (y < -0.1))) 10 | ((x + y) / (x - y)) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/hypot32.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object hypot32 { 6 | 7 | 8 | def hypot32(x1: Real, x2: Real): Real = { 9 | require(((1.0 <= x1) && (x1 <= 100.0) && (1.0 <= x2) && (x2 <= 100.0))) 10 | sqrt(((x1 * x1) + (x2 * x2))) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/nmse_problem_3_4_3.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object nmse_problem_3_4_3 { 6 | 7 | 8 | def nmse_problem_3_4_3(eps: Real): Real = { 9 | require(((-0.9999 < eps) && (eps < 0.9999))) 10 | log(((1.0 - eps) / (1.0 + eps))) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/modular/unittests/TestReuseSaved.scala: -------------------------------------------------------------------------------- 1 | import daisy.lang._ 2 | import Real._ 3 | object TestReuseSaved { 4 | 5 | def g(g1: Real): Real = { 6 | require((0 <= g1) && (g1 <= 10000)) 7 | (g1 * g1) 8 | } 9 | 10 | def f(f1: Real) = { 11 | require((1 <= f1) && (f1 <= 10)) 12 | g(g(g(f1))) 13 | } 14 | 15 | 16 | } 17 | -------------------------------------------------------------------------------- /testcases/fpbench/nmse_example_3_8.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object nmse_example_3_8 { 6 | 7 | 8 | def nmse_example_3_8(N: Real): Real = { 9 | require(((N >= 0.0001) && (N <= 10.0))) 10 | ((((N + 1.0) * log((N + 1.0))) - (N * log(N))) - 1.0) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/nmse_problem_3_4_4.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object nmse_problem_3_4_4 { 6 | 7 | 8 | def nmse_problem_3_4_4(x: Real): Real = { 9 | require(((x >= 2.0) && (x <= 12.0))) 10 | sqrt(((exp((2.0 * x)) - 1.0) / (exp(x) - 1.0))) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/verhulst.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object verhulst { 6 | 7 | 8 | def verhulst(x: Real): Real = { 9 | require(((0.1 <= x) && (x <= 0.3))) 10 | val r: Real = 4.0 11 | val K: Real = 1.11 12 | ((r * x) / (1.0 + (x / K))) 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /testcases/modular/unittests/LiteralsTest.scala: -------------------------------------------------------------------------------- 1 | import daisy.lang._ 2 | import Real._ 3 | 4 | object LiteralsTest { 5 | 6 | 7 | def g(g1: Real): Real = { 8 | require((10 <= g1) && (g1 <= 200)) 9 | g1 * g1 10 | } 11 | 12 | def r(r1: Real): Real = { 13 | require((10 <= r1) && (r1 <= 100)) 14 | g(11.0) + r1 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /testcases/fpbench/nmse_section_3_5.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object nmse_section_3_5 { 6 | 7 | 8 | def nmse_section_3_5(a: Real, x: Real): Real = { 9 | require(((a >= -10.0) && (a <= 10.0) && (x >= -10.0) && (x <= 10.0))) 10 | (exp((a * x)) - 1.0) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/nmse_problem_3_3_3.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object nmse_problem_3_3_3 { 6 | 7 | 8 | def nmse_problem_3_3_3(x: Real): Real = { 9 | require(((x >= 0.0001) && (x <= 0.9999))) 10 | (((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0))) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/nmse_example_3_3.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object nmse_example_3_3 { 6 | 7 | 8 | def nmse_example_3_3(x: Real, eps: Real): Real = { 9 | require(((x >= 0.0) && (x <= 10.0) && (eps >= -1.0) && (eps <= 1.0))) 10 | (sin((x + eps)) - sin(x)) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/nmse_problem_3_3_2.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object nmse_problem_3_3_2 { 6 | 7 | 8 | def nmse_problem_3_3_2(x: Real, eps: Real): Real = { 9 | require(((x >= -1.5) && (x <= 1.5) && (eps >= -0.01) && (eps <= 0.01))) 10 | (tan((x + eps)) - tan(x)) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/nmse_problem_3_3_5.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object nmse_problem_3_3_5 { 6 | 7 | 8 | def nmse_problem_3_3_5(x: Real, eps: Real): Real = { 9 | require(((x >= -10.0) && (x <= 10.0) && (eps >= -1.0) && (eps <= 1.0))) 10 | (cos((x + eps)) - cos(x)) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/nonlin2.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object nonlin2 { 6 | 7 | 8 | def nonlin2(x: Real, y: Real): Real = { 9 | require(((1.001 <= x) && (x <= 2.0) && (1.001 <= y) && (y <= 2.0))) 10 | val t: Real = (x * y) 11 | ((t - 1.0) / ((t * t) - 1.0)) 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /testcases/fpbench/sqroot.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object sqroot { 6 | 7 | 8 | def sqroot(x: Real): Real = { 9 | require(((0.0 <= x) && (x <= 1.0))) 10 | ((((1.0 + (0.5 * x)) - ((0.125 * x) * x)) + (((0.0625 * x) * x) * x)) - ((((0.0390625 * x) * x) * x) * x)) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/rosa/Doppler.scala: -------------------------------------------------------------------------------- 1 | 2 | 3 | import daisy.lang._ 4 | import Real._ 5 | 6 | 7 | object Doppler { 8 | 9 | def doppler(u: Real, v: Real, T: Real): Real = { 10 | require(-100.0 <= u && u <= 100 && 20 <= v && v <= 20000 && -30 <= T && T <= 50) 11 | 12 | val t1 = 331.4 + 0.6 * T 13 | (- (t1) *v) / ((t1 + u)*(t1 + u)) 14 | 15 | } 16 | 17 | 18 | } -------------------------------------------------------------------------------- /omelette/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "omelette" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | anyhow = "1.0.89" 10 | clap = { version = "4.5.19", features = ["derive"] } 11 | egg = "0.9.3" 12 | lazy_static = "1.4.0" 13 | rug = "1.26.1" 14 | -------------------------------------------------------------------------------- /testcases/fpbench/predatorPrey.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object predatorPrey { 6 | 7 | 8 | def predatorPrey(x: Real): Real = { 9 | require(((0.1 <= x) && (x <= 0.3))) 10 | val r: Real = 4.0 11 | val K: Real = 1.11 12 | (((r * x) * x) / (1.0 + ((x / K) * (x / K)))) 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /testcases/fpbench/test05_nonlin1_r4.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object test05_nonlin1_r4 { 6 | 7 | 8 | def test05_nonlin1_r4(x: Real): Real = { 9 | require(((1.00001 < x) && (x < 2.0))) 10 | val r1: Real = (x - 1.0) 11 | val r2: Real = (x * x) 12 | (r1 / (r2 - 1.0)) 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /testcases/ints/intSanity.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object intSanity { 6 | 7 | def intSanity(v: Int, u: Int): Int = { 8 | require((1.0 <= v) && (v <= 6.0) && (10.0 <= u) && (u <= 200.0)) 9 | val z: Int = 20 10 | val x: Int = v * 2 11 | (30 * u) - (v + z) + v * (u - v) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /testcases/relative/DopplerSingle.scala: -------------------------------------------------------------------------------- 1 | import daisy.lang._ 2 | import Real._ 3 | 4 | object DopplerSingle { 5 | 6 | def doppler(u: Real): Real = { 7 | require(-100.0 <= u && u <= 100) 8 | 9 | // val T: Real = 50 10 | // val v: Real = 2000 11 | // val t1 = 331.4 + 0.6 * T 12 | -722800 / ((361.4 + u)*(361.4 + u)) // times instead of Division 13 | 14 | } 15 | } -------------------------------------------------------------------------------- /testcases/fpbench/carthesianToPolar_radius.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object carthesianToPolar_radius { 6 | 7 | 8 | def carthesianToPolar_radius(x: Real, y: Real): Real = { 9 | require(((1.0 <= x) && (x <= 100.0) && (1.0 <= y) && (y <= 100.0))) 10 | sqrt(((x * x) + (y * y))) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/sec4_example.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object sec4_example { 6 | 7 | 8 | def sec4_example(x: Real, y: Real): Real = { 9 | require(((1.001 <= x) && (x <= 2.0) && (1.001 <= y) && (y <= 2.0))) 10 | val t: Real = (x * y) 11 | ((t - 1.0) / ((t * t) - 1.0)) 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /testcases/modular/unittests/paperExample1.scala: -------------------------------------------------------------------------------- 1 | import daisy.lang._ 2 | import Real._ 3 | 4 | object paperExample1 { 5 | 6 | 7 | def g(g1: Real): Real = { 8 | require((10 <= g1) && (g1 <= 100)) 9 | (g1 * g1) 10 | } 11 | 12 | def f(f1: Real, f2:Real) = { 13 | require((10 <= f1) && (f1 <= 100) && (10 <= f2) && (f2 <= 100)) 14 | g(f1) + g(f2) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /testcases/fpbench/complex_sine_cosine.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object complex_sine_cosine { 6 | 7 | 8 | def complex_sine_cosine(re: Real, im: Real): Real = { 9 | require(((re >= -10.0) && (re <= 10.0) && (im >= -10.0) && (im <= 10.0))) 10 | ((0.5 * sin(re)) * (exp(-(im)) - exp(im))) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/sine.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object sine { 6 | 7 | 8 | def sine(x: Real): Real = { 9 | require(((-1.57079632679 < x) && (x < 1.57079632679))) 10 | (((x - (((x * x) * x) / 6.0)) + (((((x * x) * x) * x) * x) / 120.0)) - (((((((x * x) * x) * x) * x) * x) * x) / 5040.0)) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/rosa/DopplerInlined.scala: -------------------------------------------------------------------------------- 1 | 2 | 3 | import daisy.lang._ 4 | import Real._ 5 | 6 | 7 | object DopplerInlined { 8 | 9 | def doppler(u: Real, v: Real, T: Real): Real = { 10 | require(-100.0 <= u && u <= 100 && 20 <= v && v <= 20000 && -30 <= T && T <= 50) 11 | 12 | (- (331.4 + 0.6 * T) *v) / (((331.4 + 0.6 * T) + u)*((331.4 + 0.6 * T) + u)) 13 | 14 | } 15 | 16 | 17 | } -------------------------------------------------------------------------------- /testcases/modular/unittests/LiteralsTest2.scala: -------------------------------------------------------------------------------- 1 | import daisy.lang._ 2 | import Real._ 3 | 4 | object LiteralsTest2 { 5 | 6 | 7 | def g(g1: Real, g2: Real): Real = { 8 | require((10 <= g1) && (g1 <= 122) && (10 <= g2) && (g2 <= 122)) 9 | g1 * g2 10 | } 11 | 12 | def r(r1: Real): Real = { 13 | require((10 <= r1) && (r1 <= 100)) 14 | g(g(11.0, 11.0), r1) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/scala/daisy/utils/DaisyFatalError.scala: -------------------------------------------------------------------------------- 1 | // Original work Copyright 2009-2016 EPFL, Lausanne 2 | // Modified work Copyright 2017 MPI-SWS, Saarbruecken, Germany 3 | 4 | package daisy 5 | 6 | case class DaisyFatalError(msg: Option[String]) extends Exception(msg.getOrElse("")) 7 | 8 | object DaisyFatalError { 9 | def apply(msg: String): DaisyFatalError = new DaisyFatalError(Some(msg)) 10 | } 11 | -------------------------------------------------------------------------------- /testcases/fpbench/cav10.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object cav10 { 6 | 7 | 8 | def cav10(x: Real): Real = { 9 | require(((0.0 < x) && (x < 10.0))) 10 | val temp: Real = if ((((x * x) - x) >= 0.0)) { 11 | (x / 10.0) 12 | } 13 | else { 14 | ((x * x) + 2.0) 15 | } 16 | temp 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /testcases/fpbench/floudas3.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object floudas3 { 6 | 7 | 8 | def floudas3(x1: Real, x2: Real): Real = { 9 | require(((0.0 <= x1) && (x1 <= 2.0) && (0.0 <= x2) && (x2 <= 3.0) && (((-2.0 * ((x1 * x1) * (x1 * x1))) + 2.0) >= x2))) 10 | (((-12.0 * x1) - (7.0 * x2)) + (x2 * x2)) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/complex_square_root.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object complex_square_root { 6 | 7 | 8 | def complex_square_root(re: Real, im: Real): Real = { 9 | require(((re >= 0.001) && (re <= 10.0) && (im >= 0.001) && (im <= 10.0))) 10 | (0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) + re)))) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/ints/rigidBody1.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object rigidBody1 { 6 | 7 | 8 | def rigidBody1(x1: Int, x2: Int, x3: Real): Real = { 9 | require(((-15.0 <= x1) && (x1 <= 15.0) && (-15.0 <= x2) && (x2 <= 15.0) && (-15.0 <= x3) && (x3 <= 15.0))) 10 | (((-((x1 * x2)) - ((2.0 * x2) * x3)) - x1) - x3) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/ints/turbine2.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object turbine2 { 6 | 7 | 8 | def turbine2(v: Int, w: Int, r: Real): Real = { 9 | require(((-4.5 <= v) && (v <= -0.3) && (0.4 <= w) && (w <= 0.9) && (3.8 <= r) && (r <= 7.8))) 10 | (((6.0 * v) - (((0.5 * v) * (((w * w) * r) * r)) / (1.0 - v))) - 2.5) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/relative/Doppler.scala: -------------------------------------------------------------------------------- 1 | 2 | 3 | import daisy.lang._ 4 | import Real._ 5 | 6 | 7 | object Doppler { 8 | def doppler(u: Real, v: Real, T: Real): Real = { 9 | require(-100.0 <= u && u <= 100 && 20 <= v && v <= 20000 && -30 <= T && T <= 50) 10 | 11 | // val t1 = 331.4 + 0.6 * T 12 | (- (331.4 + 0.6 * T) *v) / ((331.4 + 0.6 * T + u)*(331.4 + 0.6 * T + u)) 13 | 14 | } 15 | 16 | 17 | } -------------------------------------------------------------------------------- /testcases/fpbench/rigidBody1.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object rigidBody1 { 6 | 7 | 8 | def rigidBody1(x1: Real, x2: Real, x3: Real): Real = { 9 | require(((-15.0 <= x1) && (x1 <= 15.0) && (-15.0 <= x2) && (x2 <= 15.0) && (-15.0 <= x3) && (x3 <= 15.0))) 10 | (((-((x1 * x2)) - ((2.0 * x2) * x3)) - x1) - x3) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/turbine2.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object turbine2 { 6 | 7 | 8 | def turbine2(v: Real, w: Real, r: Real): Real = { 9 | require(((-4.5 <= v) && (v <= -0.3) && (0.4 <= w) && (w <= 0.9) && (3.8 <= r) && (r <= 7.8))) 10 | (((6.0 * v) - (((0.5 * v) * (((w * w) * r) * r)) / (1.0 - v))) - 2.5) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/relative/RigidBodySingle.scala: -------------------------------------------------------------------------------- 1 | import daisy.lang._ 2 | import Real._ 3 | 4 | object RigidBodySingle { 5 | def rigidBody1(x1: Real): Real = { 6 | require(-15.0 <= x1 && x1 <= 15 ) // -3.75 3.75 7 | -x1*x1 - 2*x1*x1 - x1 - x1 8 | } 9 | def rigidBody2(x1: Real): Real = { 10 | require(-15 <= x1 && x1 <= 15.0) 11 | 2*(x1*x1*x1) + (3*x1*x1) - x1*(x1*x1*x1) + (3*x1*x1) - x1 12 | } 13 | } -------------------------------------------------------------------------------- /testcases/relative/smallranges/Doppler.scala: -------------------------------------------------------------------------------- 1 | 2 | 3 | import daisy.lang._ 4 | import Real._ 5 | 6 | 7 | object Doppler { 8 | def doppler(u: Real, v: Real, T: Real): Real = { 9 | require(-100.0 <= u && u <= 100 && 20 <= v && v <= 20000 && -30 <= T && T <= 50) 10 | 11 | // val t1 = 331.4 + 0.6 * T 12 | (- (331.4 + 0.6 * T) *v) / ((331.4 + 0.6 * T + u)*(331.4 + 0.6 * T + u)) 13 | 14 | } 15 | 16 | 17 | } -------------------------------------------------------------------------------- /testcases/fpbench/squareRoot3.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object squareRoot3 { 6 | 7 | 8 | def squareRoot3(x: Real): Real = { 9 | require(((0.0 < x) && (x < 10.0))) 10 | val temp: Real = if ((x < 1.0e-05)) { 11 | (1.0 + (0.5 * x)) 12 | } 13 | else { 14 | sqrt((1.0 + x)) 15 | } 16 | temp 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /testcases/relative/wideranges/Doppler.scala: -------------------------------------------------------------------------------- 1 | 2 | 3 | import daisy.lang._ 4 | import Real._ 5 | 6 | 7 | object Doppler { 8 | def doppler(u: Real, v: Real, T: Real): Real = { 9 | require(-100.0 <= u && u <= 1000 && 2 <= v && v <= 200000 && -300 <= T && T <= 500) 10 | 11 | // val t1 = 331.4 + 0.6 * T 12 | (- (331.4 + 0.6 * T) *v) / ((331.4 + 0.6 * T + u)*(331.4 + 0.6 * T + u)) 13 | 14 | } 15 | 16 | 17 | } -------------------------------------------------------------------------------- /testcases/control/BallBeam.scala: -------------------------------------------------------------------------------- 1 | import daisy.lang._ 2 | import Real._ 3 | 4 | 5 | object BallBeam { 6 | 7 | // s1 <1, 16, 14>, s2, s3, s4: <1, 16, 15> 8 | def out(s1: Real, s2: Real, s3: Real, s4: Real) = { 9 | require(0 <= s1 && s1 <= 1 && -0.5 <= s2 && s2 <= 0.5 && 0 <= s3 && s3 <= 0.5 && 0 <= s4 && s4 <= 0.5) 10 | (-1828.6) * s1 + (-1028.6) * s2 + (-2008.0) * s3 + (-104.0) * s4 11 | } 12 | 13 | 14 | 15 | } -------------------------------------------------------------------------------- /testcases/fpbench/himmilbeau.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object himmilbeau { 6 | 7 | 8 | def himmilbeau(x1: Real, x2: Real): Real = { 9 | require(((-5.0 <= x1) && (x1 <= 5.0) && (-5.0 <= x2) && (x2 <= 5.0))) 10 | val a: Real = (((x1 * x1) + x2) - 11.0) 11 | val b: Real = ((x1 + (x2 * x2)) - 7.0) 12 | ((a * a) + (b * b)) 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /testcases/fpbench/triangle.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object triangle { 6 | 7 | 8 | def triangle(a: Real, b: Real, c: Real): Real = { 9 | require(((1.0 <= a) && (a <= 9.0) && (4.71 <= b) && (b <= 4.89) && (4.71 <= c) && (c <= 4.89))) 10 | val s: Real = (((a + b) + c) / 2.0) 11 | sqrt((((s * (s - a)) * (s - b)) * (s - c))) 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /testcases/ints/doppler1.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object doppler1 { 6 | 7 | 8 | def doppler1(u: Int, v: Real, T: Real): Real = { 9 | require(((-100.0 <= u) && (u <= 100.0) && (20.0 <= v) && (v <= 20000.0) && (-30.0 <= T) && (T <= 50.0))) 10 | val t1: Real = (331.4 + (0.6 * T)) 11 | ((-(t1) * v) / ((t1 + u) * (t1 + u))) 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /testcases/ints/doppler2.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object doppler2 { 6 | 7 | 8 | def doppler2(u: Real, v: Int, T: Real): Real = { 9 | require(((-125.0 <= u) && (u <= 125.0) && (15.0 <= v) && (v <= 25000.0) && (-40.0 <= T) && (T <= 60.0))) 10 | val t1: Real = (331.4 + (0.6 * T)) 11 | ((-(t1) * v) / ((t1 + u) * (t1 + u))) 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /testcases/ints/doppler3.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object doppler3 { 6 | 7 | 8 | def doppler3(u: Real, v: Real, T: Int): Real = { 9 | require(((-30.0 <= u) && (u <= 120.0) && (320.0 <= v) && (v <= 20300.0) && (-50.0 <= T) && (T <= 30.0))) 10 | val t1: Real = (331.4 + (0.6 * T)) 11 | ((-(t1) * v) / ((t1 + u) * (t1 + u))) 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /testcases/ints/himmilbeau.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object himmilbeau { 6 | 7 | 8 | def himmilbeau(x1: Int, x2: Real): Real = { 9 | require(((-5.0 <= x1) && (x1 <= 5.0) && (-5.0 <= x2) && (x2 <= 5.0))) 10 | val a: Real = (((x1 * x1) + x2) - 11.0) 11 | val b: Real = ((x1 + (x2 * x2)) - 7.0) 12 | ((a * a) + (b * b)) 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /testcases/fpbench/doppler1.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object doppler1 { 6 | 7 | 8 | def doppler1(u: Real, v: Real, T: Real): Real = { 9 | require(((-100.0 <= u) && (u <= 100.0) && (20.0 <= v) && (v <= 20000.0) && (-30.0 <= T) && (T <= 50.0))) 10 | val t1: Real = (331.4 + (0.6 * T)) 11 | ((-(t1) * v) / ((t1 + u) * (t1 + u))) 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /testcases/fpbench/doppler2.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object doppler2 { 6 | 7 | 8 | def doppler2(u: Real, v: Real, T: Real): Real = { 9 | require(((-125.0 <= u) && (u <= 125.0) && (15.0 <= v) && (v <= 25000.0) && (-40.0 <= T) && (T <= 60.0))) 10 | val t1: Real = (331.4 + (0.6 * T)) 11 | ((-(t1) * v) / ((t1 + u) * (t1 + u))) 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /testcases/fpbench/doppler3.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object doppler3 { 6 | 7 | 8 | def doppler3(u: Real, v: Real, T: Real): Real = { 9 | require(((-30.0 <= u) && (u <= 120.0) && (320.0 <= v) && (v <= 20300.0) && (-50.0 <= T) && (T <= 30.0))) 10 | val t1: Real = (331.4 + (0.6 * T)) 11 | ((-(t1) * v) / ((t1 + u) * (t1 + u))) 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /testcases/ints/turbine1.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object turbine1 { 6 | 7 | 8 | def turbine1(v: Real, w: Int, r: Int): Real = { 9 | require(((-4.5 <= v) && (v <= -0.3) && (0.4 <= w) && (w <= 0.9) && (3.8 <= r) && (r <= 7.8))) 10 | (((3.0 + (2.0 / (r * r))) - (((0.125 * (3.0 - (2.0 * v))) * (((w * w) * r) * r)) / (1.0 - v))) - 4.5) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/ints/turbine3.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object turbine3 { 6 | 7 | 8 | def turbine3(v: Int, w: Real, r: Int): Real = { 9 | require(((-4.5 <= v) && (v <= -0.3) && (0.4 <= w) && (w <= 0.9) && (3.8 <= r) && (r <= 7.8))) 10 | (((3.0 - (2.0 / (r * r))) - (((0.125 * (1.0 + (2.0 * v))) * (((w * w) * r) * r)) / (1.0 - v))) - 0.5) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/squareRoot3Invalid.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object squareRoot3Invalid { 6 | 7 | 8 | def squareRoot3Invalid(x: Real): Real = { 9 | require(((0.0 < x) && (x < 10.0))) 10 | val temp: Real = if ((x < 0.0001)) { 11 | (1.0 + (0.5 * x)) 12 | } 13 | else { 14 | sqrt((1.0 + x)) 15 | } 16 | temp 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /testcases/fpbench/test06_sums4_sum1.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object test06_sums4_sum1 { 6 | 7 | 8 | def test06_sums4_sum1(x0: Real, x1: Real, x2: Real, x3: Real): Real = { 9 | require(((-1.0e-05 < x0) && (x0 < 1.00001) && (0.0 < x1) && (x1 < 1.0) && (0.0 < x2) && (x2 < 1.0) && (0.0 < x3) && (x3 < 1.0))) 10 | (((x0 + x1) + x2) + x3) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/test06_sums4_sum2.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object test06_sums4_sum2 { 6 | 7 | 8 | def test06_sums4_sum2(x0: Real, x1: Real, x2: Real, x3: Real): Real = { 9 | require(((-1.0e-05 < x0) && (x0 < 1.00001) && (0.0 < x1) && (x1 < 1.0) && (0.0 < x2) && (x2 < 1.0) && (0.0 < x3) && (x3 < 1.0))) 10 | ((x0 + x1) + (x2 + x3)) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/turbine1.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object turbine1 { 6 | 7 | 8 | def turbine1(v: Real, w: Real, r: Real): Real = { 9 | require(((-4.5 <= v) && (v <= -0.3) && (0.4 <= w) && (w <= 0.9) && (3.8 <= r) && (r <= 7.8))) 10 | (((3.0 + (2.0 / (r * r))) - (((0.125 * (3.0 - (2.0 * v))) * (((w * w) * r) * r)) / (1.0 - v))) - 4.5) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/turbine3.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object turbine3 { 6 | 7 | 8 | def turbine3(v: Real, w: Real, r: Real): Real = { 9 | require(((-4.5 <= v) && (v <= -0.3) && (0.4 <= w) && (w <= 0.9) && (3.8 <= r) && (r <= 7.8))) 10 | (((3.0 - (2.0 / (r * r))) - (((0.125 * (1.0 + (2.0 * v))) * (((w * w) * r) * r)) / (1.0 - v))) - 0.5) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/relative/wideranges/Sine.scala: -------------------------------------------------------------------------------- 1 | 2 | import daisy.lang._ 3 | import Real._ 4 | 5 | 6 | object Sine { 7 | 8 | def sine(x: Real): Real = { 9 | require(x > 0.825 && x < 1.7) 10 | x - (x*x*x)/6.0 + (x*x*x*x*x)/120.0 - (x*x*x*x*x*x*x)/5040.0 11 | } 12 | 13 | 14 | def sineOrder3(x: Real): Real = { 15 | require(-2.0 < x && x < -1.125) 16 | 0.954929658551372 * x - 0.12900613773279798*(x*x*x) 17 | } 18 | 19 | 20 | } -------------------------------------------------------------------------------- /testcases/fpbench/carthesianToPolar_theta.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object carthesianToPolar_theta { 6 | 7 | 8 | def carthesianToPolar_theta(x: Real, y: Real): Real = { 9 | require(((1.0 <= x) && (x <= 100.0) && (1.0 <= y) && (y <= 100.0))) 10 | val pi: Real = 3.14159265359 11 | val radiant: Real = atan((y / x)) 12 | (radiant * (180.0 / pi)) 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /testcases/modular/unittests/FunctionAsArgExample.scala: -------------------------------------------------------------------------------- 1 | import daisy.lang._ 2 | import Real._ 3 | object FunctionAsArgExample { 4 | 5 | def g(g1: Real): Real = { 6 | require((10 <= g1) && (g1 <= 100)) 7 | (g1 * g1) 8 | } 9 | 10 | def f(f1: Real) = { 11 | require((100 <= f1) && (f1 <= 10000)) 12 | f1 * f1 * f1 13 | } 14 | 15 | def k(k1: Real): Real = { 16 | require(10 <= k1 && k1 <= 100) 17 | f(g(k1)) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /testcases/relative/smallranges/Sine.scala: -------------------------------------------------------------------------------- 1 | 2 | import daisy.lang._ 3 | import Real._ 4 | 5 | 6 | object Sine { 7 | 8 | def sine(x: Real): Real = { 9 | require(x > 0.875 && x < 1.57079632679) 10 | x - (x*x*x)/6.0 + (x*x*x*x*x)/120.0 - (x*x*x*x*x*x*x)/5040.0 11 | } 12 | 13 | 14 | def sineOrder3(x: Real): Real = { 15 | require(-2.0 < x && x < -1.125) 16 | 0.954929658551372 * x - 0.12900613773279798*(x*x*x) 17 | } 18 | 19 | 20 | } -------------------------------------------------------------------------------- /testcases/ints/rigidBody2.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object rigidBody2 { 6 | 7 | 8 | def rigidBody2(x1: Int, x2: Int, x3: Real): Real = { 9 | require(((-15.0 <= x1) && (x1 <= 15.0) && (-15.0 <= x2) && (x2 <= 15.0) && (-15.0 <= x3) && (x3 <= 15.0))) 10 | (((((((2.0 * x1) * x2) * x3) + ((3.0 * x3) * x3)) - (((x2 * x1) * x2) * x3)) + ((3.0 * x3) * x3)) - x2) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/rigidBody2.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object rigidBody2 { 6 | 7 | 8 | def rigidBody2(x1: Real, x2: Real, x3: Real): Real = { 9 | require(((-15.0 <= x1) && (x1 <= 15.0) && (-15.0 <= x2) && (x2 <= 15.0) && (-15.0 <= x3) && (x3 <= 15.0))) 10 | (((((((2.0 * x1) * x2) * x3) + ((3.0 * x3) * x3)) - (((x2 * x1) * x2) * x3)) + ((3.0 * x3) * x3)) - x2) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/misc/Sine.scala: -------------------------------------------------------------------------------- 1 | 2 | 3 | import daisy.lang._ 4 | import Real._ 5 | 6 | 7 | object SineApproximations { 8 | 9 | def sine(x: Real): Real = { 10 | require(x > -1.57079632679 && x < 1.57079632679) 11 | x - (x*x*x)/6.0 + (x*x*x*x*x)/120.0 - (x*x*x*x*x*x*x)/5040.0 12 | } 13 | 14 | 15 | def sineOrder3(x: Real): Real = { 16 | require(-2.0 < x && x < 2.0) 17 | 0.954929658551372 * x - 0.12900613773279798*(x*x*x) 18 | } 19 | 20 | 21 | } -------------------------------------------------------------------------------- /testcases/control/InvertedPendulum.scala: -------------------------------------------------------------------------------- 1 | import daisy.lang._ 2 | import Real._ 3 | 4 | 5 | object InvertedPendulum { 6 | 7 | // s1: <1, 16, 9> s2: <1, 16, 11> s3,s4: <1, 16, 15> 8 | def out(s1: Real, s2: Real, s3: Real, s4: Real) = { 9 | require(-50 <= s1 && s1 <= 50 && -10 <= s2 && s2 <= 10 && -0.785 <= s3 && s3 <= 0.785 && -0.785 <= s4 && s4 <= 0.785) 10 | 11 | 1.0000 * s1 + 1.6567 * s2 + (-18.6854) * s3 + (-3.4594) * s4 12 | } 13 | 14 | 15 | 16 | } -------------------------------------------------------------------------------- /testcases/fpbench/nmse_problem_3_4_2.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object nmse_problem_3_4_2 { 6 | 7 | 8 | def nmse_problem_3_4_2(a: Real, b: Real, eps: Real): Real = { 9 | require(((a >= 5.0) && (a <= 15.0) && (b >= -15.0) && (b <= -5.0) && (eps >= 0.9) && (eps <= 1.1))) 10 | ((eps * (exp(((a + b) * eps)) - 1.0)) / ((exp((a * eps)) - 1.0) * (exp((b * eps)) - 1.0))) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/sum.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object sum { 6 | 7 | 8 | def sum(x0: Real, x1: Real, x2: Real): Real = { 9 | require(((1.0 <= x0) && (x0 <= 2.0) && (1.0 <= x1) && (x1 <= 2.0) && (1.0 <= x2) && (x2 <= 2.0))) 10 | val p0: Real = ((x0 + x1) - x2) 11 | val p1: Real = ((x1 + x2) - x0) 12 | val p2: Real = ((x2 + x0) - x1) 13 | ((p0 + p1) + p2) 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /testcases/relative/BallBeamSingle.scala: -------------------------------------------------------------------------------- 1 | import daisy.lang._ 2 | import Real._ 3 | 4 | 5 | object BallBeamSingle { 6 | 7 | // s1 <1, 16, 14>, s2, s3, s4: <1, 16, 15> 8 | def BallBeamSingle_out(s1: Real) = { // , s2: Real, s3: Real, s4: Real 9 | require(0 <= s1 && s1 <= 1) // && -0.5 <= s2 && s2 <= 0.5 && 0 <= s3 && s3 <= 0.5 && 0 <= s4 && s4 <= 0.5) 10 | (-1828.6) * s1 + (-1028.6) * -0.487 + (-2008.0) * 0.25 + (-104.0) * 0.375 11 | } 12 | 13 | 14 | 15 | } -------------------------------------------------------------------------------- /testcases/relative/InvertedPendulum.scala: -------------------------------------------------------------------------------- 1 | import daisy.lang._ 2 | import Real._ 3 | 4 | 5 | object InvertedPendulum { 6 | 7 | // s1: <1, 16, 9> s2: <1, 16, 11> s3,s4: <1, 16, 15> 8 | def out(s1: Real, s2: Real, s3: Real, s4: Real) = { 9 | require(-50 <= s1 && s1 <= 50 && -10 <= s2 && s2 <= 10 && -0.785 <= s3 && s3 <= 0.785 && -0.785 <= s4 && s4 <= 0.785) 10 | 11 | 1.0000 * s1 + 1.6567 * s2 + (-18.6854) * s3 + (-3.4594) * s4 12 | } 13 | 14 | 15 | 16 | } -------------------------------------------------------------------------------- /testcases/relative/Sine.scala: -------------------------------------------------------------------------------- 1 | 2 | 3 | import daisy.lang._ 4 | import Real._ 5 | 6 | 7 | object SineApproximations { 8 | 9 | def sine(x: Real): Real = { 10 | require(x > -1.57079632679 && x < 1.57079632679) 11 | x - (x*x*x)/6.0 + (x*x*x*x*x)/120.0 - (x*x*x*x*x*x*x)/5040.0 12 | } 13 | 14 | 15 | def sineOrder3(x: Real): Real = { 16 | require(-2.0 < x && x < 2.0) 17 | 0.954929658551372 * x - 0.12900613773279798*(x*x*x) 18 | } 19 | 20 | 21 | } -------------------------------------------------------------------------------- /testcases/fpbench/nmse_p42_negative.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object nmse_p42_negative { 6 | 7 | 8 | def nmse_p42_negative(a: Real, b: Real, c: Real): Real = { 9 | require(((a >= -10.0) && (a <= 10.0) && (b >= -10.0) && (b <= 10.0) && (c >= -10.0) && (c <= 10.0) && ((b * b) >= (4.0 * (a * c))) && (a != 0.0))) 10 | ((-(b) - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/nmse_p42_positive.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object nmse_p42_positive { 6 | 7 | 8 | def nmse_p42_positive(a: Real, b: Real, c: Real): Real = { 9 | require(((a >= 0.001) && (a <= 10.0) && (b >= 70.0) && (b <= 120.0) && (c >= -10.0) && (c <= 10.0) && ((b * b) >= (4.0 * (a * c))) && (a != 0.0))) 10 | ((-(b) + sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/polarToCarthesian_x.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object polarToCarthesian_x { 6 | 7 | 8 | def polarToCarthesian_x(radius: Real, theta: Real): Real = { 9 | require(((1.0 <= radius) && (radius <= 10.0) && (0.0 <= theta) && (theta <= 360.0))) 10 | val pi: Real = 3.14159265359 11 | val radiant: Real = (theta * (pi / 180.0)) 12 | (radius * cos(radiant)) 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /testcases/fpbench/polarToCarthesian_y.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object polarToCarthesian_y { 6 | 7 | 8 | def polarToCarthesian_y(radius: Real, theta: Real): Real = { 9 | require(((1.0 <= radius) && (radius <= 10.0) && (0.0 <= theta) && (theta <= 360.0))) 10 | val pi: Real = 3.14159265359 11 | val radiant: Real = (theta * (pi / 180.0)) 12 | (radius * sin(radiant)) 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /testcases/fpbench/nmse_problem_3_2_1_negative.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object nmse_problem_3_2_1_negative { 6 | 7 | 8 | def nmse_problem_3_2_1_negative(a: Real, b2: Real, c: Real): Real = { 9 | require(((a >= 0.001) && (a <= 10.0) && (b2 >= 20.0) && (b2 <= 30.0) && (c >= -10.0) && (c <= 10.0) && ((b2 * b2) >= (a * c)) && (a != 0.0))) 10 | ((-(b2) - sqrt(((b2 * b2) - (a * c)))) / a) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/nmse_problem_3_2_1_positive.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object nmse_problem_3_2_1_positive { 6 | 7 | 8 | def nmse_problem_3_2_1_positive(a: Real, b2: Real, c: Real): Real = { 9 | require(((a >= 0.001) && (a <= 10.0) && (b2 >= 20.0) && (b2 <= 30.0) && (c >= -10.0) && (c <= 10.0) && ((b2 * b2) >= (a * c)) && (a != 0.0))) 10 | ((-(b2) + sqrt(((b2 * b2) - (a * c)))) / a) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/test01_sum3.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object test01_sum3 { 6 | 7 | 8 | def test01_sum3(x0: Real, x1: Real, x2: Real): Real = { 9 | require(((1.0 < x0) && (x0 < 2.0) && (1.0 < x1) && (x1 < 2.0) && (1.0 < x2) && (x2 < 2.0))) 10 | val p0: Real = ((x0 + x1) - x2) 11 | val p1: Real = ((x1 + x2) - x0) 12 | val p2: Real = ((x2 + x0) - x1) 13 | ((p0 + p1) + p2) 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /testcases/fpbench/triangle1.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object triangle1 { 6 | 7 | 8 | def triangle1(a: Real, b: Real, c: Real): Real = { 9 | require(((1.0 <= a) && (a <= 9.0) && (1.0 <= b) && (b <= 9.0) && (1.0 <= c) && (c <= 9.0) && ((a + b) > (c + 0.1)) && ((a + c) > (b + 0.1)) && ((b + c) > (a + 0.1)))) 10 | val s: Real = (((a + b) + c) / 2.0) 11 | sqrt((((s * (s - a)) * (s - b)) * (s - c))) 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /testcases/fpbench/triangle2.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object triangle2 { 6 | 7 | 8 | def triangle2(a: Real, b: Real, c: Real): Real = { 9 | require(((1.0 <= a) && (a <= 9.0) && (1.0 <= b) && (b <= 9.0) && (1.0 <= c) && (c <= 9.0) && ((a + b) > (c + 0.01)) && ((a + c) > (b + 0.01)) && ((b + c) > (a + 0.01)))) 10 | val s: Real = (((a + b) + c) / 2.0) 11 | sqrt((((s * (s - a)) * (s - b)) * (s - c))) 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /testcases/fpbench/triangle3.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object triangle3 { 6 | 7 | 8 | def triangle3(a: Real, b: Real, c: Real): Real = { 9 | require(((1.0 <= a) && (a <= 9.0) && (1.0 <= b) && (b <= 9.0) && (1.0 <= c) && (c <= 9.0) && ((a + b) > (c + 0.001)) && ((a + c) > (b + 0.001)) && ((b + c) > (a + 0.001)))) 10 | val s: Real = (((a + b) + c) / 2.0) 11 | sqrt((((s * (s - a)) * (s - b)) * (s - c))) 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /testcases/modular/unittests/multipleFuncCallInOne.scala: -------------------------------------------------------------------------------- 1 | import daisy.lang._ 2 | import Real._ 3 | 4 | object multipleFuncCallInOne { 5 | 6 | def g(g1: Real): Real = { 7 | require((10 <= g1) && (g1 <= 100)) 8 | (g1 * g1) 9 | } 10 | 11 | def f(f1: Real, f2:Real) = { 12 | require((10 <= f1) && (f1 <= 100) && (10 <= f2) && (f2 <= 100)) 13 | g(f1) + g(f2) 14 | } 15 | 16 | def h(h1: Real): Real = { 17 | require(10 <= h1 && h1 <= 100) 18 | g(h1) + h1 * f(h1, h1) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /testcases/fpbench/sphere.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object sphere { 6 | 7 | 8 | def sphere(x: Real, r: Real, lat: Real, lon: Real): Real = { 9 | require(((-10.0 <= x) && (x <= 10.0) && (0.0 <= r) && (r <= 10.0) && (-1.570796 <= lat) && (lat <= 1.570796) && (-3.14159265 <= lon) && (lon <= 3.14159265))) 10 | val sinLat: Real = sin(lat) 11 | val cosLon: Real = cos(lon) 12 | (x + ((r * sinLat) * cosLon)) 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /testcases/fpbench/triangle4.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object triangle4 { 6 | 7 | 8 | def triangle4(a: Real, b: Real, c: Real): Real = { 9 | require(((1.0 <= a) && (a <= 9.0) && (1.0 <= b) && (b <= 9.0) && (1.0 <= c) && (c <= 9.0) && ((a + b) > (c + 0.0001)) && ((a + c) > (b + 0.0001)) && ((b + c) > (a + 0.0001)))) 10 | val s: Real = (((a + b) + c) / 2.0) 11 | sqrt((((s * (s - a)) * (s - b)) * (s - c))) 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /testcases/fpbench/triangle5.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object triangle5 { 6 | 7 | 8 | def triangle5(a: Real, b: Real, c: Real): Real = { 9 | require(((1.0 <= a) && (a <= 9.0) && (1.0 <= b) && (b <= 9.0) && (1.0 <= c) && (c <= 9.0) && ((a + b) > (c + 1.0e-05)) && ((a + c) > (b + 1.0e-05)) && ((b + c) > (a + 1.0e-05)))) 10 | val s: Real = (((a + b) + c) / 2.0) 11 | sqrt((((s * (s - a)) * (s - b)) * (s - c))) 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /testcases/fpbench/triangle6.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object triangle6 { 6 | 7 | 8 | def triangle6(a: Real, b: Real, c: Real): Real = { 9 | require(((1.0 <= a) && (a <= 9.0) && (1.0 <= b) && (b <= 9.0) && (1.0 <= c) && (c <= 9.0) && ((a + b) > (c + 1.0e-06)) && ((a + c) > (b + 1.0e-06)) && ((b + c) > (a + 1.0e-06)))) 10 | val s: Real = (((a + b) + c) / 2.0) 11 | sqrt((((s * (s - a)) * (s - b)) * (s - c))) 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /testcases/fpbench/triangle7.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object triangle7 { 6 | 7 | 8 | def triangle7(a: Real, b: Real, c: Real): Real = { 9 | require(((1.0 <= a) && (a <= 9.0) && (1.0 <= b) && (b <= 9.0) && (1.0 <= c) && (c <= 9.0) && ((a + b) > (c + 1.0e-07)) && ((a + c) > (b + 1.0e-07)) && ((b + c) > (a + 1.0e-07)))) 10 | val s: Real = (((a + b) + c) / 2.0) 11 | sqrt((((s * (s - a)) * (s - b)) * (s - c))) 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /testcases/fpbench/triangle8.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object triangle8 { 6 | 7 | 8 | def triangle8(a: Real, b: Real, c: Real): Real = { 9 | require(((1.0 <= a) && (a <= 9.0) && (1.0 <= b) && (b <= 9.0) && (1.0 <= c) && (c <= 9.0) && ((a + b) > (c + 1.0e-08)) && ((a + c) > (b + 1.0e-08)) && ((b + c) > (a + 1.0e-08)))) 10 | val s: Real = (((a + b) + c) / 2.0) 11 | sqrt((((s * (s - a)) * (s - b)) * (s - c))) 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /testcases/fpbench/triangle9.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object triangle9 { 6 | 7 | 8 | def triangle9(a: Real, b: Real, c: Real): Real = { 9 | require(((1.0 <= a) && (a <= 9.0) && (1.0 <= b) && (b <= 9.0) && (1.0 <= c) && (c <= 9.0) && ((a + b) > (c + 1.0e-09)) && ((a + c) > (b + 1.0e-09)) && ((b + c) > (a + 1.0e-09)))) 10 | val s: Real = (((a + b) + c) / 2.0) 11 | sqrt((((s * (s - a)) * (s - b)) * (s - c))) 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /testcases/ints/carbonGas.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object carbonGas { 6 | 7 | 8 | def carbonGas(v: Real): Real = { 9 | require(((0.1 <= v) && (v <= 0.5))) 10 | val p: Int = 35000000 11 | val a: Real = 0.401 12 | val b: Real = 4.27e-05 13 | val t: Int = 300 14 | val n: Int = 1000 15 | val k: Real = 1.3806503e-23 16 | (((p + ((a * (n / v)) * (n / v))) * (v - (n * b))) - ((k * n) * t)) 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /testcases/rosa/JetEngine.scala: -------------------------------------------------------------------------------- 1 | 2 | 3 | import daisy.lang._ 4 | import Real._ 5 | 6 | 7 | object JetEngine { 8 | 9 | 10 | def jetEngine(x1: Real, x2: Real): Real = { 11 | require(-5 <= x1 && x1 <= 5 && -20 <= x2 && x2 <= 5) 12 | 13 | val t = (3*x1*x1 + 2*x2 - x1) 14 | 15 | x1 + ((2*x1*(t/(x1*x1 + 1))* 16 | (t/(x1*x1 + 1) - 3) + x1*x1*(4*(t/(x1*x1 + 1))-6))* 17 | (x1*x1 + 1) + 3*x1*x1*(t/(x1*x1 + 1)) + x1*x1*x1 + x1 + 18 | 3*((3*x1*x1 + 2*x2 -x1)/(x1*x1 + 1))) 19 | } 20 | 21 | 22 | } -------------------------------------------------------------------------------- /testcases/fpbench/triangle10.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object triangle10 { 6 | 7 | 8 | def triangle10(a: Real, b: Real, c: Real): Real = { 9 | require(((1.0 <= a) && (a <= 9.0) && (1.0 <= b) && (b <= 9.0) && (1.0 <= c) && (c <= 9.0) && ((a + b) > (c + 1.0e-10)) && ((a + c) > (b + 1.0e-10)) && ((b + c) > (a + 1.0e-10)))) 10 | val s: Real = (((a + b) + c) / 2.0) 11 | sqrt((((s * (s - a)) * (s - b)) * (s - c))) 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /testcases/fpbench/triangle11.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object triangle11 { 6 | 7 | 8 | def triangle11(a: Real, b: Real, c: Real): Real = { 9 | require(((1.0 <= a) && (a <= 9.0) && (1.0 <= b) && (b <= 9.0) && (1.0 <= c) && (c <= 9.0) && ((a + b) > (c + 1.0e-11)) && ((a + c) > (b + 1.0e-11)) && ((b + c) > (a + 1.0e-11)))) 10 | val s: Real = (((a + b) + c) / 2.0) 11 | sqrt((((s * (s - a)) * (s - b)) * (s - c))) 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /testcases/fpbench/triangle12.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object triangle12 { 6 | 7 | 8 | def triangle12(a: Real, b: Real, c: Real): Real = { 9 | require(((1.0 <= a) && (a <= 9.0) && (1.0 <= b) && (b <= 9.0) && (1.0 <= c) && (c <= 9.0) && ((a + b) > (c + 1.0e-12)) && ((a + c) > (b + 1.0e-12)) && ((b + c) > (a + 1.0e-12)))) 10 | val s: Real = (((a + b) + c) / 2.0) 11 | sqrt((((s * (s - a)) * (s - b)) * (s - c))) 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /testcases/fpbench/carbonGas.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object carbonGas { 6 | 7 | 8 | def carbonGas(v: Real): Real = { 9 | require(((0.1 <= v) && (v <= 0.5))) 10 | val p: Real = 35000000.0 11 | val a: Real = 0.401 12 | val b: Real = 4.27e-05 13 | val t: Real = 300.0 14 | val n: Real = 1000.0 15 | val k: Real = 1.3806503e-23 16 | (((p + ((a * (n / v)) * (n / v))) * (v - (n * b))) - ((k * n) * t)) 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /testcases/modular/unittests/paperExample2.scala: -------------------------------------------------------------------------------- 1 | import daisy.lang._ 2 | import Real._ 3 | 4 | object paperExample2 { 5 | 6 | def g(g1: Real): Real = { 7 | require((20 <= g1) && (g1 <= 200)) 8 | (g1 * g1) 9 | } 10 | 11 | def r(r1: Real, r2:Real) = { 12 | require((10 <= r1) && (r1 <= 100) && (10 <= r2) && (r2 <= 100)) 13 | r1 + r2 14 | } 15 | 16 | def p(p1: Real, p2: Real): Real = { 17 | require((10 <= p1) && (p1 <= 100) && (10 <= p2) && (p2 <= 100)) 18 | g(r(p1, p2)) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /testcases/relative/InvertedPendulumSingle.scala: -------------------------------------------------------------------------------- 1 | import daisy.lang._ 2 | import Real._ 3 | 4 | 5 | object InvertedPendulumSingle { 6 | 7 | // s1: <1, 16, 9> s2: <1, 16, 11> s3,s4: <1, 16, 15> 8 | def invertedPendulum(s1: Real) = { 9 | require(-50 <= s1 && s1 <= 50) 10 | val s2:Real = 1.2 // -10 <= s2 && s2 <= 10 11 | val s3: Real = 0.78// -0.785 <= s3 && s3 <= 0.785 12 | val s4: Real = -0.75 13 | 1.0000 * s1 + 1.6567 * 1.2 + (-18.6854) * 0.78 + (-3.4594) * (-0.75) 14 | } 15 | 16 | 17 | 18 | } -------------------------------------------------------------------------------- /testcases/relative/wideranges/InvertedPendulum.scala: -------------------------------------------------------------------------------- 1 | import daisy.lang._ 2 | import Real._ 3 | 4 | 5 | object InvertedPendulum { 6 | 7 | // s1: <1, 16, 9> s2: <1, 16, 11> s3,s4: <1, 16, 15> 8 | def invPendulum(s1: Real, s2: Real, s3: Real, s4: Real) = { 9 | require(0.005 <= s1 && s1 <= 5000 && 10 | 0.005 <= s2 && s2 <= 1000 && 11 | -0.785 <= s3 && s3 <= -0.005 && 12 | -0.785 <= s4 && s4 <= -0.005) 13 | 14 | 1.0000 * s1 + 1.6567 * s2 + (-18.6854) * s3 + (-3.4594) * s4 15 | } 16 | 17 | 18 | 19 | } -------------------------------------------------------------------------------- /testcases/relative/TurbineSingle.scala: -------------------------------------------------------------------------------- 1 | import daisy.lang._ 2 | import Real._ 3 | 4 | object TurbineSingle { 5 | def turbine1(v: Real): Real = { 6 | require(-4.5 <= v && v <= -0.3) 7 | 3 + 2/(v*v) - 0.125*(3-2*v)*(v*v*v*v)/(1-v) - 4.5 8 | } 9 | def turbine2(v: Real): Real = { 10 | require(-4.5 <= v && v <= -0.3) 11 | 6*v - 0.5 * v * (v*v*v*v) / (1-v) - 2.5 12 | } 13 | def turbine3(v: Real): Real = { 14 | require(-4.5 <= v && v <= -0.3) 15 | 3 - 2/(v*v) - 0.125 * (1+2*v) * (v*v*v*v) / (1-v) - 0.5 16 | } 17 | } -------------------------------------------------------------------------------- /testcases/relative/smallranges/InvertedPendulum.scala: -------------------------------------------------------------------------------- 1 | import daisy.lang._ 2 | import Real._ 3 | 4 | 5 | object InvertedPendulum { 6 | 7 | // s1: <1, 16, 9> s2: <1, 16, 11> s3,s4: <1, 16, 15> 8 | def invPendulum(s1: Real, s2: Real, s3: Real, s4: Real) = { 9 | require(0.005 <= s1 && s1 <= 50 && 10 | 0.005 <= s2 && s2 <= 10 && 11 | -0.785 <= s3 && s3 <= -0.005 && 12 | -0.785 <= s4 && s4 <= -0.005) 13 | 14 | 15 | 1.0000 * s1 + 1.6567 * s2 + (-18.6854) * s3 + (-3.4594) * s4 16 | } 17 | 18 | 19 | 20 | } -------------------------------------------------------------------------------- /testcases/fpbench/floudas2.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object floudas2 { 6 | 7 | 8 | def floudas2(x1: Real, x2: Real): Real = { 9 | require(((0.0 <= x1) && (x1 <= 3.0) && (0.0 <= x2) && (x2 <= 4.0) && (((((2.0 * ((x1 * x1) * (x1 * x1))) - ((8.0 * (x1 * x1)) * x1)) + ((8.0 * x1) * x1)) - x2) >= 0.0) && (((((((4.0 * ((x1 * x1) * (x1 * x1))) - ((32.0 * (x1 * x1)) * x1)) + ((88.0 * x1) * x1)) - (96.0 * x1)) + 36.0) - x2) >= 0.0))) 10 | (-(x1) - x2) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/ints/kepler1.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object kepler1 { 6 | 7 | 8 | def kepler1(x1: Int, x2: Int, x3: Real, x4: Real): Real = { 9 | require(((4.0 <= x1) && (x1 <= 6.36) && (4.0 <= x2) && (x2 <= 6.36) && (4.0 <= x3) && (x3 <= 6.36) && (4.0 <= x4) && (x4 <= 6.36))) 10 | ((((((((x1 * x4) * (((-(x1) + x2) + x3) - x4)) + (x2 * (((x1 - x2) + x3) + x4))) + (x3 * (((x1 + x2) - x3) + x4))) - ((x2 * x3) * x4)) - (x1 * x3)) - (x1 * x2)) - x4) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/kepler1.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object kepler1 { 6 | 7 | 8 | def kepler1(x1: Real, x2: Real, x3: Real, x4: Real): Real = { 9 | require(((4.0 <= x1) && (x1 <= 6.36) && (4.0 <= x2) && (x2 <= 6.36) && (4.0 <= x3) && (x3 <= 6.36) && (4.0 <= x4) && (x4 <= 6.36))) 10 | ((((((((x1 * x4) * (((-(x1) + x2) + x3) - x4)) + (x2 * (((x1 - x2) + x3) + x4))) + (x3 * (((x1 + x2) - x3) + x4))) - ((x2 * x3) * x4)) - (x1 * x3)) - (x1 * x2)) - x4) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/sine_newton.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object sine_newton { 6 | 7 | 8 | def sine_newton(x0: Real): Real = { 9 | require(((-1.0 < x0) && (x0 < 1.0))) 10 | val x_2: Real = (x0 - ((((x0 - (((x0 * x0) * x0) / 6.0)) + (((((x0 * x0) * x0) * x0) * x0) / 120.0)) + (((((((x0 * x0) * x0) * x0) * x0) * x0) * x0) / 5040.0)) / (((1.0 - ((x0 * x0) / 2.0)) + ((((x0 * x0) * x0) * x0) / 24.0)) + ((((((x0 * x0) * x0) * x0) * x0) * x0) / 720.0)))) 11 | x_2 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /testcases/relative/smallranges/JetEngine.scala: -------------------------------------------------------------------------------- 1 | 2 | 3 | import daisy.lang._ 4 | import Real._ 5 | 6 | 7 | object JetEngine { 8 | 9 | 10 | def jetEngine(x1: Real, x2: Real): Real = { 11 | require(4 <= x1 && x1 <= 4.65 && 1 <= x2 && x2 <= 5) 12 | 13 | x1 + ((2*x1*((3*x1*x1 + 2*x2 - x1)/(x1*x1 + 1))* 14 | ((3*x1*x1 + 2*x2 - x1)/(x1*x1 + 1) - 3) + x1*x1*(4*((3*x1*x1 + 2*x2 - x1)/(x1*x1 + 1))-6))* 15 | (x1*x1 + 1) + 3*x1*x1*((3*x1*x1 + 2*x2 - x1)/(x1*x1 + 1)) + x1*x1*x1 + x1 + 16 | 3*((3*x1*x1 + 2*x2 -x1)/(x1*x1 + 1))) 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /testcases/relative/wideranges/JetEngine.scala: -------------------------------------------------------------------------------- 1 | 2 | 3 | import daisy.lang._ 4 | import Real._ 5 | 6 | 7 | object JetEngine { 8 | 9 | 10 | def jetEngine(x1: Real, x2: Real): Real = { 11 | require(4 <= x1 && x1 <= 4.65 && 1 <= x2 && x2 <= 6) 12 | 13 | x1 + ((2*x1*((3*x1*x1 + 2*x2 - x1)/(x1*x1 + 1))* 14 | ((3*x1*x1 + 2*x2 - x1)/(x1*x1 + 1) - 3) + x1*x1*(4*((3*x1*x1 + 2*x2 - x1)/(x1*x1 + 1))-6))* 15 | (x1*x1 + 1) + 3*x1*x1*((3*x1*x1 + 2*x2 - x1)/(x1*x1 + 1)) + x1*x1*x1 + x1 + 16 | 3*((3*x1*x1 + 2*x2 -x1)/(x1*x1 + 1))) 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /testcases/rosa/JetEngineInlined.scala: -------------------------------------------------------------------------------- 1 | 2 | 3 | import daisy.lang._ 4 | import Real._ 5 | 6 | 7 | object JetEngineInlined { 8 | 9 | 10 | def jetEngine(x1: Real, x2: Real): Real = { 11 | require(-5 <= x1 && x1 <= 5 && -20 <= x2 && x2 <= 5) 12 | 13 | x1 + ((2*x1*((3*x1*x1 + 2*x2 - x1)/(x1*x1 + 1))* 14 | ((3*x1*x1 + 2*x2 - x1)/(x1*x1 + 1) - 3) + x1*x1*(4*((3*x1*x1 + 2*x2 - x1)/(x1*x1 + 1))-6))* 15 | (x1*x1 + 1) + 3*x1*x1*((3*x1*x1 + 2*x2 - x1)/(x1*x1 + 1)) + x1*x1*x1 + x1 + 16 | 3*((3*x1*x1 + 2*x2 -x1)/(x1*x1 + 1))) 17 | } 18 | 19 | 20 | } -------------------------------------------------------------------------------- /testcases/modular/unittests/SimpleNested.scala: -------------------------------------------------------------------------------- 1 | import daisy.lang._ 2 | import Real._ 3 | 4 | object SimpleNested { 5 | 6 | def g(g1: Real): Real = { 7 | require(10 <= g1 && g1 <= 100) 8 | g1 * g1 9 | } 10 | 11 | def f(f1: Real, f2: Real): Real = { 12 | require(10 <= f1 && f1 <= 100 && 10 <= f2 && f2 <= 100) 13 | g(f1) + g(f2) 14 | } 15 | 16 | def k(k1: Real): Real = { 17 | require(10 <= k1 && k1 <= 100) 18 | g(k1) 19 | } 20 | 21 | def h(h1: Real): Real = { 22 | require(10 <= h1 && h1 <= 100) 23 | k(h1) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /testcases/fpbench/kepler0.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object kepler0 { 6 | 7 | 8 | def kepler0(x1: Real, x2: Real, x3: Real, x4: Real, x5: Real, x6: Real): Real = { 9 | require(((4.0 <= x1) && (x1 <= 6.36) && (4.0 <= x2) && (x2 <= 6.36) && (4.0 <= x3) && (x3 <= 6.36) && (4.0 <= x4) && (x4 <= 6.36) && (4.0 <= x5) && (x5 <= 6.36) && (4.0 <= x6) && (x6 <= 6.36))) 10 | (((((x2 * x5) + (x3 * x6)) - (x2 * x3)) - (x5 * x6)) + (x1 * (((((-(x1) + x2) + x3) - x4) + x5) + x6))) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/rump_with_pow.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object rump_with_pow { 6 | 7 | 8 | def rump_with_pow(a: Real, b: Real): Real = { 9 | require(((70000.0 <= a) && (a <= 80000.0) && (30000.0 <= b) && (b <= 34000.0))) 10 | ((((333.75 * (((((b * b) * b) * b) * b) * b)) + ((a * a) * (((((11.0 * (a * a)) * (b * b)) - (((((b * b) * b) * b) * b) * b)) - (121.0 * (((b * b) * b) * b))) - 2.0))) + (5.5 * (((((((b * b) * b) * b) * b) * b) * b) * b))) + (a / (2.0 * b))) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/scala/daisy/utils/UniqueCounter.scala: -------------------------------------------------------------------------------- 1 | // Original work Copyright 2009-2016 EPFL, Lausanne 2 | // Modified work Copyright 2017 MPI-SWS, Saarbruecken, Germany 3 | 4 | package daisy 5 | package utils 6 | 7 | class UniqueCounter[K] { 8 | 9 | private var globalId = -1 10 | private var nameIds = Map[K, Int]().withDefaultValue(-1) 11 | 12 | def next(key: K): Int = synchronized { 13 | nameIds += key -> (1 + nameIds(key)) 14 | nameIds(key) 15 | } 16 | 17 | def nextGlobal: Int = synchronized { 18 | globalId += 1 19 | globalId 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/test/resources/AbsErrorRegressionJetEngine.scala: -------------------------------------------------------------------------------- 1 | import daisy.lang._ 2 | import Real._ 3 | 4 | object AbsErrorRegressionJetEngine { 5 | 6 | def jetEngine(x1: Real, x2: Real) = { 7 | require(-5 <= x1 && x1 <= 5 && -20 <= x2 && x2 <= 5) 8 | 9 | x1 + ( 10 | (2*x1*((3*x1*x1 + 2*x2 - x1)/(x1*x1 + 1))*((3*x1*x1 + 2*x2 - x1)/(x1*x1 + 1) - 3) + 11 | x1*x1*(4*((3*x1*x1 + 2*x2 - x1)/(x1*x1 + 1))-6)) 12 | *(x1*x1 + 1) + 13 | 3*x1*x1*((3*x1*x1 + 2*x2 - x1)/(x1*x1 + 1)) + x1*x1*x1 + x1 + 3*((3*x1*x1 + 2*x2 -x1)/(x1*x1 + 1))) 14 | 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /testcases/ints/kepler0.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object kepler0 { 6 | 7 | 8 | def kepler0(x1: Int, x2: Int, x3: Real, x4: Real, x5: Real, x6: Real): Real = { 9 | require(((4.0 <= x1) && (x1 <= 6.36) && (4.0 <= x2) && (x2 <= 6.36) && (4.0 <= x3) && (x3 <= 6.36) && 10 | (4.0 <= x4) && (x4 <= 6.36) && (4.0 <= x5) && (x5 <= 6.36) && (4.0 <= x6) && (x6 <= 6.36))) 11 | (((((x2 * x5) + (x3 * x6)) - (x2 * x3)) - (x5 * x6)) + (x1 * (((((-(x1) + x2) + x3) - x4) + x5) + x6))) 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /testcases/real2float/Himmilbeau.scala: -------------------------------------------------------------------------------- 1 | 2 | import daisy.lang._ 3 | import Real._ 4 | 5 | /* 6 | Real2Float 7 | From a global optimization problem 8 | A Numerical Evaluation of Several Stochastic Algorithms on 9 | Selected Continuous Global Optimization problems, 10 | Ali, Khompatraporn, Zabinsky, 2005 11 | 12 | */ 13 | object Himmilbeau { 14 | 15 | def himmilbeau(x1: Real, x2: Real) = { 16 | require(-5 <= x1 && x1 <= 5 && -5 <= x2 && x2 <= 5) 17 | 18 | (x1*x1 + x2 - 11)*(x1 * x1 + x2 - 11) + (x1 + x2*x2 - 7)*(x1 + x2*x2 - 7) 19 | 20 | } //1.43e–12 21 | 22 | } -------------------------------------------------------------------------------- /testcases/relative/Himmilbeau.scala: -------------------------------------------------------------------------------- 1 | 2 | import daisy.lang._ 3 | import Real._ 4 | 5 | /* 6 | Real2Float 7 | From a global optimization problem 8 | A Numerical Evaluation of Several Stochastic Algorithms on 9 | Selected Continuous Global Optimization problems, 10 | Ali, Khompatraporn, Zabinsky, 2005 11 | 12 | */ 13 | object Himmilbeau { 14 | 15 | def himmilbeau(x1: Real, x2: Real) = { 16 | require(-5 <= x1 && x1 <= 5 && -5 <= x2 && x2 <= 5) 17 | 18 | (x1*x1 + x2 - 11)*(x1 * x1 + x2 - 11) + (x1 + x2*x2 - 7)*(x1 + x2*x2 - 7) 19 | 20 | } //1.43e–12 21 | 22 | } -------------------------------------------------------------------------------- /testcases/control/JetEngine.scala: -------------------------------------------------------------------------------- 1 | import daisy.lang._ 2 | import Real._ 3 | 4 | 5 | object JetEngine { 6 | 7 | // x1: <1, 16, 12> x2: <1, 16, 10> 8 | def out(x1: Real, x2: Real) = { 9 | require(-5 <= x1 && x1 <= 5 && -20 <= x2 && x2 <= 5) 10 | x1 + ( 11 | (2*x1*((3*x1*x1 + 2*x2 - x1)/(x1*x1 + 1))*((3*x1*x1 + 2*x2 - x1)/(x1*x1 + 1) - 3) + 12 | x1*x1*(4*((3*x1*x1 + 2*x2 - x1)/(x1*x1 + 1))-6)) 13 | *(x1*x1 + 1) + 14 | 3*x1*x1*((3*x1*x1 + 2*x2 - x1)/(x1*x1 + 1)) + x1*x1*x1 + x1 + 3*((3*x1*x1 + 2*x2 -x1)/(x1*x1 + 1))) 15 | 16 | } 17 | 18 | 19 | 20 | } -------------------------------------------------------------------------------- /testcases/fpbench/test02_sum8.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object test02_sum8 { 6 | 7 | 8 | def test02_sum8(x0: Real, x1: Real, x2: Real, x3: Real, x4: Real, x5: Real, x6: Real, x7: Real): Real = { 9 | require(((1.0 < x0) && (x0 < 2.0) && (1.0 < x1) && (x1 < 2.0) && (1.0 < x2) && (x2 < 2.0) && (1.0 < x3) && (x3 < 2.0) && (1.0 < x4) && (x4 < 2.0) && (1.0 < x5) && (x5 < 2.0) && (1.0 < x6) && (x6 < 2.0) && (1.0 < x7) && (x7 < 2.0))) 10 | (((((((x0 + x1) + x2) + x3) + x4) + x5) + x6) + x7) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/ints/delta4.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object delta4 { 6 | 7 | 8 | def delta4(x1: Int, x2: Real, x3: Real, x4: Int, x5: Real, x6: Real): Real = { 9 | require(((4.0 <= x1) && (x1 <= 6.3504) && (4.0 <= x2) && (x2 <= 6.3504) && (4.0 <= x3) && (x3 <= 6.3504) && (4.0 <= x4) && (x4 <= 6.3504) && (4.0 <= x5) && (x5 <= 6.3504) && (4.0 <= x6) && (x6 <= 6.3504))) 10 | ((((((-(x2) * x3) - (x1 * x4)) + (x2 * x5)) + (x3 * x6)) - (x5 * x6)) + (x1 * (((((-(x1) + x2) + x3) - x4) + x5) + x6))) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/relative/HimmilbeauSingle.scala: -------------------------------------------------------------------------------- 1 | import daisy.lang._ 2 | import Real._ 3 | 4 | /* 5 | Real2Float 6 | From a global optimization problem 7 | A Numerical Evaluation of Several Stochastic Algorithms on 8 | Selected Continuous Global Optimization problems, 9 | Ali, Khompatraporn, Zabinsky, 2005 10 | 11 | */ 12 | object HimmilbeauSingle { 13 | 14 | def himmilbeau(x1: Real) = { 15 | require(-5 <= x1 && x1 <= 5) 16 | val x2: Real = 1 // && -5 <= x2 && x2 <= 5 17 | (x1*x1 + 1 - 11)*(x1 * x1 + 1 - 11) + (x1 + 1*1 - 7)*(x1 + 1*1 - 7) 18 | 19 | } //1.43e–12 20 | 21 | } -------------------------------------------------------------------------------- /testcases/relative/smallranges/Himmilbeau.scala: -------------------------------------------------------------------------------- 1 | 2 | import daisy.lang._ 3 | import Real._ 4 | 5 | /* 6 | Real2Float 7 | From a global optimization problem 8 | A Numerical Evaluation of Several Stochastic Algorithms on 9 | Selected Continuous Global Optimization problems, 10 | Ali, Khompatraporn, Zabinsky, 2005 11 | 12 | */ 13 | object Himmilbeau { 14 | 15 | def himmilbeau(x1: Real, x2: Real) = { 16 | require(0.1 <= x1 && x1 <= 0.5 && -2<= x2 && x2 <= 2) 17 | 18 | (x1*x1 + x2 - 11)*(x1 * x1 + x2 - 11) + (x1 + x2*x2 - 7)*(x1 + x2*x2 - 7) 19 | 20 | } //1.43e–12 21 | 22 | } -------------------------------------------------------------------------------- /testcases/relative/wideranges/Himmilbeau.scala: -------------------------------------------------------------------------------- 1 | 2 | import daisy.lang._ 3 | import Real._ 4 | 5 | /* 6 | Real2Float 7 | From a global optimization problem 8 | A Numerical Evaluation of Several Stochastic Algorithms on 9 | Selected Continuous Global Optimization problems, 10 | Ali, Khompatraporn, Zabinsky, 2005 11 | 12 | */ 13 | object Himmilbeau { 14 | 15 | def himmilbeau(x1: Real, x2: Real) = { 16 | require(20 <= x1 && x1 <= 100 && -2<= x2 && x2 <= 20) 17 | 18 | (x1*x1 + x2 - 11)*(x1 * x1 + x2 - 11) + (x1 + x2*x2 - 7)*(x1 + x2*x2 - 7) 19 | 20 | } //1.43e–12 21 | 22 | } -------------------------------------------------------------------------------- /testcases/rosa/RigidBody.scala: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | import daisy.lang._ 5 | import Real._ 6 | 7 | 8 | object RigidBody { 9 | 10 | def rigidBody1(x1: Real, x2: Real, x3: Real): Real = { 11 | require(-15.0 <= x1 && x1 <= 15 && -15.0 <= x2 && x2 <= 15.0 && -15.0 <= x3 && x3 <= 15) 12 | 13 | -x1*x2 - 2*x2*x3 - x1 - x3 14 | } 15 | 16 | def rigidBody2(x1: Real, x2: Real, x3: Real): Real = { 17 | require(-15.0 <= x1 && x1 <= 15 && -15.0 <= x2 && x2 <= 15.0 && 18 | -15.0 <= x3 && x3 <= 15) 19 | 20 | 2*(x1*x2*x3) + (3*x3*x3) - x2*(x1*x2*x3) + (3*x3*x3) - x2 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /testcases/fpbench/delta4.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object delta4 { 6 | 7 | 8 | def delta4(x1: Real, x2: Real, x3: Real, x4: Real, x5: Real, x6: Real): Real = { 9 | require(((4.0 <= x1) && (x1 <= 6.3504) && (4.0 <= x2) && (x2 <= 6.3504) && (4.0 <= x3) && (x3 <= 6.3504) && (4.0 <= x4) && (x4 <= 6.3504) && (4.0 <= x5) && (x5 <= 6.3504) && (4.0 <= x6) && (x6 <= 6.3504))) 10 | ((((((-(x2) * x3) - (x1 * x4)) + (x2 * x5)) + (x3 * x6)) - (x5 * x6)) + (x1 * (((((-(x1) + x2) + x3) - x4) + x5) + x6))) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/jacobisMethodX1.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object jacobisMethodX1 { 6 | 7 | 8 | def jacobisMethodX1(a11: Real, b1: Real, x1: Real, x2: Real, x3: Real, x4: Real): Real = { 9 | require(((0.001 < a11) && (a11 < 10.0) && (0.001 < b1) && (b1 < 10.0) && (0.0 < x1) && (x1 < 10.0) && (0.0 < x2) && (x2 < 10.0) && (0.0 < x3) && (x3 < 10.0) && (0.0 < x4) && (x4 < 10.0))) 10 | val x_n1: Real = ((((b1 / a11) - ((0.1 / a11) * x2)) - ((0.2 / a11) * x3)) + ((0.3 / a11) * x4)) 11 | x_n1 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /testcases/fpbench/jacobisMethodX2.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object jacobisMethodX2 { 6 | 7 | 8 | def jacobisMethodX2(a22: Real, b2: Real, x1: Real, x2: Real, x3: Real, x4: Real): Real = { 9 | require(((0.001 < a22) && (a22 < 10.0) && (0.001 < b2) && (b2 < 10.0) && (0.0 < x1) && (x1 < 10.0) && (0.0 < x2) && (x2 < 10.0) && (0.0 < x3) && (x3 < 10.0) && (0.0 < x4) && (x4 < 10.0))) 10 | val x_n2: Real = ((((b2 / a22) - ((0.3 / a22) * x1)) + ((0.1 / a22) * x3)) - ((0.2 / a22) * x4)) 11 | x_n2 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /testcases/fpbench/jacobisMethodX3.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object jacobisMethodX3 { 6 | 7 | 8 | def jacobisMethodX3(a33: Real, b3: Real, x1: Real, x2: Real, x3: Real, x4: Real): Real = { 9 | require(((0.001 < a33) && (a33 < 10.0) && (0.001 < b3) && (b3 < 10.0) && (0.0 < x1) && (x1 < 10.0) && (0.0 < x2) && (x2 < 10.0) && (0.0 < x3) && (x3 < 10.0) && (0.0 < x4) && (x4 < 10.0))) 10 | val x_n3: Real = ((((b3 / a33) - ((0.2 / a33) * x1)) + ((0.3 / a33) * x2)) - ((0.1 / a33) * x4)) 11 | x_n3 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /testcases/fpbench/jacobisMethodX4.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object jacobisMethodX4 { 6 | 7 | 8 | def jacobisMethodX4(a44: Real, b4: Real, x1: Real, x2: Real, x3: Real, x4: Real): Real = { 9 | require(((0.001 < a44) && (a44 < 10.0) && (0.001 < b4) && (b4 < 10.0) && (0.0 < x1) && (x1 < 10.0) && (0.0 < x2) && (x2 < 10.0) && (0.0 < x3) && (x3 < 10.0) && (0.0 < x4) && (x4 < 10.0))) 10 | val x_n4: Real = ((((b4 / a44) + ((0.1 / a44) * x1)) - ((0.2 / a44) * x2)) - ((0.3 / a44) * x3)) 11 | x_n4 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /testcases/fpbench/newtonRaphson.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object newtonRaphson { 6 | 7 | 8 | def newtonRaphson(x: Real): Real = { 9 | require(((0.0 < x) && (x < 3.0))) 10 | val f: Real = (((((((x * x) * ((x * x) * x)) - ((10.0 * x) * ((x * x) * x))) + ((40.0 * x) * (x * x))) - ((80.0 * x) * x)) + (80.0 * x)) - 32.0) 11 | val ff: Real = ((((((5.0 * x) * ((x * x) * x)) - ((40.0 * x) * (x * x))) + ((120.0 * x) * x)) - (160.0 * x)) + 80.0) 12 | val ret: Real = (x - (f / ff)) 13 | ret 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /testcases/relative/JetEngine.scala: -------------------------------------------------------------------------------- 1 | 2 | 3 | import daisy.lang._ 4 | import Real._ 5 | 6 | 7 | object JetEngine { 8 | 9 | 10 | def jetEngine(x1: Real, x2: Real): Real = { 11 | require(-5 <= x1 && x1 <= 5 && -20 <= x2 && x2 <= 5) 12 | 13 | // val t = (3*x1*x1 + 2*x2 - x1) 14 | 15 | x1 + ((2*x1*((3*x1*x1 + 2*x2 - x1)/(x1*x1 + 1))* 16 | ((3*x1*x1 + 2*x2 - x1)/(x1*x1 + 1) - 3) + x1*x1*(4*((3*x1*x1 + 2*x2 - x1)/(x1*x1 + 1))-6))* 17 | (x1*x1 + 1) + 3*x1*x1*((3*x1*x1 + 2*x2 - x1)/(x1*x1 + 1)) + x1*x1*x1 + x1 + 18 | 3*((3*x1*x1 + 2*x2 -x1)/(x1*x1 + 1))) 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /testcases/relative/RigidBody.scala: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | import daisy.lang._ 5 | import Real._ 6 | 7 | 8 | object RigidBody { 9 | 10 | def rigidBody1(x1: Real, x2: Real, x3: Real): Real = { 11 | require(-15.0 <= x1 && x1 <= 15 && -15.0 <= x2 && x2 <= 15.0 && -15.0 <= x3 && x3 <= 15) 12 | 13 | -x1*x2 - 2*x2*x3 - x1 - x3 14 | } 15 | 16 | def rigidBody2(x1: Real, x2: Real, x3: Real): Real = { 17 | require(-15.0 <= x1 && x1 <= 15 && -15.0 <= x2 && x2 <= 15.0 && 18 | -15.0 <= x3 && x3 <= 15) 19 | 20 | 2*(x1*x2*x3) + (3*x3*x3) - x2*(x1*x2*x3) + (3*x3*x3) - x2 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /testcases/relative/smallranges/RigidBody.scala: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | import daisy.lang._ 5 | import Real._ 6 | 7 | 8 | object RigidBody { 9 | 10 | def rigidBody1(x1: Real, x2: Real, x3: Real): Real = { 11 | require(-15.0 <= x1 && x1 <= -0.1 && 0.1 <= x2 && x2 <= 15.0 && -15.0 <= x3 && x3 <= -0.1) 12 | 13 | -x1*x2 - 2*x2*x3 - x1 - x3 14 | } 15 | 16 | def rigidBody2(x1: Real, x2: Real, x3: Real): Real = { 17 | require(-15.0 <= x1 && x1 <= -11.25 && -15.0 <= x2 && x2 <= -11.25 && 18 | -15.0 <= x3 && x3 <= -11.25) 19 | 20 | 2*(x1*x2*x3) + (3*x3*x3) - x2*(x1*x2*x3) + (3*x3*x3) - x2 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /src/main/scala/daisy/utils/Pipeline.scala: -------------------------------------------------------------------------------- 1 | // Original work Copyright 2009-2016 EPFL, Lausanne 2 | // Modified work Copyright 2017 MPI-SWS, Saarbruecken, Germany 3 | 4 | package daisy 5 | 6 | abstract class Pipeline[-F, +T] { 7 | self => 8 | 9 | def >>[G](thenn: Pipeline[T, G]): Pipeline[F, G] = new Pipeline[F,G] { 10 | def run(ctx: Context, v: F): (Context, G) = { 11 | val (ctx2, s) = self.run(ctx, v) 12 | // if(ctx.findOptionOrDefault(SharedOptions.optStrictPhases)) ctx.reporter.terminateIfError() 13 | thenn.run(ctx2, s) 14 | } 15 | } 16 | 17 | def run(ctx: Context, v: F): (Context, T) 18 | } -------------------------------------------------------------------------------- /testcases/relative/wideranges/RigidBody.scala: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | import daisy.lang._ 5 | import Real._ 6 | 7 | 8 | object RigidBody { 9 | 10 | def rigidBody1(x1: Real, x2: Real, x3: Real): Real = { 11 | require(-1500.0 <= x1 && x1 <= -0.0001 && 0.1 <= x2 && x2 <= 15.0 && -15.0 <= x3 && x3 <= -0.1) 12 | 13 | -x1*x2 - 2*x2*x3 - x1 - x3 14 | } 15 | 16 | def rigidBody2(x1: Real, x2: Real, x3: Real): Real = { 17 | require(-1500.0 <= x1 && x1 <= -1.125 && -15.0 <= x2 && x2 <= -11.25 && 18 | -15.0 <= x3 && x3 <= -11.25) 19 | 20 | 2*(x1*x2*x3) + (3*x3*x3) - x2*(x1*x2*x3) + (3*x3*x3) - x2 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /testcases/control/RigidBody.scala: -------------------------------------------------------------------------------- 1 | import daisy.lang._ 2 | import Real._ 3 | 4 | 5 | object RigidBody { 6 | 7 | //x1, x2, x3: < 1, 16 11>, [-15, 15] 8 | def out1(x1: Real, x2: Real, x3: Real): Real = { 9 | require(-15 <= x1 && x1 <= 15 && -15 <= x2 && x2 <= 15 && -15 <= x3 && x3 <= 15) 10 | -x1*x2 - 2*x2*x3 - x1 - x3 11 | } 12 | 13 | // apparently this needs 17 bits, or we've not been accurate enough 14 | def out2(x1: Real, x2: Real, x3: Real): Real = { 15 | require(-15 <= x1 && x1 <= 15 && -15 <= x2 && x2 <= 15 && -15 <= x3 && x3 <= 15) 16 | 2*x1*x2*x3 + 3*x3*x3 - x2*x1*x2*x3 + 3*x3*x3 - x2 17 | } 18 | } -------------------------------------------------------------------------------- /testcases/fpbench/rump_from_C.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object rump_from_C { 6 | 7 | 8 | def rump_from_C(a: Real, b: Real): Real = { 9 | require(((70000.0 <= a) && (a <= 80000.0) && (30000.0 <= b) && (b <= 34000.0))) 10 | val b2: Real = (b * b) 11 | val b4: Real = (b2 * b2) 12 | val b6: Real = (b4 * b2) 13 | val b8: Real = (b4 * b4) 14 | val a2: Real = (a * a) 15 | val firstexpr: Real = (((((11.0 * a2) * b2) - b6) - (121.0 * b4)) - 2.0) 16 | ((((333.75 * b6) + (a2 * firstexpr)) + (5.5 * b8)) + (a / (2.0 * b))) 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /testcases/fpbench/pendulum.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object pendulum { 6 | 7 | 8 | def pendulum(t0: Real, w0: Real): Real = { 9 | require(((-2.0 < t0) && (t0 < 2.0) && (-5.0 < w0) && (w0 < 5.0))) 10 | val h: Real = 0.01 11 | val L: Real = 2.0 12 | val m: Real = 1.5 13 | val g: Real = 9.80665 14 | val t_1: Real = t0 15 | val w_1: Real = w0 16 | val n: Real = 0.0 17 | val k1w: Real = ((-(g) / L) * sin(t_1)) 18 | val k2t: Real = (w_1 + ((h / 2.0) * k1w)) 19 | val t_3: Real = (t_1 + (h * k2t)) 20 | t_3 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /testcases/fpbench/rump_revisited.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object rump_revisited { 6 | 7 | 8 | def rump_revisited(a: Real, b: Real): Real = { 9 | require(((70000.0 <= a) && (a <= 80000.0) && (30000.0 <= b) && (b <= 34000.0))) 10 | val b2: Real = (b * b) 11 | val b4: Real = (b2 * b2) 12 | val b6: Real = (b4 * b2) 13 | val b8: Real = (b4 * b4) 14 | val a2: Real = (a * a) 15 | val firstexpr: Real = ((((11.0 * a2) * b2) - (121.0 * b4)) - 2.0) 16 | (((((333.75 - a2) * b6) + (a2 * firstexpr)) + (5.5 * b8)) + (a / (2.0 * b))) 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /scripts/metalibm/time_all.sh: -------------------------------------------------------------------------------- 1 | 2 | 3 | # benchmarks generated code and compares against math.h implementations 4 | # results are saved in the output/ folder 5 | 6 | ./scripts/metalibm/metalibm_timing.sh float64_small 7 | 8 | ./scripts/metalibm/metalibm_timing.sh float64_middle 9 | 10 | ./scripts/metalibm/metalibm_timing.sh float64_large 11 | 12 | ./scripts/metalibm/metalibm_timing.sh float64_large_deriv 13 | 14 | ./scripts/metalibm/metalibm_timing.sh tableWidth_large 15 | 16 | ./scripts/metalibm/metalibm_timing.sh compound_mid_large 17 | 18 | ./scripts/metalibm/metalibm_timing.sh compound_large_large 19 | 20 | ./scripts/metalibm/metalibm_timing.sh float32_middle -------------------------------------------------------------------------------- /testcases/control/Taylor.scala: -------------------------------------------------------------------------------- 1 | import daisy.lang._ 2 | import Real._ 3 | 4 | 5 | object Taylor { 6 | 7 | def sine(x: Real): Real = { 8 | require(x > -1.57079632679 && x < 1.57079632679) 9 | x - (x*x*x)/6.0 + (x*x*x*x*x)/120.0 - (x*x*x*x*x*x*x)/5040.0 10 | }// ensuring (res => res +/- 1e-6) 11 | 12 | def sineOrder3(x: Real): Real = { 13 | require(-2.0 < x && x < 2.0) 14 | 0.954929658551372 * x - 0.12900613773279798*(x*x*x) 15 | }// ensuring (res => res +/- 1e-6) 16 | 17 | def sqroot(x: Real): Real = { 18 | require(x >= 0.0 && x < 1.0) 19 | 1.0 + 0.5*x - 0.125*x*x + 0.0625*x*x*x - 0.0390625*x*x*x*x 20 | }// ensuring (res => res +/- 1e-6) 21 | } -------------------------------------------------------------------------------- /testcases/ints/jetEngine.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object jetEngine { 6 | 7 | 8 | def jetEngine(x1: Int, x2: Real): Real = { 9 | require(((-5.0 <= x1) && (x1 <= 5.0) && (-20.0 <= x2) && (x2 <= 5.0))) 10 | val t: Real = ((((3.0 * x1) * x1) + (2.0 * x2)) - x1) 11 | val t2: Real = ((((3.0 * x1) * x1) - (2.0 * x2)) - x1) 12 | val d: Real = ((x1 * x1) + 1.0) 13 | val s: Real = (t / d) 14 | val s2: Real = (t2 / d) 15 | (x1 + (((((((((2.0 * x1) * s) * (s - 3.0)) + ((x1 * x1) * ((4.0 * s) - 6.0))) * d) + (((3.0 * x1) * x1) * s)) + ((x1 * x1) * x1)) + x1) + (3.0 * s2))) 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /testcases/fpbench/jetEngine.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object jetEngine { 6 | 7 | 8 | def jetEngine(x1: Real, x2: Real): Real = { 9 | require(((-5.0 <= x1) && (x1 <= 5.0) && (-20.0 <= x2) && (x2 <= 5.0))) 10 | val t: Real = ((((3.0 * x1) * x1) + (2.0 * x2)) - x1) 11 | val t2: Real = ((((3.0 * x1) * x1) - (2.0 * x2)) - x1) 12 | val d: Real = ((x1 * x1) + 1.0) 13 | val s: Real = (t / d) 14 | val s2: Real = (t2 / d) 15 | (x1 + (((((((((2.0 * x1) * s) * (s - 3.0)) + ((x1 * x1) * ((4.0 * s) - 6.0))) * d) + (((3.0 * x1) * x1) * s)) + ((x1 * x1) * x1)) + x1) + (3.0 * s2))) 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /regression/reference/tuning_results.csv: -------------------------------------------------------------------------------- 1 | Function name; Absolute error; Relative error; Real range; Time 2 | doppler_64_05;2.2355864078143494e-13;7.59307436081909e-12;[-158.7191444098274, -0.02944244059231351];8589 3 | kepler0_64_05;4.3050008002865075e-14;;[-35.7792, 159.8176];8589 4 | rigidBody1_64_05;6.838973831690964e-14;;[-705.0, 705.0];8590 5 | rigidBody2_64_05;1.9532819806045154e-11;;[-58740.0, 58740.0];8590 6 | turbine1_64_05;4.0091690651094673e-14;2.5856789337040327e-14;[-58.32912689020381, -1.5505285721480735];8591 7 | turbine2_64_05;6.983917717644337e-14;;[-29.43698909090909, 80.993];8591 8 | turbine3_64_05;2.8185317327929985e-14;6.04710761484431e-14;[0.4660958448753463, 40.375126890203816];8592 9 | -------------------------------------------------------------------------------- /src/main/scala/daisy/tools/Exceptions.scala: -------------------------------------------------------------------------------- 1 | // Copyright 2017 MPI-SWS, Saarbruecken, Germany 2 | 3 | package daisy.tools 4 | 5 | case class DivisionByZeroException(s: String) extends Exception 6 | 7 | case class DenormalRangeException(s: String) extends Exception 8 | 9 | case class OverflowException(s: String) extends Exception 10 | 11 | case class RationalCannotBeCastToIntException(s: String) extends Exception 12 | 13 | case class NegativeSqrtException(s: String) extends Exception 14 | 15 | case class NoRelativeErrorException(s: String) extends Exception 16 | 17 | case class NonPositiveLogException(s: String) extends Exception 18 | 19 | case class ArcOutOfBoundsException(s: String) extends Exception 20 | -------------------------------------------------------------------------------- /testcases/ints/kepler2.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object kepler2 { 6 | 7 | 8 | def kepler2(x1: Int, x2: Int, x3: Real, x4: Real, x5: Real, x6: Real): Real = { 9 | require(((4.0 <= x1) && (x1 <= 6.36) && (4.0 <= x2) && (x2 <= 6.36) && (4.0 <= x3) && (x3 <= 6.36) && (4.0 <= x4) && (x4 <= 6.36) && (4.0 <= x5) && (x5 <= 6.36) && (4.0 <= x6) && (x6 <= 6.36))) 10 | ((((((((x1 * x4) * (((((-(x1) + x2) + x3) - x4) + x5) + x6)) + ((x2 * x5) * (((((x1 - x2) + x3) + x4) - x5) + x6))) + ((x3 * x6) * (((((x1 + x2) - x3) + x4) + x5) - x6))) - ((x2 * x3) * x4)) - ((x1 * x3) * x5)) - ((x1 * x2) * x6)) - ((x4 * x5) * x6)) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/ints/matrixDeterminant.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object matrixDeterminant { 6 | 7 | 8 | def matrixDeterminant(a: Int, b: Real, c: Real, d: Real, e: Real, f: Int, g: Real, h: Real, i: Real): Real = { 9 | require(((-10.0 <= a) && (a <= 10.0) && (-10.0 <= b) && (b <= 10.0) && (-10.0 <= c) && (c <= 10.0) && (-10.0 <= d) && (d <= 10.0) && (-10.0 <= e) && (e <= 10.0) && (-10.0 <= f) && (f <= 10.0) && (-10.0 <= g) && (g <= 10.0) && (-10.0 <= h) && (h <= 10.0) && (-10.0 <= i) && (i <= 10.0))) 10 | (((((a * e) * i) + ((b * f) * g)) + ((c * d) * h)) - ((((c * e) * g) + ((b * d) * i)) + ((a * f) * h))) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/jetEngineModified.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object jetEngineModified { 6 | 7 | 8 | def jetEngineModified(x1: Real, x2: Real): Real = { 9 | require(((0.0 <= x1) && (x1 <= 5.0) && (-20.0 <= x2) && (x2 <= 5.0))) 10 | val t: Real = ((((3.0 * x1) * x1) + (2.0 * x2)) - x1) 11 | val t2: Real = ((((3.0 * x1) * x1) - (2.0 * x2)) - x1) 12 | val d: Real = ((x1 * x1) + 1.0) 13 | val s: Real = (t / d) 14 | val s2: Real = (t2 / d) 15 | (x1 + (((((((((2.0 * x1) * s) * (s - 3.0)) + ((x1 * x1) * ((4.0 * s) - 6.0))) * d) + (((3.0 * x1) * x1) * s)) + ((x1 * x1) * x1)) + x1) + (3.0 * s2))) 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /testcases/fpbench/kepler2.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object kepler2 { 6 | 7 | 8 | def kepler2(x1: Real, x2: Real, x3: Real, x4: Real, x5: Real, x6: Real): Real = { 9 | require(((4.0 <= x1) && (x1 <= 6.36) && (4.0 <= x2) && (x2 <= 6.36) && (4.0 <= x3) && (x3 <= 6.36) && (4.0 <= x4) && (x4 <= 6.36) && (4.0 <= x5) && (x5 <= 6.36) && (4.0 <= x6) && (x6 <= 6.36))) 10 | ((((((((x1 * x4) * (((((-(x1) + x2) + x3) - x4) + x5) + x6)) + ((x2 * x5) * (((((x1 - x2) + x3) + x4) - x5) + x6))) + ((x3 * x6) * (((((x1 + x2) - x3) + x4) + x5) - x6))) - ((x2 * x3) * x4)) - ((x1 * x3) * x5)) - ((x1 * x2) * x6)) - ((x4 * x5) * x6)) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/matrixDeterminant.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object matrixDeterminant { 6 | 7 | 8 | def matrixDeterminant(a: Real, b: Real, c: Real, d: Real, e: Real, f: Real, g: Real, h: Real, i: Real): Real = { 9 | require(((-10.0 <= a) && (a <= 10.0) && (-10.0 <= b) && (b <= 10.0) && (-10.0 <= c) && (c <= 10.0) && (-10.0 <= d) && (d <= 10.0) && (-10.0 <= e) && (e <= 10.0) && (-10.0 <= f) && (f <= 10.0) && (-10.0 <= g) && (g <= 10.0) && (-10.0 <= h) && (h <= 10.0) && (-10.0 <= i) && (i <= 10.0))) 10 | (((((a * e) * i) + ((b * f) * g)) + ((c * d) * h)) - ((((c * e) * g) + ((b * d) * i)) + ((a * f) * h))) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/matrixDeterminant2.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object matrixDeterminant2 { 6 | 7 | 8 | def matrixDeterminant2(a: Real, b: Real, c: Real, d: Real, e: Real, f: Real, g: Real, h: Real, i: Real): Real = { 9 | require(((-10.0 <= a) && (a <= 10.0) && (-10.0 <= b) && (b <= 10.0) && (-10.0 <= c) && (c <= 10.0) && (-10.0 <= d) && (d <= 10.0) && (-10.0 <= e) && (e <= 10.0) && (-10.0 <= f) && (f <= 10.0) && (-10.0 <= g) && (g <= 10.0) && (-10.0 <= h) && (h <= 10.0) && (-10.0 <= i) && (i <= 10.0))) 10 | (((a * (e * i)) + ((g * (b * f)) + (c * (d * h)))) - ((e * (c * g)) + ((i * (b * d)) + (a * (f * h))))) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/matrixDeterminant2modified.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object matrixDeterminant2modified { 6 | 7 | 8 | def matrixDeterminant2modified(a: Real, b: Real, c: Real, d: Real, e: Real, f: Real, g: Real, h: Real, i: Real): Real = { 9 | require(((5.0 <= a) && (a <= 50.0) && (5.0 <= b) && (b <= 50.0) && (2.0 <= c) && (c <= 12.0) && (0.0 <= d) && (d <= 5.0) && (-10.0 <= e) && (e <= -1.0) && (3.0 <= f) && (f <= 42.0) && (-10.0 <= g) && (g <= 10.0) && (-0.5 <= h) && (h <= 1.5) && (-11.0 <= i) && (i <= -8.0))) 10 | (((a * (e * i)) + ((g * (b * f)) + (c * (d * h)))) - ((e * (c * g)) + ((i * (b * d)) + (a * (f * h))))) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/triangleSorted.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object triangleSorted { 6 | 7 | 8 | def triangleSorted(a: Real, b: Real, c: Real): Real = { 9 | require(((1.0 <= a) && (a <= 9.0) && (1.0 <= b) && (b <= 9.0) && (1.0 <= c) && (c <= 9.0) && ((a + b) > (c + 1.0e-06)) && ((a + c) > (b + 1.0e-06)) && ((b + c) > (a + 1.0e-06)) && (a < c) && (b < c))) 10 | val temp: Real = if ((a < b)) { 11 | (sqrt(((((c + (b + a)) * (a - (c - b))) * (a + (c - b))) * (c + (b - a)))) / 4.0) 12 | } 13 | else { 14 | (sqrt(((((c + (a + b)) * (b - (c - a))) * (b + (c - a))) * (c + (a - b)))) / 4.0) 15 | } 16 | temp 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /testcases/control/Bicycle.scala: -------------------------------------------------------------------------------- 1 | import daisy.lang._ 2 | import Real._ 3 | 4 | 5 | object Bicycle { 6 | 7 | // s1, s2, s3, y1: <1, 16, 14>, [-1, 1] 8 | def out1(s1: Real, s2: Real) = { 9 | require(-1 <= s1 && s1 <= 1 && -1 <= s2 && s2 <= 1) 10 | (-3.025300) * s1 + (-12.608900) * s2 11 | } 12 | 13 | def state1(s1: Real, s2: Real, y1: Real) = { 14 | require(-1 <= s1 && s1 <= 1 && -1 <= s2 && s2 <= 1 && -1 <= y1 && y1 <= 1) 15 | (0.961270) * s1 + (-0.095962) * s2 + (0.013200) * y1 16 | } 17 | 18 | def state2(s1: Real, s2: Real, y1: Real) = { 19 | require(-1 <= s1 && s1 <= 1 && -1 <= s2 && s2 <= 1 && -1 <= y1 && y1 <= 1) 20 | (-0.058217) * s1 + (0.727430) * s2 + (0.102100) * y1 21 | } 22 | 23 | 24 | } -------------------------------------------------------------------------------- /testcases/fpbench/delta.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object delta { 6 | 7 | 8 | def delta(x1: Real, x2: Real, x3: Real, x4: Real, x5: Real, x6: Real): Real = { 9 | require(((4.0 <= x1) && (x1 <= 6.3504) && (4.0 <= x2) && (x2 <= 6.3504) && (4.0 <= x3) && (x3 <= 6.3504) && (4.0 <= x4) && (x4 <= 6.3504) && (4.0 <= x5) && (x5 <= 6.3504) && (4.0 <= x6) && (x6 <= 6.3504))) 10 | ((((((((x1 * x4) * (((((-(x1) + x2) + x3) - x4) + x5) + x6)) + ((x2 * x5) * (((((x1 - x2) + x3) + x4) - x5) + x6))) + ((x3 * x6) * (((((x1 + x2) - x3) + x4) + x5) - x6))) + ((-(x2) * x3) * x4)) + ((-(x1) * x3) * x5)) + ((-(x1) * x2) * x6)) + ((-(x4) * x5) * x6)) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /testcases/fpbench/pid.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object pid { 6 | 7 | 8 | def pid(m: Real, c: Real): Real = { 9 | require(((-10.0 < m) && (m < 10.0) && (-10.0 < c) && (c < 10.0))) 10 | val ki: Real = 0.69006 11 | val kp: Real = 9.4514 12 | val kd: Real = 2.8454 13 | val i_0: Real = 0.0 14 | val dt: Real = 0.2 15 | val invdt: Real = 5.0 16 | val eold: Real = 0.0 17 | val e_1: Real = (c - m) 18 | val p_1: Real = (kp * e_1) 19 | val i_1: Real = (i_0 + ((ki * dt) * e_1)) 20 | val d_1: Real = ((kd * invdt) * (e_1 - eold)) 21 | val r_1: Real = ((p_1 + i_1) + d_1) 22 | (m + (0.01 * r_1)) 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/scala/daisy/solvers/Exceptions.scala: -------------------------------------------------------------------------------- 1 | // Original work Copyright 2009-2016 EPFL, Lausanne 2 | // Modified work Copyright 2017 MPI-SWS, Saarbruecken, Germany 3 | 4 | package daisy 5 | package solvers 6 | 7 | import lang.Trees.Tree 8 | 9 | case class CantResetException(s: SMTLibSolver) extends Exception(s"Unable to reset solver $s") 10 | 11 | case class SMTLIBUnsupportedError(t: Tree, s: SMTLibSolver, reason: Option[String] = None) 12 | extends Exception(s"$t is unsupported by ${s.targetName}" + reason.map(":\n " + _).getOrElse("")) 13 | 14 | case class SolverUnsupportedError(t: Tree, s: SMTLibSolver, reason: Option[String] = None) 15 | extends Exception(s"$t is unsupported by solver ${s.name}" + reason.map(":\n " + _).getOrElse("")) 16 | -------------------------------------------------------------------------------- /testcases/ints/delta.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object delta { 6 | 7 | 8 | def delta(x1: Int, x2: Int, x3: Real, x4: Real, x5: Real, x6: Real): Real = { 9 | require(((4.0 <= x1) && (x1 <= 6.3504) && (4.0 <= x2) && (x2 <= 6.3504) && (4.0 <= x3) && 10 | (x3 <= 6.3504) && (4.0 <= x4) && (x4 <= 6.3504) && (4.0 <= x5) && (x5 <= 6.3504) && (4.0 <= x6) && (x6 <= 6.3504))) 11 | ((((((((x1 * x4) * (((((-(x1) + x2) + x3) - x4) + x5) + x6)) + ((x2 * x5) * (((((x1 - x2) + x3) + x4) - x5) + x6))) + 12 | ((x3 * x6) * (((((x1 + x2) - x3) + x4) + x5) - x6))) + ((-(x2) * x3) * x4)) + 13 | ((-(x1) * x3) * x5)) + ((-(x1) * x2) * x6)) + ((-(x4) * x5) * x6)) 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /testcases/fpbench/azimuth.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object azimuth { 6 | 7 | 8 | def azimuth(lat1: Real, lat2: Real, lon1: Real, lon2: Real): Real = { 9 | require(((0.0 <= lat1) && (lat1 <= 0.4) && (0.5 <= lat2) && (lat2 <= 1.0) && (0.0 <= lon1) && (lon1 <= 3.14159265) && (-3.14159265 <= lon2) && (lon2 <= -0.5))) 10 | val dLon: Real = (lon2 - lon1) 11 | val s_lat1: Real = sin(lat1) 12 | val c_lat1: Real = cos(lat1) 13 | val s_lat2: Real = sin(lat2) 14 | val c_lat2: Real = cos(lat2) 15 | val s_dLon: Real = sin(dLon) 16 | val c_dLon: Real = cos(dLon) 17 | atan(((c_lat2 * s_dLon) / ((c_lat1 * s_lat2) - ((s_lat1 * c_lat2) * c_dLon)))) 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/scala/daisy/tools/RangeArithmetic.scala: -------------------------------------------------------------------------------- 1 | // Copyright 2017 MPI-SWS, Saarbruecken, Germany 2 | 3 | package daisy 4 | package tools 5 | 6 | 7 | trait RangeArithmetic[T] { self: T => 8 | 9 | def unary_- : T 10 | def +(other: T): T 11 | def -(other: T): T 12 | def *(other: T): T 13 | def *(r: Rational): T 14 | def /(other: T): T 15 | // def ^(n: T): T 16 | def ^(n: Int): T 17 | def squareRoot: T 18 | def inverse: T 19 | def sine: T 20 | def cosine: T 21 | def tangent: T 22 | def arcsine: T 23 | def arccosine: T 24 | def arctangent: T 25 | def exp: T 26 | def log: T 27 | def toInterval: Interval 28 | 29 | /* Add an error */ 30 | def +/-(r: Rational): T 31 | 32 | def addConstraint(e: Set[lang.Trees.Expr]): T 33 | } 34 | -------------------------------------------------------------------------------- /testcases/relative/JetEngineSingle.scala: -------------------------------------------------------------------------------- 1 | 2 | 3 | import daisy.lang._ 4 | import Real._ 5 | 6 | object JetEngineSingle { 7 | def jetEngine(x1: Real): Real = { 8 | require(-5 <= x1 && x1 <= 5) 9 | // val t = (3*x1*x1 + 2*x1 - x1) 10 | // x1 + ((2*x1*(t/(x1*x1 + 1))* 11 | // (t/(x1*x1 + 1) - 3) + x1*x1*(4*(t/(x1*x1 + 1))-6))* 12 | // (x1*x1 + 1) + 3*x1*x1*(t/(x1*x1 + 1)) + x1*x1*x1 + x1 + 13 | // 3*((3*x1*x1 + 2*x1 -x1)/(x1*x1 + 1))) 14 | 15 | x1 + ((2*x1*((3*x1*x1 + 2*x1 - x1)/(x1*x1 + 1))* 16 | ((3*x1*x1 + 2*x1 - x1)/(x1*x1 + 1) - 3) + x1*x1*(4*((3*x1*x1 + 2*x1 - x1)/(x1*x1 + 1))-6))* 17 | (x1*x1 + 1) + 3*x1*x1*((3*x1*x1 + 2*x1 - x1)/(x1*x1 + 1)) + x1*x1*x1 + x1 + 18 | 3*((3*x1*x1 + 2*x1 -x1)/(x1*x1 + 1))) 19 | 20 | } 21 | } -------------------------------------------------------------------------------- /testcases/fpbench/n_body.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object n_body { 6 | 7 | 8 | def n_body(x0: Real, y0: Real, z0: Real, vx0: Real, vy0: Real, vz0: Real): Real = { 9 | require(((-6.0 < x0) && (x0 < 6.0) && (-6.0 < y0) && (y0 < 6.0) && (-0.2 < z0) && (z0 < 0.2) && (-3.0 < vx0) && (vx0 < 3.0) && (-3.0 < vy0) && (vy0 < 3.0) && (-0.1 < vz0) && (vz0 < 0.1))) 10 | val dt: Real = 0.1 11 | val solarMass: Real = 39.47841760435743 12 | val distance: Real = sqrt((((x0 * x0) + (y0 * y0)) + (z0 * z0))) 13 | val mag: Real = (dt / ((distance * distance) * distance)) 14 | val vxNew: Real = (vx0 - ((x0 * solarMass) * mag)) 15 | val x_2: Real = (x0 + (dt * vxNew)) 16 | x_2 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /testcases/relative/Turbine.scala: -------------------------------------------------------------------------------- 1 | 2 | 3 | import daisy.lang._ 4 | import Real._ 5 | 6 | 7 | object Turbine { 8 | 9 | def turbine1(v: Real, w: Real, r: Real): Real = { 10 | require(-4.5 <= v && v <= -0.3 && 0.4 <= w && w <= 0.9 && 3.8 <= r && r <= 7.8) 11 | 12 | 3 + 2/(r*r) - 0.125*(3-2*v)*(w*w*r*r)/(1-v) - 4.5 13 | 14 | } 15 | 16 | def turbine2(v: Real, w: Real, r: Real): Real = { 17 | require(-4.5 <= v && v <= -0.3 && 0.4 <= w && w <= 0.9 && 3.8 <= r && r <= 7.8) 18 | 19 | 6*v - 0.5 * v * (w*w*r*r) / (1-v) - 2.5 20 | 21 | } 22 | 23 | def turbine3(v: Real, w: Real, r: Real): Real = { 24 | require(-4.5 <= v && v <= -0.3 && 0.4 <= w && w <= 0.9 && 3.8 <= r && r <= 7.8) 25 | 26 | 3 - 2/(r*r) - 0.125 * (1+2*v) * (w*w*r*r) / (1-v) - 0.5 27 | 28 | } 29 | } -------------------------------------------------------------------------------- /testcases/rosa/Turbine.scala: -------------------------------------------------------------------------------- 1 | 2 | 3 | import daisy.lang._ 4 | import Real._ 5 | 6 | 7 | object Turbine { 8 | 9 | def turbine1(v: Real, w: Real, r: Real): Real = { 10 | require(-4.5 <= v && v <= -0.3 && 0.4 <= w && w <= 0.9 && 3.8 <= r && r <= 7.8) 11 | 12 | 3 + 2/(r*r) - 0.125*(3-2*v)*(w*w*r*r)/(1-v) - 4.5 13 | 14 | } 15 | 16 | def turbine2(v: Real, w: Real, r: Real): Real = { 17 | require(-4.5 <= v && v <= -0.3 && 0.4 <= w && w <= 0.9 && 3.8 <= r && r <= 7.8) 18 | 19 | 6*v - 0.5 * v * (w*w*r*r) / (1-v) - 2.5 20 | 21 | } 22 | 23 | def turbine3(v: Real, w: Real, r: Real): Real = { 24 | require(-4.5 <= v && v <= -0.3 && 0.4 <= w && w <= 0.9 && 3.8 <= r && r <= 7.8) 25 | 26 | 3 - 2/(r*r) - 0.125 * (1+2*v) * (w*w*r*r) / (1-v) - 0.5 27 | 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /testcases/relative/smallranges/Turbine.scala: -------------------------------------------------------------------------------- 1 | 2 | 3 | import daisy.lang._ 4 | import Real._ 5 | 6 | 7 | object Turbine { 8 | 9 | def turbine1(v: Real, w: Real, r: Real): Real = { 10 | require(-4.5 <= v && v <= -0.3 && 0.4 <= w && w <= 0.9 && 3.8 <= r && r <= 7.8) 11 | 12 | 3 + 2/(r*r) - 0.125*(3-2*v)*(w*w*r*r)/(1-v) - 4.5 13 | 14 | } 15 | 16 | def turbine2(v: Real, w: Real, r: Real): Real = { 17 | require(-4.5 <= v && v <= -3.3 && -0.4 <= w && w <= -0.1 && 3.8 <= r && r <= 7.8) 18 | 19 | 6*v - 0.5 * v * (w*w*r*r) / (1-v) - 2.5 20 | 21 | } 22 | 23 | def turbine3(v: Real, w: Real, r: Real): Real = { 24 | require(-4.5 <= v && v <= -0.3 && 0.4 <= w && w <= 0.9 && 3.8 <= r && r <= 7.8) 25 | 26 | 3 - 2/(r*r) - 0.125 * (1+2*v) * (w*w*r*r) / (1-v) - 0.5 27 | 28 | } 29 | } -------------------------------------------------------------------------------- /testcases/fpbench/n_bodyXmodified.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object n_bodyXmodified { 6 | 7 | 8 | def n_bodyXmodified(x0: Real, y0: Real, z0: Real, vx0: Real, vy0: Real, vz0: Real): Real = { 9 | require(((0.001 < x0) && (x0 < 6.0) && (0.001 < y0) && (y0 < 6.0) && (0.001 < z0) && (z0 < 0.2) && (-3.0 < vx0) && (vx0 < 3.0) && (-3.0 < vy0) && (vy0 < 3.0) && (-0.1 < vz0) && (vz0 < 0.1))) 10 | val dt: Real = 0.1 11 | val solarMass: Real = 39.47841760435743 12 | val distance: Real = sqrt((((x0 * x0) + (y0 * y0)) + (z0 * z0))) 13 | val mag: Real = (dt / ((distance * distance) * distance)) 14 | val vxNew: Real = (vx0 - ((x0 * solarMass) * mag)) 15 | val x_2: Real = (x0 + (dt * vxNew)) 16 | x_2 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /testcases/fpbench/n_bodyZmodified.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object n_bodyZmodified { 6 | 7 | 8 | def n_bodyZmodified(x0: Real, y0: Real, z0: Real, vx0: Real, vy0: Real, vz0: Real): Real = { 9 | require(((0.001 < x0) && (x0 < 6.0) && (0.001 < y0) && (y0 < 6.0) && (0.001 < z0) && (z0 < 0.2) && (-3.0 < vx0) && (vx0 < 3.0) && (-3.0 < vy0) && (vy0 < 3.0) && (-0.1 < vz0) && (vz0 < 0.1))) 10 | val dt: Real = 0.1 11 | val solarMass: Real = 39.47841760435743 12 | val distance: Real = sqrt((((x0 * x0) + (y0 * y0)) + (z0 * z0))) 13 | val mag: Real = (dt / ((distance * distance) * distance)) 14 | val vzNew: Real = (vz0 - ((z0 * solarMass) * mag)) 15 | val z_2: Real = (z0 + (dt * vzNew)) 16 | z_2 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /testcases/relative/wideranges/Turbine.scala: -------------------------------------------------------------------------------- 1 | 2 | 3 | import daisy.lang._ 4 | import Real._ 5 | 6 | 7 | object Turbine { 8 | 9 | def turbine1(v: Real, w: Real, r: Real): Real = { 10 | require(-5.5 <= v && v <= -0.3 && 0.001 <= w && w <= 1.9 && 3.8 <= r && r <= 10.8) 11 | 12 | 3 + 2/(r*r) - 0.125*(3-2*v)*(w*w*r*r)/(1-v) - 4.5 13 | 14 | } 15 | 16 | def turbine2(v: Real, w: Real, r: Real): Real = { 17 | require(-4.5 <= v && v <= -3.3 && -0.4 <= w && w <= -0.01 && 3.8 <= r && r <= 16.25) 18 | 19 | 6*v - 0.5 * v * (w*w*r*r) / (1-v) - 2.5 20 | 21 | } 22 | 23 | def turbine3(v: Real, w: Real, r: Real): Real = { 24 | require(-4.5 <= v && v <= -0.3 && 0.4 <= w && w <= 0.9 && 2.85 <= r && r <= 8.5) 25 | 26 | 3 - 2/(r*r) - 0.125 * (1+2*v) * (w*w*r*r) / (1-v) - 0.5 27 | 28 | } 29 | } -------------------------------------------------------------------------------- /testcases/relative/BicycleSingle.scala: -------------------------------------------------------------------------------- 1 | import daisy.lang._ 2 | import Real._ 3 | 4 | 5 | object BicycleSingle { 6 | 7 | // s1, s2, s3, y1: <1, 16, 14>, [-1, 1] 8 | def BicycleSingle_out1(s1: Real) = { // , s2: Real 9 | require(-1 <= s1 && s1 <= 1) // && -1 <= s2 && s2 <= 1) 10 | (-3.025300) * s1 + (-12.608900) * 0.0001 11 | } 12 | 13 | def BicycleSingle_state1(s1: Real) = {//, s2: Real, y1: Real 14 | require(-1 <= s1 && s1 <= 1) // && -1 <= s2 && s2 <= 1 && -1 <= y1 && y1 <= 1) 15 | (0.961270) * s1 + (-0.095962) * 0.0001 + (0.013200) * -0.435 16 | } 17 | 18 | def BicycleSingle_state2(s1: Real) = { // , s2: Real, y1: Real 19 | require(-1 <= s1 && s1 <= 1) // && -1 <= s2 && s2 <= 1 && -1 <= y1 && y1 <= 1) 20 | (-0.058217) * s1 + (0.727430) * 0.0001 + (0.102100) * -0.435 21 | } 22 | 23 | 24 | } -------------------------------------------------------------------------------- /scripts/analysis_ds2l.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash --posix 2 | # 3 | # This script runs Daisy's datastructure-based analysis (DS2L) on the 4 | # available benchmarks, including code generation (generated code goes to output/). 5 | # Prints the results to standard output as well as to a CSV file in output/; 6 | # if the file already exists, the results are appended. 7 | 8 | # make sure the code is compiled 9 | sbt compile 10 | 11 | # generate daisy script, if it doesn't exist 12 | if [ ! -e daisy ]; then 13 | sbt script 14 | fi 15 | 16 | if [ "$1" = "" ]; then 17 | prec="Float64" 18 | else 19 | prec="$1" 20 | fi 21 | 22 | # run Daisy on each testfile 23 | for file in testcases/ds2l/AllDiffSmall/*.scala; do 24 | echo "*******" 25 | echo ${file} 26 | time ./daisy --precision="${prec}" --results-csv=ds2l_results.csv \ 27 | --ds --codegen --lang=Scala ${file} 28 | done -------------------------------------------------------------------------------- /testcases/fpbench/runge_kutta_4.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object runge_kutta_4 { 6 | 7 | 8 | def runge_kutta_4(h: Real, y_n: Real, c: Real): Real = { 9 | require(((0.0 <= y_n) && (y_n <= 100.0) && (1.0e-05 < h) && (h < 0.1) && (50.0 < c) && (c < 200.0))) 10 | val sixieme: Real = 0.0 11 | val eps: Real = 0.005 12 | val k: Real = 1.2 13 | val v_1: Real = (c - y_n) 14 | val k1: Real = ((k * v_1) * v_1) 15 | val v_2: Real = (c - (y_n + ((0.5 * h) * k1))) 16 | val k2: Real = ((k * v_2) * v_2) 17 | val v_3: Real = (c - (y_n + ((0.5 * h) * k2))) 18 | val k3: Real = ((k * v_3) * v_3) 19 | val v_4: Real = (c - (y_n + (h * k3))) 20 | val k4: Real = ((k * v_4) * v_4) 21 | (y_n + ((sixieme * h) * (((k1 + (2.0 * k2)) + (2.0 * k3)) + k4))) 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /testcases/fpbench/floudas1.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object floudas1 { 6 | 7 | 8 | def floudas1(x1: Real, x2: Real, x3: Real, x4: Real, x5: Real, x6: Real): Real = { 9 | require(((0.0 <= x1) && (x1 <= 6.0) && (0.0 <= x2) && (x2 <= 6.0) && (1.0 <= x3) && (x3 <= 5.0) && (0.0 <= x4) && (x4 <= 6.0) && (0.0 <= x5) && (x5 <= 6.0) && (0.0 <= x6) && (x6 <= 10.0) && (((((x3 - 3.0) * (x3 - 3.0)) + x4) - 4.0) >= 0.0) && (((((x5 - 3.0) * (x5 - 3.0)) + x6) - 4.0) >= 0.0) && (((2.0 - x1) + (3.0 * x2)) >= 0.0) && (((2.0 + x1) - x2) >= 0.0) && (((6.0 - x1) - x2) >= 0.0) && (((x1 + x2) - 2.0) >= 0.0))) 10 | ((((((-25.0 * ((x1 - 2.0) * (x1 - 2.0))) - ((x2 - 2.0) * (x2 - 2.0))) - ((x3 - 1.0) * (x3 - 1.0))) - ((x4 - 4.0) * (x4 - 4.0))) - ((x5 - 1.0) * (x5 - 1.0))) - ((x6 - 4.0) * (x6 - 4.0))) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /scripts/analysis_dataflow_IA_AA.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash --posix 2 | # 3 | # This script runs Daisy on all FPBench benchmarks computing absolute rounding 4 | # errors using the default analysis options (made explicit here). 5 | # Prints the results to standard output as well as to a CSV file in output/; 6 | # if the file already exists, the results are appended. 7 | 8 | # make sure the code is compiled 9 | sbt compile 10 | 11 | # generate daisy script, if it doesn't exist 12 | if [ ! -e daisy ]; then 13 | sbt script 14 | fi 15 | 16 | if [ "$1" = "" ]; then 17 | prec="Float64" 18 | else 19 | prec="$1" 20 | fi 21 | 22 | # run Daisy on each testfile 23 | for file in testcases/fpbench/*.scala; do 24 | echo "*******" 25 | echo ${file} 26 | time ./daisy --silent --precision="${prec}" --results-csv=dataflow_IA_AA_results.csv \ 27 | --analysis=dataflow --rangeMethod=interval --errorMethod=affine ${file} 28 | done -------------------------------------------------------------------------------- /testcases/ints/floudas1.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object floudas1 { 6 | 7 | 8 | def floudas1(x1: Int, x2: Real, x3: Real, x4: Int, x5: Real, x6: Real): Real = { 9 | require(((0.0 <= x1) && (x1 <= 6.0) && (0.0 <= x2) && (x2 <= 6.0) && (1.0 <= x3) && 10 | (x3 <= 5.0) && (0.0 <= x4) && (x4 <= 6.0) && (0.0 <= x5) && (x5 <= 6.0) && (0.0 <= x6) && 11 | (x6 <= 10.0) && (((((x3 - 3.0) * (x3 - 3.0)) + x4) - 4.0) >= 0.0) && (((((x5 - 3.0) * (x5 - 3.0)) + x6) - 4.0) >= 0.0) && (((2.0 - x1) + (3.0 * x2)) >= 0.0) && (((2.0 + x1) - x2) >= 0.0) && (((6.0 - x1) - x2) >= 0.0) && (((x1 + x2) - 2.0) >= 0.0))) 12 | 13 | ((((((-25.0 * ((x1 - 2.0) * (x1 - 2.0))) - ((x2 - 2.0) * (x2 - 2.0))) - ((x3 - 1.0) * (x3 - 1.0))) - 14 | ((x4 - 4.0) * (x4 - 4.0))) - ((x5 - 1.0) * (x5 - 1.0))) - ((x6 - 4.0) * (x6 - 4.0))) 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /testcases/fpbench/test04_dqmom9.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object test04_dqmom9 { 6 | 7 | 8 | def test04_dqmom9(m0: Real, m1: Real, m2: Real, w0: Real, w1: Real, w2: Real, a0: Real, a1: Real, a2: Real): Real = { 9 | require(((-1.0 < m0) && (m0 < 1.0) && (-1.0 < m1) && (m1 < 1.0) && (-1.0 < m2) && (m2 < 1.0) && (1.0e-05 < w0) && (w0 < 1.0) && (1.0e-05 < w1) && (w1 < 1.0) && (1.0e-05 < w2) && (w2 < 1.0) && (1.0e-05 < a0) && (a0 < 1.0) && (1.0e-05 < a1) && (a1 < 1.0) && (1.0e-05 < a2) && (a2 < 1.0))) 10 | val v2: Real = ((w2 * (0.0 - m2)) * (-3.0 * ((1.0 * (a2 / w2)) * (a2 / w2)))) 11 | val v1: Real = ((w1 * (0.0 - m1)) * (-3.0 * ((1.0 * (a1 / w1)) * (a1 / w1)))) 12 | val v0: Real = ((w0 * (0.0 - m0)) * (-3.0 * ((1.0 * (a0 / w0)) * (a0 / w0)))) 13 | (0.0 + ((v0 * 1.0) + ((v1 * 1.0) + ((v2 * 1.0) + 0.0)))) 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /testcases/rosa/Science.scala: -------------------------------------------------------------------------------- 1 | 2 | 3 | import daisy.lang._ 4 | import Real._ 5 | 6 | 7 | 8 | object Science { 9 | 10 | def verhulst(r: Real, K: Real, x: Real): Real = { 11 | require(r >= 4.0 && r <= 4.0 && K >= 1.11 && K <= 1.11 && 0.1 <= x && x <= 0.3) 12 | 13 | (r*x) / (1 + (x/K)) 14 | 15 | } 16 | 17 | def predatorPrey(r: Real, K: Real, x: Real): Real = { 18 | require(r >= 4.0 && r <= 4.0 && K >= 1.11 && K <= 1.11 && 0.1 <= x && x <= 0.3) 19 | 20 | (r*x*x) / (1 + (x/K)*(x/K)) 21 | 22 | } 23 | 24 | def carbonGas(T: Real, a: Real, b: Real, N: Real, p: Real, V: Real): Real = { 25 | require(T >= 300 && T <= 300 && a >= 0.401 && a <= 0.401 && b >= 42.7e-6 && b <= 42.7e-6 && N >= 1000 && N <= 1000 && 26 | p >= 3.5e7 && p <= 3.5e7 && 0.1 < V && V < 0.5) 27 | 28 | val k: Real = 1.3806503e-23 29 | (p + a * (N / V) * (N / V)) * (V - N * b) - k * N * T 30 | 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /scripts/analysis_dataflow_z3_AA.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash --posix 2 | # 3 | # This script runs Daisy on all FPBench benchmarks computing absolute rounding 4 | # errors using Z3 to compute tighter ranges, and affine arithmetic for errors. 5 | # Prints the results to standard output as well as to a CSV file in output/; 6 | # if the file already exists, the results are appended. 7 | 8 | # make sure the code is compiled 9 | sbt compile 10 | 11 | # generate daisy script, if it doesn't exist 12 | if [ ! -e daisy ]; then 13 | sbt script 14 | fi 15 | 16 | if [ "$1" = "" ]; then 17 | prec="Float64" 18 | else 19 | prec="$1" 20 | fi 21 | 22 | # run Daisy on each testfile 23 | for file in testcases/fpbench/*.scala; do 24 | echo "*******" 25 | echo ${file} 26 | time ./daisy --silent --precision="${prec}" --results-csv=dataflow_z3_AA_results.csv \ 27 | --analysis=dataflow --rangeMethod=smt --solver=z3 --errorMethod=affine ${file} 28 | done -------------------------------------------------------------------------------- /scripts/analysis_taylor.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash --posix 2 | # 3 | # This script runs Daisy on all FPBench benchmarks computing absolute rounding 4 | # errors using FPTaylor's analysis (options made explicit here). 5 | # Prints the results to standard output as well as to a CSV file in output/; 6 | # if the file already exists, the results are appended. 7 | 8 | # make sure the code is compiled 9 | sbt compile 10 | 11 | # generate daisy script, if it doesn't exist 12 | if [ ! -e daisy ]; then 13 | sbt script 14 | fi 15 | 16 | if [ "$1" = "" ]; then 17 | prec="Float64" 18 | else 19 | prec="$1" 20 | fi 21 | 22 | # run Daisy on each testfile 23 | for file in testcases/fpbench/*.scala; do 24 | echo "*******" 25 | echo ${file} 26 | # --silent 27 | # TODO: check if precision is taken into account 28 | time ./daisy --precision="${prec}" --results-csv=taylor_results.csv \ 29 | --FPTaylor ${file} 30 | # --gelpia --bb 31 | done -------------------------------------------------------------------------------- /scripts/analysis_subdivision_IA_AA.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash --posix 2 | # 3 | # This script runs Daisy on all FPBench benchmarks computing absolute rounding 4 | # errors using subdivision to compute tighter ranges, and affine arithmetic for errors. 5 | # Prints the results to standard output as well as to a CSV file in output/; 6 | # if the file already exists, the results are appended. 7 | 8 | # make sure the code is compiled 9 | sbt compile 10 | 11 | # generate daisy script, if it doesn't exist 12 | if [ ! -e daisy ]; then 13 | sbt script 14 | fi 15 | 16 | if [ "$1" = "" ]; then 17 | prec="Float64" 18 | else 19 | prec="$1" 20 | fi 21 | 22 | # run Daisy on each testfile 23 | for file in testcases/fpbench/*.scala; do 24 | echo "*******" 25 | echo ${file} 26 | time ./daisy --silent --precision="${prec}" --results-csv=dataflow_subdiv_IA_AA_results.csv \ 27 | --analysis=dataflow --rangeMethod=interval --errorMethod=affine \ 28 | --subdiv --divLimit=3 --totalOpt=32 ${file} 29 | done -------------------------------------------------------------------------------- /src/main/scala/daisy/frontend/DaisyExtraction.scala: -------------------------------------------------------------------------------- 1 | // Original work Copyright 2009-2016 EPFL, Lausanne 2 | // Modified work Copyright 2017 MPI-SWS, Saarbruecken, Germany 3 | 4 | package daisy 5 | package frontend 6 | 7 | import scala.tools.nsc._ 8 | import lang.Trees.{Program => DaisyProgram} 9 | 10 | trait DaisyExtraction extends SubComponent with CodeExtraction { 11 | import global._ 12 | 13 | val phaseName = "daisy" 14 | 15 | var units: List[CompilationUnit] = Nil 16 | 17 | var imports: Map[RefTree,List[Import]] = Map() 18 | 19 | def setImports(imports: Map[RefTree,List[Import]]): Unit = { 20 | this.imports = imports 21 | } 22 | 23 | def compiledProgram: Option[DaisyProgram] = { 24 | new Extraction(units).extractProgram 25 | } 26 | 27 | def newPhase(prev: scala.tools.nsc.Phase): StdPhase = new Phase(prev) 28 | 29 | class Phase(prev: scala.tools.nsc.Phase) extends StdPhase(prev) { 30 | def apply(unit: CompilationUnit): Unit = { 31 | units ::= unit 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /testcases/relative/wideranges/Bsplines.scala: -------------------------------------------------------------------------------- 1 | 2 | import daisy.lang._ 3 | import Real._ 4 | 5 | object Bsplines { 6 | 7 | def bspline0(u: Real): Real = { 8 | require(0 <= u && u <= 0.875) 9 | (1 - u) * (1 - u) * (1 - u) / 6.0 10 | } ensuring (res => 0 <= res && res <= 0.17 && res +/- 1e-15) 11 | // proven in paper: [-0.05, 0.17] 12 | 13 | def bspline1(u: Real): Real = { 14 | require(0.875 <= u && u <= 1) 15 | (3 * u*u*u - 6 * u*u + 4) / 6.0 16 | } ensuring (res => 0.16 <= res && res <= 0.7 && res +/- 1e-15) 17 | // in paper [-0.05, 0.98] 18 | 19 | def bspline2(u: Real): Real = { 20 | require(0.5 <= u && u <= 1) 21 | (-3 * u*u*u + 3*u*u + 3*u + 1) / 6.0 22 | } ensuring (res => 0.16 <= res && res <= 0.7 && res +/- 1e-15) 23 | // in paper [-0.02, 0.89] 24 | 25 | def bspline3(u: Real): Real = { 26 | require(0.125 <= u && u <= 10) 27 | -u*u*u / 6.0 28 | } ensuring (res => -0.17 <= res && res <= 0.0 && res +/- 1e-15) 29 | // in paper [-0.17, 0.05] 30 | 31 | } 32 | -------------------------------------------------------------------------------- /testcases/relative/smallranges/Bsplines.scala: -------------------------------------------------------------------------------- 1 | 2 | import daisy.lang._ 3 | import Real._ 4 | 5 | object Bsplines { 6 | 7 | def bspline0(u: Real): Real = { 8 | require(0 <= u && u <= 0.875) 9 | (1 - u) * (1 - u) * (1 - u) / 6.0 10 | } ensuring (res => 0 <= res && res <= 0.17 && res +/- 1e-15) 11 | // proven in paper: [-0.05, 0.17] 12 | 13 | def bspline1(u: Real): Real = { 14 | require(0.875 <= u && u <= 1) 15 | (3 * u*u*u - 6 * u*u + 4) / 6.0 16 | } ensuring (res => 0.16 <= res && res <= 0.7 && res +/- 1e-15) 17 | // in paper [-0.05, 0.98] 18 | 19 | def bspline2(u: Real): Real = { 20 | require(0.5 <= u && u <= 1) 21 | (-3 * u*u*u + 3*u*u + 3*u + 1) / 6.0 22 | } ensuring (res => 0.16 <= res && res <= 0.7 && res +/- 1e-15) 23 | // in paper [-0.02, 0.89] 24 | 25 | def bspline3(u: Real): Real = { 26 | require(0.125 <= u && u <= 1) 27 | -u*u*u / 6.0 28 | } ensuring (res => -0.17 <= res && res <= 0.0 && res +/- 1e-15) 29 | // in paper [-0.17, 0.05] 30 | 31 | } 32 | 33 | -------------------------------------------------------------------------------- /testcases/fpbench/smartRoot.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object smartRoot { 6 | 7 | 8 | def smartRoot(c: Real): Real = { 9 | require(((c >= -10.0) && (c <= 10.0) && (-2.0 <= c) && (c <= 2.0) && ((12.25 - ((3.0 * c) * 4.0)) > 0.1))) 10 | val a: Real = 3.0 11 | val b: Real = 3.5 12 | val a_1: Real = 3.0 13 | val b_1: Real = 3.5 14 | val discr: Real = ((b_1 * b_1) - ((a_1 * c) * 4.0)) 15 | val temp: Real = if ((((b_1 * b_1) - (a_1 * c)) > 10.0)) { 16 | val temp_1: Real = if ((b_1 > 0.0)) { 17 | ((c * 2.0) / (-(b_1) - sqrt(discr))) 18 | } 19 | else { 20 | val temp_2: Real = if ((b_1 < 0.0)) { 21 | ((-(b_1) + sqrt(discr)) / (a_1 * 2.0)) 22 | } 23 | else { 24 | ((-(b_1) + sqrt(discr)) / (a_1 * 2.0)) 25 | } 26 | temp_2 27 | } 28 | temp_1 29 | } 30 | else { 31 | ((-(b_1) + sqrt(discr)) / (a_1 * 2.0)) 32 | } 33 | temp 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /scripts/optimization_rewriting.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash --posix 2 | # 3 | # This script runs Daisy on all FPBench benchmarks computing absolute rounding 4 | # errors using the default analysis options after the rewriting optimization. 5 | # Prints the results to standard output as well as to a CSV file in output/; 6 | # if the file already exists, the results are appended. 7 | # If you want to fix the random seed for determinism, use --rewrite-seed=1490 8 | # with a non-zero number. 9 | 10 | # make sure the code is compiled 11 | sbt compile 12 | 13 | # generate daisy script, if it doesn't exist 14 | if [ ! -e daisy ]; then 15 | sbt script 16 | fi 17 | 18 | if [ "$1" = "" ]; then 19 | prec="Float64" 20 | else 21 | prec="$1" 22 | fi 23 | 24 | # run Daisy on each testfile 25 | for file in testcases/fpbench/*.scala; do 26 | echo "*******" 27 | echo ${file} 28 | time ./daisy --precision="${prec}" --results-csv=rewriting_IA_AA_results.csv \ 29 | --rewrite --rewrite-seed=0 \ 30 | --analysis=dataflow --rangeMethod=interval --errorMethod=affine ${file} 31 | done -------------------------------------------------------------------------------- /testcases/modular/unittests/UltimateUnitTest.scala: -------------------------------------------------------------------------------- 1 | import daisy.lang._ 2 | import Real._ 3 | 4 | object UltimateUnitTest { 5 | 6 | /* def f(f1: Real, f2:Real) = { 7 | require((10 <= f1) && (f1 <= 200) && (10 <= f2) && (f2 <= 200)) 8 | f1 * f2 9 | } 10 | 11 | def g(g1: Real): Real = { 12 | require((10 <= g1) && (g1 <= 200)) 13 | f(g1, g1) 14 | } 15 | 16 | def r(r1: Real, r2:Real) = { 17 | require((10 <= r1) && (r1 <= 100) && (10 <= r2) && (r2 <= 100)) 18 | r1 + r2 19 | } 20 | 21 | def p(p1: Real, p2: Real): Real = { 22 | require((10 <= p1) && (p1 <= 100) && (10 <= p2) && (p2 <= 100)) 23 | g(r(p1, p2)) 24 | }*/ 25 | 26 | def g(g1: Real): Real = { 27 | require((10 <= g1) && (g1 <= 200)) 28 | g1 29 | } 30 | 31 | def r(r1: Real): Real = { 32 | require((10 <= r1) && (r1 <= 200)) 33 | r1 34 | } 35 | 36 | def f(f1: Real) = { 37 | require((10 <= f1) && (f1 <= 200)) 38 | g(r(f1)) 39 | } 40 | 41 | def h(h1: Real) = { 42 | require((10 <= h1) && (h1 <= 200)) 43 | f(h1) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /regression/reference/modular_results.csv: -------------------------------------------------------------------------------- 1 | Function name; Absolute error; Relative error; Real range; Time 2 | determinant;1.9217761491052697e-09;;;83425 3 | solveEquationX;4.142035700897964e-15;;;83425 4 | solveEquationY;4.675349927357128e-15;;;83425 5 | solveEquationZ;5.163524705181817e-15;;;83425 6 | solveEquationsVector;4.72929820976945e-15;;;83426 7 | _add;2.176037128265307e-15;;;83426 8 | radius;3.5699443522945146e-11;;;83426 9 | divideRe;3.106358390597793e-08;;;83426 10 | divideIm;1.6719275461906195e-08;;;83426 11 | reciprocalRe;8.146314323038656e-14;;;83426 12 | reciprocalIm;8.146314323038656e-14;;;83426 13 | impedanceIm;2.977680533462615e-14;;;83426 14 | instantVoltage;2.1832762651253357e-11;;;83427 15 | computeCurrentRe;6.118021475989196e-10;;;83427 16 | computeCurrentIm;6.710563243483105e-10;;;83427 17 | computeInstantCurrent;0.003338808244302116;;;83427 18 | approxEnergy;0.10016425140953455;;;83427 19 | computeRadiusVector;3.578330185246922e-11;;;83427 20 | computeDivideVector;1.2241011433677547e-08;;;83427 21 | computeReciprocalRadiusVector;3.315017992082885e-14;;;83427 22 | -------------------------------------------------------------------------------- /src/main/scala/daisy/analysis/ModularContext.scala: -------------------------------------------------------------------------------- 1 | package daisy.analysis 2 | 3 | import daisy.lang.Identifiers.Identifier 4 | import daisy.lang.Trees.{Epsilon, Expr, FunctionInvocation, ValDef} 5 | import daisy.tools.{Interval, MPFRInterval} 6 | 7 | case class ModularContext( 8 | 9 | roundOffFirstOrderWrtEpsSum: List[Expr] = List(), 10 | roundOffRemainder: MPFRInterval = MPFRInterval.zero, 11 | roundOffFirstOrderWrtFuncEps: List[(Epsilon, Expr)] = List(), 12 | roundOffFunEpsMap: Map[Epsilon, FunctionInvocation] = Map(), 13 | roundOffRemaindersWrtEpsContainingFuncEps: List[Expr] = List(), 14 | roundOffRemainderWrtFunEps: List[(Expr, Expr, Expr)] = List(), 15 | roundOffOptReport: String = "noOpt", 16 | transcendentalEpsilons: Seq[Identifier] = Seq.empty, 17 | 18 | propFirstOder: List[(Identifier, Expr)] = List(), 19 | propRemainder: List[(Expr, Expr, Expr)] = List(), 20 | propFirstOrderWrtFun: List[(FunctionInvocation, Expr)] = List(), 21 | propOptReport: String = "noOpt", 22 | 23 | firstOderWrtInitAbsErrs: List[(Identifier, Expr)] = List(), 24 | absErrVarsErrBounds: Map[Identifier, Interval] = Map()) 25 | 26 | -------------------------------------------------------------------------------- /testcases/control/DCMotor.scala: -------------------------------------------------------------------------------- 1 | import daisy.lang._ 2 | import Real._ 3 | 4 | 5 | object DCMotor { 6 | 7 | // s1, s2, s3, y1: <1, 16, 14>, [-1, 1] 8 | def out1(s1: Real, s2: Real, s3: Real) = { 9 | require(-1 <= s1 && s1 <= 1 && -1 <= s2 && s2 <= 1 && -1 <= s3 && s3 <= 1) 10 | (-0.112900) * s1 + (-0.021100) * s2 + (-0.009300) * s3 11 | } 12 | 13 | def state1(s1: Real, s2: Real, s3: Real, y1: Real) = { 14 | require(-1 <= s1 && s1 <= 1 && -1 <= s2 && s2 <= 1 && -1 <= s3 && s3 <= 1 && -1 <= y1 && y1 <= 1) 15 | (0.960883) * s1 + (0.000949) * s2 + (-0.000004) * s3 + (0.039000) * y1 16 | } 17 | 18 | def state2(s1: Real, s2: Real, s3: Real, y1: Real) = { 19 | require(-1 <= s1 && s1 <= 1 && -1 <= s2 && s2 <= 1 && -1 <= s3 && s3 <= 1 && -1 <= y1 && y1 <= 1) 20 | (-0.602449) * s1 + (0.899089) * s2 + (-0.013648) * s3 + (0.370000) * y1 21 | } 22 | 23 | def state3(s1: Real, s2: Real, s3: Real, y1: Real) = { 24 | require(-1 <= s1 && s1 <= 1 && -1 <= s2 && s2 <= 1 && -1 <= s3 && s3 <= 1 && -1 <= y1 && y1 <= 1) 25 | (-0.009134) * s1 + (-0.011434) * s2 + (-0.002232) * s3 + (-0.017500) * y1 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /testcases/fpbench/instantaneousCurrent.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object instantaneousCurrent { 6 | 7 | 8 | def instantaneousCurrent(t: Real, resistance: Real, frequency: Real, inductance: Real, maxVoltage: Real): Real = { 9 | require(((0.0 <= t) && (t <= 300.0) && (1.0 <= resistance) && (resistance <= 50.0) && (1.0 <= frequency) && (frequency <= 100.0) && (0.001 <= inductance) && (inductance <= 0.004) && (1.0 <= maxVoltage) && (maxVoltage <= 12.0))) 10 | val pi: Real = 3.14159265359 11 | val impedance_re: Real = resistance 12 | val impedance_im: Real = (((2.0 * pi) * frequency) * inductance) 13 | val denom: Real = ((impedance_re * impedance_re) + (impedance_im * impedance_im)) 14 | val current_re: Real = ((maxVoltage * impedance_re) / denom) 15 | val current_im: Real = (-((maxVoltage * impedance_im)) / denom) 16 | val maxCurrent: Real = sqrt(((current_re * current_re) + (current_im * current_im))) 17 | val theta: Real = atan((current_im / current_re)) 18 | (maxCurrent * cos(((((2.0 * pi) * frequency) * t) + theta))) 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /scripts/analysis_fixed_codegen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash --posix 2 | # 3 | # This script runs Daisy on all FPBench benchmarks using dataflow analysis 4 | # (default options made explicit here) assuming a uniform fixed-point bitlength, 5 | # and generates fixed-point code using either bitshift operations in Scala or C, 6 | # or generates C++ code using Xilinx apfixed library (to compile to FPGAs). 7 | # Generated code is saved in the output/ folder. 8 | # 9 | # Note: not all of the FPBench benchmarks are supported for fixed-point code 10 | # generation; for simplicity they are included here, but will not produce code. 11 | 12 | # Make sure the code is compiled 13 | sbt compile 14 | 15 | # generate daisy script 16 | if [ ! -e daisy ] 17 | then 18 | sbt script 19 | fi 20 | 21 | # run Daisy on each testfile 22 | for file in testcases/fpbench/*.scala; do 23 | echo "*******" 24 | echo ${file} 25 | ./daisy --analysis=dataflow --rangeMethod=interval --errorMethod=affine \ 26 | --codegen --lang=C --precision=Fixed32 ${file} 27 | #./daisy --analysis=dataflow --rangeMethod=interval --errorMethod=affine \ 28 | # --codegen --apfixed --precision=Fixed32 ${file} 29 | done -------------------------------------------------------------------------------- /testcases/fpbench/hartman3.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object hartman3 { 6 | 7 | 8 | def hartman3(x1: Real, x2: Real, x3: Real): Real = { 9 | require(((0.0 <= x1) && (x1 <= 1.0) && (0.0 <= x2) && (x2 <= 1.0) && (0.0 <= x3) && (x3 <= 1.0))) 10 | val e1: Real = (((3.0 * ((x1 - 0.3689) * (x1 - 0.3689))) + (10.0 * ((x2 - 0.117) * (x2 - 0.117)))) + (30.0 * ((x3 - 0.2673) * (x3 - 0.2673)))) 11 | val e2: Real = (((0.1 * ((x1 - 0.4699) * (x1 - 0.4699))) + (10.0 * ((x2 - 0.4387) * (x2 - 0.4387)))) + (35.0 * ((x3 - 0.747) * (x3 - 0.747)))) 12 | val e3: Real = (((3.0 * ((x1 - 0.1091) * (x1 - 0.1091))) + (10.0 * ((x2 - 0.8732) * (x2 - 0.8732)))) + (30.0 * ((x3 - 0.5547) * (x3 - 0.5547)))) 13 | val e4: Real = (((0.1 * ((x1 - 0.03815) * (x1 - 0.03815))) + (10.0 * ((x2 - 0.5743) * (x2 - 0.5743)))) + (35.0 * ((x3 - 0.8828) * (x3 - 0.8828)))) 14 | val exp1: Real = exp(-(e1)) 15 | val exp2: Real = exp(-(e2)) 16 | val exp3: Real = exp(-(e3)) 17 | val exp4: Real = exp(-(e4)) 18 | -(((((1.0 * exp1) + (1.2 * exp2)) + (3.0 * exp3)) + (3.2 * exp4))) 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /testcases/control/Pitch.scala: -------------------------------------------------------------------------------- 1 | import daisy.lang._ 2 | import Real._ 3 | 4 | 5 | object Pitch { 6 | 7 | // s1, s2, s3, y1: <1, 32, 30>, [-1, 1] 8 | def out1(s1: Real, s2: Real, s3: Real) = { 9 | require(-1 <= s1 && s1 <= 1 && -1 <= s2 && s2 <= 1 && -1 <= s3 && s3 <= 1) 10 | (0.120200) * state1 + (-42.565500) * state2 + (-1.000100) * state3 11 | } 12 | 13 | def state1(s1: Real, s2: Real, s3: Real, y1: Real) = { 14 | require(-1 <= s1 && s1 <= 1 && -1 <= s2 && s2 <= 1 && -1 <= s3 && s3 <= 1 && -1 <= y1 && y1 <= 1) 15 | (0.999715) * state1 + (0.046781) * state2 + (-0.000333) * state3 + (0.000100) * y1 16 | } 17 | 18 | def state2(s1: Real, s2: Real, s3: Real, y1: Real) = { 19 | require(-1 <= s1 && s1 <= 1 && -1 <= s2 && s2 <= 1 && -1 <= s3 && s3 <= 1 && -1 <= y1 && y1 <= 1) 20 | (-0.000011) * state1 + (0.998710) * state2 + (-0.000020) * state3 + (0.000000) * y1 21 | } 22 | 23 | def state3(s1: Real, s2: Real, s3: Real, y1: Real) = { 24 | require(-1 <= s1 && s1 <= 1 && -1 <= s2 && s2 <= 1 && -1 <= s3 && s3 <= 1 && -1 <= y1 && y1 <= 1) 25 | (-0.000000) * state1 + (0.056663) * state2 + (0.998299) * state3 + (0.001700) * y1 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /testcases/rosa/Bsplines.scala: -------------------------------------------------------------------------------- 1 | 2 | import daisy.lang._ 3 | import Real._ 4 | 5 | /** 6 | Equation and initial ranges from: 7 | L. Zhang, Y. Zhang, and W. Zhou. Tradeoff between Approximation Accuracy and 8 | Complexity for Range Analysis using Affine Arithmetic. 9 | */ 10 | object Bsplines { 11 | 12 | def bspline0(u: Real): Real = { 13 | require(0 <= u && u <= 1) 14 | (1 - u) * (1 - u) * (1 - u) / 6.0 15 | } ensuring (res => 0 <= res && res <= 0.17 && res +/- 1e-15) 16 | // proven in paper: [-0.05, 0.17] 17 | 18 | def bspline1(u: Real): Real = { 19 | require(0 <= u && u <= 1) 20 | (3 * u*u*u - 6 * u*u + 4) / 6.0 21 | } ensuring (res => 0.16 <= res && res <= 0.7 && res +/- 1e-15) 22 | // in paper [-0.05, 0.98] 23 | 24 | def bspline2(u: Real): Real = { 25 | require(0 <= u && u <= 1) 26 | (-3 * u*u*u + 3*u*u + 3*u + 1) / 6.0 27 | } ensuring (res => 0.16 <= res && res <= 0.7 && res +/- 1e-15) 28 | // in paper [-0.02, 0.89] 29 | 30 | def bspline3(u: Real): Real = { 31 | require(0 <= u && u <= 1) 32 | -u*u*u / 6.0 33 | } ensuring (res => -0.17 <= res && res <= 0.0 && res +/- 1e-15) 34 | // in paper [-0.17, 0.05] 35 | 36 | } 37 | -------------------------------------------------------------------------------- /testcases/relative/Bsplines.scala: -------------------------------------------------------------------------------- 1 | 2 | import daisy.lang._ 3 | import Real._ 4 | 5 | /** 6 | Equation and initial ranges from: 7 | L. Zhang, Y. Zhang, and W. Zhou. Tradeoff between Approximation Accuracy and 8 | Complexity for Range Analysis using Affine Arithmetic. 9 | */ 10 | object Bsplines { 11 | 12 | def bspline0(u: Real): Real = { 13 | require(0 <= u && u <= 1) 14 | (1 - u) * (1 - u) * (1 - u) / 6.0 15 | } ensuring (res => 0 <= res && res <= 0.17 && res +/- 1e-15) 16 | // proven in paper: [-0.05, 0.17] 17 | 18 | def bspline1(u: Real): Real = { 19 | require(0 <= u && u <= 1) 20 | (3 * u*u*u - 6 * u*u + 4) / 6.0 21 | } ensuring (res => 0.16 <= res && res <= 0.7 && res +/- 1e-15) 22 | // in paper [-0.05, 0.98] 23 | 24 | def bspline2(u: Real): Real = { 25 | require(0 <= u && u <= 1) 26 | (-3 * u*u*u + 3*u*u + 3*u + 1) / 6.0 27 | } ensuring (res => 0.16 <= res && res <= 0.7 && res +/- 1e-15) 28 | // in paper [-0.02, 0.89] 29 | 30 | def bspline3(u: Real): Real = { 31 | require(0 <= u && u <= 1) 32 | -u*u*u / 6.0 33 | } ensuring (res => -0.17 <= res && res <= 0.0 && res +/- 1e-15) 34 | // in paper [-0.17, 0.05] 35 | 36 | } 37 | -------------------------------------------------------------------------------- /scripts/metalibm/timedata_processing.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from scipy import stats 3 | #import matplotlib.pyplot as plt 4 | import sys 5 | 6 | with open(sys.argv[1]) as filestream: 7 | for line in filestream: 8 | values1 = line.split(",") 9 | 10 | values1.pop() 11 | values1 = [int(e) for e in values1] 12 | 13 | values1.sort() 14 | 15 | # remove the upper 10% 16 | newList1 = values1[0 : int(len(values1) * 0.90)] 17 | 18 | with open(sys.argv[2]) as filestream: 19 | for line in filestream: 20 | values2 = line.split(",") 21 | 22 | values2.pop() 23 | values2 = [int(e) for e in values2] 24 | 25 | values2.sort() 26 | 27 | # remove the upper 10% 28 | newList2 = values2[0 : int(len(values2) * 0.90)] 29 | 30 | mean1, stdDev1, min1, max1 = (np.mean(newList1), np.std(newList1), np.min(newList1), np.max(newList1)) 31 | 32 | mean2, stdDev2, min2, max2 = (np.mean(newList2), np.std(newList2), np.min(newList2), np.max(newList2)) 33 | 34 | print ("mathh : %f, %f, %f, %f") % (mean1, stdDev1, min1, max1) 35 | 36 | print ("metalibm: %f, %f, %f, %f") % (mean2, stdDev2, min2, max2) 37 | 38 | # plt.hist(newList1, bins=50) 39 | # plt.show() 40 | 41 | # plt.hist(newList2, bins=50) 42 | # plt.show() 43 | 44 | 45 | -------------------------------------------------------------------------------- /src/main/scala/daisy/frontend/CExtractionPhase.scala: -------------------------------------------------------------------------------- 1 | // Original work Copyright 2009-2016 EPFL, Lausanne 2 | // Modified work Copyright 2017 MPI-SWS, Saarbruecken, Germany 3 | 4 | package daisy 5 | package frontend 6 | 7 | import lang.Trees._ 8 | import scala.reflect.io.File 9 | 10 | object CExtractionPhase extends DaisyPhase with CASTExtractor { 11 | override val name = "C Extraction" 12 | override val description = "Extraction of trees from the C Compiler" 13 | 14 | override implicit val debugSection = DebugSectionFrontend 15 | 16 | def runPhase(ctx: Context, prg: Program): (Context, Program) = { 17 | 18 | val specFile = ctx.option[Option[String]]("spec") 19 | specFile match { 20 | case None => throw new DaisyFatalError(Some("Specification file is not defined")) 21 | case Some(x) if !File(specFile.get).exists => throw new DaisyFatalError(Some(s"Specification file $x is not found")) 22 | case _ => 23 | } 24 | 25 | val prgOpt = CodeParser.getProgram(ctx.file, specFile.get) 26 | 27 | val prg = prgOpt match { 28 | case None => ctx.reporter.fatalError("Failed to extract Daisy program. Source: ${ctx.file}") 29 | case Some(x) => x 30 | } 31 | (ctx, prg) 32 | } 33 | } -------------------------------------------------------------------------------- /testcases/misc/TranscendentalsInlined.scala: -------------------------------------------------------------------------------- 1 | import daisy.lang._ 2 | import Real._ 3 | 4 | 5 | object Transcendentals { 6 | 7 | 8 | def pendulum1(t: Real, w: Real): Real = { 9 | require(-2 <= t && t <= 2 && -5 <= w && w <= 5) 10 | 11 | t + 0.01*(w + 0.01/2*(-9.80665/2.0 * sin(t))) 12 | 13 | } 14 | 15 | 16 | def pendulum2(t: Real, w: Real): Real = { 17 | require(-2 <= t && t <= 2 && -5 <= w && w <= 5) 18 | 19 | w + 0.01*(-9.80665/2.0 * sin(t + 0.01/2*w)) 20 | 21 | } 22 | 23 | def analysis1(x: Real): Real = { 24 | require(x > -1.57079632679 && x < 1.57079632679) 25 | sin(x) * sin(x) * cos(x) * cos(x) 26 | } 27 | 28 | def analysis2(x: Real): Real = { 29 | require(-1.1 <= x && x < 0.9) 30 | 31 | ((1 / cos(x)) * (1 / cos(x))) / (4 + (tan(x)) * (tan(x))) 32 | } 33 | 34 | // from FPTaylor 35 | def logExp(x: Real): Real = { 36 | require(-8 <= x && x <= 8) 37 | 38 | log(1 + exp(x)) 39 | } 40 | 41 | // from FPTaylor 42 | def sphere(r: Real, x: Real, lat: Real, lon: Real): Real = { 43 | require(0 <= r && r <= 10 && -10 <= x && x <= 10 && 44 | -1.570796 <= lat && lat <= 1.570796 && -3.14159265 <= lon && lon <= 3.14159265) 45 | 46 | x + r * sin(lat) * cos(lon) 47 | } 48 | 49 | } -------------------------------------------------------------------------------- /scripts/analysis_dynamic.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash --posix 2 | # 3 | # This script runs Daisy's dynamic analysis to compute an under-approximation 4 | # of rounding errors on all FPBench benchmarks. 5 | # Prints the results to standard output as well as to a CSV file in output/; 6 | # if the file already exists, the results are appended. 7 | # Use --dynamic-method=bgrt to try our re-implementation for maximizing errors 8 | # from "Efficient Search for Inputs Causing High Floating-point Errors", PPoPP'14. 9 | # 10 | # Setting the dynamic-seed to 0 (default setting) will produce a random seed based 11 | # on current time. If you want to fix the seed (e.g. for reproducibility), set 12 | # the option to a non-zero number. 13 | 14 | # make sure the code is compiled 15 | sbt compile 16 | 17 | # generate daisy script, if it doesn't exist 18 | if [ ! -e daisy ]; then 19 | sbt script 20 | fi 21 | 22 | 23 | # run Daisy on each testfile 24 | for file in testcases/fpbench/*.scala; do 25 | echo "*******" 26 | echo ${file} 27 | time ./daisy --dynamic --sampleSize=100000 --dynamic-seed=0 --dynamic-method=uniformMPFR \ 28 | --silent --results-csv=dynamic_results.csv ${file} 29 | 30 | # time ./daisy --dynamic --sampleSize=10000 --dynamic-seed=0 --dynamic-method=bgrt \ 31 | # --silent --results-csv=dynamic_results.csv ${file} 32 | done -------------------------------------------------------------------------------- /src/main/scala/daisy/analysis/Sampler.scala: -------------------------------------------------------------------------------- 1 | // Copyright 2017 MPI-SWS, Saarbruecken, Germany 2 | 3 | package daisy 4 | package analysis 5 | 6 | import scala.util.Random 7 | 8 | import lang.Identifiers._ 9 | import tools.{Rational, Interval} 10 | 11 | import collection.immutable.Map 12 | 13 | object Sampler { 14 | 15 | 16 | // trait Sample[T] { 17 | // def next: Map[Identifier, T] 18 | // } 19 | 20 | class Uniform(ranges: Map[Identifier, Interval], seed: Long = System.currentTimeMillis) { 21 | 22 | val diameter: Map[Identifier, Double] = ranges.map({ 23 | case (x, Interval(a, b)) => (x -> (Rational.abs(b - a).toDouble)) 24 | }) 25 | 26 | val lowerBounds: Map[Identifier, Double] = ranges.map({ 27 | case (x, Interval(a, b)) => (x -> a.toDouble) 28 | }) 29 | 30 | val random = new Random(seed) // TODO: System.millis 31 | 32 | def next: Map[Identifier, Double] = { 33 | ranges.map({ 34 | case (x, Interval(a, b)) => 35 | (x -> (lowerBounds(x) + random.nextDouble() * diameter(x))) 36 | }) 37 | } 38 | 39 | def nextString: Map[Identifier, String] = { 40 | ranges.map({ 41 | case (x, Interval(a, b)) => 42 | (x -> (lowerBounds(x) + random.nextDouble() * diameter(x)).toString) 43 | }) 44 | } 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/scala/daisy/utils/CachingMap.scala: -------------------------------------------------------------------------------- 1 | package daisy.utils 2 | 3 | import scala.collection.mutable 4 | 5 | object CachingMap { 6 | def empty[K,V]() = new CachingMap[K,V]() 7 | def fromMap[K,V](m: mutable.HashMap[K,V]): CachingMap[K,V] = { 8 | val res = new CachingMap[K,V]() 9 | m.foreach({case (k, v) => res.put(k,v)}) 10 | res 11 | } 12 | } 13 | 14 | // we have a special class here because of the getOrAdd function 15 | class CachingMap[K, V] { 16 | private val underlying = mutable.HashMap[K, V]() 17 | 18 | def getOrAdd(k: K, v: K => V): V = 19 | underlying.getOrElseUpdate(k, v(k)) 20 | 21 | def put(k: K, v: V): Option[V] = 22 | underlying.put(k, v) 23 | 24 | def get(k: K): Option[V] = 25 | underlying.get(k) 26 | 27 | def apply(k: K): V = 28 | underlying(k) 29 | 30 | def update(k: K, v: V): Unit = 31 | underlying.update(k, v) 32 | 33 | def remove(k: K): Option[V] = 34 | underlying.remove(k) 35 | 36 | def isEmpty(): Boolean = 37 | underlying.isEmpty 38 | 39 | def nonEmpty(): Boolean = 40 | underlying.nonEmpty 41 | 42 | def getOrElse(k: K, default: => V): V = 43 | underlying.getOrElse(k, default) 44 | 45 | def mapValues[W](f: V => W): Map[K, W] = 46 | underlying.view.mapValues(f).toMap 47 | 48 | def toMap: Map[K, V] = 49 | underlying.toMap 50 | } -------------------------------------------------------------------------------- /src/main/scala/daisy/utils/Timer.scala: -------------------------------------------------------------------------------- 1 | // Original work Copyright 2009-2016 EPFL, Lausanne 2 | // Modified work Copyright 2017 MPI-SWS, Saarbruecken, Germany 3 | 4 | package daisy 5 | 6 | import scala.language.dynamics 7 | 8 | 9 | class Timer { 10 | var beginning: Long = 0L 11 | var end: Long = 0L 12 | 13 | def start(): Unit = { 14 | beginning = System.currentTimeMillis 15 | end = 0L 16 | } 17 | 18 | def stop(): Unit = { 19 | assert(end == 0L) 20 | end = System.currentTimeMillis 21 | } 22 | 23 | override def toString: String = { 24 | "%6d ms".format(end - beginning) 25 | } 26 | 27 | def millisNow: Long = { 28 | (System.currentTimeMillis - beginning) 29 | } 30 | 31 | } 32 | 33 | 34 | // The fancy way of doing this 35 | class TimerStorage extends Dynamic { 36 | var keys = List[String]() 37 | var fields = Map[String, Timer]() 38 | 39 | def get(name: String): Timer = { 40 | fields.get(name) match { 41 | case Some(t) => 42 | t 43 | 44 | case None => 45 | val t = new Timer() 46 | fields += name -> t 47 | keys ::= name 48 | t 49 | } 50 | } 51 | 52 | def selectDynamic(name: String): Timer = get(name) 53 | 54 | override def toString: String = keys.map(key => s"$key: ${fields(key).toString}").mkString(", ") 55 | } 56 | -------------------------------------------------------------------------------- /omelette/src/context.rs: -------------------------------------------------------------------------------- 1 | use std::{collections::HashMap, rc::Rc}; 2 | use rug::{float::Round, Float}; 3 | use crate::{ 4 | ast::Identifier, 5 | cli::{Settings, Variable}, 6 | interval::Interval, 7 | }; 8 | 9 | /// Storage for global data. 10 | /// 11 | /// A reference is given to all modules. 12 | pub struct Context { 13 | /// Various settings used during the evaluation. 14 | pub settings: Settings, 15 | /// A LUT of the intervals of all variables. Defined as private to allow alternate representations. 16 | intervals: HashMap, 17 | } 18 | 19 | impl Context { 20 | pub fn new(settings: Settings, intervals: impl IntoIterator) -> Rc { 21 | let intervals = intervals 22 | .into_iter() 23 | .map(|var| { 24 | let (min, _) = Float::with_val_round(settings.precision, var.min, Round::Down); 25 | let (max, _) = Float::with_val_round(settings.precision, var.max, Round::Up); 26 | let interval = Interval(min, max); 27 | (var.identifier, interval) 28 | }) 29 | .collect(); 30 | Rc::new(Context{ settings, intervals }) 31 | } 32 | 33 | pub fn get_interval(&self, id: &Identifier) -> Option<&Interval> { 34 | self.intervals.get(id) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /testcases/modular/unittests/Bsplines_Test.scala: -------------------------------------------------------------------------------- 1 | 2 | import daisy.lang._ 3 | import Real._ 4 | 5 | /** 6 | Equation and initial ranges from: 7 | L. Zhang, Y. Zhang, and W. Zhou. Tradeoff between Approximation Accuracy and 8 | Complexity for Range Analysis using Affine Arithmetic. 9 | */ 10 | object Bsplines { 11 | 12 | def test(x: Real): Real = { 13 | require(0 <= x && x <= 1) 14 | 15 | bspline0(x) + bspline1(x) + bspline2(x) * bspline1(2*x) 16 | 17 | } 18 | 19 | def bspline0(u: Real): Real = { 20 | require(0 <= u && u <= 1) 21 | (1 - u) * (1 - u) * (1 - u) / 6.0 22 | } ensuring (res => 0 <= res && res <= 0.17 && res +/- 1e-15) 23 | // proven in paper: [-0.05, 0.17] 24 | 25 | def bspline1(u: Real): Real = { 26 | require(0 <= u && u <= 1) 27 | (3 * u*u*u - 6 * u*u + 4) / 6.0 28 | } ensuring (res => 0.16 <= res && res <= 0.7 && res +/- 1e-15) 29 | // in paper [-0.05, 0.98] 30 | 31 | def bspline2(u: Real): Real = { 32 | require(0 <= u && u <= 1) 33 | (-3 * u*u*u + 3*u*u + 3*u + 1) / 6.0 34 | } ensuring (res => 0.16 <= res && res <= 0.7 && res +/- 1e-15) 35 | // in paper [-0.02, 0.89] 36 | 37 | def bspline3(u: Real): Real = { 38 | require(0 <= u && u <= 1) 39 | -u*u*u / 6.0 40 | } ensuring (res => -0.17 <= res && res <= 0.0 && res +/- 1e-15) 41 | // in paper [-0.17, 0.05] 42 | 43 | } 44 | -------------------------------------------------------------------------------- /testcases/control/Misc.scala: -------------------------------------------------------------------------------- 1 | import daisy.lang._ 2 | import Real._ 3 | 4 | object Misc { 5 | 6 | // a, d: <1, 16, 11>, b, c, e: <1, 16, 13> 7 | def martel(a: Real, b: Real, c: Real, d: Real) = { 8 | require(-14 <= a && a <= -13 && -3 <= b && b <= -2 && 3 <= c && c <= 3.5 && 12.5 <= d && d <= 13.5 && 2 <= e && e <= 2) 9 | (a + (b + (c + d))) * e 10 | } 11 | 12 | def euclideanProjection() = { 13 | Block 0 14 | ai ai 1 16 11 -10.0 10.0 15 | aj aj 1 16 11 -10.0 10.0 16 | ak ak 1 16 11 -10.0 10.0 17 | xi xi 1 16 8 -100.0 100.0 18 | xj xj 1 16 8 -100.0 100.0 19 | xk xk 1 16 8 -100.0 100.0 20 | b b 1 16 11 -10.0 10.0 21 | End of Inputs 22 | xi + ((b - (ai*xi + aj*xj + ak*xk))/(ai*ai + aj*aj + ak*ak)) * ai 23 | } 24 | 25 | 26 | def fieldControlledDCMotor() = { 27 | Block 0 28 | iff iff 1 16 14 0 1.5 29 | ia ia 1 16 14 0.1 1.5 30 | omega omega 1 16 14 0.1 1.5 31 | End of Inputs 32 | 33 | (1 / ((0.01) + ia)) * ((((1.0) * ((1.0 + 1.0) * (iff * ia))) + ((1.0) * ((1.0) * iff))) - ((1.0) * (((iff * iff) * omega) * (1.0)))) 34 | } 35 | 36 | 37 | def newtonsmethod() = { 38 | Block 0 39 | c0 c0 1 16 11 -10.0 10.0 40 | c1 c1 1 16 11 7.5 8.5 41 | c2 c2 1 16 13 -3.75 -3.25 42 | c3 c3 1 16 14 0.833 1.167 43 | x x 1 16 8 -100.0 100.0 44 | End of Inputs 45 | 46 | x - (c3*x*x*x + c2*x*x + c1*x + c0)/(3.0*c3*x*x + 2.0*c2*x + c1) 47 | } 48 | 49 | def 50 | } -------------------------------------------------------------------------------- /src/main/scala/daisy/lang/TypeOps.scala: -------------------------------------------------------------------------------- 1 | // Original work Copyright 2009-2016 EPFL, Lausanne 2 | // Modified work Copyright 2017 MPI-SWS, Saarbruecken, Germany 3 | 4 | package daisy 5 | package lang 6 | 7 | import Types._ 8 | import daisy.tools.FinitePrecision.{FixedPrecision, FloatPrecision} 9 | 10 | object TypeOps { 11 | 12 | def leastUpperBound(t1: TypeTree, t2: TypeTree): Option[TypeTree] = (t1,t2) match { 13 | case (FunctionType(from1, to1), FunctionType(from2, to2)) => 14 | if (from1 == from2) { 15 | leastUpperBound(to1, to2) map { FunctionType(from1, _) } 16 | } else { 17 | None 18 | } 19 | 20 | case (o1, o2) if o1 == o2 => Some(o1) 21 | // TODO: are there more false negatives? 22 | case (FinitePrecisionType(p1), FinitePrecisionType(p2)) => (p1, p2) match { 23 | case (FixedPrecision(b1),FixedPrecision(b2)) => Some(FinitePrecisionType(FixedPrecision(math.max(b1, b2)))) 24 | case (FloatPrecision(f1), FloatPrecision(f2)) => if (f1 >= f2) Some(FinitePrecisionType(p1)) else Some(FinitePrecisionType(p2)) 25 | case _ => None 26 | } 27 | case _ => None 28 | } 29 | 30 | def isSubtypeOf(t1: TypeTree, t2: TypeTree): Boolean = { 31 | leastUpperBound(t1, t2) == Some(t2) 32 | } 33 | 34 | def typesCompatible(t1: TypeTree, t2: TypeTree): Boolean = { 35 | leastUpperBound(t1, t2).isDefined 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /testcases/modular/keyfloat/matrix2/matrix2.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object matrix2 { 6 | 7 | def determinant(a: Real, b: Real, c: Real, d: Real): Real = { 8 | require((1.0 <= a) && (a <= 10.0) && (1.0 <= b) && (b <= 10.0) && 9 | (1.0 <= c) && (c <= 10.0) && (1.0 <= d) && (d <= 10.0)) 10 | 11 | a * d - b * c 12 | } 13 | 14 | def transposedEqV1(a: Real, b: Real, c: Real, d: Real): Real = { 15 | require((1.0 <= a) && (a <= 10.0) && (1.0 <= b) && (b <= 10.0) && 16 | (1.0 <= c) && (c <= 10.0) && (1.0 <= d) && (d <= 10.0)) 17 | 18 | val det: Real = determinant(a, b, c, d) 19 | val trans_11: Real = a 20 | val trans_12: Real = c 21 | val trans_21: Real = b 22 | val trans_22: Real = d 23 | val transDet: Real = determinant(trans_11, trans_12, trans_21, trans_22) 24 | 25 | transDet - det 26 | } 27 | 28 | def transposedEqV2(a: Real, b: Real, c: Real, d: Real): Real = { 29 | require((3.0 <= a) && (a <= 6.0) && (3.0 <= b) && (b <= 6.0) && 30 | (3.0 <= c) && (c <= 6.0) && (3.0 <= d) && (d <= 6.0)) 31 | 32 | val det: Real = determinant(a, b, c, d) 33 | val trans_11: Real = a 34 | val trans_12: Real = c 35 | val trans_21: Real = b 36 | val trans_22: Real = d 37 | val transDet: Real = determinant(trans_11, trans_12, trans_21, trans_22) 38 | 39 | transDet - det 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /scripts/analysis_modular.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash --posix 2 | # 3 | # This script runs Daisy on all modular benchmarks computing absolute rounding 4 | # errors using the default analysis options (made explicit here). 5 | # Prints the results to standard output as well as to a CSV file in output/; 6 | # if the file already exists, the results are appended. 7 | 8 | # make sure the code is compiled 9 | sbt compile 10 | 11 | # generate daisy script, if it doesn't exist 12 | if [ ! -e daisy ]; then 13 | sbt script 14 | fi 15 | 16 | if [ "$1" = "" ]; then 17 | prec="Float64" 18 | else 19 | prec="$1" 20 | fi 21 | 22 | # run Daisy on each testfile from unittests 23 | for file in testcases/modular/unittests/*.scala; do 24 | echo "*******" 25 | echo ${file} 26 | 27 | # --silent 28 | # TODO: check if precision is taken into account 29 | time ./daisy --precision="${prec}" --results-csv=modular_results.csv \ 30 | --modularRoundOffEval ${file} 31 | # bb/gelpia 32 | #--checkInterval 33 | #--shorterInterval 34 | done 35 | 36 | # run Daisy on each testfile from case studies 37 | for file in testcases/modular/case_studies/*.scala; do 38 | echo "*******" 39 | echo ${file} 40 | 41 | # --silent 42 | # TODO: check if precision is taken into account 43 | time ./daisy --precision="${prec}" --results-csv=modular_results.csv \ 44 | --modularRoundOffEval ${file} 45 | # bb/gelpia 46 | #--checkInterval 47 | #--shorterInterval 48 | done -------------------------------------------------------------------------------- /regression/reference/rewriting_results.csv: -------------------------------------------------------------------------------- 1 | Function name; Absolute error; Relative error; Real range; Time 2 | bspline3;9.714451465470121e-17;;[-0.16666666666666666, 0.0];133889 3 | complex_sine_cosine;3.724754450490231e-11;;[-11013.232874703395, 11013.232874703395];133889 4 | doppler1;1.980501095711251e-13;6.726687923515067e-12;[-158.7191444098274, -0.02944244059231351];133890 5 | doppler2;3.874656039583571e-13;2.0373897725610582e-11;[-276.0765331640505, -0.019017745606492446];133890 6 | doppler3;9.787777205044545e-14;2.2360268765039075e-13;[-96.29400542724778, -0.43773074947775303];133891 7 | jacobisMethodX1;1.1551333112279045e-08;;[-2999.9999, 13000.0];133891 8 | kepler0;6.336264846140694e-14;;[-28.0384, 140.9376];133892 9 | kepler1;3.2418121520549905e-13;;[-501.459968, 282.739712];133892 10 | kepler2;1.707691410501866e-12;;[-911.479936, 1860.323072];133892 11 | predatorPrey;1.6472768398036668e-16;4.419009637822473e-15;[0.03727705922396188, 0.35710168263424846];133892 12 | rigidBody1;1.971756091734278e-13;;[-705.0, 705.0];133893 13 | rigidBody2;2.899280815427119e-11;;[-58740.0, 58740.0];133893 14 | turbine1;8.021557111621937e-14;5.1734339216393936e-14;[-58.32912689020381, -1.5505285721480735];133893 15 | turbine2;1.2349922886986813e-13;;[-29.43698909090909, 80.993];133893 16 | turbine3;5.685430749602335e-14;;[-2.345498700579199, 45.06111779929472];133894 17 | verhulst;3.718955188047529e-16;1.1810195529610398e-15;[0.3148936170212766, 1.1008264462809918];133894 18 | -------------------------------------------------------------------------------- /testcases/relative/TimesPlusReal.scala: -------------------------------------------------------------------------------- 1 | import daisy.lang._ 2 | import Real._ 3 | 4 | object TimesPlusReal { 5 | 6 | // def sumPlus2terms(u: Real): Real = { 7 | // require(-11.633685649025693 <= u && u <= -11.633685649025693) // 100 8 | // // maxAbsError: 2.926454093647371e-17 maxRelError: 4.6812116338827325e-12 9 | // 0.0447 * u + 0.483292 + 0.03674 10 | // 11 | // } 12 | 13 | def plusSum(u: Real): Real ={ 14 | require(-11.633685649025693 <= u && u <= -11.633685649025693) 15 | // maxAbsError: 7.783679826382432e-17 maxRelError: 1.2450922307913817e-11 16 | 0.483292 + 0.03674 + 0.0447 * u 17 | } 18 | 19 | def plus2TermsSum(u: Real): Real = { 20 | require(-11.633685649025693 <= u && u <= -11.633685649025693) 21 | 0.520032 + 0.0447 * u 22 | } 23 | // def sumPlus1term(u: Real): Real ={ 24 | // require(-11.633685649025693 <= u && u <= -11.633685649025693) 25 | // maxAbsError: 7.783679826382432e-17 maxRelError: 1.2450922307913817e-11 26 | // 0.0447 * u + 0.520032 27 | // } 28 | // 29 | // def plusSum2TermsPure(u: Real, x: Real): Real = { 30 | // require(-11.633685649025693 <= u && u <= -11.633685649025693 && 1 <= x && x<=1) 31 | // (0.483292 + 0.03674*x ) + 0.0447 * u 32 | // } 33 | 34 | // def plusSum2TermsParenthesis(u: Real, x: Real): Real = { 35 | // require(-11.633685649025693 <= u && u <= -11.633685649025693 && 1<=x && x<=1) 36 | // 0.483292 + (0.03674 *x + 0.0447 * u) 37 | // } 38 | } 39 | 40 | // seed = 1486647796240 41 | -------------------------------------------------------------------------------- /testcases/rosa/Triangle.scala: -------------------------------------------------------------------------------- 1 | 2 | import daisy.lang._ 3 | import Real._ 4 | 5 | 6 | /* 7 | The famous formula for computing the area of a triangle. 8 | */ 9 | object Triangle { 10 | 11 | def triangleUnstable(a: Real, b: Real, c: Real): Real = { 12 | // TODO: this precondition can only be handled with SMT, and only 13 | // if we add the usage of the additional constraints 14 | //require(1 < a && a < 9 && 1 < b && b < 9 && 1 < c && c < 9 && 15 | // a + b > c + 0.000001 && a + c > b + 0.000001 && b + c > a + 0.000001) 16 | require(4 <= a && a <= 5 && 4 <= b && b <= 4 && 4 <= c && c <= 5) 17 | 18 | val s = (a + b + c)/2.0 19 | sqrt(s * (s - a) * (s - b) * (s - c)) 20 | 21 | } ensuring (res => res >= 0.0 && res +/- 2e-9) 22 | 23 | 24 | // def triangleKahan(aa: Real, bb: Real, cc: Real): Real = { 25 | // var a = aa 26 | // var b = bb 27 | // var c = cc 28 | 29 | // if(b < a) { 30 | // val t = a 31 | // if(c < b) { 32 | // a = c; c = t 33 | // } 34 | // else { 35 | // if(c < a) { 36 | // a = b; b = c; c = t 37 | // } 38 | // else { 39 | // a = b; b = t 40 | // } 41 | // } 42 | // } 43 | // else if(c < b) { 44 | // val t = c; c = b; 45 | // if(c < a) { 46 | // b = a; a = t 47 | // } 48 | // else { 49 | // b = t 50 | // } 51 | // } 52 | // sqrt((a+(b+c)) * (c-(a-b)) * (c+(a-b)) * (a+(b-c))) / 4.0 53 | // } 54 | 55 | } -------------------------------------------------------------------------------- /testcases/misc/Transcendentals.scala: -------------------------------------------------------------------------------- 1 | import daisy.lang._ 2 | import Real._ 3 | 4 | 5 | object Transcendentals { 6 | 7 | 8 | def pendulum1(t: Real, w: Real): Real = { 9 | require(-2 <= t && t <= 2 && -5 <= w && w <= 5) 10 | 11 | val h: Real = 0.01 12 | val L: Real = 2.0 13 | val g: Real = 9.80665 14 | val k1w = -g/L * sin(t) 15 | val k2t = w + h/2*k1w 16 | t + h*k2t 17 | 18 | } 19 | 20 | 21 | def pendulum2(t: Real, w: Real): Real = { 22 | require(-2 <= t && t <= 2 && -5 <= w && w <= 5) 23 | 24 | val h: Real = 0.01 25 | val L: Real = 2.0 26 | val g: Real = 9.80665 27 | val k1t = w 28 | val k2w = -g/L * sin(t + h/2*k1t) 29 | w + h*k2w 30 | 31 | } 32 | 33 | def analysis1(x: Real): Real = { 34 | require(x > -1.57079632679 && x < 1.57079632679) 35 | val x1 = sin(x) 36 | val x2 = cos(x) 37 | x1 * x1 * x2 * x2 38 | } 39 | 40 | def analysis2(x: Real): Real = { 41 | require(-1.1 <= x && x < 0.9) 42 | val x1 = 1 / cos(x) 43 | val x2 = tan(x) 44 | (x1 * x1) / (4 + x2 * x2) 45 | } 46 | 47 | // from FPTaylor 48 | def logExp(x: Real): Real = { 49 | require(-8 <= x && x <= 8) 50 | val e = exp(x) 51 | val t = 1 + e 52 | log(t) 53 | } 54 | 55 | // from FPTaylor 56 | def sphere(r: Real, x: Real, lat: Real, lon: Real): Real = { 57 | require(0 <= r && r <= 10 && -10 <= x && x <= 10 && 58 | -1.570796 <= lat && lat <= 1.570796 && -3.14159265 <= lon && lon <= 3.14159265) 59 | 60 | x + r * sin(lat) * cos(lon) 61 | } 62 | 63 | } -------------------------------------------------------------------------------- /testcases/relative/Kepler.scala: -------------------------------------------------------------------------------- 1 | 2 | import daisy.lang._ 3 | import Real._ 4 | 5 | /* 6 | These benchmarks were used by the Real2Float tool, 7 | and come from the proof of the Kepler conjecture 8 | Introduction to the flyspec project, T.C. Hales, Dagstuhl 2006 9 | */ 10 | object Kepler { 11 | 12 | def kepler0(x1: Real, x2: Real, x3: Real, x4: Real, x5: Real, x6: Real): Real = { 13 | require(4 <= x1 && x1 <= 6.36 && 4 <= x2 && x2 <= 6.36 && 4 <= x3 && x3 <= 6.36 && 14 | 4 <= x4 && x4 <= 6.36 && 4 <= x5 && x5 <= 6.36 && 4 <= x6 && x6 <= 6.36) 15 | 16 | x2 * x5 + x3 * x6 - x2 * x3 - x5 * x6 + x1 * (-x1 + x2 + x3 - x4 + x5 + x6) 17 | 18 | } // 1.15e-15 19 | 20 | 21 | def kepler1(x1: Real, x2: Real, x3: Real, x4: Real): Real = { 22 | require(4 <= x1 && x1 <= 6.36 && 4 <= x2 && x2 <= 6.36 && 4 <= x3 && x3 <= 6.36 && 23 | 4 <= x4 && x4 <= 6.36) 24 | 25 | x1 * x4 * (-x1 + x2 + x3 - x4) + x2 * (x1 - x2 + x3 + x4) + x3 * (x1 + x2 - x3 + x4) - 26 | x2 * x3 * x4 - x1 * x3 - x1 * x2 - x4 27 | 28 | } // 4.50e–13 29 | 30 | def kepler2(x1: Real, x2: Real, x3: Real, x4: Real, x5: Real, x6: Real): Real = { 31 | require(4 <= x1 && x1 <= 6.36 && 4 <= x2 && x2 <= 6.36 && 4 <= x3 && x3 <= 6.36 && 32 | 4 <= x4 && x4 <= 6.36 && 4 <= x5 && x5 <= 6.36 && 4 <= x6 && x6 <= 6.36) 33 | 34 | x1 * x4 * (-x1 + x2 + x3 - x4 + x5 + x6) + x2 * x5 * (x1 - x2 + x3 + x4 - x5 + x6) + 35 | x3* x6 * (x1 + x2 - x3 + x4 + x5 - x6) - x2 * x3 * x4 - 36 | x1* x3* x5 - x1 * x2 * x6 - x4 * x5 * x6 37 | 38 | } //2.08e–12 39 | } -------------------------------------------------------------------------------- /testcases/real2float/Kepler.scala: -------------------------------------------------------------------------------- 1 | 2 | import daisy.lang._ 3 | import Real._ 4 | 5 | /* 6 | These benchmarks were used by the Real2Float tool, 7 | and come from the proof of the Kepler conjecture 8 | Introduction to the flyspec project, T.C. Hales, Dagstuhl 2006 9 | */ 10 | object Kepler { 11 | 12 | def kepler0(x1: Real, x2: Real, x3: Real, x4: Real, x5: Real, x6: Real): Real = { 13 | require(4 <= x1 && x1 <= 6.36 && 4 <= x2 && x2 <= 6.36 && 4 <= x3 && x3 <= 6.36 && 14 | 4 <= x4 && x4 <= 6.36 && 4 <= x5 && x5 <= 6.36 && 4 <= x6 && x6 <= 6.36) 15 | 16 | x2 * x5 + x3 * x6 - x2 * x3 - x5 * x6 + x1 * (-x1 + x2 + x3 - x4 + x5 + x6) 17 | 18 | } // 1.15e-15 19 | 20 | 21 | def kepler1(x1: Real, x2: Real, x3: Real, x4: Real): Real = { 22 | require(4 <= x1 && x1 <= 6.36 && 4 <= x2 && x2 <= 6.36 && 4 <= x3 && x3 <= 6.36 && 23 | 4 <= x4 && x4 <= 6.36) 24 | 25 | x1 * x4 * (-x1 + x2 + x3 - x4) + x2 * (x1 - x2 + x3 + x4) + x3 * (x1 + x2 - x3 + x4) - 26 | x2 * x3 * x4 - x1 * x3 - x1 * x2 - x4 27 | 28 | } // 4.50e–13 29 | 30 | def kepler2(x1: Real, x2: Real, x3: Real, x4: Real, x5: Real, x6: Real): Real = { 31 | require(4 <= x1 && x1 <= 6.36 && 4 <= x2 && x2 <= 6.36 && 4 <= x3 && x3 <= 6.36 && 32 | 4 <= x4 && x4 <= 6.36 && 4 <= x5 && x5 <= 6.36 && 4 <= x6 && x6 <= 6.36) 33 | 34 | x1 * x4 * (-x1 + x2 + x3 - x4 + x5 + x6) + x2 * x5 * (x1 - x2 + x3 + x4 - x5 + x6) + 35 | x3* x6 * (x1 + x2 - x3 + x4 + x5 - x6) - x2 * x3 * x4 - 36 | x1* x3* x5 - x1 * x2 * x6 - x4 * x5 * x6 37 | 38 | } //2.08e–12 39 | } -------------------------------------------------------------------------------- /testcases/relative/wideranges/Kepler.scala: -------------------------------------------------------------------------------- 1 | 2 | import daisy.lang._ 3 | import Real._ 4 | 5 | /* 6 | These benchmarks were used by the Real2Float tool, 7 | and come from the proof of the Kepler conjecture 8 | Introduction to the flyspec project, T.C. Hales, Dagstuhl 2006 9 | */ 10 | object Kepler { 11 | 12 | def kepler0(x1: Real, x2: Real, x3: Real, x4: Real, x5: Real, x6: Real): Real = { 13 | require(4 <= x1 && x1 <= 6.36 && 0.0001 <= x2 && x2 <= 0.00015 && 4.63 <= x3 && x3 <= 6306 && 14 | -10 <= x4 && x4 <= -0.01 && 4 <= x5 && x5 <= 6.36 && 4 <= x6 && x6 <= 6.36) 15 | 16 | x2 * x5 + x3 * x6 - x2 * x3 - x5 * x6 + x1 * (-x1 + x2 + x3 - x4 + x5 + x6) 17 | 18 | } // 1.15e-15 19 | 20 | 21 | def kepler1(x1: Real, x2: Real, x3: Real, x4: Real): Real = { 22 | require(4 <= x1 && x1 <= 6.36 && 0.04 <= x2 && x2 <= 0.0636 && 40 <= x3 && x3 <= 6300.6 && 23 | 0.001 <= x4 && x4 <= 0.015) 24 | 25 | x1 * x4 * (-x1 + x2 + x3 - x4) + x2 * (x1 - x2 + x3 + x4) + x3 * (x1 + x2 - x3 + x4) - 26 | x2 * x3 * x4 - x1 * x3 - x1 * x2 - x4 27 | 28 | } // 4.50e–13 29 | 30 | def kepler2(x1: Real, x2: Real, x3: Real, x4: Real, x5: Real, x6: Real): Real = { 31 | require(4 <= x1 && x1 <= 6.36 && 0 <= x2 && x2 <= 0 && 40 <= x3 && x3 <= 63.6 && 32 | 0 <= x4 && x4 <= 0 && 4 <= x5 && x5 <= 6.36 && 4 <= x6 && x6 <= 6000.36) 33 | 34 | x1 * x4 * (-x1 + x2 + x3 - x4 + x5 + x6) + x2 * x5 * (x1 - x2 + x3 + x4 - x5 + x6) + 35 | x3* x6 * (x1 + x2 - x3 + x4 + x5 - x6) - x2 * x3 * x4 - 36 | x1* x3* x5 - x1 * x2 * x6 - x4 * x5 * x6 37 | 38 | } //2.08e–12 39 | } -------------------------------------------------------------------------------- /testcases/relative/smallranges/Kepler.scala: -------------------------------------------------------------------------------- 1 | 2 | import daisy.lang._ 3 | import Real._ 4 | 5 | /* 6 | These benchmarks were used by the Real2Float tool, 7 | and come from the proof of the Kepler conjecture 8 | Introduction to the flyspec project, T.C. Hales, Dagstuhl 2006 9 | */ 10 | object Kepler { 11 | 12 | def kepler0(x1: Real, x2: Real, x3: Real, x4: Real, x5: Real, x6: Real): Real = { 13 | require(4 <= x1 && x1 <= 6.36 && 0.0001 <= x2 && x2 <= 0.00011 && 40 <= x3 && x3 <= 63.6 && 14 | -6.36 <= x4 && x4 <= -4 && 4 <= x5 && x5 <= 6.36 && 4 <= x6 && x6 <= 6.36) 15 | 16 | x2 * x5 + x3 * x6 - x2 * x3 - x5 * x6 + x1 * (-x1 + x2 + x3 - x4 + x5 + x6) 17 | 18 | } // 1.15e-15 19 | 20 | 21 | def kepler1(x1: Real, x2: Real, x3: Real, x4: Real): Real = { 22 | require(4 <= x1 && x1 <= 6.36 && 0.04 <= x2 && x2 <= 0.0636 && 40 <= x3 && x3 <= 63.6 && 23 | -6.36 <= x4 && x4 <= -4) 24 | 25 | x1 * x4 * (-x1 + x2 + x3 - x4) + x2 * (x1 - x2 + x3 + x4) + x3 * (x1 + x2 - x3 + x4) - 26 | x2 * x3 * x4 - x1 * x3 - x1 * x2 - x4 27 | 28 | } // 4.50e–13 29 | 30 | def kepler2(x1: Real, x2: Real, x3: Real, x4: Real, x5: Real, x6: Real): Real = { 31 | require(4 <= x1 && x1 <= 6.36 && 0.0001 <= x2 && x2 <= 0.00011 && 40 <= x3 && x3 <= 63.6 && 32 | -6.36 <= x4 && x4 <= -4 && 4 <= x5 && x5 <= 6.36 && 4 <= x6 && x6 <= 6.36) 33 | 34 | x1 * x4 * (-x1 + x2 + x3 - x4 + x5 + x6) + x2 * x5 * (x1 - x2 + x3 + x4 - x5 + x6) + 35 | x3* x6 * (x1 + x2 - x3 + x4 + x5 - x6) - x2 * x3 * x4 - 36 | x1* x3* x5 - x1 * x2 * x6 - x4 * x5 * x6 37 | 38 | } //2.08e–12 39 | } -------------------------------------------------------------------------------- /src/main/scala/daisy/tools/MonotonicityPhase.scala: -------------------------------------------------------------------------------- 1 | package daisy 2 | package tools 3 | 4 | abstract sealed class MonotonicityPhase 5 | case class Rising() extends MonotonicityPhase 6 | case class Falling() extends MonotonicityPhase 7 | case class Mixed() extends MonotonicityPhase 8 | 9 | object MonotonicityPhase { 10 | 11 | /** Determines whether the sine function over this interval is rising, falling 12 | * or not monotone 13 | */ 14 | def getMonotonicityPhaseSine(iv: Interval): MonotonicityPhase = { 15 | def mod(a: BigInt, b: BigInt): BigInt = {(a % b + b) % b} 16 | 17 | val (_, (posLo, posHi)) = iv.reduceRange() 18 | 19 | if (posHi - posLo >= 4) { 20 | Mixed() 21 | } else { 22 | (mod(posLo, 4).toInt, mod(posHi, 4).toInt) match { 23 | case (0, 0) | (3, 0) | (3, 3) => Rising() 24 | case (1, 1) | (1, 2) | (2, 2) => Falling() 25 | case _ => Mixed() 26 | } 27 | } 28 | } 29 | 30 | /** Determines whether the sine function over this interval is rising, falling 31 | * or not monotone for Interval using MPFRFloat 32 | */ 33 | def getMonotonicityPhaseSine(iv: MPFRInterval): MonotonicityPhase = { 34 | def mod(a: BigInt, b: BigInt): BigInt = {(a % b + b) % b} 35 | 36 | val (_, (posLo, posHi)) = iv.reduceRange() 37 | 38 | if (posHi - posLo >= 4) { 39 | Mixed() 40 | } else { 41 | (mod(posLo, 4).toInt, mod(posHi, 4).toInt) match { 42 | case (0, 0) | (3, 0) | (3, 3) => Rising() 43 | case (1, 1) | (1, 2) | (2, 2) => Falling() 44 | case _ => Mixed() 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /testcases/control/InvertedPendulum4.scala: -------------------------------------------------------------------------------- 1 | import daisy.lang._ 2 | import Real._ 3 | 4 | 5 | object InvertedPendulum4 { 6 | 7 | // all: <1, 32, 30> [-1, 1] 8 | def out1() = { 9 | require(-1 <= s1 && s1 <= 1 && -1 <= s2 && s2 <= 1 && -1 <= s3 && s3 <= 1 && -1 <= s4 && s4 <= 1) 10 | (1.536200) * s1 + (2.025400) * s2 + (-16.519200) * s3 + (-2.735800) * s4 11 | } 12 | 13 | def state1() = { 14 | require(-1 <= s1 && s1 <= 1 && -1 <= s2 && s2 <= 1 && -1 <= s3 && s3 <= 1 && -1 <= s4 && s4 <= 1 && 15 | -1 <= y1 && y1 <= 1 && -1 <= y2 && y2 <= 1) 16 | (0.998301) * s1 + (0.001002) * s2 + (-0.000114) * s3 + (-0.000002) * s4 + (0.001700) * y1 + (0.000100) * y2 17 | } 18 | 19 | def state2() = { 20 | require(-1 <= s1 && s1 <= 1 && -1 <= s2 && s2 <= 1 && -1 <= s3 && s3 <= 1 && -1 <= s4 && s4 <= 1 && 21 | -1 <= y1 && y1 <= 1 && -1 <= y2 && y2 <= 1) 22 | (0.000693) * s1 + (1.003500) * s2 + (-0.029160) * s3 + (-0.004972) * s4 + (0.002100) * y1 + (0.001800) * y2 23 | } 24 | 25 | def state3() = { 26 | require(-1 <= s1 && s1 <= 1 && -1 <= s2 && s2 <= 1 && -1 <= s3 && s3 <= 1 && -1 <= s4 && s4 <= 1 && 27 | -1 <= y1 && y1 <= 1 && -1 <= y2 && y2 <= 1) 28 | (-0.001197) * s1 + (0.000004) * s2 + (0.987778) * s3 + (0.000994) * s4 + (0.001200) * y1 + (0.012200) * y2 29 | } 30 | 31 | def state4() = { 32 | require(-1 <= s1 && s1 <= 1 && -1 <= s2 && s2 <= 1 && -1 <= s3 && s3 <= 1 && -1 <= s4 && s4 <= 1 && 33 | -1 <= y1 && y1 <= 1 && -1 <= y2 && y2 <= 1) 34 | (0.006982) * s1 + (0.008751) * s2 + (-0.120899) * s3 + (0.987581) * s4 + (0.000000) * y1 + (0.077000) * y2 35 | } 36 | 37 | 38 | 39 | } -------------------------------------------------------------------------------- /testcases/control/Traincar1.scala: -------------------------------------------------------------------------------- 1 | 2 | import daisy.lang._ 3 | import Real._ 4 | 5 | object Traincar1 { 6 | 7 | // y1, y2: <1, 30, 16> s1, s2, s3: <1, 30, 25> 8 | def out1(s0: Real, s1: Real, s2: Real) = { 9 | require(0 <= s0 && s0 <= 4.6 && 0 <= s1 && s1 <= 10 && 0 <= s2 && s2 <= 10) 10 | (-3.795323e2) * s0 + (-5.443608e2) * s1 + 92.729 * s2 + 4.5165916241610748e3 11 | } 12 | 13 | def state1(s0: Real, s1: Real, s2: Real, y0: Real, y1: Real) = { 14 | require(0 <= s0 && s0 <= 4.6 && 0 <= s1 && s1 <= 10 && 0 <= s2 && s2 <= 10 && 15 | 0 <= y0 && y0 <= 10 && 0 <= y1 && y1 <= 10) 16 | (9.9992292212695999e-01)*s0+ (6.7987387059578006e-02)*s1+ (-5.7849982690687002e-02)*s2 + 17 | (-6.7093068270769995e-02)*y0 + (5.6868444245656999e-02)*y1+ (1.93109421e-07)*4.5165916241610748e+03 18 | } 19 | 20 | def state2(s0: Real, s1: Real, s2: Real, y0: Real, y1: Real) = { 21 | require(0 <= s0 && s0 <= 4.6 && 0 <= s1 && s1 <= 10 && 0 <= s2 && s2 <= 10 && 22 | 0 <= y0 && y0 <= 10 && 0 <= y1 && y1 <= 10) 23 | (-2.1755689728790001e-03)*s0+ (9.8343791204296505e-01)*s1+ (2.6908497812900001e-03)*s2 + 24 | (1.3497550507479000e-02)*y0 + (-2.1628302791680000e-03)*y1+ (5.615999103e-06)*4.5165916241610748e+03 25 | } 26 | 27 | def state3(s0: Real, s1: Real, s2: Real, y0: Real, y1: Real) = { 28 | require(0 <= s0 && s0 <= 4.6 && 0 <= s1 && s1 <= 10 && 0 <= s2 && s2 <= 10 && 29 | 0 <= y0 && y0 <= 10 && 0 <= y1 && y1 <= 10) 30 | (7.5141305955000001e-05)*s0+ (2.4840831806619999e-03)*s1+ (9.9188004018882503e-01)*s2 + (-2.4770170720600001e-03)*y0 + 31 | (8.1097048460159991e-03)*y1+ (7.060315e-09)*4.5165916241610748e+03 32 | } 33 | 34 | 35 | } -------------------------------------------------------------------------------- /src/main/scala/daisy/utils/Bijection.scala: -------------------------------------------------------------------------------- 1 | // Original work Copyright 2009-2016 EPFL, Lausanne 2 | // Modified work Copyright 2017 MPI-SWS, Saarbruecken, Germany 3 | 4 | package daisy 5 | package utils 6 | 7 | // This is a fancy name for a two-way map. 8 | class Bijection[A, B] { 9 | protected var a2b = Map[A, B]() 10 | protected var b2a = Map[B, A]() 11 | 12 | def +=(a: A, b: B): Unit = { 13 | a2b += a -> b 14 | b2a += b -> a 15 | } 16 | 17 | def +=(t: (A,B)): Unit = { 18 | this += (t._1, t._2) 19 | } 20 | 21 | def clear(): Unit = { 22 | a2b = Map() 23 | b2a = Map() 24 | } 25 | 26 | def getA(b: B): Option[A] = b2a.get(b) 27 | def getB(a: A): Option[B] = a2b.get(a) 28 | 29 | def toA(b: B): A = getA(b).get 30 | def toB(a: A): B = getB(a).get 31 | 32 | def aToB: Map[A,B] = { 33 | a2b 34 | } 35 | 36 | def bToA: Map[B, A] = { 37 | b2a 38 | } 39 | 40 | // def fromA(a: A): B = getB(a).get 41 | // def fromB(b: B): A = getA(b).get 42 | 43 | /* Check if a is already present, 44 | if not, add a new mapping. 45 | */ 46 | def getOrElseAddB(a: A)(c: => B): B = { 47 | getB(a).getOrElse { 48 | val res = c 49 | this += a -> res 50 | res 51 | } 52 | } 53 | 54 | /* Check if b is already present, 55 | if not, add a new mapping. 56 | */ 57 | def getOrElseAddA(b: B)(c: => A): A = { 58 | getA(b).getOrElse { 59 | val res = c 60 | this += res -> b 61 | res 62 | } 63 | } 64 | 65 | def containsA(a: A): Boolean = a2b contains a 66 | def containsB(b: B): Boolean = b2a contains b 67 | 68 | def aSet: Set[A] = a2b.keySet 69 | def bSet: Set[B] = b2a.keySet 70 | } 71 | -------------------------------------------------------------------------------- /testcases/mixed-precision/Bsplines0.scala: -------------------------------------------------------------------------------- 1 | 2 | import daisy.lang._ 3 | import Real._ 4 | 5 | 6 | object Bsplines0 { 7 | 8 | // f32 9 | def bspline0_32(u: Real): Real = { 10 | require(0 <= u && u <= 1) 11 | (1 - u) * (1 - u) * (1 - u) / 6.0 12 | } ensuring(res => res +/- 9e-8) 13 | 14 | // 0.5 f32 15 | def bspline0_32_05(u: Real): Real = { 16 | require(0 <= u && u <= 1) 17 | (1 - u) * (1 - u) * (1 - u) / 6.0 18 | } ensuring(res => res +/- 4.5e-8) 19 | 20 | // 0.1 f32 21 | def bspline0_32_01(u: Real): Real = { 22 | require(0 <= u && u <= 1) 23 | (1 - u) * (1 - u) * (1 - u) / 6.0 24 | } ensuring(res => res +/- 9e-9) 25 | 26 | // 0.01 f32 27 | def bspline0_32_001(u: Real): Real = { 28 | require(0 <= u && u <= 1) 29 | (1 - u) * (1 - u) * (1 - u) / 6.0 30 | } ensuring(res => res +/- 9e-10) 31 | 32 | // f64 33 | def bspline0_64(u: Real): Real = { 34 | require(0 <= u && u <= 1) 35 | (1 - u) * (1 - u) * (1 - u) / 6.0 36 | } ensuring(res => res +/- 2e-16) 37 | 38 | // 0.5 f64 39 | def bspline0_64_05(u: Real): Real = { 40 | require(0 <= u && u <= 1) 41 | (1 - u) * (1 - u) * (1 - u) / 6.0 42 | } ensuring(res => res +/- 1e-16) 43 | 44 | // 0.1 f64 45 | def bspline0_64_01(u: Real): Real = { 46 | require(0 <= u && u <= 1) 47 | (1 - u) * (1 - u) * (1 - u) / 6.0 48 | } ensuring(res => res +/- 2e-17) 49 | 50 | // 0.01 f64 51 | def bspline0_64_001(u: Real): Real = { 52 | require(0 <= u && u <= 1) 53 | (1 - u) * (1 - u) * (1 - u) / 6.0 54 | } ensuring(res => res +/- 2e-18) 55 | 56 | // dbldbl 57 | def bspline0_dbldbl(u: Real): Real = { 58 | require(0 <= u && u <= 1) 59 | (1 - u) * (1 - u) * (1 - u) / 6.0 60 | } ensuring(res => res +/- 4e-32) 61 | 62 | } 63 | -------------------------------------------------------------------------------- /testcases/mixed-precision/Bsplines1.scala: -------------------------------------------------------------------------------- 1 | 2 | import daisy.lang._ 3 | import Real._ 4 | 5 | 6 | object Bsplines1 { 7 | 8 | // f32 9 | def bspline1_32(u: Real): Real = { 10 | require(0 <= u && u <= 1) 11 | (3 * u*u*u - 6 * u*u + 4) / 6.0 12 | } ensuring (res => res +/- 4e-7) 13 | 14 | //0.5 f32 15 | def bspline1_32_05(u: Real): Real = { 16 | require(0 <= u && u <= 1) 17 | (3 * u*u*u - 6 * u*u + 4) / 6.0 18 | } ensuring (res => res +/- 2e-7) 19 | 20 | // 0.1 f32 21 | def bspline1_32_01(u: Real): Real = { 22 | require(0 <= u && u <= 1) 23 | (3 * u*u*u - 6 * u*u + 4) / 6.0 24 | } ensuring (res => res +/- 4e-8) 25 | 26 | // 0.01 f32 27 | def bspline1_32_001(u: Real): Real = { 28 | require(0 <= u && u <= 1) 29 | (3 * u*u*u - 6 * u*u + 4) / 6.0 30 | } ensuring (res => res +/- 4e-9) 31 | 32 | // f64 33 | def bspline1_64(u: Real): Real = { 34 | require(0 <= u && u <= 1) 35 | (3 * u*u*u - 6 * u*u + 4) / 6.0 36 | } ensuring (res => res +/- 7.5e-16) 37 | 38 | // 0.5 f64 39 | def bspline1_64_05(u: Real): Real = { 40 | require(0 <= u && u <= 1) 41 | (3 * u*u*u - 6 * u*u + 4) / 6.0 42 | } ensuring (res => res +/- 3.75e-16) 43 | 44 | // 0.1 f64 45 | def bspline1_64_01(u: Real): Real = { 46 | require(0 <= u && u <= 1) 47 | (3 * u*u*u - 6 * u*u + 4) / 6.0 48 | } ensuring (res => res +/- 7.5e-17) 49 | 50 | // 0.01 f64 51 | def bspline1_64_001(u: Real): Real = { 52 | require(0 <= u && u <= 1) 53 | (3 * u*u*u - 6 * u*u + 4) / 6.0 54 | } ensuring (res => res +/- 7.5e-18) 55 | 56 | // dbldbl 57 | def bspline1_dbldbl(u: Real): Real = { 58 | require(0 <= u && u <= 1) 59 | (3 * u*u*u - 6 * u*u + 4) / 6.0 60 | } ensuring (res => res +/- 2e-31) 61 | 62 | 63 | } 64 | -------------------------------------------------------------------------------- /testcases/modular/keyfloat/rotation/rotation.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object rotation { 6 | 7 | def rotate_x(vec0: Real, vec1: Real, degree: Real): Real = { 8 | require((-3.0 <= vec0) && (vec0 <= 3.0)&& (-3.0 <= vec1) && (vec1 <= 3.0) && (0.0 <= degree) && (degree <= 360)) 9 | vec0 * cos(degree) - vec1 * sin(degree) 10 | } 11 | 12 | 13 | def rotate_y(vec0: Real, vec1: Real, degree: Real): Real = { 14 | require((-3.0 <= vec0) && (vec0 <= 3.0)&& (-3.0 <= vec1) && (vec1 <= 3.0) && (0.0 <= degree) && (degree <= 360)) 15 | vec0 * sin(degree) + vec1 * cos(degree) 16 | } 17 | 18 | def computeError_x(vec0: Real, vec1: Real): Real = { 19 | require((1.0 <= vec0) && (vec0 <= 2.0)&& (1.0 <= vec1) && (vec1 <= 2.0)) 20 | 21 | val t1_x: Real = rotate_x(vec0,vec1, 90.0) 22 | val t1_y: Real = rotate_y(vec0,vec1, 90.0) 23 | val t2_x: Real = rotate_x(t1_x,t1_y, 90.0) 24 | val t2_y: Real = rotate_y(t1_x,t1_y, 90.0) 25 | val t3_x: Real = rotate_x(t2_x,t2_y, 90.0) 26 | val t3_y: Real = rotate_y(t2_x,t2_y, 90.0) 27 | val t4_x: Real = rotate_x(t3_x,t3_y, 90.0) 28 | // t4_x - vec0 29 | t4_x 30 | } 31 | 32 | def computeError_y(vec0: Real, vec1: Real): Real = { 33 | require((1.0 <= vec0) && (vec0 <= 2.0)&& (1.0 <= vec1) && (vec1 <= 2.0)) 34 | 35 | val t1_x: Real = rotate_x(vec0,vec1, 90.0) 36 | val t1_y: Real = rotate_y(vec0,vec1, 90.0) 37 | val t2_x: Real = rotate_x(t1_x,t1_y, 90.0) 38 | val t2_y: Real = rotate_y(t1_x,t1_y, 90.0) 39 | val t3_x: Real = rotate_x(t2_x,t2_y, 90.0) 40 | val t3_y: Real = rotate_y(t2_x,t2_y, 90.0) 41 | val t4_y: Real = rotate_y(t3_x,t3_y, 90.0) 42 | // t4_y - vec1 43 | t4_y 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /testcases/fpbench/hartman6.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.strictfp 2 | import daisy.lang._ 3 | import Real._ 4 | @strictfp 5 | object hartman6 { 6 | 7 | 8 | def hartman6(x1: Real, x2: Real, x3: Real, x4: Real, x5: Real, x6: Real): Real = { 9 | require(((0.0 <= x1) && (x1 <= 1.0) && (0.0 <= x2) && (x2 <= 1.0) && (0.0 <= x3) && (x3 <= 1.0) && (0.0 <= x4) && (x4 <= 1.0) && (0.0 <= x5) && (x5 <= 1.0) && (0.0 <= x6) && (x6 <= 1.0))) 10 | val e1: Real = ((((((10.0 * ((x1 - 0.1312) * (x1 - 0.1312))) + (3.0 * ((x2 - 0.1696) * (x2 - 0.1696)))) + (17.0 * ((x3 - 0.5569) * (x3 - 0.5569)))) + (3.5 * ((x4 - 0.0124) * (x4 - 0.0124)))) + (1.7 * ((x5 - 0.8283) * (x5 - 0.8283)))) + (8.0 * ((x6 - 0.5886) * (x6 - 0.5886)))) 11 | val e2: Real = ((((((0.05 * ((x1 - 0.2329) * (x1 - 0.2329))) + (10.0 * ((x2 - 0.4135) * (x2 - 0.4135)))) + (17.0 * ((x3 - 0.8307) * (x3 - 0.8307)))) + (0.1 * ((x4 - 0.3736) * (x4 - 0.3736)))) + (8.0 * ((x5 - 0.1004) * (x5 - 0.1004)))) + (14.0 * ((x6 - 0.9991) * (x6 - 0.9991)))) 12 | val e3: Real = ((((((3.0 * ((x1 - 0.2348) * (x1 - 0.2348))) + (3.5 * ((x2 - 0.1451) * (x2 - 0.1451)))) + (1.7 * ((x3 - 0.3522) * (x3 - 0.3522)))) + (10.0 * ((x4 - 0.2883) * (x4 - 0.2883)))) + (17.0 * ((x5 - 0.3047) * (x5 - 0.3047)))) + (8.0 * ((x6 - 0.665) * (x6 - 0.665)))) 13 | val e4: Real = ((((((17.0 * ((x1 - 0.4047) * (x1 - 0.4047))) + (8.0 * ((x2 - 0.8828) * (x2 - 0.8828)))) + (0.05 * ((x3 - 0.8732) * (x3 - 0.8732)))) + (10.0 * ((x4 - 0.5743) * (x4 - 0.5743)))) + (0.1 * ((x5 - 0.1091) * (x5 - 0.1091)))) + (14.0 * ((x6 - 0.0381) * (x6 - 0.0381)))) 14 | val exp1: Real = exp(-(e1)) 15 | val exp2: Real = exp(-(e2)) 16 | val exp3: Real = exp(-(e3)) 17 | val exp4: Real = exp(-(e4)) 18 | -(((((1.0 * exp1) + (1.2 * exp2)) + (3.0 * exp3)) + (3.2 * exp4))) 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /LEON_LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009-2015 EPFL, Lausanne, unless otherwise specified. All rights 2 | reserved. 3 | 4 | This software was developed by the Laboratory for Automated Reasoning and 5 | Analysis (LARA) of the Swiss Federal Institute of Technology (EPFL), Lausanne, 6 | Switzerland. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright notice, 12 | this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright notice, 15 | this list of conditions and the following disclaimer in the documentation 16 | and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY 19 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY 22 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | The views and conclusions contained in the software and documentation are those 30 | of the authors and should not be interpreted as representing official policies, 31 | either expressed or implied, of EPFL. 32 | -------------------------------------------------------------------------------- /src/main/scala/daisy/transform/PowTransformerPhase.scala: -------------------------------------------------------------------------------- 1 | package daisy 2 | package transform 3 | 4 | import daisy.lang.TreeOps 5 | import lang.Trees._ 6 | 7 | /** 8 | * Transforms expressions of form (x * x * ... * x) to IntPow(x, n) and back, depending on the value of "powers" 9 | * command line option 10 | * 11 | * Motivation: this avoids handling the cases of even powers for times and IntPow 12 | * simultaneously at the later stages of analysis 13 | */ 14 | object PowTransformerPhase extends DaisyPhase { 15 | 16 | override val name = "Pow transformer" 17 | override val description = "Converts between expressions of form (x * x * ... * x) and IntPow(x, n)" 18 | override implicit val debugSection = DebugSectionTransform 19 | 20 | override def runPhase(ctx: Context, prg: Program): (Context, Program) = { 21 | val transformationFunction = if (ctx.hasFlag("pow-roll")) { 22 | timesToPow 23 | } else { 24 | assert(ctx.hasFlag("pow-unroll")) 25 | powToTimes 26 | } 27 | 28 | val newDefs = transformConsideredFunctions(ctx, prg){ fnc => 29 | fnc.copy(body = Some(transformationFunction(fnc.body.get))) 30 | } 31 | (ctx, Program(prg.id, newDefs)) 32 | } 33 | 34 | private val rollTimes: PartialFunction[Expr, Expr] = { 35 | case Times(x, y) if x == y => IntPow(x, 2) 36 | case Times(x, IntPow(y, n)) if x == y => IntPow(x, n + 1) 37 | case Times(IntPow(y, n), x) if x == y => IntPow(x, n + 1) 38 | } 39 | 40 | private val unrollTimes: PartialFunction[Expr, Expr] = { 41 | case IntPow(x, 1) => x 42 | case IntPow(x, n) => Times(x, IntPow(x, n -1)) 43 | } 44 | 45 | val timesToPow: Expr => Expr = TreeOps.replace(rollTimes, applyRec = true) 46 | val powToTimes: Expr => Expr = TreeOps.replace(unrollTimes, applyRec = true) 47 | } 48 | -------------------------------------------------------------------------------- /testcases/mixed-precision/Bsplines2.scala: -------------------------------------------------------------------------------- 1 | 2 | import daisy.lang._ 3 | import Real._ 4 | 5 | 6 | object Bsplines2 { 7 | 8 | // f32 9 | def bspline2_32(u: Real): Real = { 10 | require(0 <= u && u <= 1) 11 | (-3 * u*u*u + 3*u*u + 3*u + 1) / 6.0 12 | } ensuring(res => res +/- 3.5e-7) 13 | 14 | // 0.5 f32 15 | def bspline2_32_05(u: Real): Real = { 16 | require(0 <= u && u <= 1) 17 | (-3 * u*u*u + 3*u*u + 3*u + 1) / 6.0 18 | } ensuring(res => res +/- 1.75e-7) 19 | 20 | // 0.1 f32 21 | def bspline2_32_01(u: Real): Real = { 22 | require(0 <= u && u <= 1) 23 | (-3 * u*u*u + 3*u*u + 3*u + 1) / 6.0 24 | } ensuring(res => res +/- 3.5e-8) 25 | 26 | // 0.01 f32 27 | def bspline2_32_001(u: Real): Real = { 28 | require(0 <= u && u <= 1) 29 | (-3 * u*u*u + 3*u*u + 3*u + 1) / 6.0 30 | } ensuring(res => res +/- 3.5e-9) 31 | 32 | // f64 33 | def bspline2_64(u: Real): Real = { 34 | require(0 <= u && u <= 1) 35 | (-3 * u*u*u + 3*u*u + 3*u + 1) / 6.0 36 | } ensuring(res => res +/- 6.5e-16) 37 | 38 | // 0.5 f64 39 | def bspline2_64_05(u: Real): Real = { 40 | require(0 <= u && u <= 1) 41 | (-3 * u*u*u + 3*u*u + 3*u + 1) / 6.0 42 | } ensuring(res => res +/- 3.25e-16) 43 | 44 | // 0.1 f64 45 | def bspline2_64_01(u: Real): Real = { 46 | require(0 <= u && u <= 1) 47 | (-3 * u*u*u + 3*u*u + 3*u + 1) / 6.0 48 | } ensuring(res => res +/- 6.5e-17) 49 | 50 | // 0.01 f64 51 | def bspline2_64_001(u: Real): Real = { 52 | require(0 <= u && u <= 1) 53 | (-3 * u*u*u + 3*u*u + 3*u + 1) / 6.0 54 | } ensuring(res => res +/- 6.5e-18) 55 | 56 | // dbldbl 57 | def bspline2_dbldbl(u: Real): Real = { 58 | require(0 <= u && u <= 1) 59 | (-3 * u*u*u + 3*u*u + 3*u + 1) / 6.0 60 | } ensuring(res => res +/- 2e-31) 61 | 62 | } 63 | -------------------------------------------------------------------------------- /scripts/metalibm/elem_overhead_timing.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash --posix 2 | 3 | # This script runs all executables in the output/$outputFolderName, and analyzes 4 | # the recorded running times. 5 | 6 | # to be run from the main directory 7 | 8 | outputFolderName=$1 9 | echo "output folder: $outputFolderName" 10 | 11 | outputFolder=output/$outputFolderName 12 | echo "going to time executables in folder: ${outputFolder}" 13 | 14 | resultsFile="${outputFolder}/timing_results.txt" 15 | rm -f "${resultsFile}" 16 | touch "${resultsFile}" 17 | 18 | declare -a functions=("sinxx10" "xu1" "xu2" "integrate18257" \ 19 | "integrateStoutemyer2007" "axisRotationX" \ 20 | "axisRotationY" "rodriguesRotation" "pendulum1" "pendulum2" \ 21 | "forwardk2jX" "forwardk2jY" \ 22 | "ex2_1" "ex2_2" "ex2_3" "ex2_4" "ex2_5" \ 23 | "ex2_9" "ex2_10" "ex2_11" "ex3_d") 24 | 25 | echo "# Stats: mean cycles, std. deviation, min cycles, max cycles" >> "${resultsFile}" 26 | 27 | 28 | for fnc in "${functions[@]}" 29 | do 30 | 31 | if [ -f ${outputFolder}/exe_mathh_$fnc ]; then 32 | 33 | echo "measuring: ${fnc}" 34 | echo "${fnc}" >> "${resultsFile}" 35 | 36 | TIMEDATA_FILENAME_MATHH="${fnc}_timedata_mathh.txt" 37 | 38 | TIMEDATA_FILENAME_METALIBM="${fnc}_timedata.txt" 39 | 40 | ./${outputFolder}/exe_mathh_$fnc "${TIMEDATA_FILENAME_MATHH}" 41 | 42 | ./${outputFolder}/exe_arith_$fnc "${TIMEDATA_FILENAME_METALIBM}" 43 | 44 | STATS="$(python scripts/metalibm/timedata_processing.py ${TIMEDATA_FILENAME_MATHH} ${TIMEDATA_FILENAME_METALIBM} )" 45 | 46 | echo "${STATS}" 47 | 48 | echo "${STATS}" >> "${resultsFile}" 49 | 50 | rm $TIMEDATA_FILENAME_MATHH 51 | rm $TIMEDATA_FILENAME_METALIBM 52 | 53 | echo "" >> "${resultsFile}" 54 | echo "" >> "${resultsFile}" 55 | echo "" 56 | 57 | fi 58 | 59 | done -------------------------------------------------------------------------------- /scripts/metalibm/metalibm_timing.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash --posix 2 | 3 | # This script runs all executables in the output/$outputFolderName, and analyzes 4 | # the recorded running times. 5 | 6 | # to be run from the main directory 7 | 8 | outputFolderName=$1 9 | echo "output folder: $outputFolderName" 10 | 11 | outputFolder=output/$outputFolderName 12 | echo "going to time executables in folder: ${outputFolder}" 13 | 14 | resultsFile="${outputFolder}/timing_results.txt" 15 | rm -f "${resultsFile}" 16 | touch "${resultsFile}" 17 | 18 | declare -a functions=("sinxx10" "xu1" "xu2" "integrate18257" \ 19 | "integrateStoutemyer2007" "axisRotationX" \ 20 | "axisRotationY" "rodriguesRotation" "pendulum1" "pendulum2" \ 21 | "forwardk2jX" "forwardk2jY" \ 22 | "ex2_1" "ex2_2" "ex2_3" "ex2_4" "ex2_5" \ 23 | "ex2_9" "ex2_10" "ex2_11" "ex3_d") 24 | 25 | echo "# Stats: mean cycles, std. deviation, min cycles, max cycles" >> "${resultsFile}" 26 | 27 | 28 | for fnc in "${functions[@]}" 29 | do 30 | 31 | if [ -f ${outputFolder}/exe_mathh_$fnc ]; then 32 | 33 | echo "measuring: ${fnc}" 34 | echo "${fnc}" >> "${resultsFile}" 35 | 36 | TIMEDATA_FILENAME_MATHH="${fnc}_timedata_mathh.txt" 37 | 38 | TIMEDATA_FILENAME_METALIBM="${fnc}_timedata.txt" 39 | 40 | ./${outputFolder}/exe_mathh_$fnc "${TIMEDATA_FILENAME_MATHH}" 41 | 42 | ./${outputFolder}/exe_metalibm_$fnc "${TIMEDATA_FILENAME_METALIBM}" 43 | 44 | STATS="$(python scripts/metalibm/timedata_processing.py ${TIMEDATA_FILENAME_MATHH} ${TIMEDATA_FILENAME_METALIBM} )" 45 | 46 | echo "${STATS}" 47 | 48 | echo "${STATS}" >> "${resultsFile}" 49 | 50 | rm $TIMEDATA_FILENAME_MATHH 51 | rm $TIMEDATA_FILENAME_METALIBM 52 | 53 | echo "" >> "${resultsFile}" 54 | echo "" >> "${resultsFile}" 55 | echo "" 56 | 57 | fi 58 | 59 | done -------------------------------------------------------------------------------- /testcases/relative/KeplerSingle.scala: -------------------------------------------------------------------------------- 1 | 2 | import daisy.lang._ 3 | import Real._ 4 | 5 | /* 6 | These benchmarks were used by the Real2Float tool, 7 | and come from the proof of the Kepler conjecture 8 | Introduction to the flyspec project, T.C. Hales, Dagstuhl 2006 9 | */ 10 | object KeplerSingle { 11 | 12 | def kepler0(x1: Real): Real = { 13 | require(4 <= x1 && x1 <= 6.36) 14 | 15 | val x2: Real = 4 // 4 <= x2 && x2 <= 6.36 16 | val x3: Real = 4.03 //4 <= x3 && x3 <= 6.36 17 | val x4: Real = 6.36 //4 <= x4 && x4 <= 6.36 18 | val x5: Real = 6.2 //4 <= x5 && x5 <= 6.36 19 | val x6: Real = 5.18 //4 <= x6 && x6 <= 6.36 20 | 21 | 4 * 6.2 + 4.03 * 5.18 - 4 * 4.03 - 6.2 * 5.18 + x1 * (-x1 + 4 + 4.03 - 6.36 + 6.2 + 5.18) 22 | 23 | } // 1.15e-15 24 | 25 | 26 | def kepler1(x1: Real): Real = { 27 | require(4 <= x1 && x1 <= 6.36) 28 | val x2: Real = 4 // 4 <= x2 && x2 <= 6.36 29 | val x3: Real = 4.03 //4 <= x3 && x3 <= 6.36 30 | val x4: Real = 6.36 //4 <= x4 && x4 <= 6.36 31 | 32 | x1 * 6.36 * (-x1 + 4 + 4.03 - 6.36) + 4 * (x1 - 4 + 4.03 + 6.36) + 4.03 * (x1 + 4 - 4.03 + 6.36) - 33 | 4 * 4.03 * 6.36 - x1 * 4.03 - x1 * 4 - 6.36 34 | 35 | } // 4.50e–13 36 | 37 | def kepler2(x1: Real): Real = { 38 | require(4 <= x1 && x1 <= 6.36) 39 | 40 | val x2: Real = 4 // 4 <= x2 && x2 <= 6.36 41 | val x3: Real = 4.03 //4 <= x3 && x3 <= 6.36 42 | val x4: Real = 6.36 //4 <= x4 && x4 <= 6.36 43 | val x5: Real = 6.2 //4 <= x5 && x5 <= 6.36 44 | val x6: Real = 5.18 //4 <= x6 && x6 <= 6.36 45 | 46 | x1 * 6.36 * (-x1 + 4 + 4.03 - 6.36 + 6.2 + 5.18) + 4 * 6.2 * (x1 - 4 + 4.03 + 6.36 - 6.2 + 5.18) + 47 | 4.03* 5.18 * (x1 + 4 - 4.03 + 6.36 + 6.2 - 5.18) - 4 * 4.03 * 6.36 - 48 | x1* 4.03* 6.2 - x1 * 4 * 5.18 - 6.36 * 6.2 * 5.18 49 | 50 | } //2.08e–12 51 | } -------------------------------------------------------------------------------- /src/main/scala/daisy/frontend/ScalaCompiler.scala: -------------------------------------------------------------------------------- 1 | // Original work Copyright 2009-2016 EPFL, Lausanne 2 | // Modified work Copyright 2017 MPI-SWS, Saarbruecken, Germany 3 | 4 | package daisy 5 | package frontend 6 | 7 | import scala.tools.nsc.{Global,Settings=>NSCSettings} 8 | import scala.reflect.internal.Positions 9 | 10 | class ScalaCompiler(settings: NSCSettings, ctx: Context) extends Global( 11 | settings, new SimpleReporter(settings, ctx.reporter)) with Positions { 12 | 13 | object daisyExtraction extends { 14 | val global: ScalaCompiler.this.type = ScalaCompiler.this 15 | val runsAfter = List[String]("refchecks") 16 | val runsRightAfter = None 17 | val ctx = ScalaCompiler.this.ctx 18 | } with DaisyExtraction 19 | 20 | override protected def computeInternalPhases(): Unit = { 21 | val phs = List( 22 | syntaxAnalyzer -> "parse source into ASTs, perform simple desugaring", 23 | analyzer.namerFactory -> "resolve names, attach symbols to named trees", 24 | analyzer.packageObjects -> "load package objects", 25 | analyzer.typerFactory -> "the meat and potatoes: type the trees", 26 | patmat -> "translate match expressions", 27 | superAccessors -> "add super accessors in traits and nested classes", 28 | extensionMethods -> "add extension methods for inline classes", 29 | pickler -> "serialize symbol tables", 30 | refChecks -> "reference/override checking, translate nested objects", 31 | daisyExtraction -> "extracts daisy trees out of scala trees" 32 | ) 33 | phs foreach { phasesSet += _._1 } 34 | } 35 | 36 | class Run extends super.Run { 37 | override def progress(current: Int, total: Int): Unit = { 38 | ctx.reporter.onCompilerProgress(current, total) 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /scripts/optimization_mixed-tuning_rewriting.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash --posix 2 | # 3 | # This script runs Daisy's mixed-precision tuning on the set of benchmarks 4 | # used in the ICCPS'18 paper. The automatically generated code will be saved 5 | # in the output/ folder. 6 | # Using the non-default --rangeMethod=smt is optional; --errorMethod=affine is 7 | # the default option, made explicit here. 8 | # 9 | # The second command below runs rewriting before mixed-precision tuning. The 10 | # range method is set to the default for performance reasons. If you want to fix 11 | # the random seed for determinism, use --rewrite-seed with a non-zero number. 12 | 13 | 14 | # make sure the code is compiled 15 | sbt compile 16 | 17 | # generate daisy script, if it doesn't exist 18 | if [ ! -e daisy ]; then 19 | sbt script 20 | fi 21 | 22 | # run Daisy on each testfile 23 | for file in testcases/mixed-precision/*.scala; do 24 | echo "*******" 25 | echo ${file} 26 | time ./daisy --silent --mixed-tuning --rangeMethod=smt --errorMethod=affine ${file} 27 | 28 | # also use rewriting 29 | # time ./daisy --silent --mixed-tuning --rewrite --rewrite-seed=0 \ 30 | # --rangeMethod=interval --errorMethod=affine ${file} 31 | done 32 | 33 | 34 | 35 | # for file in "${arr[@]}" 36 | # do 37 | # echo "---> $file" # --rangeMethod=smt #--rewrite-seed-system-millis \ 38 | # if [ "$1" = "rewriting" ]; then 39 | # ./daisy --mixed-tuning --rewrite --rangeMethod=smt \ 40 | # --rewrite-seed=1490794789615 "testcases/mixed-precision/${file}.scala" 41 | # #--rewrite-seed-system-millis "testcases/mixed-precision/${file}.scala" 42 | 43 | # else 44 | # ./daisy --mixed-tuning --rangeMethod=smt "testcases/mixed-precision/${file}.scala" 45 | # #./daisy --mixed-fixedpoint --mixed-tuning --rangeMethod=smt "testcases/mixed-precision/fixedpoint/${file}.scala" 46 | # fi 47 | # done 48 | -------------------------------------------------------------------------------- /regression/reference/dataflow_z3_AA_results.csv: -------------------------------------------------------------------------------- 1 | Function name; Absolute error; Relative error; Real range; Time 2 | bspline3;1.0639637319324417e-16;;[-0.16666666666666666, 0.0];149331 3 | carbonGas;3.913245008146802e-08;1.8657518085392216e-14;[2097409.2, 3.434323E7];149331 4 | complex_sine_cosine;3.724754450490231e-11;;[-11013.232874703395, 11013.232874703395];149332 5 | complex_square_root;1.6271354747651043e-10;4.683288034152426e-09;[0.03474344227601155, 3.474344227601157];149333 6 | doppler1;4.1911988101104756e-13;1.4235228893370562e-11;[-158.7191444098274, -0.02944244059231351];149334 7 | doppler2;1.0471093297316197e-12;5.505959283492299e-11;[-276.0765331640505, -0.019017745606492446];149334 8 | doppler3;1.682927721863026e-13;3.844664154553662e-13;[-96.29400542724778, -0.43773074947775303];149334 9 | floudas1;4.4941828036826337e-13;;[-509.0, 0.0634765625];149336 10 | floudas2;1.1102230246251565e-15;;[-4.9697265625, 0.0];149336 11 | floudas3;1.532107773982716e-14;;[-45.0, 4.0078125];149336 12 | kepler0;9.063860773039779e-14;4.3457894586374306e-15;[20.85664954390506, 95.90993040043205];149336 13 | kepler1;4.5220254207833936e-13;;[-452.570616588663, 30.167869944123886];149336 14 | kepler2;2.2374660346713427e-12;;[-645.0601225429688, 1287.5673739765625];149337 15 | predatorPrey;1.7488154636295659e-16;4.691398677998233e-15;[0.03727705922396188, 0.35710168263424846];149337 16 | rigidBody1;2.948752353404416e-13;;[-705.0, 705.0];149337 17 | rigidBody2;3.6066261088762985e-11;;[-58740.0, 58740.0];149337 18 | turbine1;8.648499855918151e-14;5.57777522534569e-14;[-58.32912689020381, -1.5505285721480735];149338 19 | turbine2;1.3068946018619626e-13;;[-29.43698909090909, 80.993];149338 20 | turbine3;6.230844036785958e-14;1.3368160444451825e-13;[0.4660958448753463, 40.375126890203816];149338 21 | verhulst;3.718955188047529e-16;1.1810195529610398e-15;[0.3148936170212766, 1.1008264462809918];149339 22 | x_by_xy;1.776356839400254e-15;8.960538933723448e-15;[0.1982421875, 0.80615234375];149339 23 | -------------------------------------------------------------------------------- /library/Real.scala: -------------------------------------------------------------------------------- 1 | // Original work Copyright 2009-2016 EPFL, Lausanne 2 | // Modified work Copyright 2017 MPI-SWS, Saarbruecken, Germany 3 | 4 | package daisy.lang 5 | 6 | import scala.annotation.StaticAnnotation 7 | 8 | 9 | import scala.language.implicitConversions 10 | import scala.math.{ScalaNumericConversions, ScalaNumber} 11 | 12 | @ignore 13 | class ignore extends StaticAnnotation 14 | 15 | @ignore 16 | object Real { 17 | @ignore 18 | implicit def double2real(d: Double): Real = Real(d) 19 | 20 | @ignore 21 | implicit def int2real(i: Int): Real = Real(i.toDouble) 22 | 23 | @ignore 24 | def sqrt(x: Real): Real = ??? 25 | 26 | @ignore 27 | def sin(x: Real): Real = ??? 28 | 29 | @ignore 30 | def cos(x: Real): Real = ??? 31 | 32 | @ignore 33 | def tan(x: Real): Real = ??? 34 | 35 | @ignore 36 | def asin(x: Real): Real = ??? 37 | 38 | @ignore 39 | def acos(x: Real): Real = ??? 40 | 41 | @ignore 42 | def atan(x: Real): Real = ??? 43 | 44 | @ignore 45 | def log(x: Real): Real = ??? 46 | 47 | @ignore 48 | def exp(x: Real): Real = ??? 49 | 50 | @ignore 51 | def pow(x: Real, y: Int): Real = ??? 52 | 53 | @ignore 54 | def fma(x: Real, y: Real, z: Real): Real = ??? 55 | } 56 | 57 | @ignore 58 | case class Real private[daisy](v: Double) extends ScalaNumber with ScalaNumericConversions with Ordered[Real] { 59 | def unary_-(): Real = ??? 60 | def +(other: Real): Real = ??? 61 | def -(other: Real): Real = ??? 62 | def *(other: Real): Real = ??? 63 | def /(other: Real): Real = ??? 64 | 65 | // Uncertainty on this value 66 | def +/-(x: Real): Boolean = ??? 67 | 68 | def compare(other: Real): Int = ??? 69 | 70 | def underlying(): AnyRef = this 71 | def isWhole(): Boolean = ??? 72 | def doubleValue(): Double = ??? 73 | def floatValue(): Float = ??? 74 | def longValue(): Long = ??? 75 | def intValue(): Int = ??? 76 | } -------------------------------------------------------------------------------- /src/main/scala/daisy/utils/DebugSection.scala: -------------------------------------------------------------------------------- 1 | // Original work Copyright 2009-2016 EPFL, Lausanne 2 | // Modified work Copyright 2017 MPI-SWS, Saarbruecken, Germany 3 | 4 | package daisy 5 | 6 | import scala.annotation.implicitNotFound 7 | 8 | @implicitNotFound("No implicit debug section found in scope. " + 9 | "You need define an implicit DebugSection to use debug/ifDebug") 10 | sealed abstract class DebugSection(val name: String, val mask: Int) 11 | 12 | case object DebugSectionFrontend extends DebugSection("frontend", 1 << 0) 13 | case object DebugSectionSolver extends DebugSection("solver", 1 << 1) 14 | case object DebugSectionTools extends DebugSection("tools", 1 << 2) 15 | case object DebugSectionAnalysis extends DebugSection("analysis", 1 << 3) 16 | case object DebugSectionBackend extends DebugSection("backend", 1 << 4) 17 | case object DebugSectionTaylor extends DebugSection("taylor", 1 << 5) 18 | case object DebugSectionOptimization extends DebugSection("opt", 1 << 6) 19 | case object DebugSectionExprOptimizer extends DebugSection("expr-optimizer", 1 << 7) 20 | case object DebugSectionFitnessEval extends DebugSection("fitness-eval", 1 << 8) 21 | case object DebugSectionSimplify extends DebugSection("simplify", 1 << 9) 22 | case object DebugSectionExperiment extends DebugSection("experiment", 1 << 10) 23 | case object DebugSectionTransform extends DebugSection("transform", 1 << 11) 24 | 25 | object DebugSections { 26 | val all = Set[DebugSection]( 27 | DebugSectionFrontend, 28 | DebugSectionSolver, 29 | DebugSectionTools, 30 | DebugSectionAnalysis, 31 | DebugSectionBackend, 32 | DebugSectionTaylor, 33 | DebugSectionOptimization, 34 | DebugSectionExprOptimizer, 35 | DebugSectionFitnessEval, 36 | DebugSectionSimplify, 37 | DebugSectionExperiment, 38 | DebugSectionTransform 39 | ) 40 | 41 | } 42 | -------------------------------------------------------------------------------- /testcases/mixed-precision/Sqrt.scala: -------------------------------------------------------------------------------- 1 | 2 | 3 | import daisy.lang._ 4 | import Real._ 5 | 6 | 7 | object Sqrt { 8 | 9 | // f32 10 | def sqroot_32(x: Real): Real = { 11 | require(x >= 0.0 && x < 10.0) 12 | 1.0 + 0.5*x - 0.125*x*x + 0.0625*x*x*x - 0.0390625*x*x*x*x 13 | } ensuring(res => res +/- 2e-4) 14 | 15 | // 0.5 f32 16 | def sqroot_32_05(x: Real): Real = { 17 | require(x >= 0.0 && x < 10.0) 18 | 1.0 + 0.5*x - 0.125*x*x + 0.0625*x*x*x - 0.0390625*x*x*x*x 19 | } ensuring(res => res +/- 1e-4) 20 | 21 | // 0.1 f32 22 | def sqroot_32_01(x: Real): Real = { 23 | require(x >= 0.0 && x < 10.0) 24 | 1.0 + 0.5*x - 0.125*x*x + 0.0625*x*x*x - 0.0390625*x*x*x*x 25 | } ensuring(res => res +/- 2e-5) 26 | 27 | // 0.01 f32 28 | def sqroot_32_001(x: Real): Real = { 29 | require(x >= 0.0 && x < 10.0) 30 | 1.0 + 0.5*x - 0.125*x*x + 0.0625*x*x*x - 0.0390625*x*x*x*x 31 | } ensuring(res => res +/- 2e-6) 32 | 33 | // f64 34 | def sqroot_64(x: Real): Real = { 35 | require(x >= 0.0 && x < 10.0) 36 | 1.0 + 0.5*x - 0.125*x*x + 0.0625*x*x*x - 0.0390625*x*x*x*x 37 | } ensuring(res => res +/- 3.5e-13) 38 | 39 | // 0.5 f64 40 | def sqroot_64_05(x: Real): Real = { 41 | require(x >= 0.0 && x < 10.0) 42 | 1.0 + 0.5*x - 0.125*x*x + 0.0625*x*x*x - 0.0390625*x*x*x*x 43 | } ensuring(res => res +/- 1.75e-13) 44 | 45 | // 0.1 f64 46 | def sqroot_64_01(x: Real): Real = { 47 | require(x >= 0.0 && x < 10.0) 48 | 1.0 + 0.5*x - 0.125*x*x + 0.0625*x*x*x - 0.0390625*x*x*x*x 49 | } ensuring(res => res +/- 3.5e-14) 50 | 51 | // 0.01 f64 52 | def sqroot_64_001(x: Real): Real = { 53 | require(x >= 0.0 && x < 10.0) 54 | 1.0 + 0.5*x - 0.125*x*x + 0.0625*x*x*x - 0.0390625*x*x*x*x 55 | } ensuring(res => res +/- 3.5e-15) 56 | 57 | // dbldbl 58 | def sqroot_dbldbl(x: Real): Real = { 59 | require(x >= 0.0 && x < 10.0) 60 | 1.0 + 0.5*x - 0.125*x*x + 0.0625*x*x*x - 0.0390625*x*x*x*x 61 | } ensuring(res => res +/- 1.5e-28) 62 | 63 | } -------------------------------------------------------------------------------- /src/main/scala/daisy/solvers/Z3Solver.scala: -------------------------------------------------------------------------------- 1 | // Original work Copyright 2009-2016 EPFL, Lausanne 2 | // Modified work Copyright 2017 MPI-SWS, Saarbruecken, Germany 3 | 4 | package daisy 5 | package solvers 6 | 7 | import scala.collection.immutable.Seq 8 | import smtlib.interpreters.Z3Interpreter 9 | import smtlib.trees.Commands.{AttributeOption, SetOption} 10 | import smtlib.trees.Terms._ 11 | import lang.Trees.Expr 12 | 13 | // TODO has to be singleton 14 | object Z3Solver { 15 | 16 | val timeoutOption = AttributeOption(Attribute( 17 | SKeyword("timeout"), value = Some(SNumeral(1000)))) 18 | 19 | // TODO set the option properly!!!!!!!! 20 | val decimalOption = AttributeOption(Attribute 21 | (SKeyword("pp.decimal"), value = Some(SSymbol("true")))) 22 | 23 | def checkSat(query: Expr, ctx: Context): Option[Boolean] = { 24 | val solver = new Z3Solver(ctx) 25 | solver.emit(SetOption(timeoutOption)) 26 | solver.assertConstraint(query) 27 | val res = solver.checkSat 28 | solver.free() 29 | res 30 | } 31 | 32 | def checkAndGetModel(query: Expr, ctx: Context): Option[Model] = { 33 | val solver = new Z3Solver(ctx) 34 | solver.emit(SetOption(timeoutOption)) 35 | solver.emit(SetOption(decimalOption)) 36 | solver.assertConstraint(query) 37 | val tmp = solver.checkSat 38 | val res = tmp match { 39 | case Some(true) => Some(solver.getModel) 40 | case Some(false) => None 41 | case None => None 42 | } 43 | solver.free() 44 | res 45 | } 46 | 47 | // global counter of "Unknown"s or timeouts 48 | var unknownCounter = 0 49 | } 50 | 51 | 52 | class Z3Solver(ctx: Context) extends SMTLibSolver(ctx) { 53 | 54 | override def targetName: String = "z3" 55 | 56 | val interpreterOpts = Seq("-in", "-smt2") 57 | 58 | 59 | def getNewInterpreter(): Z3Interpreter = { 60 | val opts = interpreterOpts 61 | ctx.reporter.debug("Invoking solver " + targetName + " with " + opts.mkString(" ")) 62 | 63 | new Z3Interpreter("z3", opts.toArray) 64 | } 65 | } 66 | --------------------------------------------------------------------------------