
(FPCore (x y z t) :precision binary64 (+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y))))))
double code(double x, double y, double z, double t) {
return x + ((y * z) * (tanh((t / y)) - tanh((x / y))));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x + ((y * z) * (tanh((t / y)) - tanh((x / y))))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y * z) * (Math.tanh((t / y)) - Math.tanh((x / y))));
}
def code(x, y, z, t): return x + ((y * z) * (math.tanh((t / y)) - math.tanh((x / y))))
function code(x, y, z, t) return Float64(x + Float64(Float64(y * z) * Float64(tanh(Float64(t / y)) - tanh(Float64(x / y))))) end
function tmp = code(x, y, z, t) tmp = x + ((y * z) * (tanh((t / y)) - tanh((x / y)))); 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]
\begin{array}{l}
\\
x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y))))))
double code(double x, double y, double z, double t) {
return x + ((y * z) * (tanh((t / y)) - tanh((x / y))));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x + ((y * z) * (tanh((t / y)) - tanh((x / y))))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y * z) * (Math.tanh((t / y)) - Math.tanh((x / y))));
}
def code(x, y, z, t): return x + ((y * z) * (math.tanh((t / y)) - math.tanh((x / y))))
function code(x, y, z, t) return Float64(x + Float64(Float64(y * z) * Float64(tanh(Float64(t / y)) - tanh(Float64(x / y))))) end
function tmp = code(x, y, z, t) tmp = x + ((y * z) * (tanh((t / y)) - tanh((x / y)))); 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]
\begin{array}{l}
\\
x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)
\end{array}
y_m = (fabs.f64 y) (FPCore (x y_m z t) :precision binary64 (if (<= y_m 8.2e+215) (fma (* y_m (- (tanh (/ t y_m)) (tanh (/ x y_m)))) z x) (fma z (- t x) x)))
y_m = fabs(y);
double code(double x, double y_m, double z, double t) {
double tmp;
if (y_m <= 8.2e+215) {
tmp = fma((y_m * (tanh((t / y_m)) - tanh((x / y_m)))), z, x);
} else {
tmp = fma(z, (t - x), x);
}
return tmp;
}
y_m = abs(y) function code(x, y_m, z, t) tmp = 0.0 if (y_m <= 8.2e+215) tmp = fma(Float64(y_m * Float64(tanh(Float64(t / y_m)) - tanh(Float64(x / y_m)))), z, x); else tmp = fma(z, Float64(t - x), x); end return tmp end
y_m = N[Abs[y], $MachinePrecision] code[x_, y$95$m_, z_, t_] := If[LessEqual[y$95$m, 8.2e+215], N[(N[(y$95$m * N[(N[Tanh[N[(t / y$95$m), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y$95$m), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * z + x), $MachinePrecision], N[(z * N[(t - x), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
y_m = \left|y\right|
\\
\begin{array}{l}
\mathbf{if}\;y\_m \leq 8.2 \cdot 10^{+215}:\\
\;\;\;\;\mathsf{fma}\left(y\_m \cdot \left(\tanh \left(\frac{t}{y\_m}\right) - \tanh \left(\frac{x}{y\_m}\right)\right), z, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, t - x, x\right)\\
\end{array}
\end{array}
if y < 8.2000000000000007e215Initial program 96.0%
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
--lowering--.f64N/A
tanh-lowering-tanh.f64N/A
/-lowering-/.f64N/A
tanh-lowering-tanh.f64N/A
/-lowering-/.f6497.3
Applied egg-rr97.3%
if 8.2000000000000007e215 < y Initial program 74.2%
Taylor expanded in y around inf
+-commutativeN/A
accelerator-lowering-fma.f64N/A
--lowering--.f6495.2
Simplified95.2%
Final simplification97.1%
y_m = (fabs.f64 y) (FPCore (x y_m z t) :precision binary64 (let* ((t_1 (+ x (* (- (tanh (/ t y_m)) (tanh (/ x y_m))) (* y_m z))))) (if (<= t_1 (- INFINITY)) (* t z) (if (<= t_1 5e+306) x (* t z)))))
y_m = fabs(y);
double code(double x, double y_m, double z, double t) {
double t_1 = x + ((tanh((t / y_m)) - tanh((x / y_m))) * (y_m * z));
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = t * z;
} else if (t_1 <= 5e+306) {
tmp = x;
} else {
tmp = t * z;
}
return tmp;
}
y_m = Math.abs(y);
public static double code(double x, double y_m, double z, double t) {
double t_1 = x + ((Math.tanh((t / y_m)) - Math.tanh((x / y_m))) * (y_m * z));
double tmp;
if (t_1 <= -Double.POSITIVE_INFINITY) {
tmp = t * z;
} else if (t_1 <= 5e+306) {
tmp = x;
} else {
tmp = t * z;
}
return tmp;
}
y_m = math.fabs(y) def code(x, y_m, z, t): t_1 = x + ((math.tanh((t / y_m)) - math.tanh((x / y_m))) * (y_m * z)) tmp = 0 if t_1 <= -math.inf: tmp = t * z elif t_1 <= 5e+306: tmp = x else: tmp = t * z return tmp
y_m = abs(y) function code(x, y_m, z, t) t_1 = Float64(x + Float64(Float64(tanh(Float64(t / y_m)) - tanh(Float64(x / y_m))) * Float64(y_m * z))) tmp = 0.0 if (t_1 <= Float64(-Inf)) tmp = Float64(t * z); elseif (t_1 <= 5e+306) tmp = x; else tmp = Float64(t * z); end return tmp end
y_m = abs(y); function tmp_2 = code(x, y_m, z, t) t_1 = x + ((tanh((t / y_m)) - tanh((x / y_m))) * (y_m * z)); tmp = 0.0; if (t_1 <= -Inf) tmp = t * z; elseif (t_1 <= 5e+306) tmp = x; else tmp = t * z; end tmp_2 = tmp; end
y_m = N[Abs[y], $MachinePrecision]
code[x_, y$95$m_, z_, t_] := Block[{t$95$1 = N[(x + N[(N[(N[Tanh[N[(t / y$95$m), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y$95$m), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(y$95$m * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(t * z), $MachinePrecision], If[LessEqual[t$95$1, 5e+306], x, N[(t * z), $MachinePrecision]]]]
\begin{array}{l}
y_m = \left|y\right|
\\
\begin{array}{l}
t_1 := x + \left(\tanh \left(\frac{t}{y\_m}\right) - \tanh \left(\frac{x}{y\_m}\right)\right) \cdot \left(y\_m \cdot z\right)\\
\mathbf{if}\;t\_1 \leq -\infty:\\
\;\;\;\;t \cdot z\\
\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{+306}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t \cdot z\\
\end{array}
\end{array}
if (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) < -inf.0 or 4.99999999999999993e306 < (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) Initial program 58.7%
Taylor expanded in y around inf
+-commutativeN/A
accelerator-lowering-fma.f64N/A
--lowering--.f64100.0
Simplified100.0%
Taylor expanded in t around inf
*-commutativeN/A
*-lowering-*.f6454.2
Simplified54.2%
if -inf.0 < (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) < 4.99999999999999993e306Initial program 98.4%
Taylor expanded in x around inf
Simplified66.1%
Final simplification64.9%
y_m = (fabs.f64 y)
(FPCore (x y_m z t)
:precision binary64
(if (<= y_m 1.6e-97)
x
(if (<= y_m 1.35e-36)
(fma (* y_m (- (tanh (/ t y_m)) (/ x y_m))) z x)
(fma (fma t 1.0 (* (tanh (/ x y_m)) (- y_m))) z x))))y_m = fabs(y);
double code(double x, double y_m, double z, double t) {
double tmp;
if (y_m <= 1.6e-97) {
tmp = x;
} else if (y_m <= 1.35e-36) {
tmp = fma((y_m * (tanh((t / y_m)) - (x / y_m))), z, x);
} else {
tmp = fma(fma(t, 1.0, (tanh((x / y_m)) * -y_m)), z, x);
}
return tmp;
}
y_m = abs(y) function code(x, y_m, z, t) tmp = 0.0 if (y_m <= 1.6e-97) tmp = x; elseif (y_m <= 1.35e-36) tmp = fma(Float64(y_m * Float64(tanh(Float64(t / y_m)) - Float64(x / y_m))), z, x); else tmp = fma(fma(t, 1.0, Float64(tanh(Float64(x / y_m)) * Float64(-y_m))), z, x); end return tmp end
y_m = N[Abs[y], $MachinePrecision] code[x_, y$95$m_, z_, t_] := If[LessEqual[y$95$m, 1.6e-97], x, If[LessEqual[y$95$m, 1.35e-36], N[(N[(y$95$m * N[(N[Tanh[N[(t / y$95$m), $MachinePrecision]], $MachinePrecision] - N[(x / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * z + x), $MachinePrecision], N[(N[(t * 1.0 + N[(N[Tanh[N[(x / y$95$m), $MachinePrecision]], $MachinePrecision] * (-y$95$m)), $MachinePrecision]), $MachinePrecision] * z + x), $MachinePrecision]]]
\begin{array}{l}
y_m = \left|y\right|
\\
\begin{array}{l}
\mathbf{if}\;y\_m \leq 1.6 \cdot 10^{-97}:\\
\;\;\;\;x\\
\mathbf{elif}\;y\_m \leq 1.35 \cdot 10^{-36}:\\
\;\;\;\;\mathsf{fma}\left(y\_m \cdot \left(\tanh \left(\frac{t}{y\_m}\right) - \frac{x}{y\_m}\right), z, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(t, 1, \tanh \left(\frac{x}{y\_m}\right) \cdot \left(-y\_m\right)\right), z, x\right)\\
\end{array}
\end{array}
if y < 1.5999999999999999e-97Initial program 97.2%
Taylor expanded in x around inf
Simplified66.5%
if 1.5999999999999999e-97 < y < 1.35000000000000004e-36Initial program 100.0%
Taylor expanded in x around 0
/-lowering-/.f6485.4
Simplified85.4%
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
--lowering--.f64N/A
tanh-lowering-tanh.f64N/A
/-lowering-/.f64N/A
/-lowering-/.f6485.4
Applied egg-rr85.4%
if 1.35000000000000004e-36 < y Initial program 86.3%
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
--lowering--.f64N/A
tanh-lowering-tanh.f64N/A
/-lowering-/.f64N/A
tanh-lowering-tanh.f64N/A
/-lowering-/.f6492.1
Applied egg-rr92.1%
Taylor expanded in t around 0
/-lowering-/.f6483.7
Simplified83.7%
*-commutativeN/A
sub-negN/A
distribute-rgt-inN/A
div-invN/A
associate-*l*N/A
lft-mult-inverseN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
neg-lowering-neg.f64N/A
tanh-lowering-tanh.f64N/A
/-lowering-/.f6489.3
Applied egg-rr89.3%
Final simplification73.5%
y_m = (fabs.f64 y) (FPCore (x y_m z t) :precision binary64 (if (<= y_m 4.4e-36) x (fma (fma t 1.0 (* (tanh (/ x y_m)) (- y_m))) z x)))
y_m = fabs(y);
double code(double x, double y_m, double z, double t) {
double tmp;
if (y_m <= 4.4e-36) {
tmp = x;
} else {
tmp = fma(fma(t, 1.0, (tanh((x / y_m)) * -y_m)), z, x);
}
return tmp;
}
y_m = abs(y) function code(x, y_m, z, t) tmp = 0.0 if (y_m <= 4.4e-36) tmp = x; else tmp = fma(fma(t, 1.0, Float64(tanh(Float64(x / y_m)) * Float64(-y_m))), z, x); end return tmp end
y_m = N[Abs[y], $MachinePrecision] code[x_, y$95$m_, z_, t_] := If[LessEqual[y$95$m, 4.4e-36], x, N[(N[(t * 1.0 + N[(N[Tanh[N[(x / y$95$m), $MachinePrecision]], $MachinePrecision] * (-y$95$m)), $MachinePrecision]), $MachinePrecision] * z + x), $MachinePrecision]]
\begin{array}{l}
y_m = \left|y\right|
\\
\begin{array}{l}
\mathbf{if}\;y\_m \leq 4.4 \cdot 10^{-36}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(t, 1, \tanh \left(\frac{x}{y\_m}\right) \cdot \left(-y\_m\right)\right), z, x\right)\\
\end{array}
\end{array}
if y < 4.3999999999999999e-36Initial program 97.4%
Taylor expanded in x around inf
Simplified65.4%
if 4.3999999999999999e-36 < y Initial program 86.1%
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
--lowering--.f64N/A
tanh-lowering-tanh.f64N/A
/-lowering-/.f64N/A
tanh-lowering-tanh.f64N/A
/-lowering-/.f6492.0
Applied egg-rr92.0%
Taylor expanded in t around 0
/-lowering-/.f6483.6
Simplified83.6%
*-commutativeN/A
sub-negN/A
distribute-rgt-inN/A
div-invN/A
associate-*l*N/A
lft-mult-inverseN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
neg-lowering-neg.f64N/A
tanh-lowering-tanh.f64N/A
/-lowering-/.f6489.3
Applied egg-rr89.3%
Final simplification71.7%
y_m = (fabs.f64 y) (FPCore (x y_m z t) :precision binary64 (if (<= y_m 5.5e-33) x (fma z (- t x) x)))
y_m = fabs(y);
double code(double x, double y_m, double z, double t) {
double tmp;
if (y_m <= 5.5e-33) {
tmp = x;
} else {
tmp = fma(z, (t - x), x);
}
return tmp;
}
y_m = abs(y) function code(x, y_m, z, t) tmp = 0.0 if (y_m <= 5.5e-33) tmp = x; else tmp = fma(z, Float64(t - x), x); end return tmp end
y_m = N[Abs[y], $MachinePrecision] code[x_, y$95$m_, z_, t_] := If[LessEqual[y$95$m, 5.5e-33], x, N[(z * N[(t - x), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
y_m = \left|y\right|
\\
\begin{array}{l}
\mathbf{if}\;y\_m \leq 5.5 \cdot 10^{-33}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, t - x, x\right)\\
\end{array}
\end{array}
if y < 5.5e-33Initial program 97.4%
Taylor expanded in x around inf
Simplified65.4%
if 5.5e-33 < y Initial program 86.1%
Taylor expanded in y around inf
+-commutativeN/A
accelerator-lowering-fma.f64N/A
--lowering--.f6480.7
Simplified80.7%
y_m = (fabs.f64 y) (FPCore (x y_m z t) :precision binary64 (if (<= y_m 8.5e-32) x (fma z t x)))
y_m = fabs(y);
double code(double x, double y_m, double z, double t) {
double tmp;
if (y_m <= 8.5e-32) {
tmp = x;
} else {
tmp = fma(z, t, x);
}
return tmp;
}
y_m = abs(y) function code(x, y_m, z, t) tmp = 0.0 if (y_m <= 8.5e-32) tmp = x; else tmp = fma(z, t, x); end return tmp end
y_m = N[Abs[y], $MachinePrecision] code[x_, y$95$m_, z_, t_] := If[LessEqual[y$95$m, 8.5e-32], x, N[(z * t + x), $MachinePrecision]]
\begin{array}{l}
y_m = \left|y\right|
\\
\begin{array}{l}
\mathbf{if}\;y\_m \leq 8.5 \cdot 10^{-32}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, t, x\right)\\
\end{array}
\end{array}
if y < 8.5000000000000003e-32Initial program 97.4%
Taylor expanded in x around inf
Simplified65.4%
if 8.5000000000000003e-32 < y Initial program 86.1%
Taylor expanded in y around inf
+-commutativeN/A
accelerator-lowering-fma.f64N/A
--lowering--.f6480.7
Simplified80.7%
Taylor expanded in t around inf
Simplified66.3%
y_m = (fabs.f64 y) (FPCore (x y_m z t) :precision binary64 x)
y_m = fabs(y);
double code(double x, double y_m, double z, double t) {
return x;
}
y_m = abs(y)
real(8) function code(x, y_m, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y_m
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x
end function
y_m = Math.abs(y);
public static double code(double x, double y_m, double z, double t) {
return x;
}
y_m = math.fabs(y) def code(x, y_m, z, t): return x
y_m = abs(y) function code(x, y_m, z, t) return x end
y_m = abs(y); function tmp = code(x, y_m, z, t) tmp = x; end
y_m = N[Abs[y], $MachinePrecision] code[x_, y$95$m_, z_, t_] := x
\begin{array}{l}
y_m = \left|y\right|
\\
x
\end{array}
Initial program 94.4%
Taylor expanded in x around inf
Simplified59.7%
(FPCore (x y z t) :precision binary64 (+ x (* y (* z (- (tanh (/ t y)) (tanh (/ x y)))))))
double code(double x, double y, double z, double t) {
return x + (y * (z * (tanh((t / y)) - tanh((x / y)))));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x + (y * (z * (tanh((t / y)) - tanh((x / y)))))
end function
public static double code(double x, double y, double z, double t) {
return x + (y * (z * (Math.tanh((t / y)) - Math.tanh((x / y)))));
}
def code(x, y, z, t): return x + (y * (z * (math.tanh((t / y)) - math.tanh((x / y)))))
function code(x, y, z, t) return Float64(x + Float64(y * Float64(z * Float64(tanh(Float64(t / y)) - tanh(Float64(x / y)))))) end
function tmp = code(x, y, z, t) tmp = x + (y * (z * (tanh((t / y)) - tanh((x / y))))); end
code[x_, y_, z_, t_] := N[(x + N[(y * N[(z * N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)\right)
\end{array}
herbie shell --seed 2024198
(FPCore (x y z t)
:name "SynthBasics:moogVCF from YampaSynth-0.2"
:precision binary64
:alt
(! :herbie-platform default (+ x (* y (* z (- (tanh (/ t y)) (tanh (/ x y)))))))
(+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y))))))