@@ -346,6 +346,26 @@ pltk = new function() { const lib = this;
346
346
} else return it
347
347
}
348
348
349
+ lib . deepReplaceBy = function ( it , what , by ) {
350
+ if ( _ . isEqual ( it , what ) ) {
351
+ return by
352
+ } else {
353
+ if ( lib . isAtom ( it ) ) {
354
+ return it
355
+ } else return { op : it . op , args : _ . map ( it . args , arg => lib . deepReplaceBy ( arg , what , by ) ) }
356
+ }
357
+ }
358
+
359
+ /* deep replacement successively (it's NOT simultaneously)*/
360
+ lib . deepReplaceBys = function ( it , whats , bys ) {
361
+ const replacements = _ . zip ( whats , bys )
362
+ return _ . reduce ( replacements , function ( acc , replacement ) { return lib . deepReplaceBy ( acc , replacement [ 0 ] , replacement [ 1 ] ) } , it )
363
+ }
364
+
365
+ /* deep replacement successively (it's NOT simultaneously)*/
366
+ lib . deepReplaceBys1 = function ( it , replacements ) {
367
+ return _ . reduce ( replacements , function ( acc , replacement ) { return lib . deepReplaceBy ( acc , replacement [ 0 ] , replacement [ 1 ] ) } , it )
368
+ }
349
369
350
370
/* true if a subsumes b */
351
371
lib . disjClauseSubsumes = function ( a , b ) {
@@ -365,6 +385,24 @@ pltk = new function() { const lib = this;
365
385
}
366
386
return lib . isVariable ( f )
367
387
}
388
+
389
+ /* pre: isUnitFormula */
390
+ lib . getUnitFormulaPolarity = function ( f ) {
391
+ if ( lib . isNeg ( f ) ) {
392
+ return { op : 'LF' , args : [ ] }
393
+ } else {
394
+ return { op : 'LF' , args : [ ] }
395
+ }
396
+ }
397
+
398
+ /* pre: isUnitFormula */
399
+ lib . getUnitFormulaBody = function ( f ) {
400
+ if ( lib . isNeg ( f ) ) {
401
+ return f . args [ 0 ]
402
+ } else {
403
+ return f
404
+ }
405
+ }
368
406
369
407
lib . isVariable = function ( f ) {
370
408
return _ . get ( f , 'op' , '' ) == 'Var'
@@ -397,6 +435,10 @@ pltk = new function() { const lib = this;
397
435
return _ . has ( f , 'op' ) && f . op == 'LF'
398
436
}
399
437
438
+ lib . isAtom = function ( f ) {
439
+ return lib . isVariable ( f ) || lib . isT ( f ) || lib . isF ( f )
440
+ }
441
+
400
442
// ###############################
401
443
/* Export to dimacs */
402
444
// ###############################
0 commit comments