
(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 (+ (* 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}
Initial program 99.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* z (cos y)))) (if (<= z -5.8e+53) t_0 (if (<= z 1.62e+74) (+ (* x (sin y)) z) t_0))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -5.8e+53) {
tmp = t_0;
} else if (z <= 1.62e+74) {
tmp = (x * sin(y)) + z;
} 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 = z * cos(y)
if (z <= (-5.8d+53)) then
tmp = t_0
else if (z <= 1.62d+74) then
tmp = (x * sin(y)) + z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * Math.cos(y);
double tmp;
if (z <= -5.8e+53) {
tmp = t_0;
} else if (z <= 1.62e+74) {
tmp = (x * Math.sin(y)) + z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) tmp = 0 if z <= -5.8e+53: tmp = t_0 elif z <= 1.62e+74: tmp = (x * math.sin(y)) + z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (z <= -5.8e+53) tmp = t_0; elseif (z <= 1.62e+74) tmp = Float64(Float64(x * sin(y)) + z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * cos(y); tmp = 0.0; if (z <= -5.8e+53) tmp = t_0; elseif (z <= 1.62e+74) tmp = (x * sin(y)) + z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -5.8e+53], t$95$0, If[LessEqual[z, 1.62e+74], N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -5.8 \cdot 10^{+53}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.62 \cdot 10^{+74}:\\
\;\;\;\;x \cdot \sin y + z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -5.8000000000000004e53 or 1.62e74 < z Initial program 99.9%
Taylor expanded in x around 0
*-lowering-*.f64N/A
cos-lowering-cos.f6489.7%
Simplified89.7%
if -5.8000000000000004e53 < z < 1.62e74Initial program 99.8%
Taylor expanded in y around 0
Simplified87.4%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (sin y)))) (if (<= x -2.4e+123) t_0 (if (<= x 9.5e+74) (* z (cos y)) t_0))))
double code(double x, double y, double z) {
double t_0 = x * sin(y);
double tmp;
if (x <= -2.4e+123) {
tmp = t_0;
} else if (x <= 9.5e+74) {
tmp = z * cos(y);
} 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 (x <= (-2.4d+123)) then
tmp = t_0
else if (x <= 9.5d+74) then
tmp = z * cos(y)
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 (x <= -2.4e+123) {
tmp = t_0;
} else if (x <= 9.5e+74) {
tmp = z * Math.cos(y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.sin(y) tmp = 0 if x <= -2.4e+123: tmp = t_0 elif x <= 9.5e+74: tmp = z * math.cos(y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * sin(y)) tmp = 0.0 if (x <= -2.4e+123) tmp = t_0; elseif (x <= 9.5e+74) tmp = Float64(z * cos(y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * sin(y); tmp = 0.0; if (x <= -2.4e+123) tmp = t_0; elseif (x <= 9.5e+74) tmp = z * cos(y); 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[x, -2.4e+123], t$95$0, If[LessEqual[x, 9.5e+74], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
\mathbf{if}\;x \leq -2.4 \cdot 10^{+123}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 9.5 \cdot 10^{+74}:\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -2.39999999999999989e123 or 9.5000000000000006e74 < x Initial program 99.8%
Taylor expanded in x around inf
*-lowering-*.f64N/A
sin-lowering-sin.f6473.4%
Simplified73.4%
if -2.39999999999999989e123 < x < 9.5000000000000006e74Initial program 99.9%
Taylor expanded in x around 0
*-lowering-*.f64N/A
cos-lowering-cos.f6480.2%
Simplified80.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (sin y))))
(if (<= y -0.037)
t_0
(if (<= y 0.112) (+ 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.037) {
tmp = t_0;
} else if (y <= 0.112) {
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.037d0)) then
tmp = t_0
else if (y <= 0.112d0) 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.037) {
tmp = t_0;
} else if (y <= 0.112) {
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.037: tmp = t_0 elif y <= 0.112: 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.037) tmp = t_0; elseif (y <= 0.112) 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.037) tmp = t_0; elseif (y <= 0.112) 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.037], t$95$0, If[LessEqual[y, 0.112], 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.037:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.112:\\
\;\;\;\;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.0369999999999999982 or 0.112000000000000002 < y Initial program 99.7%
Taylor expanded in x around inf
*-lowering-*.f64N/A
sin-lowering-sin.f6450.0%
Simplified50.0%
if -0.0369999999999999982 < y < 0.112000000000000002Initial 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-*.f6499.7%
Simplified99.7%
(FPCore (x y z) :precision binary64 (if (<= z -2.5e-230) z (if (<= z 1.65e-151) (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.5e-230) {
tmp = z;
} else if (z <= 1.65e-151) {
tmp = x * y;
} else {
tmp = 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 <= (-2.5d-230)) then
tmp = z
else if (z <= 1.65d-151) then
tmp = x * y
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -2.5e-230) {
tmp = z;
} else if (z <= 1.65e-151) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.5e-230: tmp = z elif z <= 1.65e-151: tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.5e-230) tmp = z; elseif (z <= 1.65e-151) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.5e-230) tmp = z; elseif (z <= 1.65e-151) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.5e-230], z, If[LessEqual[z, 1.65e-151], N[(x * y), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.5 \cdot 10^{-230}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 1.65 \cdot 10^{-151}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -2.50000000000000017e-230 or 1.6499999999999999e-151 < z Initial program 99.9%
Taylor expanded in y around 0
Simplified45.8%
if -2.50000000000000017e-230 < z < 1.6499999999999999e-151Initial program 99.8%
Taylor expanded in y around 0
Simplified95.1%
Taylor expanded in y around 0
*-commutativeN/A
*-lowering-*.f6454.1%
Simplified54.1%
Taylor expanded in y around inf
*-commutativeN/A
*-lowering-*.f6444.8%
Simplified44.8%
Final simplification45.6%
(FPCore (x y z) :precision binary64 (+ z (* x y)))
double code(double x, double y, double z) {
return z + (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 = z + (x * y)
end function
public static double code(double x, double y, double z) {
return z + (x * y);
}
def code(x, y, z): return z + (x * y)
function code(x, y, z) return Float64(z + Float64(x * y)) end
function tmp = code(x, y, z) tmp = z + (x * y); end
code[x_, y_, z_] := N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + x \cdot y
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6452.8%
Simplified52.8%
Final simplification52.8%
(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.8%
Taylor expanded in y around 0
Simplified39.9%
herbie shell --seed 2024155
(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))))