Simon Schubert
10/21/2019, 4:30 PM33
or 66
. So I wrote a function like value - value.toInt()
which returns e.g. 0.33f
. I thought it works fine. But today I noticed that for some values it doesn’t work. For example: 8.33 returns 0.32999992
. I assume it's already a known bug? Anyway I found that very odd. Whats an efficient workaround?
for(i in 0..8) {
println("${8.33f - i}")
}
returns
8.33
7.33
6.33
5.33
4.33
3.33
2.33
1.3299999
0.32999992
1.3.50 jvmaltavir
12/07/2019, 8:40 AMaltavir
12/08/2019, 2:24 PMRealField
). It is not a conclussion, we need to test it further, but I think it is time to forget "native means fast". I've already showed some tests, where kotlin code runs faster than numpy.altavir
12/09/2019, 12:42 PMaltavir
12/09/2019, 4:59 PMJérémie Labroquère
01/04/2020, 12:37 PMaltavir
01/29/2020, 3:37 PMT:Any
, what should be default cell value return type T
or T?
?altavir
04/30/2020, 8:43 AMaltavir
05/05/2020, 4:22 PMaltavir
06/10/2020, 5:21 AMaltavir
06/13/2020, 8:07 AMbreandan
06/23/2020, 9:31 AMFun<X>: Field<X>
where X
is a member of some algebra over the reals equipped with the usual operators (when you apply an operator, it is evaluated and you get X
back). Another way is (2) to treat the function as a member of a field whose elements are themselves functions, e.g. Fun<X>: Field<Fun<X>>
, and instead of returning X
, applying an operator instead returns Fun<X>
which can be later evaluated by calling invoke(...)
, returning X
(so X
and Fun<X>
are both fields).
It turns out the second representation comes from finite field theory, which has important implications for expression parsing and language design. It would be useful to understand this connection more deeply.altavir
06/27/2020, 2:23 PMIaroslav Postovalov
06/27/2020, 2:26 PMkmath-ast
module: https://github.com/mipt-npm/kmath/blob/dev/kmath-ast/README.mdbreandan
07/26/2020, 4:11 PMbreandan
07/26/2020, 7:13 PMaltavir
07/29/2020, 10:03 AMemedinaa
08/20/2020, 3:07 PMbreandan
08/22/2020, 6:05 AMaltavir
09/13/2020, 12:09 PMaltavir
10/04/2020, 8:40 AMbjonnh
10/12/2020, 11:14 PMbjonnh
10/12/2020, 11:32 PMbjonnh
10/20/2020, 7:54 PMbjonnh
10/20/2020, 7:55 PMaltavir
10/22/2020, 6:39 AMaltavir
10/24/2020, 5:30 PMbreandan
10/29/2020, 4:11 AMassertEquals(f.derivativeOrNull(mapOf(x to 2)), f.derivativeOrNull(mapOf(x to 1)).derivativeOrNull(mapOf(x to 1)))
. This helps to clarify what is meant by derivativeOrNull(orders: Map<Symbol, Int>): Expression<T>
and suggests one possible implementation. Assuming you only care about SFun
and SVar
then it should be possible to define derivativeOrNull
using fold
, noting the above restrictions on evaluation order.
More generally, due to the semantics of mixing partial derivatives, depending how Map
is implemented, you cannot assume f.derivativeOrNull(mapOf(y to 1)).derivativeOrNull(mapOf(x to 1)) == f.derivativeOrNull(mapOf(x to 1, y to 1))
without knowing more about the function under differentiation. To implement derivativeOrNull
correctly, you would need a data structure whose traversal order preserves the semantics of the end-user program. Although it is possible to implement something like OrderPreservingMap
, I would just use List<Symbol>
. Then your implementation becomes cleaner:
public override fun derivativeOrNull(orders: List<Symbol>): Expression<T> =
orders.map { MstAlgebra.symbol(it.identity).toSVar(proto) }
.fold(mst.toSFun(proto)) { result, sVar -> result.d(sVar) } // This will produce Derivative(...Derivative(mst.toSFun(proto))...)
.invoke() // Do you want to evaluate it?
.toKMathExpression()
Iaroslav Postovalov
10/29/2020, 5:15 PMIaroslav Postovalov
10/29/2020, 5:15 PMaltavir
10/29/2020, 5:19 PMbreandan
10/29/2020, 5:19 PMimplementation("com.github.breandan:kaliningraph:0.1.2")
to the dependency block of your build.gradle.kts
filealtavir
10/29/2020, 5:22 PMbreandan
10/29/2020, 5:24 PMIaroslav Postovalov
10/29/2020, 5:33 PM