
(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 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}
\\
\left(x + \sin y\right) + z \cdot \cos y
\end{array}
(FPCore (x y z) :precision binary64 (fma (cos y) z (+ (sin y) x)))
double code(double x, double y, double z) {
return fma(cos(y), z, (sin(y) + x));
}
function code(x, y, z) return fma(cos(y), z, Float64(sin(y) + x)) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * z + N[(N[Sin[y], $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, z, \sin y + x\right)
\end{array}
Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.9
lift-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
(FPCore (x y z)
:precision binary64
(if (<= x -4.8e+26)
(+ z x)
(if (<= x -5e-93)
(* (cos y) z)
(if (<= x 3.7e-12) (fma 1.0 z (sin y)) (+ z x)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.8e+26) {
tmp = z + x;
} else if (x <= -5e-93) {
tmp = cos(y) * z;
} else if (x <= 3.7e-12) {
tmp = fma(1.0, z, sin(y));
} else {
tmp = z + x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -4.8e+26) tmp = Float64(z + x); elseif (x <= -5e-93) tmp = Float64(cos(y) * z); elseif (x <= 3.7e-12) tmp = fma(1.0, z, sin(y)); else tmp = Float64(z + x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -4.8e+26], N[(z + x), $MachinePrecision], If[LessEqual[x, -5e-93], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], If[LessEqual[x, 3.7e-12], N[(1.0 * z + N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(z + x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.8 \cdot 10^{+26}:\\
\;\;\;\;z + x\\
\mathbf{elif}\;x \leq -5 \cdot 10^{-93}:\\
\;\;\;\;\cos y \cdot z\\
\mathbf{elif}\;x \leq 3.7 \cdot 10^{-12}:\\
\;\;\;\;\mathsf{fma}\left(1, z, \sin y\right)\\
\mathbf{else}:\\
\;\;\;\;z + x\\
\end{array}
\end{array}
if x < -4.80000000000000009e26 or 3.69999999999999999e-12 < x Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
lower-+.f6488.9
Applied rewrites88.9%
if -4.80000000000000009e26 < x < -4.99999999999999994e-93Initial program 99.9%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
div-add-revN/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-sin.f64N/A
lower-cos.f6499.8
Applied rewrites99.8%
Taylor expanded in z around inf
Applied rewrites77.8%
if -4.99999999999999994e-93 < x < 3.69999999999999999e-12Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f64N/A
lower-sin.f6496.8
Applied rewrites96.8%
Taylor expanded in y around 0
Applied rewrites73.8%
Final simplification82.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.2e+138) (not (<= z 8.8e+69))) (* (cos y) z) (fma 1.0 z (+ (sin y) x))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.2e+138) || !(z <= 8.8e+69)) {
tmp = cos(y) * z;
} else {
tmp = fma(1.0, z, (sin(y) + x));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -2.2e+138) || !(z <= 8.8e+69)) tmp = Float64(cos(y) * z); else tmp = fma(1.0, z, Float64(sin(y) + x)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.2e+138], N[Not[LessEqual[z, 8.8e+69]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], N[(1.0 * z + N[(N[Sin[y], $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.2 \cdot 10^{+138} \lor \neg \left(z \leq 8.8 \cdot 10^{+69}\right):\\
\;\;\;\;\cos y \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(1, z, \sin y + x\right)\\
\end{array}
\end{array}
if z < -2.2000000000000001e138 or 8.8000000000000006e69 < z Initial program 99.8%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
div-add-revN/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-sin.f64N/A
lower-cos.f6499.8
Applied rewrites99.8%
Taylor expanded in z around inf
Applied rewrites90.0%
if -2.2000000000000001e138 < z < 8.8000000000000006e69Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
lift-+.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites94.6%
Final simplification93.0%
(FPCore (x y z) :precision binary64 (if (<= z -2.2e+138) (* (cos y) z) (if (<= z 1.2e+45) (fma 1.0 z (+ (sin y) x)) (fma (cos y) z (+ x y)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.2e+138) {
tmp = cos(y) * z;
} else if (z <= 1.2e+45) {
tmp = fma(1.0, z, (sin(y) + x));
} else {
tmp = fma(cos(y), z, (x + y));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -2.2e+138) tmp = Float64(cos(y) * z); elseif (z <= 1.2e+45) tmp = fma(1.0, z, Float64(sin(y) + x)); else tmp = fma(cos(y), z, Float64(x + y)); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -2.2e+138], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], If[LessEqual[z, 1.2e+45], N[(1.0 * z + N[(N[Sin[y], $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision], N[(N[Cos[y], $MachinePrecision] * z + N[(x + y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.2 \cdot 10^{+138}:\\
\;\;\;\;\cos y \cdot z\\
\mathbf{elif}\;z \leq 1.2 \cdot 10^{+45}:\\
\;\;\;\;\mathsf{fma}\left(1, z, \sin y + x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\cos y, z, x + y\right)\\
\end{array}
\end{array}
if z < -2.2000000000000001e138Initial program 99.8%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
div-add-revN/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-sin.f64N/A
lower-cos.f6499.8
Applied rewrites99.8%
Taylor expanded in z around inf
Applied rewrites99.7%
if -2.2000000000000001e138 < z < 1.19999999999999995e45Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
lift-+.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites94.4%
if 1.19999999999999995e45 < z Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
lower-+.f6487.4
Applied rewrites87.4%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6487.4
Applied rewrites87.4%
Final simplification93.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.2e+138) (not (<= z 8.8e+69))) (* (cos y) z) (+ z x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.2e+138) || !(z <= 8.8e+69)) {
tmp = cos(y) * z;
} else {
tmp = z + 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 ((z <= (-2.2d+138)) .or. (.not. (z <= 8.8d+69))) then
tmp = cos(y) * z
else
tmp = z + x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2.2e+138) || !(z <= 8.8e+69)) {
tmp = Math.cos(y) * z;
} else {
tmp = z + x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.2e+138) or not (z <= 8.8e+69): tmp = math.cos(y) * z else: tmp = z + x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.2e+138) || !(z <= 8.8e+69)) tmp = Float64(cos(y) * z); else tmp = Float64(z + x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.2e+138) || ~((z <= 8.8e+69))) tmp = cos(y) * z; else tmp = z + x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.2e+138], N[Not[LessEqual[z, 8.8e+69]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], N[(z + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.2 \cdot 10^{+138} \lor \neg \left(z \leq 8.8 \cdot 10^{+69}\right):\\
\;\;\;\;\cos y \cdot z\\
\mathbf{else}:\\
\;\;\;\;z + x\\
\end{array}
\end{array}
if z < -2.2000000000000001e138 or 8.8000000000000006e69 < z Initial program 99.8%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
div-add-revN/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-sin.f64N/A
lower-cos.f6499.8
Applied rewrites99.8%
Taylor expanded in z around inf
Applied rewrites90.0%
if -2.2000000000000001e138 < z < 8.8000000000000006e69Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-+.f6470.0
Applied rewrites70.0%
Final simplification77.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -65000.0) (not (<= y 1.15e+28))) (+ z x) (fma (fma (fma -0.16666666666666666 y (* -0.5 z)) y 1.0) y (+ z x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -65000.0) || !(y <= 1.15e+28)) {
tmp = z + x;
} else {
tmp = fma(fma(fma(-0.16666666666666666, y, (-0.5 * z)), y, 1.0), y, (z + x));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -65000.0) || !(y <= 1.15e+28)) tmp = Float64(z + x); else tmp = fma(fma(fma(-0.16666666666666666, y, Float64(-0.5 * z)), y, 1.0), y, Float64(z + x)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -65000.0], N[Not[LessEqual[y, 1.15e+28]], $MachinePrecision]], N[(z + x), $MachinePrecision], N[(N[(N[(-0.16666666666666666 * y + N[(-0.5 * z), $MachinePrecision]), $MachinePrecision] * y + 1.0), $MachinePrecision] * y + N[(z + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -65000 \lor \neg \left(y \leq 1.15 \cdot 10^{+28}\right):\\
\;\;\;\;z + x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, y, -0.5 \cdot z\right), y, 1\right), y, z + x\right)\\
\end{array}
\end{array}
if y < -65000 or 1.14999999999999992e28 < y Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
lower-+.f6437.7
Applied rewrites37.7%
if -65000 < y < 1.14999999999999992e28Initial program 100.0%
Taylor expanded in y around 0
associate-+r+N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6497.0
Applied rewrites97.0%
Final simplification69.2%
(FPCore (x y z) :precision binary64 (+ z x))
double code(double x, double y, double z) {
return z + 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 + x
end function
public static double code(double x, double y, double z) {
return z + x;
}
def code(x, y, z): return z + x
function code(x, y, z) return Float64(z + x) end
function tmp = code(x, y, z) tmp = z + x; end
code[x_, y_, z_] := N[(z + x), $MachinePrecision]
\begin{array}{l}
\\
z + x
\end{array}
Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
lower-+.f6466.1
Applied rewrites66.1%
(FPCore (x y z) :precision binary64 (+ z y))
double code(double x, double y, double z) {
return z + 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 + y
end function
public static double code(double x, double y, double z) {
return z + y;
}
def code(x, y, z): return z + y
function code(x, y, z) return Float64(z + y) end
function tmp = code(x, y, z) tmp = z + y; end
code[x_, y_, z_] := N[(z + y), $MachinePrecision]
\begin{array}{l}
\\
z + y
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f64N/A
lower-sin.f6460.4
Applied rewrites60.4%
Taylor expanded in y around 0
Applied rewrites29.4%
herbie shell --seed 2024320
(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))))