I have some problems while using the notI construct in Welder. Take the following as an example proof:
My example uses usual lemmas about the structure of rings and a derived lemma (zeroDivisorLemma) that says that for all 'a' in the ring a0 = 0 = 0a.
I proof that if two elements are not zero, their product is not zero. As follows.
val theorem: Theorem =
forallI("a"::F,"b"::F){ case (a,b) =>
implI(and(a !== z, b !== z,multInverseElement,multNeutralElement,multAssociative,
addOppositeElement,addNeutralElement,addAssociative,isDistributive)){ axioms =>
val Seq(aNotZero,bNotZero,multInverseElement,multNeutralElement,multAssociative,
addOppositeElement,addNeutralElement,addAssociative,isDistributive) = andE(axioms) : Seq[Theorem]
notI((a ^* b) === z) { case (hyp,_) =>
((a ^* b) === z) ==| andI(bNotZero,hyp) |
(((a ^* b) ^* inv(b)) === (z ^* inv(b))) ==| forallE(multAssociative)(a,b,inv(b)) |
((a ^* (b ^* inv(b))) === (z ^* inv(b))) ==| andI(forallE(multInverseElement)(b),bNotZero) |
((a ^* one) === (z ^* inv(b))) ==| forallE(multNeutralElement)(a) |
(a === (z ^* inv(b))) ==| forallE(implE(zeroDivisorLemma)(g => axioms))(inv(b)) |
(a === z) ==| aNotZero |
((a !== z) && (a === z)) ==| trivial |
(a !== a) ==| trivial |
BooleanLiteral(false)
}
}
}
The code compiles but Welder says:
SMT solver could not prove the property: false
from hypotheses:
(mult(a, b) == zero()) == false.
I'd say I'm not passing the right function to the construct. Could someone explain what should I write to succeed? Does it have to do with the type, i.e., (Theorem, Goal) => Attempt[Witness]? Do I need to provide a theorem and that proves the goal?
What else can I proof to get false? Should I use some sort of implication introduction?
What the error says is that it could not deduce a contradiction from what you shown. Indeed, you have not shown a contradiction in body of the notI. The derivation to prove that (mult(a, b) == zero()) == false is correct, but you still have to explicitly show the contradiction by taking the conjunction with hyp.
Would something like this work ?
val theorem: Theorem =
forallI("a"::F,"b"::F){ case (a,b) =>
implI(and(a !== z, b !== z,multInverseElement,multNeutralElement,multAssociative,
addOppositeElement,addNeutralElement,addAssociative,isDistributive)){ axioms =>
val Seq(aNotZero,bNotZero,multInverseElement,multNeutralElement,multAssociative,
addOppositeElement,addNeutralElement,addAssociative,isDistributive) = andE(axioms) : Seq[Theorem]
notI((a ^* b) === z) { case (hyp,_) =>
val deriv = ((a ^* b) === z) ==| andI(bNotZero,hyp) |
(((a ^* b) ^* inv(b)) === (z ^* inv(b))) ==| forallE(multAssociative)(a,b,inv(b)) |
((a ^* (b ^* inv(b))) === (z ^* inv(b))) ==| andI(forallE(multInverseElement)(b),bNotZero) |
((a ^* one) === (z ^* inv(b))) ==| forallE(multNeutralElement)(a) |
(a === (z ^* inv(b))) ==| forallE(implE(zeroDivisorLemma)(g => axioms))(inv(b)) |
(a === z) ==| aNotZero |
((a !== z) && (a === z)) ==| trivial |
(a !== a) ==| trivial |
BooleanLiteral(false)
andI(deriv, hyp)
}
}
}
Related
I need your help with this error I am facing colleagues. I am new to vue so I am finding it quite difficult to solve the error though I what what exactly is causing the error. I am creating a datatable in vue and I am trying to achieve data sorting with this tutorial I am following but end up getting the following error:
TypeError: Cannot read properties of undefined (reading 'type')
computed: {
filteredAccommodations(){
let accommodations = this.accommodations;
if (this.search) {
accommodations = accommodations.filter((row) => {
return Object.keys(row).some((key) => {
return String(row[key]).toLowerCase().indexOf(this.search.toLowerCase()) > -1;
})
});
}
let sortKey = this.sortKey;
let order = this.sortOrders[sortKey] || 1;
if(sortKey){
accommodations = accommodations.slice().sort((a, b) => {
let index = this.getIndex(this.columns, 'name', sortKey);
a = String(a[sortKey]).toLowerCase();
b = String(b[sortKey]).toLowerCase();
if (this.columns[index].type && this.columns[index].type === 'date') {
return (a === b ? 0 : new Date(a).getTime() > new Date(b).getTime() ? 1 : -1) * order;
} else if (this.columns[index].type && this.columns[index].type === 'number') {
return (+a === +b ? 0 : +a > +b ? 1 : -1) * order;
} else {
return (a === b ? 0 : a > b ? 1 : -1) * order;
}
});
}
return accommodations;
},
paginatedAccommodations(){
return this.paginate(this.filteredAccommodations, this.length, this.pagination.currentPage);
}
},
The reason for your error is because the value of this.columns[index] is a null value ,Adding a null check in ur if loop might help you solve this but I suggest you to check for the reason of null value.
computed: {
filteredAccommodations() {
let accommodations = this.accommodations;
if (this.search) {
accommodations = accommodations.filter((row) => {
return Object.keys(row).some((key) => {
return String(row[key]).toLowerCase().indexOf(this.search.toLowerCase()) > -1;
})
});
}
let sortKey = this.sortKey;
let order = this.sortOrders[sortKey] || 1;
if (sortKey) {
accommodations = accommodations.slice().sort((a, b) => {
let index = this.getIndex(this.columns, 'name', sortKey);
a = String(a[sortKey]).toLowerCase();
b = String(b[sortKey]).toLowerCase();
if (this.columns[index] && this.columns[index].type && this.columns[index].type === 'date') {
return (a === b ? 0 : new Date(a).getTime() > new Date(b).getTime() ? 1 : -1) * order;
} else if (this.columns[index] && this.columns[index].type && this.columns[index].type === 'number') {
return (+a === +b ? 0 : +a > +b ? 1 : -1) * order;
} else {
return (a === b ? 0 : a > b ? 1 : -1) * order;
}
});
}
return accommodations;
},
paginatedAccommodations() {
return this.paginate(this.filteredAccommodations, this.length, this.pagination.currentPage);
}
},
The API I'm testing may return a string or a number for many fields. I've been able to use a self validation expression to check this behavior: { a: '#? typeof _ === "number" || typeof _ === "string"' }.
Is there (or should there be) a way to do this with Karate's fuzzy match markers? Like { a: '#string OR #number'}?
No, I think this is IMO a badly designed API and I don't want to bloat the syntax to solve for these.
Note that you can make this more elegant as follows, so you can write this function once, define it "globally" and re-use to your heart's content:
* def isNumOrStr = function(x){ return typeof x === 'number' || typeof x === 'string' }
* def foo = { a: 1 }
* match foo == { a: '#? isNumOrStr(_)' }
* def bar = { a: 'z' }
* match bar == { a: '#? isNumOrStr(_)' }
I'm creating a custom sort plugin for DataTables which will sort numeric columns which contain non-numeric rows as well. I got the part where it puts the 'N/A' rows at the bottom but cannot seem to figure out, how to make it ignore the commas in the numbers.
For example:
$12,443.00
362,123,231
N/A
N/A
null
34,242.42
23,234
null
The code below manages to ignore everything except for the commas in the numbers.
Code:
function numeric_sort(a, b, high) {
var reg = /[+-]?((\d+(\.\d*)?)|\.\d+)([eE][+-]?[0-9]+)?/;
a = a.match(reg);
a = a !== null ? parseFloat(a[0]) : high;
b = b.match(reg);
b = b !== null ? parseFloat(b[0]) : high;
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
}
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"numeric-empty-bottom-asc": function (a, b) {
return numeric_sort(a, b, Number.POSITIVE_INFINITY);
},
"numeric-empty-bottom-desc": function (a, b) {
return numeric_sort(a, b, Number.NEGATIVE_INFINITY) * -1;
}
} );
I got the code from: http://jsfiddle.net/6qmkY/
Any help will be appreciated.
You can just use replace() to remove commas.
function sortNumbersIgnoreText(a, b, high) {
var reg = /[+-]?((\d+(\.\d*)?)|\.\d+)([eE][+-]?[0-9]+)?/;
a = a.replace(/,/g, '');
a = a.match(reg);
a = a !== null ? parseFloat(a[0]) : high;
b = b.replace(/,/g, '');
b = b.match(reg);
b = b !== null ? parseFloat(b[0]) : high;
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
}
See updated jsFiddle for code and demonstration.
You could replace all non numeric chars including commas (excluding the decimal).
function sortNumbersIgnoreText(a, b, high) {
a = a.replace(/[^0-9\.]+/g, '');
a = (a !== null && a !== '') ? parseFloat(a) : high;
b = b.replace(/[^0-9\.]+/g, '');
b = (b !== null && b !== '') ? parseFloat(b) : high;
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
}
From this page, I inserted to my /client/helpers/handlebars.js file this handlebars helper:
Handlebars.registerHelper('compare', function (lvalue, operator, rvalue, options) {
var operators, result;
if (arguments.length < 3) {
throw new Error("Handlerbars Helper 'compare' needs 2 parameters");
}
if (options === undefined) {
options = rvalue;
rvalue = operator;
operator = "===";
}
operators = {
'==': function (l, r) { return l == r; },
'===': function (l, r) { return l === r; },
'!=': function (l, r) { return l != r; },
'!==': function (l, r) { return l !== r; },
'<': function (l, r) { return l < r; },
'>': function (l, r) { return l > r; },
'<=': function (l, r) { return l <= r; },
'>=': function (l, r) { return l >= r; },
'typeof': function (l, r) { return typeof l == r; }
};
if (!operators[operator]) {
throw new Error("Handlerbars Helper 'compare' doesn't know the operator " + operator);
}
result = operators[operator](lvalue, rvalue);
if (result) {
return options.fn(this);
} else {
return options.inverse(this);
}
});
And to the template:
{{#compare "Test" "Test"}}
Default comparison of "==="
{{/compare}}
And in console I always see: Exception from Deps recompute: Error: Handlerbars Helper 'compare' needs 2 parameters
I tried this as well:
{{#compare "Test" "==" "Test"}}
But this did not help.
Try
{{#compare "Test" "Test" operator="=="}}
I have a method
List<MyType> DoQuery(bool FilterWeek) {
var result = session.QueryOver<MyType>()
.Where (r => r.isValid == 1
&& r.value1 == 2
&& r.name == "XYZ"
&& [...etc, more columns are used...]
)
// how do I go on from this point?
}
if the FilterWeek parameter is true, I want to add an extra "&& r.xyz == 1" clause to the Where criteria. If FilterWeek is false, the query is done.
How do I do that?
if (FilterWeek)
result = result.Where(r => r.xyz ==1);
//...whenever you're done, execute the query using List() or SingleOrDefault()
this:
List<MyType> DoQuery(bool FilterWeek) {
var result = session.QueryOver<MyType>()
.Where (r => r.isValid == 1
&& r.value1 == 2
&& r.name == "XYZ"
&& [...etc, more columns are used...]
);
if(FilterWeek)
result.Where(x => x.Whatever == 1)
//the query won't get executed until here
result.List();
}