
(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}
\\
\left(x + \sin y\right) + z \cdot \cos y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 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}
\\
\left(x + \sin y\right) + z \cdot \cos y
\end{array}
(FPCore (x y z) :precision binary64 (+ (* z (cos y)) (+ x (sin y))))
double code(double x, double y, double z) {
return (z * cos(y)) + (x + sin(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 * cos(y)) + (x + sin(y))
end function
public static double code(double x, double y, double z) {
return (z * Math.cos(y)) + (x + Math.sin(y));
}
def code(x, y, z): return (z * math.cos(y)) + (x + math.sin(y))
function code(x, y, z) return Float64(Float64(z * cos(y)) + Float64(x + sin(y))) end
function tmp = code(x, y, z) tmp = (z * cos(y)) + (x + sin(y)); end
code[x_, y_, z_] := N[(N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \cos y + \left(x + \sin y\right)
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ (* z (cos y)) (+ x (sin y)))))
(if (<= t_0 -5.0)
(+ x z)
(if (<= t_0 -0.15)
(sin y)
(if (<= t_0 2e-5) (+ y (+ x z)) (if (<= t_0 1.0) (sin y) (+ x z)))))))
double code(double x, double y, double z) {
double t_0 = (z * cos(y)) + (x + sin(y));
double tmp;
if (t_0 <= -5.0) {
tmp = x + z;
} else if (t_0 <= -0.15) {
tmp = sin(y);
} else if (t_0 <= 2e-5) {
tmp = y + (x + z);
} else if (t_0 <= 1.0) {
tmp = sin(y);
} else {
tmp = x + 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) :: t_0
real(8) :: tmp
t_0 = (z * cos(y)) + (x + sin(y))
if (t_0 <= (-5.0d0)) then
tmp = x + z
else if (t_0 <= (-0.15d0)) then
tmp = sin(y)
else if (t_0 <= 2d-5) then
tmp = y + (x + z)
else if (t_0 <= 1.0d0) then
tmp = sin(y)
else
tmp = x + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (z * Math.cos(y)) + (x + Math.sin(y));
double tmp;
if (t_0 <= -5.0) {
tmp = x + z;
} else if (t_0 <= -0.15) {
tmp = Math.sin(y);
} else if (t_0 <= 2e-5) {
tmp = y + (x + z);
} else if (t_0 <= 1.0) {
tmp = Math.sin(y);
} else {
tmp = x + z;
}
return tmp;
}
def code(x, y, z): t_0 = (z * math.cos(y)) + (x + math.sin(y)) tmp = 0 if t_0 <= -5.0: tmp = x + z elif t_0 <= -0.15: tmp = math.sin(y) elif t_0 <= 2e-5: tmp = y + (x + z) elif t_0 <= 1.0: tmp = math.sin(y) else: tmp = x + z return tmp
function code(x, y, z) t_0 = Float64(Float64(z * cos(y)) + Float64(x + sin(y))) tmp = 0.0 if (t_0 <= -5.0) tmp = Float64(x + z); elseif (t_0 <= -0.15) tmp = sin(y); elseif (t_0 <= 2e-5) tmp = Float64(y + Float64(x + z)); elseif (t_0 <= 1.0) tmp = sin(y); else tmp = Float64(x + z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (z * cos(y)) + (x + sin(y)); tmp = 0.0; if (t_0 <= -5.0) tmp = x + z; elseif (t_0 <= -0.15) tmp = sin(y); elseif (t_0 <= 2e-5) tmp = y + (x + z); elseif (t_0 <= 1.0) tmp = sin(y); else tmp = x + z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -5.0], N[(x + z), $MachinePrecision], If[LessEqual[t$95$0, -0.15], N[Sin[y], $MachinePrecision], If[LessEqual[t$95$0, 2e-5], N[(y + N[(x + z), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 1.0], N[Sin[y], $MachinePrecision], N[(x + z), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y + \left(x + \sin y\right)\\
\mathbf{if}\;t\_0 \leq -5:\\
\;\;\;\;x + z\\
\mathbf{elif}\;t\_0 \leq -0.15:\\
\;\;\;\;\sin y\\
\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-5}:\\
\;\;\;\;y + \left(x + z\right)\\
\mathbf{elif}\;t\_0 \leq 1:\\
\;\;\;\;\sin y\\
\mathbf{else}:\\
\;\;\;\;x + z\\
\end{array}
\end{array}
if (+.f64 (+.f64 x (sin.f64 y)) (*.f64 z (cos.f64 y))) < -5 or 1 < (+.f64 (+.f64 x (sin.f64 y)) (*.f64 z (cos.f64 y))) Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
+-lowering-+.f6476.6
Simplified76.6%
if -5 < (+.f64 (+.f64 x (sin.f64 y)) (*.f64 z (cos.f64 y))) < -0.149999999999999994 or 2.00000000000000016e-5 < (+.f64 (+.f64 x (sin.f64 y)) (*.f64 z (cos.f64 y))) < 1Initial program 99.9%
Taylor expanded in z around 0
+-commutativeN/A
+-lowering-+.f64N/A
sin-lowering-sin.f6498.5
Simplified98.5%
Taylor expanded in x around 0
sin-lowering-sin.f6496.6
Simplified96.6%
if -0.149999999999999994 < (+.f64 (+.f64 x (sin.f64 y)) (*.f64 z (cos.f64 y))) < 2.00000000000000016e-5Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
associate-+l+N/A
+-commutativeN/A
+-lowering-+.f64N/A
+-commutativeN/A
+-lowering-+.f64100.0
Simplified100.0%
Final simplification81.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma (cos y) z x))) (if (<= x -3.4e-5) t_0 (if (<= x 4.5e-20) (fma z (cos y) (sin y)) t_0))))
double code(double x, double y, double z) {
double t_0 = fma(cos(y), z, x);
double tmp;
if (x <= -3.4e-5) {
tmp = t_0;
} else if (x <= 4.5e-20) {
tmp = fma(z, cos(y), sin(y));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(cos(y), z, x) tmp = 0.0 if (x <= -3.4e-5) tmp = t_0; elseif (x <= 4.5e-20) tmp = fma(z, cos(y), sin(y)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Cos[y], $MachinePrecision] * z + x), $MachinePrecision]}, If[LessEqual[x, -3.4e-5], t$95$0, If[LessEqual[x, 4.5e-20], N[(z * N[Cos[y], $MachinePrecision] + N[Sin[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\cos y, z, x\right)\\
\mathbf{if}\;x \leq -3.4 \cdot 10^{-5}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 4.5 \cdot 10^{-20}:\\
\;\;\;\;\mathsf{fma}\left(z, \cos y, \sin y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -3.4e-5 or 4.5000000000000001e-20 < x Initial program 100.0%
Taylor expanded in x around inf
Simplified99.9%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
cos-lowering-cos.f6499.9
Applied egg-rr99.9%
if -3.4e-5 < x < 4.5000000000000001e-20Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f64N/A
cos-lowering-cos.f64N/A
sin-lowering-sin.f6494.5
Simplified94.5%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma (cos y) z x))) (if (<= z -8.6e-9) t_0 (if (<= z 4.1e-18) (+ x (sin y)) t_0))))
double code(double x, double y, double z) {
double t_0 = fma(cos(y), z, x);
double tmp;
if (z <= -8.6e-9) {
tmp = t_0;
} else if (z <= 4.1e-18) {
tmp = x + sin(y);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(cos(y), z, x) tmp = 0.0 if (z <= -8.6e-9) tmp = t_0; elseif (z <= 4.1e-18) tmp = Float64(x + sin(y)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Cos[y], $MachinePrecision] * z + x), $MachinePrecision]}, If[LessEqual[z, -8.6e-9], t$95$0, If[LessEqual[z, 4.1e-18], N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\cos y, z, x\right)\\
\mathbf{if}\;z \leq -8.6 \cdot 10^{-9}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 4.1 \cdot 10^{-18}:\\
\;\;\;\;x + \sin y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -8.59999999999999925e-9 or 4.0999999999999998e-18 < z Initial program 99.9%
Taylor expanded in x around inf
Simplified99.9%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
cos-lowering-cos.f6499.9
Applied egg-rr99.9%
if -8.59999999999999925e-9 < z < 4.0999999999999998e-18Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
+-lowering-+.f64N/A
sin-lowering-sin.f6494.7
Simplified94.7%
Final simplification97.5%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* z (cos y)))) (if (<= z -2.1e+30) t_0 (if (<= z 2.95e+23) (+ x (sin y)) t_0))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -2.1e+30) {
tmp = t_0;
} else if (z <= 2.95e+23) {
tmp = x + sin(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 = z * cos(y)
if (z <= (-2.1d+30)) then
tmp = t_0
else if (z <= 2.95d+23) then
tmp = x + sin(y)
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 <= -2.1e+30) {
tmp = t_0;
} else if (z <= 2.95e+23) {
tmp = x + Math.sin(y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) tmp = 0 if z <= -2.1e+30: tmp = t_0 elif z <= 2.95e+23: tmp = x + math.sin(y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (z <= -2.1e+30) tmp = t_0; elseif (z <= 2.95e+23) tmp = Float64(x + sin(y)); 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 <= -2.1e+30) tmp = t_0; elseif (z <= 2.95e+23) tmp = x + sin(y); 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, -2.1e+30], t$95$0, If[LessEqual[z, 2.95e+23], N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -2.1 \cdot 10^{+30}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 2.95 \cdot 10^{+23}:\\
\;\;\;\;x + \sin y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -2.1e30 or 2.94999999999999994e23 < z Initial program 99.9%
Taylor expanded in z around inf
*-lowering-*.f64N/A
cos-lowering-cos.f6478.5
Simplified78.5%
if -2.1e30 < z < 2.94999999999999994e23Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
+-lowering-+.f64N/A
sin-lowering-sin.f6491.1
Simplified91.1%
Final simplification85.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ x (sin y))))
(if (<= y -0.0295)
t_0
(if (<= y 19000.0)
(+ (fma (* y -0.16666666666666666) (* y y) y) (+ x z))
t_0))))
double code(double x, double y, double z) {
double t_0 = x + sin(y);
double tmp;
if (y <= -0.0295) {
tmp = t_0;
} else if (y <= 19000.0) {
tmp = fma((y * -0.16666666666666666), (y * y), y) + (x + z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x + sin(y)) tmp = 0.0 if (y <= -0.0295) tmp = t_0; elseif (y <= 19000.0) tmp = Float64(fma(Float64(y * -0.16666666666666666), Float64(y * y), y) + Float64(x + z)); 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, -0.0295], t$95$0, If[LessEqual[y, 19000.0], N[(N[(N[(y * -0.16666666666666666), $MachinePrecision] * N[(y * y), $MachinePrecision] + y), $MachinePrecision] + N[(x + z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x + \sin y\\
\mathbf{if}\;y \leq -0.0295:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 19000:\\
\;\;\;\;\mathsf{fma}\left(y \cdot -0.16666666666666666, y \cdot y, y\right) + \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.029499999999999998 or 19000 < y Initial program 99.8%
Taylor expanded in z around 0
+-commutativeN/A
+-lowering-+.f64N/A
sin-lowering-sin.f6464.1
Simplified64.1%
if -0.029499999999999998 < y < 19000Initial program 100.0%
Taylor expanded in y around 0
+-lowering-+.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f6499.1
Simplified99.1%
+-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
distribute-rgt-inN/A
*-commutativeN/A
associate-*l*N/A
*-lft-identityN/A
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f6499.1
Applied egg-rr99.1%
Taylor expanded in y around inf
*-commutativeN/A
*-lowering-*.f6499.3
Simplified99.3%
Final simplification80.0%
(FPCore (x y z) :precision binary64 (if (<= x -1.65e-84) x (if (<= x 2.5e-13) z x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.65e-84) {
tmp = x;
} else if (x <= 2.5e-13) {
tmp = z;
} else {
tmp = 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 <= (-1.65d-84)) then
tmp = x
else if (x <= 2.5d-13) then
tmp = z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.65e-84) {
tmp = x;
} else if (x <= 2.5e-13) {
tmp = z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.65e-84: tmp = x elif x <= 2.5e-13: tmp = z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.65e-84) tmp = x; elseif (x <= 2.5e-13) tmp = z; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.65e-84) tmp = x; elseif (x <= 2.5e-13) tmp = z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.65e-84], x, If[LessEqual[x, 2.5e-13], z, x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.65 \cdot 10^{-84}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 2.5 \cdot 10^{-13}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1.64999999999999992e-84 or 2.49999999999999995e-13 < x Initial program 99.9%
Taylor expanded in x around inf
Simplified68.9%
if -1.64999999999999992e-84 < x < 2.49999999999999995e-13Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
+-lowering-+.f6442.9
Simplified42.9%
Taylor expanded in z around inf
Simplified41.3%
(FPCore (x y z) :precision binary64 (+ x z))
double code(double x, double y, double z) {
return x + 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 + z
end function
public static double code(double x, double y, double z) {
return x + z;
}
def code(x, y, z): return x + z
function code(x, y, z) return Float64(x + z) end
function tmp = code(x, y, z) tmp = x + z; end
code[x_, y_, z_] := N[(x + z), $MachinePrecision]
\begin{array}{l}
\\
x + z
\end{array}
Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
+-lowering-+.f6466.2
Simplified66.2%
Final simplification66.2%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.9%
Taylor expanded in x around inf
Simplified43.2%
herbie shell --seed 2024205
(FPCore (x y z)
:name "Graphics.Rasterific.Svg.PathConverter:segmentToBezier from rasterific-svg-0.2.3.1, C"
:precision binary64
(+ (+ x (sin y)) (* z (cos y))))