
(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 9 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}
(FPCore (x y z t) :precision binary64 (fma (fma (tanh (/ t y)) y (* (tanh (/ x y)) (- y))) z x))
double code(double x, double y, double z, double t) {
return fma(fma(tanh((t / y)), y, (tanh((x / y)) * -y)), z, x);
}
function code(x, y, z, t) return fma(fma(tanh(Float64(t / y)), y, Float64(tanh(Float64(x / y)) * Float64(-y))), z, x) end
code[x_, y_, z_, t_] := N[(N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] * y + N[(N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision] * (-y)), $MachinePrecision]), $MachinePrecision] * z + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(\tanh \left(\frac{t}{y}\right), y, \tanh \left(\frac{x}{y}\right) \cdot \left(-y\right)\right), z, x\right)
\end{array}
Initial program 92.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6497.7
Applied rewrites97.7%
lift-*.f64N/A
*-commutativeN/A
lift--.f64N/A
lift-tanh.f64N/A
lift-/.f64N/A
sub-negN/A
distribute-rgt-inN/A
lower-fma.f64N/A
lift-/.f64N/A
lift-tanh.f64N/A
lower-*.f64N/A
lower-neg.f6497.7
Applied rewrites97.7%
Final simplification97.7%
(FPCore (x y z t) :precision binary64 (fma (* y (- (tanh (/ t y)) (tanh (/ x y)))) z x))
double code(double x, double y, double z, double t) {
return fma((y * (tanh((t / y)) - tanh((x / y)))), z, x);
}
function code(x, y, z, t) return fma(Float64(y * Float64(tanh(Float64(t / y)) - tanh(Float64(x / y)))), z, x) end
code[x_, y_, z_, t_] := N[(N[(y * N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * z + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right), z, x\right)
\end{array}
Initial program 92.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6497.7
Applied rewrites97.7%
Final simplification97.7%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (fma (fma (tanh (/ t y)) y (- x)) z x)))
(if (<= t -4.5e-48)
t_1
(if (<= t 3.5e-65) (fma (- (/ t y) (tanh (/ x y))) (* y z) x) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = fma(fma(tanh((t / y)), y, -x), z, x);
double tmp;
if (t <= -4.5e-48) {
tmp = t_1;
} else if (t <= 3.5e-65) {
tmp = fma(((t / y) - tanh((x / y))), (y * z), x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = fma(fma(tanh(Float64(t / y)), y, Float64(-x)), z, x) tmp = 0.0 if (t <= -4.5e-48) tmp = t_1; elseif (t <= 3.5e-65) tmp = fma(Float64(Float64(t / y) - tanh(Float64(x / y))), Float64(y * z), x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] * y + (-x)), $MachinePrecision] * z + x), $MachinePrecision]}, If[LessEqual[t, -4.5e-48], t$95$1, If[LessEqual[t, 3.5e-65], N[(N[(N[(t / y), $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(y * z), $MachinePrecision] + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(\mathsf{fma}\left(\tanh \left(\frac{t}{y}\right), y, -x\right), z, x\right)\\
\mathbf{if}\;t \leq -4.5 \cdot 10^{-48}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t \leq 3.5 \cdot 10^{-65}:\\
\;\;\;\;\mathsf{fma}\left(\frac{t}{y} - \tanh \left(\frac{x}{y}\right), y \cdot z, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if t < -4.49999999999999988e-48 or 3.50000000000000005e-65 < t Initial program 94.3%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6499.9
Applied rewrites99.9%
lift-*.f64N/A
*-commutativeN/A
lift--.f64N/A
lift-tanh.f64N/A
lift-/.f64N/A
sub-negN/A
distribute-rgt-inN/A
lower-fma.f64N/A
lift-/.f64N/A
lift-tanh.f64N/A
lower-*.f64N/A
lower-neg.f6499.9
Applied rewrites99.9%
Taylor expanded in y around inf
mul-1-negN/A
lower-neg.f6477.8
Applied rewrites77.8%
if -4.49999999999999988e-48 < t < 3.50000000000000005e-65Initial program 90.7%
Taylor expanded in t around 0
lower-/.f6483.4
Applied rewrites83.4%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6483.4
Applied rewrites83.4%
(FPCore (x y z t) :precision binary64 (fma (fma (tanh (/ t y)) y (- x)) z x))
double code(double x, double y, double z, double t) {
return fma(fma(tanh((t / y)), y, -x), z, x);
}
function code(x, y, z, t) return fma(fma(tanh(Float64(t / y)), y, Float64(-x)), z, x) end
code[x_, y_, z_, t_] := N[(N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] * y + (-x)), $MachinePrecision] * z + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(\tanh \left(\frac{t}{y}\right), y, -x\right), z, x\right)
\end{array}
Initial program 92.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6497.7
Applied rewrites97.7%
lift-*.f64N/A
*-commutativeN/A
lift--.f64N/A
lift-tanh.f64N/A
lift-/.f64N/A
sub-negN/A
distribute-rgt-inN/A
lower-fma.f64N/A
lift-/.f64N/A
lift-tanh.f64N/A
lower-*.f64N/A
lower-neg.f6497.7
Applied rewrites97.7%
Taylor expanded in y around inf
mul-1-negN/A
lower-neg.f6476.2
Applied rewrites76.2%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* z (- t x)))) (if (<= z -5.5e-6) t_1 (if (<= z 1.64e-15) (- x (* x z)) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = z * (t - x);
double tmp;
if (z <= -5.5e-6) {
tmp = t_1;
} else if (z <= 1.64e-15) {
tmp = x - (x * z);
} else {
tmp = t_1;
}
return tmp;
}
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
real(8) :: t_1
real(8) :: tmp
t_1 = z * (t - x)
if (z <= (-5.5d-6)) then
tmp = t_1
else if (z <= 1.64d-15) then
tmp = x - (x * z)
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = z * (t - x);
double tmp;
if (z <= -5.5e-6) {
tmp = t_1;
} else if (z <= 1.64e-15) {
tmp = x - (x * z);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = z * (t - x) tmp = 0 if z <= -5.5e-6: tmp = t_1 elif z <= 1.64e-15: tmp = x - (x * z) else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(z * Float64(t - x)) tmp = 0.0 if (z <= -5.5e-6) tmp = t_1; elseif (z <= 1.64e-15) tmp = Float64(x - Float64(x * z)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = z * (t - x); tmp = 0.0; if (z <= -5.5e-6) tmp = t_1; elseif (z <= 1.64e-15) tmp = x - (x * z); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(z * N[(t - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -5.5e-6], t$95$1, If[LessEqual[z, 1.64e-15], N[(x - N[(x * z), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := z \cdot \left(t - x\right)\\
\mathbf{if}\;z \leq -5.5 \cdot 10^{-6}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 1.64 \cdot 10^{-15}:\\
\;\;\;\;x - x \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -5.4999999999999999e-6 or 1.64000000000000002e-15 < z Initial program 87.6%
Taylor expanded in y around inf
+-commutativeN/A
lower-fma.f64N/A
lower--.f6446.4
Applied rewrites46.4%
Taylor expanded in z around inf
Applied rewrites45.9%
if -5.4999999999999999e-6 < z < 1.64000000000000002e-15Initial program 99.1%
Taylor expanded in y around inf
+-commutativeN/A
lower-fma.f64N/A
lower--.f6478.2
Applied rewrites78.2%
Taylor expanded in t around 0
Applied rewrites85.1%
(FPCore (x y z t) :precision binary64 (if (<= t -7.2e-24) (* t z) (if (<= t 2.7e-171) (* z (- x)) (* t z))))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -7.2e-24) {
tmp = t * z;
} else if (t <= 2.7e-171) {
tmp = z * -x;
} else {
tmp = t * z;
}
return tmp;
}
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
real(8) :: tmp
if (t <= (-7.2d-24)) then
tmp = t * z
else if (t <= 2.7d-171) then
tmp = z * -x
else
tmp = t * z
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (t <= -7.2e-24) {
tmp = t * z;
} else if (t <= 2.7e-171) {
tmp = z * -x;
} else {
tmp = t * z;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -7.2e-24: tmp = t * z elif t <= 2.7e-171: tmp = z * -x else: tmp = t * z return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -7.2e-24) tmp = Float64(t * z); elseif (t <= 2.7e-171) tmp = Float64(z * Float64(-x)); else tmp = Float64(t * z); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= -7.2e-24) tmp = t * z; elseif (t <= 2.7e-171) tmp = z * -x; else tmp = t * z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -7.2e-24], N[(t * z), $MachinePrecision], If[LessEqual[t, 2.7e-171], N[(z * (-x)), $MachinePrecision], N[(t * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -7.2 \cdot 10^{-24}:\\
\;\;\;\;t \cdot z\\
\mathbf{elif}\;t \leq 2.7 \cdot 10^{-171}:\\
\;\;\;\;z \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;t \cdot z\\
\end{array}
\end{array}
if t < -7.2000000000000002e-24 or 2.70000000000000014e-171 < t Initial program 94.7%
Taylor expanded in y around inf
+-commutativeN/A
lower-fma.f64N/A
lower--.f6451.7
Applied rewrites51.7%
Taylor expanded in t around inf
Applied rewrites25.7%
if -7.2000000000000002e-24 < t < 2.70000000000000014e-171Initial program 89.5%
Taylor expanded in y around inf
+-commutativeN/A
lower-fma.f64N/A
lower--.f6477.1
Applied rewrites77.1%
Taylor expanded in z around inf
Applied rewrites32.6%
Taylor expanded in t around 0
Applied rewrites25.8%
Final simplification25.7%
(FPCore (x y z t) :precision binary64 (if (<= y 2.25e-17) (- x (* x z)) (fma z (- t x) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 2.25e-17) {
tmp = x - (x * z);
} else {
tmp = fma(z, (t - x), x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (y <= 2.25e-17) tmp = Float64(x - Float64(x * z)); else tmp = fma(z, Float64(t - x), x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[y, 2.25e-17], N[(x - N[(x * z), $MachinePrecision]), $MachinePrecision], N[(z * N[(t - x), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.25 \cdot 10^{-17}:\\
\;\;\;\;x - x \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, t - x, x\right)\\
\end{array}
\end{array}
if y < 2.24999999999999989e-17Initial program 95.4%
Taylor expanded in y around inf
+-commutativeN/A
lower-fma.f64N/A
lower--.f6453.1
Applied rewrites53.1%
Taylor expanded in t around 0
Applied rewrites51.7%
if 2.24999999999999989e-17 < y Initial program 85.1%
Taylor expanded in y around inf
+-commutativeN/A
lower-fma.f64N/A
lower--.f6484.1
Applied rewrites84.1%
(FPCore (x y z t) :precision binary64 (* z (- t x)))
double code(double x, double y, double z, double t) {
return z * (t - x);
}
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 = z * (t - x)
end function
public static double code(double x, double y, double z, double t) {
return z * (t - x);
}
def code(x, y, z, t): return z * (t - x)
function code(x, y, z, t) return Float64(z * Float64(t - x)) end
function tmp = code(x, y, z, t) tmp = z * (t - x); end
code[x_, y_, z_, t_] := N[(z * N[(t - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \left(t - x\right)
\end{array}
Initial program 92.8%
Taylor expanded in y around inf
+-commutativeN/A
lower-fma.f64N/A
lower--.f6460.8
Applied rewrites60.8%
Taylor expanded in z around inf
Applied rewrites30.0%
(FPCore (x y z t) :precision binary64 (* t z))
double code(double x, double y, double z, double t) {
return t * z;
}
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 = t * z
end function
public static double code(double x, double y, double z, double t) {
return t * z;
}
def code(x, y, z, t): return t * z
function code(x, y, z, t) return Float64(t * z) end
function tmp = code(x, y, z, t) tmp = t * z; end
code[x_, y_, z_, t_] := N[(t * z), $MachinePrecision]
\begin{array}{l}
\\
t \cdot z
\end{array}
Initial program 92.8%
Taylor expanded in y around inf
+-commutativeN/A
lower-fma.f64N/A
lower--.f6460.8
Applied rewrites60.8%
Taylor expanded in t around inf
Applied rewrites19.9%
Final simplification19.9%
(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 2024228
(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))))))