
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * 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 * y) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * 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 * y) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (fma (+ z y) x (- z)))
double code(double x, double y, double z) {
return fma((z + y), x, -z);
}
function code(x, y, z) return fma(Float64(z + y), x, Float64(-z)) end
code[x_, y_, z_] := N[(N[(z + y), $MachinePrecision] * x + (-z)), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z + y, x, -z\right)
\end{array}
Initial program 98.8%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (if (<= x -3.55e-10) (* y x) (if (<= x 4.2e-90) (- z) (if (<= x 6.9e+81) (* y x) (* z x)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.55e-10) {
tmp = y * x;
} else if (x <= 4.2e-90) {
tmp = -z;
} else if (x <= 6.9e+81) {
tmp = y * x;
} 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 (x <= (-3.55d-10)) then
tmp = y * x
else if (x <= 4.2d-90) then
tmp = -z
else if (x <= 6.9d+81) then
tmp = y * x
else
tmp = z * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -3.55e-10) {
tmp = y * x;
} else if (x <= 4.2e-90) {
tmp = -z;
} else if (x <= 6.9e+81) {
tmp = y * x;
} else {
tmp = z * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.55e-10: tmp = y * x elif x <= 4.2e-90: tmp = -z elif x <= 6.9e+81: tmp = y * x else: tmp = z * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.55e-10) tmp = Float64(y * x); elseif (x <= 4.2e-90) tmp = Float64(-z); elseif (x <= 6.9e+81) tmp = Float64(y * x); else tmp = Float64(z * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -3.55e-10) tmp = y * x; elseif (x <= 4.2e-90) tmp = -z; elseif (x <= 6.9e+81) tmp = y * x; else tmp = z * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.55e-10], N[(y * x), $MachinePrecision], If[LessEqual[x, 4.2e-90], (-z), If[LessEqual[x, 6.9e+81], N[(y * x), $MachinePrecision], N[(z * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.55 \cdot 10^{-10}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 4.2 \cdot 10^{-90}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 6.9 \cdot 10^{+81}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot x\\
\end{array}
\end{array}
if x < -3.5500000000000001e-10 or 4.1999999999999998e-90 < x < 6.8999999999999996e81Initial program 99.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64100.0
Applied rewrites100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6460.5
Applied rewrites60.5%
if -3.5500000000000001e-10 < x < 4.1999999999999998e-90Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6474.6
Applied rewrites74.6%
if 6.8999999999999996e81 < x Initial program 94.9%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6460.1
Applied rewrites60.1%
Taylor expanded in x around inf
Applied rewrites60.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.5e-9) (not (<= x 7800.0))) (* (+ z y) x) (- (* z x) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.5e-9) || !(x <= 7800.0)) {
tmp = (z + y) * x;
} else {
tmp = (z * 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) :: tmp
if ((x <= (-6.5d-9)) .or. (.not. (x <= 7800.0d0))) then
tmp = (z + y) * x
else
tmp = (z * x) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -6.5e-9) || !(x <= 7800.0)) {
tmp = (z + y) * x;
} else {
tmp = (z * x) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.5e-9) or not (x <= 7800.0): tmp = (z + y) * x else: tmp = (z * x) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.5e-9) || !(x <= 7800.0)) tmp = Float64(Float64(z + y) * x); else tmp = Float64(Float64(z * x) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -6.5e-9) || ~((x <= 7800.0))) tmp = (z + y) * x; else tmp = (z * x) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.5e-9], N[Not[LessEqual[x, 7800.0]], $MachinePrecision]], N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision], N[(N[(z * x), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.5 \cdot 10^{-9} \lor \neg \left(x \leq 7800\right):\\
\;\;\;\;\left(z + y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot x - z\\
\end{array}
\end{array}
if x < -6.5000000000000003e-9 or 7800 < x Initial program 97.3%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6498.0
Applied rewrites98.0%
if -6.5000000000000003e-9 < x < 7800Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6471.3
Applied rewrites71.3%
Applied rewrites71.3%
Final simplification83.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.5e-9) (not (<= x 7800.0))) (* (+ z y) x) (* (- x 1.0) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.5e-9) || !(x <= 7800.0)) {
tmp = (z + y) * x;
} else {
tmp = (x - 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 ((x <= (-6.5d-9)) .or. (.not. (x <= 7800.0d0))) then
tmp = (z + y) * x
else
tmp = (x - 1.0d0) * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -6.5e-9) || !(x <= 7800.0)) {
tmp = (z + y) * x;
} else {
tmp = (x - 1.0) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.5e-9) or not (x <= 7800.0): tmp = (z + y) * x else: tmp = (x - 1.0) * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.5e-9) || !(x <= 7800.0)) tmp = Float64(Float64(z + y) * x); else tmp = Float64(Float64(x - 1.0) * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -6.5e-9) || ~((x <= 7800.0))) tmp = (z + y) * x; else tmp = (x - 1.0) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.5e-9], N[Not[LessEqual[x, 7800.0]], $MachinePrecision]], N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision], N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.5 \cdot 10^{-9} \lor \neg \left(x \leq 7800\right):\\
\;\;\;\;\left(z + y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(x - 1\right) \cdot z\\
\end{array}
\end{array}
if x < -6.5000000000000003e-9 or 7800 < x Initial program 97.3%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6498.0
Applied rewrites98.0%
if -6.5000000000000003e-9 < x < 7800Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6471.3
Applied rewrites71.3%
Final simplification83.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.5e-10) (not (<= x 4.2e-90))) (* (+ z y) x) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.5e-10) || !(x <= 4.2e-90)) {
tmp = (z + y) * x;
} 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 ((x <= (-3.5d-10)) .or. (.not. (x <= 4.2d-90))) then
tmp = (z + y) * x
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3.5e-10) || !(x <= 4.2e-90)) {
tmp = (z + y) * x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.5e-10) or not (x <= 4.2e-90): tmp = (z + y) * x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.5e-10) || !(x <= 4.2e-90)) tmp = Float64(Float64(z + y) * x); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.5e-10) || ~((x <= 4.2e-90))) tmp = (z + y) * x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.5e-10], N[Not[LessEqual[x, 4.2e-90]], $MachinePrecision]], N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.5 \cdot 10^{-10} \lor \neg \left(x \leq 4.2 \cdot 10^{-90}\right):\\
\;\;\;\;\left(z + y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -3.4999999999999998e-10 or 4.1999999999999998e-90 < x Initial program 97.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6489.8
Applied rewrites89.8%
if -3.4999999999999998e-10 < x < 4.1999999999999998e-90Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6474.6
Applied rewrites74.6%
Final simplification82.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (* z x) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = z * x;
} 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 ((x <= (-1.0d0)) .or. (.not. (x <= 1.0d0))) then
tmp = z * x
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = z * x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.0) or not (x <= 1.0): tmp = z * x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) tmp = Float64(z * x); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.0) || ~((x <= 1.0))) tmp = z * x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(z * x), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;z \cdot x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 97.2%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6450.9
Applied rewrites50.9%
Taylor expanded in x around inf
Applied rewrites49.1%
if -1 < x < 1Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6468.1
Applied rewrites68.1%
Final simplification60.0%
(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 Float64(-z) end
function tmp = code(x, y, z) tmp = -z; end
code[x_, y_, z_] := (-z)
\begin{array}{l}
\\
-z
\end{array}
Initial program 98.8%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6440.4
Applied rewrites40.4%
(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 98.8%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6440.4
Applied rewrites40.4%
Applied rewrites2.4%
herbie shell --seed 2024318
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))