Changeset 1577
- Timestamp:
- Oct 1, 2020 9:17:01 AM (4 years ago)
- Location:
- trunk/magnolia-basic-library/src
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/magnolia-basic-library/src/Basic/FiniteInteger.mg
r1454 r1577 82 82 concept BoundedNatural = { 83 83 use BoundedInteger; 84 axiom zero_bound () {84 axiom zero_bound_BoundedNaturalAxiom () { 85 85 assert minimum() == zero(); 86 86 } … … 91 91 concept ModulusInteger = { 92 92 use TorusInteger; 93 axiom zero_bound () {93 axiom zero_bound_ModulusIntegerAxiom () { 94 94 assert minimum() == zero(); 95 95 } -
trunk/magnolia-basic-library/src/BasicCxx/FloatCxx.mg
r1454 r1577 85 85 function trunc( x:Float ) : Float; 86 86 function zero() : Float; 87 function one () : Float; 87 88 function floor( x:Float ) : Float; 88 89 function abs( x:Float ) : Float; 89 90 function uminus( x:Float ) : Float; 91 function pow ( x:Float, y:Float ) : Float; 92 function _+_ ( x:Float, y:Float ) : Float; 93 function _*_ ( x:Float, y:Float ) : Float; 90 94 predicate _<=_ ( x:Float, y:Float ); 91 95 function raw_plus( x:Float, y:Float ) : Float; … … 121 125 end; 122 126 127 /** Powers of ten. */ 128 function exp10 ( b:Float ) : Float = 129 pow ( (one()+one()+one())*(one()+one()+one())+one(), b ); 130 123 131 124 132 /** Checks that a float is an integer. */ -
trunk/magnolia-basic-library/src/BasicCxxExamples/ArrayCxxDemo.mg
r1454 r1577 28 28 29 29 /** Properties of {@link dynamicArrayFloatCxx}. 30 * - The program dynamicArrayFloat satisf yes DynamicArray on floats.30 * - The program dynamicArrayFloat satisfies DynamicArray on floats. 31 31 * - Concatenation of arrays forms a monoid. 32 * - Reversion is self dual.32 * - Reversion is an involution. 33 33 */ 34 34 satisfaction dynamicArrayFloatCxx_properties = … … 96 96 function prod ( a:Float, b:Float ) : Float = a*b; 97 97 function sum ( a:Float, b:Float ) : Float = a+b; 98 use dynamicArrayPrefixCxx[E=>Float][star => max, scan => maximum, bar_scan => bar_scanMax ];99 use dynamicArrayPrefixCxx[E=>Float][star => min, scan => minimum, bar_scan => bar_scanMin ];100 use dynamicArrayPrefixCxx[E=>Float][star => prod, scan => product, bar_scan => bar_scanProd ];101 use dynamicArrayPrefixCxx[E=>Float][star => sum, scan => s ummation, bar_scan => bar_scanSum ];98 use dynamicArrayPrefixCxx[E=>Float][star => max, scan => scan_max, bar_scan => bar_scanMax ]; 99 use dynamicArrayPrefixCxx[E=>Float][star => min, scan => scan_min, bar_scan => bar_scanMin ]; 100 use dynamicArrayPrefixCxx[E=>Float][star => prod, scan => scan_prod, bar_scan => bar_scanProd ]; 101 use dynamicArrayPrefixCxx[E=>Float][star => sum, scan => scan_sum, bar_scan => bar_scanSum ]; 102 102 } models { 103 use ArrayParallelPrefix[E=>Float][star => max, scan => maximum];104 use ArrayParallelPrefix[E=>Float][star => min, scan => minimum];105 use ArrayParallelPrefix[E=>Float][star => prod, scan => product];106 use ArrayParallelPrefix[E=>Float][star => sum, scan => s ummation];103 use ArrayParallelPrefix[E=>Float][star => max, scan => scan_max ]; 104 use ArrayParallelPrefix[E=>Float][star => min, scan => scan_min ]; 105 use ArrayParallelPrefix[E=>Float][star => prod, scan => scan_prod ]; 106 use ArrayParallelPrefix[E=>Float][star => sum, scan => scan_sum ]; 107 107 }; 108 108 -
trunk/magnolia-basic-library/src/BasicCxxRaw/CxxBoundedArrayRaw.hxx
r1454 r1577 54 54 } 55 55 56 bar_A&operator=(const bar_A& a) {56 void operator=(const bar_A& a) { 57 57 Intex size = a.data_size; 58 if(data_size <a.data_size) {59 // Magnolia::Assert::guardFailed("Source data size larger thantarget data size","","BasicCxxRaw.CxxBoundedArrayRaw.CxxBoundedArrayRaw_impl.operator=");58 if(data_size != a.data_size) { 59 // Magnolia::Assert::guardFailed("Source data size different from target data size","","BasicCxxRaw.CxxBoundedArrayRaw.CxxBoundedArrayRaw_impl.operator="); 60 60 // std::cerr << "operator= Resizing bar_A data from " << data_size << " to " << size << std::endl; 61 61 delete [] data; … … 67 67 } 68 68 } 69 bar_A&operator=(bar_A&& a) {69 void operator=(bar_A&& a) { 70 70 delete [] data; 71 71 data_size = a.data_size; -
trunk/magnolia-basic-library/src/BasicGeneral/ArrayNumberCxx.mg
r1454 r1577 188 188 [ A => A, zeroA => zeroA, oneA => oneA, eA => eA, piA => piA ] 189 189 [ createA => createA, bar_A => bar_A, bar_createA => bar_createA ]; 190 satisfaction aGenericCRCDynamicArrayCxx_models_ GenericCRCArrays =190 satisfaction aGenericCRCDynamicArrayCxx_models_FreeModuleCRCArrays = 191 191 RCRC[ operators_to_names ] 192 192 with aGenericCRCDynamicArrayCxx 193 models GenericCRCArrays;193 models FreeModuleCRCArrays; 194 194 195 195 … … 325 325 326 326 327 /** Lifting the continuous real/complex operations (division, roots, trigonometry, exponentials, hyperbol es) to arrays. */327 /** Lifting the continuous real/complex operations (division, roots, trigonometry, exponentials, hyperbolics) to arrays. */ 328 328 implementation aCRCDynamicArrayCxx = { 329 329 /** Lifting of extended field operations to an array. */ … … 359 359 [ func => exp2, aibmc => aibmc_exp2 ]; 360 360 extend unaryMapArrayDynamicArrayCxx[ createarray_to_createa_etc ] 361 [ func => exp10, aibmc => aibmc_exp10 ]; 362 extend unaryMapArrayDynamicArrayCxx[ createarray_to_createa_etc ] 361 363 [ func => log, aibmc => aibmc_log ]; 362 364 extend unaryMapArrayDynamicArrayCxx[ createarray_to_createa_etc ] … … 367 369 [ func => pow, aibmc => aibmc_pow ]; 368 370 function eA() : A = createA(eR()); 369 /*** Lifting of the trigonometric hyperbol eoperations. */371 /*** Lifting of the trigonometric hyperbolic operations. */ 370 372 extend unaryMapArrayDynamicArrayCxx[ createarray_to_createa_etc ] 371 373 [ func => acosh, aibmc => aibmc_acosh ]; -
trunk/magnolia-basic-library/src/Fundamentals/Exponents.mg
r1454 r1577 20 20 */ 21 21 concept Logarithm = { 22 use Isomorphism [ I=>T, J=>T, jFromI=>exp, iFromJ=>log ]; 22 use Isomorphism [ I=>T, J=>T, jFromI=>exp, iFromJ=>log ] 23 [ section => logSectionAxiom, retraction => logRetractionAxiom ]; 23 24 use Semiring; 24 25 25 axiom logHomomorphismMult ( a:T, b:T ) {26 axiom logHomomorphismMultAxiom ( a:T, b:T ) { 26 27 assert log(mult(a,b)) == plus(log(a),log(b)); 27 28 }; 28 29 29 axiom logHomomorphismOne () {30 axiom logHomomorphismOneAxiom () { 30 31 assert log(one()) == zero(); 31 32 }; 32 33 33 }; 34 } [ logHomomorphismMultAxiom => logHomomorphismMultAxiom, logHomomorphismOneAxiom => logHomomorphismOneAxiom ] 35 [ logSectionAxiom => logSectionAxiom, logRetractionAxiom => logRetractionAxiom ]; 34 36 35 37 /** … … 38 40 */ 39 41 concept Exponent = { 40 use Isomorphism [ I=>T, J=>T, jFromI=>exp, iFromJ=>log ]; 42 use Isomorphism [ I=>T, J=>T, jFromI=>exp, iFromJ=>log ] 43 [ section => expSectionAxiom, retraction => expRetractionAxiom ]; 41 44 use Semiring; 42 45 43 axiom expHomomorphismPlus ( a:T, b:T ) {46 axiom expHomomorphismPlusAxiom ( a:T, b:T ) { 44 47 assert exp(plus(a,b)) == mult(exp(a),exp(b)); 45 48 }; 46 49 47 axiom expHomomorphismZero () {50 axiom expHomomorphismZeroAxiom () { 48 51 assert exp(zero()) == one(); 49 52 }; 50 53 51 }; 54 } [ expHomomorphismPlusAxiom => expHomomorphismPlusAxiom, expHomomorphismZeroAxiom => expHomomorphismZeroAxiom ] 55 [ expSectionAxiom => expSectionAxiom, expRetractionAxiom => expRetractionAxiom ]; 52 56 53 57 /** -
trunk/magnolia-basic-library/src/Fundamentals/Monoid.mg
r1477 r1577 60 60 } models { 61 61 theorem uniqueNeutral() { 62 assert binop(n(),m()) == m() by leftNeutral( n());63 assert binop(n(),m()) == n() by rightNeutral( m());62 assert binop(n(),m()) == m() by leftNeutral(m()); 63 assert binop(n(),m()) == n() by rightNeutral(n()); 64 64 assert n() == m() qed by simplify binop(n(),m()); 65 65 } -
trunk/magnolia-basic-library/src/Makefile
r1576 r1577 11 11 12 12 compile: $(cxxobj) $(cppobj) 13 BasicCxxRaw/StringCxxRaw/stringHashCxxRaw_soundness stringHashCxxRaw_hashCode_repeatable_validation14 13 test `BasicCxxRaw/FloatCxxRaw/ieee754float80rawCxx_approximates_RawRealInterface d_pow 2 1234` = inf && echo 80bit float NOT supported || echo 80bit float OK 15 14 … … 23 22 run: 24 23 BasicCxxExamples/StringCxxDemo/helloWorlds hello -i1 BasicCxxExamples/LanguageMessages.txt '"en"' 25 BasicCxxRaw/StringCxxRaw/stringHashCxxRaw_soundness stringHashCxxRaw_hashCode_repeatable_validation 24 BasicCxxRaw/StringCxxRaw/stringHashCxxRaw_soundness stringHashCxxRaw_hashCode_repeatable_validation || echo You are not using g++ 26 25 test `BasicCxxRaw/FloatCxxRaw/ieee754float80rawCxx_approximates_RawRealInterface d_pow 2 1234` = inf && echo 80bit float not supported || true 27 26 test `BasicCxxRaw/IntegerCxxRaw/int8rawCxx_models_2complement plus 45 30` -eq 75 28 27 test `BasicCxxRaw/FloatCxxRaw/ieee754float64rawCxx_approximates_RawRealInterface d_integer_maximum` = 9007199254740992 29 28 test `BasicCxxRaw/FloatCxxRaw/ieee754float32rawCxx_approximates_RawRealInterface d_abs -- -93` -eq 93 30 test `BasicCxxRaw/RepetitionCountCxxRawTest/ repetitionTestrepeatq 7 7` -eq 11231 test `BasicCxxRaw/RepetitionCountCxxRawTest/ repetitionTestrepeatr 7 7` -eq -12832 test `BasicCxxRaw/RepetitionCountCxxRawTest/ powerProductSumsum 7` -eq 2833 test `BasicCxxRaw/RepetitionCountCxxRawTest/ powerProductSumproduct 5` -eq 12034 test `BasicCxxRaw/RepetitionCountCxxRawTest/ powerProductSumraise 3 5` -eq 24329 test `BasicCxxRaw/RepetitionCountCxxRawTest/test_repetitionCxx repeatq 7 7` -eq 112 30 test `BasicCxxRaw/RepetitionCountCxxRawTest/test_repetitionCxx repeatr 7 7` -eq -128 31 test `BasicCxxRaw/RepetitionCountCxxRawTest/test_powerProductSumCxx sum 7` -eq 28 32 test `BasicCxxRaw/RepetitionCountCxxRawTest/test_powerProductSumCxx product 5` -eq 120 33 test `BasicCxxRaw/RepetitionCountCxxRawTest/test_powerProductSumCxx raise 3 5` -eq 243 35 34 BasicCxx/IntegerCxx/boundedInteger8bitCxx_is_BoundedInteger -- modLatticeAxiom 3 -4 36 35 BasicCxx/IntegerCxx/boundedInteger8bitCxx_is_BoundedInteger -- pmodLatticeAxiom 3 -4 … … 79 78 BasicCxx/FloatCxx/float32bitCxx_is_FiniteReal pmodLatticeAxiom -- 1.456789 -9.876543 80 79 BasicCxx/FloatCxx/float32bitCxx_is_FiniteReal remLatticeAxiom -- 1.456789 -9.876543 81 BasicCxx/FloatCxx/float32bitCxx_is_FiniteReal expHomomorphismZero 82 BasicCxx/FloatCxx/float32bitCxx_is_FiniteReal expHomomorphismPlus 19 380 BasicCxx/FloatCxx/float32bitCxx_is_FiniteReal expHomomorphismZeroAxiom 81 BasicCxx/FloatCxx/float32bitCxx_is_FiniteReal expHomomorphismPlusAxiom 19 3 83 82 #test `BasicGeneral/ArrayRingCxxDemo/arrayRingConstructionsDynamicArrayCxx_models_ArrayRingProperties_on_float64bitCxx idiv -- -45 -7` -eq `BasicGeneral/ArrayRingCxxDemo/arrayRingConstructionsDynamicArrayCxx_models_ArrayRingProperties_on_float64bitCxx idiv1 45 7` 84 83 #test `BasicGeneral/ArrayRingCxxDemo/freeModuleDynamicArrayCxx_models_FreeModule_on_float80bitCxx product '<FM#Intex.bar_FM>2<Array#>3 65 98 94</Array#></FM#Intex.bar_FM>'` -eq 6370 -
trunk/magnolia-basic-library/src/Mathematics/Group.mg
r1454 r1577 3 3 * 4 4 * A group has one type {@code T}, a binary operation {@code plus}, a unary function {@code uminus} and a constant {@code zero}. 5 * These naming conventions gollow from mathematics.5 * These naming conventions follow from mathematics. 6 6 * Some of the support concepts have slightly different notation. 7 7 * -
trunk/magnolia-basic-library/src/Mathematics/IndexableNumber.mg
r1454 r1577 113 113 concept TorusToTorusIntegerArrays = TorusToTorusIntegerA[ I => Intex ]; 114 114 115 /** Dynamic generic CRC arrays: types A (suffix A)R (suffix R). */116 concept GenericCRCArrays = {115 /** Free module on CRC arrays: types A (suffix A), Intex, R (suffix R). */ 116 concept FreeModuleCRCArrays = { 117 117 use ACRC[ I => Intex ]; 118 118 use FreeModule; … … 526 526 use UnaryMapAR[ func => exp ]; 527 527 use UnaryMapAR[ func => exp2 ]; 528 use UnaryMapAR[ func => exp10 ]; 528 529 use UnaryMapAR[ func => log ]; 529 530 use UnaryMapAR[ func => log2 ]; -
trunk/magnolia-basic-library/src/Mathematics/Numbers.mg
r1576 r1577 546 546 function exp(x : Number) : Number; 547 547 /** Base 2 exponentiation. */ 548 function exp2(x : Number) : Number; 548 function exp2(x : Number) : Number; 549 /** Base 10 exponentiation. */ 550 function exp10(x : Number) : Number; 549 551 /** natural, base e, logarithm. */ 550 552 function log(x : Number) : Number; … … 562 564 use Exponent[ T => Number, exp => exp2, log => log2 ][ names_to_operators ]; 563 565 use Logarithm[ T => Number, exp => exp2, log => log2 ][ names_to_operators ]; 566 /*** Properties of the base 10 exponentiation and logarithms. */ 567 use Exponent[ T => Number, exp => exp10, log => log10 ][ names_to_operators ]; 568 use Logarithm[ T => Number, exp => exp10, log => log10 ][ names_to_operators ]; 564 569 565 570 axiom naturalLogarithmAxiom () { … … 584 589 var two:Number = one() + one(); 585 590 var ten:Number = two + two * two * two; 586 assert pow(ten,zero()) == one();587 assert pow(ten,one()) == ten;591 assert exp10(zero()) == one(); 592 assert exp10(one()) == ten; 588 593 assert log10(ten) == one(); 589 594 assert log10(one()) == zero(); … … 604 609 assert exp(x) == exp2( x * log2(e()) ); 605 610 assert log10(x) == log2(x) * log10(two); 606 assert pow(ten,x) == exp2( x * log2(ten) );611 assert exp10(x) == exp2( x * log2(ten) ); 607 612 }; 608 613 }; -
trunk/magnolia-basic-library/src/TutorialExamples/Tutorial3Cxx.mg
r1576 r1577 62 62 }; 63 63 64 program strenging = {65 use stringCxx;66 use recurring67 [ T => String, binop => concatenate ]68 [ once => square, twice => cube, thrice => tesseract ];69 };70 64 71 65 /** Creating a simple implementation by combining implementations. … … 118 112 [ once => max1, twice => max2, thrice => max3 ]; 119 113 120 function min5 ( a:Float, b:Float, c:Float, d:Float, e:Float ) : Float121 = min(min(min(a,b),min(b,c)),e);122 123 114 /** Uses recurring directly on the power function. 124 115 * Notice how fast the function grows. … … 132 123 }; 133 124 125 126 /** And now for something completely different: 127 * Using the implementation recurring with strings. 128 * The renamings first match the requirements of recurring to the context, 129 * then renames the defined functions according to their role in the combined context. 130 * Example use (to make you happy): 131 TutorialExamples/Tutorial3Cxx/stringingTogetherCxx quadruple '"ð"' 132 * This shows that what we might have thought of as integer or numeric functions can be used with any type as long as we can match the operations. 133 */ 134 program stringingTogetherCxx = { 135 use stringCxx; 136 use recurring 137 [ T => String, binop => concatenate ] 138 [ once => double, twice => triple, thrice => quadruple ]; 139 };
Note:
See TracChangeset
for help on using the changeset viewer.