
(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 8 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 (cos y) z (* x (sin y))))
double code(double x, double y, double z) {
return fma(cos(y), z, (x * sin(y)));
}
function code(x, y, z) return fma(cos(y), z, Float64(x * sin(y))) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * z + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, z, x \cdot \sin y\right)
\end{array}
Initial program 99.9%
+-commutativeN/A
*-commutativeN/A
fma-defineN/A
fma-lowering-fma.f64N/A
cos-lowering-cos.f64N/A
*-lowering-*.f64N/A
sin-lowering-sin.f6499.9%
Applied egg-rr99.9%
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* (cos y) z)))
double code(double x, double y, double z) {
return (x * sin(y)) + (cos(y) * z);
}
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)) + (cos(y) * z)
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (Math.cos(y) * z);
}
def code(x, y, z): return (x * math.sin(y)) + (math.cos(y) * z)
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(cos(y) * z)) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (cos(y) * z); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + \cos y \cdot z
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (sin y))) (t_1 (* z (+ 1.0 (* x (/ (sin y) z))))))
(if (<= x -1.12e+136)
t_0
(if (<= x -5.4e+17)
t_1
(if (<= x 2.4e-13) (* (cos y) z) (if (<= x 2.1e+218) t_1 t_0))))))
double code(double x, double y, double z) {
double t_0 = x * sin(y);
double t_1 = z * (1.0 + (x * (sin(y) / z)));
double tmp;
if (x <= -1.12e+136) {
tmp = t_0;
} else if (x <= -5.4e+17) {
tmp = t_1;
} else if (x <= 2.4e-13) {
tmp = cos(y) * z;
} else if (x <= 2.1e+218) {
tmp = t_1;
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = x * sin(y)
t_1 = z * (1.0d0 + (x * (sin(y) / z)))
if (x <= (-1.12d+136)) then
tmp = t_0
else if (x <= (-5.4d+17)) then
tmp = t_1
else if (x <= 2.4d-13) then
tmp = cos(y) * z
else if (x <= 2.1d+218) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * Math.sin(y);
double t_1 = z * (1.0 + (x * (Math.sin(y) / z)));
double tmp;
if (x <= -1.12e+136) {
tmp = t_0;
} else if (x <= -5.4e+17) {
tmp = t_1;
} else if (x <= 2.4e-13) {
tmp = Math.cos(y) * z;
} else if (x <= 2.1e+218) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.sin(y) t_1 = z * (1.0 + (x * (math.sin(y) / z))) tmp = 0 if x <= -1.12e+136: tmp = t_0 elif x <= -5.4e+17: tmp = t_1 elif x <= 2.4e-13: tmp = math.cos(y) * z elif x <= 2.1e+218: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * sin(y)) t_1 = Float64(z * Float64(1.0 + Float64(x * Float64(sin(y) / z)))) tmp = 0.0 if (x <= -1.12e+136) tmp = t_0; elseif (x <= -5.4e+17) tmp = t_1; elseif (x <= 2.4e-13) tmp = Float64(cos(y) * z); elseif (x <= 2.1e+218) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * sin(y); t_1 = z * (1.0 + (x * (sin(y) / z))); tmp = 0.0; if (x <= -1.12e+136) tmp = t_0; elseif (x <= -5.4e+17) tmp = t_1; elseif (x <= 2.4e-13) tmp = cos(y) * z; elseif (x <= 2.1e+218) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(z * N[(1.0 + N[(x * N[(N[Sin[y], $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.12e+136], t$95$0, If[LessEqual[x, -5.4e+17], t$95$1, If[LessEqual[x, 2.4e-13], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], If[LessEqual[x, 2.1e+218], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
t_1 := z \cdot \left(1 + x \cdot \frac{\sin y}{z}\right)\\
\mathbf{if}\;x \leq -1.12 \cdot 10^{+136}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -5.4 \cdot 10^{+17}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq 2.4 \cdot 10^{-13}:\\
\;\;\;\;\cos y \cdot z\\
\mathbf{elif}\;x \leq 2.1 \cdot 10^{+218}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.12000000000000001e136 or 2.0999999999999999e218 < x Initial program 99.9%
Taylor expanded in x around inf
*-lowering-*.f64N/A
sin-lowering-sin.f6476.8%
Simplified76.8%
if -1.12000000000000001e136 < x < -5.4e17 or 2.3999999999999999e-13 < x < 2.0999999999999999e218Initial program 99.9%
+-commutativeN/A
*-commutativeN/A
fma-defineN/A
fma-lowering-fma.f64N/A
cos-lowering-cos.f64N/A
*-lowering-*.f64N/A
sin-lowering-sin.f6499.9%
Applied egg-rr99.9%
Taylor expanded in z around inf
*-lowering-*.f64N/A
+-lowering-+.f64N/A
cos-lowering-cos.f64N/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
sin-lowering-sin.f6498.2%
Simplified98.2%
Taylor expanded in y around 0
Simplified86.1%
if -5.4e17 < x < 2.3999999999999999e-13Initial program 99.9%
Taylor expanded in x around 0
*-lowering-*.f64N/A
cos-lowering-cos.f6486.7%
Simplified86.7%
Final simplification84.1%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cos y) z)))
(if (<= y -5.1e+229)
t_0
(if (<= y -0.0005)
(* x (sin y))
(if (<= y 1.3e-8) (+ z (* y (+ x (* y (* z -0.5))))) t_0)))))
double code(double x, double y, double z) {
double t_0 = cos(y) * z;
double tmp;
if (y <= -5.1e+229) {
tmp = t_0;
} else if (y <= -0.0005) {
tmp = x * sin(y);
} else if (y <= 1.3e-8) {
tmp = z + (y * (x + (y * (z * -0.5))));
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = cos(y) * z
if (y <= (-5.1d+229)) then
tmp = t_0
else if (y <= (-0.0005d0)) then
tmp = x * sin(y)
else if (y <= 1.3d-8) then
tmp = z + (y * (x + (y * (z * (-0.5d0)))))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = Math.cos(y) * z;
double tmp;
if (y <= -5.1e+229) {
tmp = t_0;
} else if (y <= -0.0005) {
tmp = x * Math.sin(y);
} else if (y <= 1.3e-8) {
tmp = z + (y * (x + (y * (z * -0.5))));
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = math.cos(y) * z tmp = 0 if y <= -5.1e+229: tmp = t_0 elif y <= -0.0005: tmp = x * math.sin(y) elif y <= 1.3e-8: tmp = z + (y * (x + (y * (z * -0.5)))) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(cos(y) * z) tmp = 0.0 if (y <= -5.1e+229) tmp = t_0; elseif (y <= -0.0005) tmp = Float64(x * sin(y)); elseif (y <= 1.3e-8) tmp = Float64(z + Float64(y * Float64(x + Float64(y * Float64(z * -0.5))))); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = cos(y) * z; tmp = 0.0; if (y <= -5.1e+229) tmp = t_0; elseif (y <= -0.0005) tmp = x * sin(y); elseif (y <= 1.3e-8) tmp = z + (y * (x + (y * (z * -0.5)))); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[y, -5.1e+229], t$95$0, If[LessEqual[y, -0.0005], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.3e-8], N[(z + N[(y * N[(x + N[(y * N[(z * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos y \cdot z\\
\mathbf{if}\;y \leq -5.1 \cdot 10^{+229}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -0.0005:\\
\;\;\;\;x \cdot \sin y\\
\mathbf{elif}\;y \leq 1.3 \cdot 10^{-8}:\\
\;\;\;\;z + y \cdot \left(x + y \cdot \left(z \cdot -0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -5.0999999999999996e229 or 1.3000000000000001e-8 < y Initial program 99.8%
Taylor expanded in x around 0
*-lowering-*.f64N/A
cos-lowering-cos.f6458.4%
Simplified58.4%
if -5.0999999999999996e229 < y < -5.0000000000000001e-4Initial program 99.7%
Taylor expanded in x around inf
*-lowering-*.f64N/A
sin-lowering-sin.f6463.8%
Simplified63.8%
if -5.0000000000000001e-4 < y < 1.3000000000000001e-8Initial program 100.0%
Taylor expanded in y around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f64100.0%
Simplified100.0%
Final simplification81.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (sin y))))
(if (<= y -0.036)
t_0
(if (<= y 0.1) (+ z (* y (+ x (* y (* z -0.5))))) t_0))))
double code(double x, double y, double z) {
double t_0 = x * sin(y);
double tmp;
if (y <= -0.036) {
tmp = t_0;
} else if (y <= 0.1) {
tmp = z + (y * (x + (y * (z * -0.5))));
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = x * sin(y)
if (y <= (-0.036d0)) then
tmp = t_0
else if (y <= 0.1d0) then
tmp = z + (y * (x + (y * (z * (-0.5d0)))))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * Math.sin(y);
double tmp;
if (y <= -0.036) {
tmp = t_0;
} else if (y <= 0.1) {
tmp = z + (y * (x + (y * (z * -0.5))));
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.sin(y) tmp = 0 if y <= -0.036: tmp = t_0 elif y <= 0.1: tmp = z + (y * (x + (y * (z * -0.5)))) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * sin(y)) tmp = 0.0 if (y <= -0.036) tmp = t_0; elseif (y <= 0.1) tmp = Float64(z + Float64(y * Float64(x + Float64(y * Float64(z * -0.5))))); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * sin(y); tmp = 0.0; if (y <= -0.036) tmp = t_0; elseif (y <= 0.1) tmp = z + (y * (x + (y * (z * -0.5)))); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.036], t$95$0, If[LessEqual[y, 0.1], N[(z + N[(y * N[(x + N[(y * N[(z * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
\mathbf{if}\;y \leq -0.036:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.1:\\
\;\;\;\;z + y \cdot \left(x + y \cdot \left(z \cdot -0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.0359999999999999973 or 0.10000000000000001 < y Initial program 99.8%
Taylor expanded in x around inf
*-lowering-*.f64N/A
sin-lowering-sin.f6449.0%
Simplified49.0%
if -0.0359999999999999973 < y < 0.10000000000000001Initial program 100.0%
Taylor expanded in y around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f64100.0%
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (<= x -7e+72) (* y x) (if (<= x 1.65e+45) z (* y x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -7e+72) {
tmp = y * x;
} else if (x <= 1.65e+45) {
tmp = z;
} else {
tmp = y * x;
}
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 (x <= (-7d+72)) then
tmp = y * x
else if (x <= 1.65d+45) then
tmp = z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -7e+72) {
tmp = y * x;
} else if (x <= 1.65e+45) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -7e+72: tmp = y * x elif x <= 1.65e+45: tmp = z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -7e+72) tmp = Float64(y * x); elseif (x <= 1.65e+45) tmp = z; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -7e+72) tmp = y * x; elseif (x <= 1.65e+45) tmp = z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -7e+72], N[(y * x), $MachinePrecision], If[LessEqual[x, 1.65e+45], z, N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7 \cdot 10^{+72}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 1.65 \cdot 10^{+45}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -7.0000000000000002e72 or 1.65e45 < x Initial program 99.9%
Taylor expanded in x around inf
*-lowering-*.f64N/A
sin-lowering-sin.f6468.4%
Simplified68.4%
Taylor expanded in y around 0
*-lowering-*.f6435.0%
Simplified35.0%
if -7.0000000000000002e72 < x < 1.65e45Initial program 99.9%
Taylor expanded in y around 0
Simplified52.1%
Final simplification45.0%
(FPCore (x y z) :precision binary64 (+ z (* y x)))
double code(double x, double y, double z) {
return z + (y * x);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + (y * x)
end function
public static double code(double x, double y, double z) {
return z + (y * x);
}
def code(x, y, z): return z + (y * x)
function code(x, y, z) return Float64(z + Float64(y * x)) end
function tmp = code(x, y, z) tmp = z + (y * x); end
code[x_, y_, z_] := N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + y \cdot x
\end{array}
Initial program 99.9%
Taylor expanded in y around 0
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6456.7%
Simplified56.7%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 99.9%
Taylor expanded in y around 0
Simplified39.5%
herbie shell --seed 2024138
(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))))