Debian Codegraph @

reasoning/dairy-energy-balance/dairy-energy-balance.n3

raw
1 # -------------------------------------------------------------------
2 # dairy-energy-balance.n3
3 #
4 # Case study: energy balance in dairy cows under different
5 # feeding and production situations.
6 #
7 # For each cow C we have:
8 # - bodyWeight (kg)
9 # - milkYield (kg/day)
10 # - nelDensity (MJ NEL / kg DM)
11 # - dmi (kg DM / day; dry matter intake)
12 #
13 # Simple energy model:
14 # maintenanceNEL = 0.08 * bodyWeight (MJ/day)
15 # milkNEL = 3.2 * milkYield (MJ/day)
16 # energyReq = maintenanceNEL + milkNEL
17 # energySupply = nelDensity * dmi
18 # energyBalance = energySupply - energyReq
19 #
20 # We also derive the "milk supported by the ration":
21 # milkSupported = (energySupply - maintenanceNEL) / 3.2
22 # (how many kg of milk could be produced if all net energy above
23 # maintenance went into milk).
24 #
25 # Classification:
26 # - energyStatus "negative" if energyBalance < -10 MJ
27 # - energyStatus "near" if -10 MJ ≤ energyBalance ≤ 10 MJ
28 # - energyStatus "positive" if energyBalance > 10 MJ
29 #
30 # Four example cows:
31 # - EarlyLactDeficit : high yield early lactation, energy deficit
32 # - MidLactBalanced : moderate yield, ration roughly matches demand
33 # - LateLactPositive : lower yield late lactation, positive balance
34 # - PastureLowEnergy : grazing cow with slight energy deficit
35 #
36 # ARC layer:
37 # - :answer – summary of which cows are in negative / near / positive
38 # energy balance and how ration-supported milk compares.
39 # - :reason – mathematical-English explanation of the pattern.
40 # - :check1..5 – harness checks about balances and supported milk.
41 #
42 # This is a didactic model, not a ration formulation tool.
43 # -------------------------------------------------------------------
44
45 @prefix : <http://example.org/dairy#> .
46 @prefix dairy: <http://example.org/dairy#> .
47 @prefix thm: <http://example.org/theorem#> .
48 @prefix rel: <http://example.org/rel#> .
49
50 @prefix math: <http://www.w3.org/2000/10/swap/math#> .
51 @prefix list: <http://www.w3.org/2000/10/swap/list#> .
52 @prefix log: <http://www.w3.org/2000/10/swap/log#> .
53 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
54 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
55 @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
56
57 # -------------------------------------------------------------------
58 # Cow and feeding properties
59 # -------------------------------------------------------------------
60
61 :Cow a rdfs:Class .
62
63 :bodyWeight a rdf:Property . # kg
64 :milkYield a rdf:Property . # kg/day
65 :nelDensity a rdf:Property . # MJ/kg DM
66 :dmi a rdf:Property . # kg DM/day
67 :daysInMilk a rdf:Property . # days since calving (for context)
68
69 :maintenanceNEL a rdf:Property . # MJ/day
70 :milkNEL a rdf:Property . # MJ/day
71 :energyReq a rdf:Property . # MJ/day
72 :energySupply a rdf:Property . # MJ/day
73 :energyBalance a rdf:Property . # MJ/day
74 :milkSupported a rdf:Property . # kg/day
75
76 :energyStatus a rdf:Property . # "negative" | "near" | "positive"
77
78 # -------------------------------------------------------------------
79 # Derived quantities (backward rules)
80 # -------------------------------------------------------------------
81
82 # maintenanceNEL = 0.08 * bodyWeight
83
84 {
85 ?C :maintenanceNEL ?mNEL .
86 }
87 <=
88 {
89 ?C a :Cow ;
90 :bodyWeight ?BW .
91
92 (?BW 0.08) math:product ?mNEL .
93 } .
94
95 # milkNEL = 3.2 * milkYield
96
97 {
98 ?C :milkNEL ?milkE .
99 }
100 <=
101 {
102 ?C a :Cow ;
103 :milkYield ?MY .
104
105 (?MY 3.2) math:product ?milkE .
106 } .
107
108 # energyReq = maintenanceNEL + milkNEL
109
110 {
111 ?C :energyReq ?Req .
112 }
113 <=
114 {
115 ?C :maintenanceNEL ?mNEL ;
116 :milkNEL ?milkE .
117
118 (?mNEL ?milkE) math:sum ?Req .
119 } .
120
121 # energySupply = nelDensity * dmi
122
123 {
124 ?C :energySupply ?Sup .
125 }
126 <=
127 {
128 ?C :nelDensity ?NEL ;
129 :dmi ?DMI .
130
131 (?NEL ?DMI) math:product ?Sup .
132 } .
133
134 # energyBalance = energySupply - energyReq
135
136 {
137 ?C :energyBalance ?EB .
138 }
139 <=
140 {
141 ?C :energySupply ?Sup ;
142 :energyReq ?Req .
143
144 (?Sup ?Req) math:difference ?EB .
145 } .
146
147 # milkSupported = (energySupply - maintenanceNEL) / 3.2
148
149 {
150 ?C :milkSupported ?MS .
151 }
152 <=
153 {
154 ?C :energySupply ?Sup ;
155 :maintenanceNEL ?mNEL .
156
157 (?Sup ?mNEL) math:difference ?Eabove .
158 (?Eabove 3.2) math:quotient ?MS .
159 } .
160
161 # -------------------------------------------------------------------
162 # Energy status classification
163 #
164 # negative : EB < -10
165 # near : -10 ≤ EB ≤ 10
166 # positive : EB > 10
167 # -------------------------------------------------------------------
168
169 {
170 ?C :energyStatus "negative" .
171 }
172 <=
173 {
174 ?C :energyBalance ?EB .
175 ?EB math:lessThan -10.0 .
176 } .
177
178 {
179 ?C :energyStatus "near" .
180 }
181 <=
182 {
183 ?C :energyBalance ?EB .
184
185 ?EB math:notLessThan -10.0 .
186 ?EB math:notGreaterThan 10.0 .
187 } .
188
189 {
190 ?C :energyStatus "positive" .
191 }
192 <=
193 {
194 ?C :energyBalance ?EB .
195 ?EB math:greaterThan 10.0 .
196 } .
197
198 # -------------------------------------------------------------------
199 # Example cows (numbers tuned to match ARC expectations)
200 #
201 # All calculations are internal to the model; units are MJ/day
202 # for energy and kg/day for milk and intake.
203 # -------------------------------------------------------------------
204
205 # EarlyLactDeficit:
206 # bodyWeight = 650 kg
207 # milkYield = 40 kg/d
208 # nelDensity = 6.5 MJ/kg DM
209 # dmi = 21 kg DM/d
210 #
211 # maintenanceNEL = 0.08 * 650 = 52
212 # milkNEL = 3.2 * 40 = 128
213 # energyReq = 180
214 # energySupply = 6.5 * 21 = 136.5
215 # energyBalance = -43.5 → "negative"
216 # milkSupported ≈ (136.5 - 52)/3.2 ≈ 26.4
217
218 :EarlyLactDeficit a :Cow ;
219 :description "early-lactation high-yield cow on an energy-short ration" ;
220 :bodyWeight 650.0 ;
221 :milkYield 40.0 ;
222 :nelDensity 6.5 ;
223 :dmi 21.0 ;
224 :daysInMilk 30 .
225
226 # MidLactBalanced:
227 # bodyWeight = 620 kg
228 # milkYield = 28 kg/d
229 # nelDensity = 6.5 MJ/kg DM
230 # dmi = 22.5 kg DM/d
231 #
232 # maintenanceNEL = 49.6
233 # milkNEL = 89.6
234 # energyReq = 139.2
235 # energySupply = 146.25
236 # energyBalance ≈ 7.05 → "near"
237 # milkSupported ≈ (146.25 - 49.6)/3.2 ≈ 30.2
238
239 :MidLactBalanced a :Cow ;
240 :description "mid-lactation cow with ration roughly matching her yield" ;
241 :bodyWeight 620.0 ;
242 :milkYield 28.0 ;
243 :nelDensity 6.5 ;
244 :dmi 22.5 ;
245 :daysInMilk 80 .
246
247 # LateLactPositive:
248 # bodyWeight = 650 kg
249 # milkYield = 18 kg/d
250 # nelDensity = 6.5 MJ/kg DM
251 # dmi = 20 kg DM/d
252 #
253 # maintenanceNEL = 52
254 # milkNEL = 57.6
255 # energyReq = 109.6
256 # energySupply = 130
257 # energyBalance ≈ 20.4 → "positive"
258 # milkSupported ≈ (130 - 52)/3.2 ≈ 24.4
259
260 :LateLactPositive a :Cow ;
261 :description "late-lactation cow gaining condition on the ration" ;
262 :bodyWeight 650.0 ;
263 :milkYield 18.0 ;
264 :nelDensity 6.5 ;
265 :dmi 20.0 ;
266 :daysInMilk 220 .
267
268 # PastureLowEnergy:
269 # bodyWeight = 600 kg
270 # milkYield = 14 kg/d
271 # nelDensity = 5.3 MJ/kg DM
272 # dmi = 16 kg DM/d
273 #
274 # maintenanceNEL = 48
275 # milkNEL = 44.8
276 # energyReq = 92.8
277 # energySupply = 84.8
278 # energyBalance ≈ -8.0 → "near" (mild deficit)
279 # milkSupported ≈ (84.8 - 48)/3.2 ≈ 11.5
280
281 :PastureLowEnergy a :Cow ;
282 :description "cow on modest pasture intake with a small energy deficit" ;
283 :bodyWeight 600.0 ;
284 :milkYield 14.0 ;
285 :nelDensity 5.3 ;
286 :dmi 16.0 ;
287 :daysInMilk 150 .
288
289 # -------------------------------------------------------------------
290 # ARC-style Answer / Reason / Checks
291 # -------------------------------------------------------------------
292
293 :text a rdf:Property .
294 :usesCow a rdf:Property .
295 :says a rdf:Property .
296 :ok a rdf:Property .
297 :msg a rdf:Property .
298
299 # A: Answer
300 #
301 # We assert :answer when:
302 # - EarlyLactDeficit :energyStatus "negative"
303 # - MidLactBalanced :energyStatus "near"
304 # - LateLactPositive :energyStatus "positive"
305 # - PastureLowEnergy :energyStatus "near"
306 # and LateLactPositive has the highest energyBalance.
307
308 {
309 :EarlyLactDeficit
310 :energyStatus "negative" ;
311 :energyBalance ?ebEarly ;
312 :milkYield ?myEarly ;
313 :milkSupported ?msEarly .
314
315 :MidLactBalanced
316 :energyStatus "near" ;
317 :energyBalance ?ebMid ;
318 :milkYield ?myMid ;
319 :milkSupported ?msMid .
320
321 :LateLactPositive
322 :energyStatus "positive" ;
323 :energyBalance ?ebLate ;
324 :milkYield ?myLate ;
325 :milkSupported ?msLate .
326
327 :PastureLowEnergy
328 :energyStatus "near" ;
329 :energyBalance ?ebPast ;
330 :milkYield ?myPast ;
331 :milkSupported ?msPast .
332
333 ?ebLate math:greaterThan ?ebMid .
334 ?ebLate math:greaterThan ?ebPast .
335 ?ebLate math:greaterThan ?ebEarly .
336 }
337 =>
338 {
339 :answer
340 :text "In this dairy energy-balance model, the EarlyLactDeficit cow is in clear negative energy balance, MidLactBalanced is close to break-even, LateLactPositive has a comfortable positive balance, and PastureLowEnergy has a small deficit that still falls in the near-neutral band. For EarlyLactDeficit, the ration’s net energy can only support roughly two thirds of her actual milk yield, so the remaining energy must come from mobilising body reserves. MidLactBalanced receives enough energy that the milk supported by the ration is close to her production, giving a small positive balance. LateLactPositive produces less milk on the same kind of energy-dense ration, so the ration supports more milk than she actually gives and the surplus energy goes into weight gain. PastureLowEnergy receives lower energy density and intake, so the ration supports slightly less milk than she produces and the balance is mildly negative." ;
341 :usesCow :EarlyLactDeficit, :MidLactBalanced, :LateLactPositive, :PastureLowEnergy .
342 } .
343
344 # R: Reason
345 #
346 # Mathematical-English explanation of how the balances arise from
347 # maintenance, milk requirements and ration energy.
348
349 {
350 :EarlyLactDeficit
351 :maintenanceNEL ?mEarly ;
352 :milkNEL ?eMilkEarly ;
353 :energyReq ?reqEarly ;
354 :energySupply ?supEarly ;
355 :energyBalance ?ebEarly ;
356 :milkYield ?myEarly ;
357 :milkSupported ?msEarly ;
358 :energyStatus "negative" .
359
360 :MidLactBalanced
361 :maintenanceNEL ?mMid ;
362 :milkNEL ?eMilkMid ;
363 :energyReq ?reqMid ;
364 :energySupply ?supMid ;
365 :energyBalance ?ebMid ;
366 :milkYield ?myMid ;
367 :milkSupported ?msMid ;
368 :energyStatus "near" .
369
370 :LateLactPositive
371 :maintenanceNEL ?mLate ;
372 :milkNEL ?eMilkLate ;
373 :energyReq ?reqLate ;
374 :energySupply ?supLate ;
375 :energyBalance ?ebLate ;
376 :milkYield ?myLate ;
377 :milkSupported ?msLate ;
378 :energyStatus "positive" .
379
380 :PastureLowEnergy
381 :maintenanceNEL ?mPast ;
382 :milkNEL ?eMilkPast ;
383 :energyReq ?reqPast ;
384 :energySupply ?supPast ;
385 :energyBalance ?ebPast ;
386 :milkYield ?myPast ;
387 :milkSupported ?msPast ;
388 :energyStatus "near" .
389
390 ?ebEarly math:lessThan ?ebPast .
391 ?ebLate math:greaterThan ?ebMid .
392 }
393 =>
394 {
395 :reason
396 :says "The model decomposes each cow’s net energy requirement into maintenanceNEL = 0.08 · bodyWeight and milkNEL = 3.2 · milkYield, so the total requirement is energyReq = maintenanceNEL + milkNEL. The ration contributes energySupply = nelDensity · dmi. The energy balance is then energySupply − energyReq. For EarlyLactDeficit, a large milk yield makes milkNEL big compared to the energy brought in by the ration, so energySupply − energyReq is strongly negative and the ration would only support around 26 kg of milk instead of her 40 kg/day. For MidLactBalanced, the same formulas give a requirement and supply that differ by only a few megajoules, so the ration-supported milk is close to the actual yield and the balance lies near zero. In LateLactPositive, milkNEL is much smaller while maintenance stays similar, but the ration still supplies plenty of energy, so energySupply − energyReq becomes clearly positive and the ration-supported milk exceeds the actual yield; mathematically, the surplus is largest for this cow. The PastureLowEnergy case has lower nelDensity and intake, so energySupply only slightly undershoots energyReq and the balance is mildly negative. These patterns all follow from the linear dependence of energyReq on bodyWeight and milkYield and of energySupply on intake and energy density, together with the definition of energy balance as supply minus requirement." .
397 } .
398
399 # -------------------------------------------------------------------
400 # C: Checks – harness rules
401 #
402 # Five small checks about energy balances and milkSupported.
403 # -------------------------------------------------------------------
404
405 # Check 1: All cows have derived maintenanceNEL, milkNEL,
406 # energyReq, energySupply, energyBalance and milkSupported.
407
408 {
409 :EarlyLactDeficit
410 :maintenanceNEL ?m1 ;
411 :milkNEL ?ml1 ;
412 :energyReq ?r1 ;
413 :energySupply ?s1 ;
414 :energyBalance ?eb1 ;
415 :milkSupported ?ms1 .
416
417 :MidLactBalanced
418 :maintenanceNEL ?m2 ;
419 :milkNEL ?ml2 ;
420 :energyReq ?r2 ;
421 :energySupply ?s2 ;
422 :energyBalance ?eb2 ;
423 :milkSupported ?ms2 .
424
425 :LateLactPositive
426 :maintenanceNEL ?m3 ;
427 :milkNEL ?ml3 ;
428 :energyReq ?r3 ;
429 :energySupply ?s3 ;
430 :energyBalance ?eb3 ;
431 :milkSupported ?ms3 .
432
433 :PastureLowEnergy
434 :maintenanceNEL ?m4 ;
435 :milkNEL ?ml4 ;
436 :energyReq ?r4 ;
437 :energySupply ?s4 ;
438 :energyBalance ?eb4 ;
439 :milkSupported ?ms4 .
440 }
441 =>
442 {
443 :check1
444 :ok true ;
445 :msg "Check 1: all four cows have derived maintenance energy, milk energy, total requirement, ration energy supply, energy balance and ration-supported milk." .
446 } .
447
448 # Check 2: EarlyLactDeficit is in the strongest negative balance and
449 # the ration supports clearly less milk than she produces.
450
451 {
452 :EarlyLactDeficit
453 :energyBalance ?ebEarly ;
454 :milkYield ?myEarly ;
455 :milkSupported ?msEarly .
456
457 :PastureLowEnergy
458 :energyBalance ?ebPast .
459
460 ?ebEarly math:lessThan ?ebPast .
461 ?msEarly math:lessThan ?myEarly .
462 }
463 =>
464 {
465 :check2
466 :ok true ;
467 :msg "Check 2: the EarlyLactDeficit cow has the most negative energy balance of the group, and the ration-supported milk is well below her actual yield, indicating a substantial energy deficit covered from body reserves." .
468 } .
469
470 # Check 3: MidLactBalanced has a near-zero balance and only a small
471 # gap between ration-supported milk and actual milk yield.
472
473 {
474 :MidLactBalanced
475 :energyBalance ?ebMid ;
476 :milkYield ?myMid ;
477 :milkSupported ?msMid .
478
479 ?ebMid math:notLessThan -10.0 .
480 ?ebMid math:notGreaterThan 10.0 .
481 }
482 =>
483 {
484 :check3
485 :ok true ;
486 :msg "Check 3: the MidLactBalanced cow has an energy balance within the ±10 MJ band used for 'near', consistent with the idea that the ration just about covers her production." .
487 } .
488
489 # Check 4: LateLactPositive has a positive balance and the ration
490 # supports more milk than she actually produces.
491
492 {
493 :LateLactPositive
494 :energyBalance ?ebLate ;
495 :milkYield ?myLate ;
496 :milkSupported ?msLate .
497
498 ?ebLate math:greaterThan 10.0 .
499 ?msLate math:greaterThan ?myLate .
500 }
501 =>
502 {
503 :check4
504 :ok true ;
505 :msg "Check 4: the LateLactPositive cow has a clearly positive energy balance and the ration-supported milk exceeds her actual yield, which is consistent with storing surplus energy as body condition." .
506 } .
507
508 # Check 5: Among the four cows, LateLactPositive has the highest
509 # energy balance.
510
511 {
512 :EarlyLactDeficit :energyBalance ?ebEarly .
513 :MidLactBalanced :energyBalance ?ebMid .
514 :LateLactPositive :energyBalance ?ebLate .
515 :PastureLowEnergy :energyBalance ?ebPast .
516
517 ?ebLate math:greaterThan ?ebEarly .
518 ?ebLate math:greaterThan ?ebMid .
519 ?ebLate math:greaterThan ?ebPast .
520 }
521 =>
522 {
523 :check5
524 :ok true ;
525 :msg "Check 5: among these four examples, the LateLactPositive cow has the highest energy balance, confirming that she is the most comfortably fed relative to her requirements." .
526 } .
527