| Alternative 1 | |
|---|---|
| Error | 1.5 |
| Cost | 19904 |
\[\mathsf{fma}\left(z, y \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right), x\right)
\]
(FPCore (x y z t) :precision binary64 (+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y))))))
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* z (- t x)))
(t_2 (+ x (* (- (tanh (/ t y)) (tanh (/ x y))) (* z y)))))
(if (<= t_2 (- INFINITY)) t_1 (if (<= t_2 2e+292) t_2 (+ x t_1)))))double code(double x, double y, double z, double t) {
return x + ((y * z) * (tanh((t / y)) - tanh((x / y))));
}
double code(double x, double y, double z, double t) {
double t_1 = z * (t - x);
double t_2 = x + ((tanh((t / y)) - tanh((x / y))) * (z * y));
double tmp;
if (t_2 <= -((double) INFINITY)) {
tmp = t_1;
} else if (t_2 <= 2e+292) {
tmp = t_2;
} else {
tmp = x + t_1;
}
return tmp;
}
public static double code(double x, double y, double z, double t) {
return x + ((y * z) * (Math.tanh((t / y)) - Math.tanh((x / y))));
}
public static double code(double x, double y, double z, double t) {
double t_1 = z * (t - x);
double t_2 = x + ((Math.tanh((t / y)) - Math.tanh((x / y))) * (z * y));
double tmp;
if (t_2 <= -Double.POSITIVE_INFINITY) {
tmp = t_1;
} else if (t_2 <= 2e+292) {
tmp = t_2;
} else {
tmp = x + t_1;
}
return tmp;
}
def code(x, y, z, t): return x + ((y * z) * (math.tanh((t / y)) - math.tanh((x / y))))
def code(x, y, z, t): t_1 = z * (t - x) t_2 = x + ((math.tanh((t / y)) - math.tanh((x / y))) * (z * y)) tmp = 0 if t_2 <= -math.inf: tmp = t_1 elif t_2 <= 2e+292: tmp = t_2 else: tmp = x + t_1 return tmp
function code(x, y, z, t) return Float64(x + Float64(Float64(y * z) * Float64(tanh(Float64(t / y)) - tanh(Float64(x / y))))) end
function code(x, y, z, t) t_1 = Float64(z * Float64(t - x)) t_2 = Float64(x + Float64(Float64(tanh(Float64(t / y)) - tanh(Float64(x / y))) * Float64(z * y))) tmp = 0.0 if (t_2 <= Float64(-Inf)) tmp = t_1; elseif (t_2 <= 2e+292) tmp = t_2; else tmp = Float64(x + t_1); end return tmp end
function tmp = code(x, y, z, t) tmp = x + ((y * z) * (tanh((t / y)) - tanh((x / y)))); end
function tmp_2 = code(x, y, z, t) t_1 = z * (t - x); t_2 = x + ((tanh((t / y)) - tanh((x / y))) * (z * y)); tmp = 0.0; if (t_2 <= -Inf) tmp = t_1; elseif (t_2 <= 2e+292) tmp = t_2; else tmp = x + t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := N[(x + N[(N[(y * z), $MachinePrecision] * N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(z * N[(t - x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(x + N[(N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, (-Infinity)], t$95$1, If[LessEqual[t$95$2, 2e+292], t$95$2, N[(x + t$95$1), $MachinePrecision]]]]]
x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)
\begin{array}{l}
t_1 := z \cdot \left(t - x\right)\\
t_2 := x + \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \cdot \left(z \cdot y\right)\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_2 \leq 2 \cdot 10^{+292}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;x + t_1\\
\end{array}
Results
| Original | 4.7 |
|---|---|
| Target | 2.0 |
| Herbie | 1.2 |
if (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) < -inf.0Initial program 64.0
Simplified2.3
[Start]64.0 | \[ x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)
\] |
|---|---|
+-commutative [=>]64.0 | \[ \color{blue}{\left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) + x}
\] |
*-commutative [=>]64.0 | \[ \color{blue}{\left(z \cdot y\right)} \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) + x
\] |
associate-*l* [=>]2.3 | \[ \color{blue}{z \cdot \left(y \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)\right)} + x
\] |
fma-def [=>]2.3 | \[ \color{blue}{\mathsf{fma}\left(z, y \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right), x\right)}
\] |
Taylor expanded in y around inf 0.1
Taylor expanded in z around inf 0.2
if -inf.0 < (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) < 2e292Initial program 0.6
if 2e292 < (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) Initial program 47.7
Simplified16.6
[Start]47.7 | \[ x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)
\] |
|---|---|
+-commutative [=>]47.7 | \[ \color{blue}{\left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) + x}
\] |
*-commutative [=>]47.7 | \[ \color{blue}{\left(z \cdot y\right)} \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) + x
\] |
associate-*l* [=>]16.6 | \[ \color{blue}{z \cdot \left(y \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)\right)} + x
\] |
fma-def [=>]16.6 | \[ \color{blue}{\mathsf{fma}\left(z, y \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right), x\right)}
\] |
Taylor expanded in y around inf 11.1
Final simplification1.2
| Alternative 1 | |
|---|---|
| Error | 1.5 |
| Cost | 19904 |
| Alternative 2 | |
|---|---|
| Error | 1.5 |
| Cost | 13760 |
| Alternative 3 | |
|---|---|
| Error | 7.0 |
| Cost | 13380 |
| Alternative 4 | |
|---|---|
| Error | 10.0 |
| Cost | 7504 |
| Alternative 5 | |
|---|---|
| Error | 7.9 |
| Cost | 7369 |
| Alternative 6 | |
|---|---|
| Error | 7.0 |
| Cost | 7369 |
| Alternative 7 | |
|---|---|
| Error | 9.1 |
| Cost | 7241 |
| Alternative 8 | |
|---|---|
| Error | 14.8 |
| Cost | 713 |
| Alternative 9 | |
|---|---|
| Error | 22.7 |
| Cost | 584 |
| Alternative 10 | |
|---|---|
| Error | 20.3 |
| Cost | 584 |
| Alternative 11 | |
|---|---|
| Error | 19.2 |
| Cost | 584 |
| Alternative 12 | |
|---|---|
| Error | 22.4 |
| Cost | 64 |
herbie shell --seed 2023073
(FPCore (x y z t)
:name "SynthBasics:moogVCF from YampaSynth-0.2"
:precision binary64
:herbie-target
(+ x (* y (* z (- (tanh (/ t y)) (tanh (/ x y))))))
(+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y))))))