
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * cos(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * cos(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
(FPCore (x y z) :precision binary64 (fma (sin y) x (* z (cos y))))
double code(double x, double y, double z) {
return fma(sin(y), x, (z * cos(y)));
}
function code(x, y, z) return fma(sin(y), x, Float64(z * cos(y))) end
code[x_, y_, z_] := N[(N[Sin[y], $MachinePrecision] * x + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin y, x, z \cdot \cos y\right)
\end{array}
Initial program 99.8%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (sin y))))
(if (<= y -2.3e+19)
t_0
(if (<= y 0.0156)
(fma (fma (* -0.5 y) z x) y z)
(if (<= y 1.5e+254) (* z (cos y)) t_0)))))
double code(double x, double y, double z) {
double t_0 = x * sin(y);
double tmp;
if (y <= -2.3e+19) {
tmp = t_0;
} else if (y <= 0.0156) {
tmp = fma(fma((-0.5 * y), z, x), y, z);
} else if (y <= 1.5e+254) {
tmp = z * cos(y);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * sin(y)) tmp = 0.0 if (y <= -2.3e+19) tmp = t_0; elseif (y <= 0.0156) tmp = fma(fma(Float64(-0.5 * y), z, x), y, z); elseif (y <= 1.5e+254) tmp = Float64(z * cos(y)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2.3e+19], t$95$0, If[LessEqual[y, 0.0156], N[(N[(N[(-0.5 * y), $MachinePrecision] * z + x), $MachinePrecision] * y + z), $MachinePrecision], If[LessEqual[y, 1.5e+254], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
\mathbf{if}\;y \leq -2.3 \cdot 10^{+19}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.0156:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-0.5 \cdot y, z, x\right), y, z\right)\\
\mathbf{elif}\;y \leq 1.5 \cdot 10^{+254}:\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.3e19 or 1.50000000000000003e254 < y Initial program 99.6%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-sin.f6459.0
Applied rewrites59.0%
if -2.3e19 < y < 0.015599999999999999Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6498.6
Applied rewrites98.6%
if 0.015599999999999999 < y < 1.50000000000000003e254Initial program 99.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6458.4
Applied rewrites58.4%
Final simplification78.7%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= z -6e+87)
t_0
(if (<= z 410000000.0) (fma (sin y) x (* 1.0 z)) t_0))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -6e+87) {
tmp = t_0;
} else if (z <= 410000000.0) {
tmp = fma(sin(y), x, (1.0 * z));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (z <= -6e+87) tmp = t_0; elseif (z <= 410000000.0) tmp = fma(sin(y), x, Float64(1.0 * z)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -6e+87], t$95$0, If[LessEqual[z, 410000000.0], N[(N[Sin[y], $MachinePrecision] * x + N[(1.0 * z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -6 \cdot 10^{+87}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 410000000:\\
\;\;\;\;\mathsf{fma}\left(\sin y, x, 1 \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -5.9999999999999998e87 or 4.1e8 < z Initial program 99.8%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6482.8
Applied rewrites82.8%
if -5.9999999999999998e87 < z < 4.1e8Initial program 99.8%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.9
Applied rewrites99.9%
Taylor expanded in y around 0
Applied rewrites94.8%
Final simplification88.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= y -0.0044)
t_0
(if (<= y 0.0156) (fma (fma (* -0.5 y) z x) y z) t_0))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (y <= -0.0044) {
tmp = t_0;
} else if (y <= 0.0156) {
tmp = fma(fma((-0.5 * y), z, x), y, z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (y <= -0.0044) tmp = t_0; elseif (y <= 0.0156) tmp = fma(fma(Float64(-0.5 * y), z, x), y, z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.0044], t$95$0, If[LessEqual[y, 0.0156], N[(N[(N[(-0.5 * y), $MachinePrecision] * z + x), $MachinePrecision] * y + z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;y \leq -0.0044:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.0156:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-0.5 \cdot y, z, x\right), y, z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.00440000000000000027 or 0.015599999999999999 < y Initial program 99.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6450.2
Applied rewrites50.2%
if -0.00440000000000000027 < y < 0.015599999999999999Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64100.0
Applied rewrites100.0%
Final simplification74.5%
(FPCore (x y z) :precision binary64 (if (<= z -4.5e-187) (* 1.0 z) (if (<= z 6.8e-133) (* x y) (* 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.5e-187) {
tmp = 1.0 * z;
} else if (z <= 6.8e-133) {
tmp = x * y;
} else {
tmp = 1.0 * z;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (z <= (-4.5d-187)) then
tmp = 1.0d0 * z
else if (z <= 6.8d-133) then
tmp = x * y
else
tmp = 1.0d0 * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -4.5e-187) {
tmp = 1.0 * z;
} else if (z <= 6.8e-133) {
tmp = x * y;
} else {
tmp = 1.0 * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4.5e-187: tmp = 1.0 * z elif z <= 6.8e-133: tmp = x * y else: tmp = 1.0 * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4.5e-187) tmp = Float64(1.0 * z); elseif (z <= 6.8e-133) tmp = Float64(x * y); else tmp = Float64(1.0 * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -4.5e-187) tmp = 1.0 * z; elseif (z <= 6.8e-133) tmp = x * y; else tmp = 1.0 * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4.5e-187], N[(1.0 * z), $MachinePrecision], If[LessEqual[z, 6.8e-133], N[(x * y), $MachinePrecision], N[(1.0 * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.5 \cdot 10^{-187}:\\
\;\;\;\;1 \cdot z\\
\mathbf{elif}\;z \leq 6.8 \cdot 10^{-133}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot z\\
\end{array}
\end{array}
if z < -4.4999999999999998e-187 or 6.80000000000000012e-133 < z Initial program 99.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6472.1
Applied rewrites72.1%
Taylor expanded in y around 0
Applied rewrites44.5%
if -4.4999999999999998e-187 < z < 6.80000000000000012e-133Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6459.5
Applied rewrites59.5%
Taylor expanded in z around 0
Applied rewrites38.3%
Final simplification42.9%
(FPCore (x y z) :precision binary64 (fma y x z))
double code(double x, double y, double z) {
return fma(y, x, z);
}
function code(x, y, z) return fma(y, x, z) end
code[x_, y_, z_] := N[(y * x + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, z\right)
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6451.8
Applied rewrites51.8%
(FPCore (x y z) :precision binary64 (* x y))
double code(double x, double y, double z) {
return x * y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * y
end function
public static double code(double x, double y, double z) {
return x * y;
}
def code(x, y, z): return x * y
function code(x, y, z) return Float64(x * y) end
function tmp = code(x, y, z) tmp = x * y; end
code[x_, y_, z_] := N[(x * y), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6451.8
Applied rewrites51.8%
Taylor expanded in z around 0
Applied rewrites16.3%
Final simplification16.3%
herbie shell --seed 2024277
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ (* x (sin y)) (* z (cos y))))