
(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 x (+ y z) (- z)))
double code(double x, double y, double z) {
return fma(x, (y + z), -z);
}
function code(x, y, z) return fma(x, Float64(y + z), Float64(-z)) end
code[x_, y_, z_] := N[(x * N[(y + z), $MachinePrecision] + (-z)), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y + z, -z\right)
\end{array}
Initial program 96.1%
*-commutative96.1%
sub-neg96.1%
distribute-rgt-in96.1%
metadata-eval96.1%
neg-mul-196.1%
associate-+r+96.1%
distribute-lft-out100.0%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -1.7e+193)
(* x y)
(if (<= x -550000000.0)
(* x z)
(if (<= x -1.55e-66)
(* x y)
(if (<= x 1.9e-14)
(- z)
(if (<= x 7.6e+95) (* x y) (if (<= x 1.25e+179) (* x z) (* x y))))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.7e+193) {
tmp = x * y;
} else if (x <= -550000000.0) {
tmp = x * z;
} else if (x <= -1.55e-66) {
tmp = x * y;
} else if (x <= 1.9e-14) {
tmp = -z;
} else if (x <= 7.6e+95) {
tmp = x * y;
} else if (x <= 1.25e+179) {
tmp = x * z;
} else {
tmp = x * y;
}
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.7d+193)) then
tmp = x * y
else if (x <= (-550000000.0d0)) then
tmp = x * z
else if (x <= (-1.55d-66)) then
tmp = x * y
else if (x <= 1.9d-14) then
tmp = -z
else if (x <= 7.6d+95) then
tmp = x * y
else if (x <= 1.25d+179) then
tmp = x * z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.7e+193) {
tmp = x * y;
} else if (x <= -550000000.0) {
tmp = x * z;
} else if (x <= -1.55e-66) {
tmp = x * y;
} else if (x <= 1.9e-14) {
tmp = -z;
} else if (x <= 7.6e+95) {
tmp = x * y;
} else if (x <= 1.25e+179) {
tmp = x * z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.7e+193: tmp = x * y elif x <= -550000000.0: tmp = x * z elif x <= -1.55e-66: tmp = x * y elif x <= 1.9e-14: tmp = -z elif x <= 7.6e+95: tmp = x * y elif x <= 1.25e+179: tmp = x * z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.7e+193) tmp = Float64(x * y); elseif (x <= -550000000.0) tmp = Float64(x * z); elseif (x <= -1.55e-66) tmp = Float64(x * y); elseif (x <= 1.9e-14) tmp = Float64(-z); elseif (x <= 7.6e+95) tmp = Float64(x * y); elseif (x <= 1.25e+179) tmp = Float64(x * z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.7e+193) tmp = x * y; elseif (x <= -550000000.0) tmp = x * z; elseif (x <= -1.55e-66) tmp = x * y; elseif (x <= 1.9e-14) tmp = -z; elseif (x <= 7.6e+95) tmp = x * y; elseif (x <= 1.25e+179) tmp = x * z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.7e+193], N[(x * y), $MachinePrecision], If[LessEqual[x, -550000000.0], N[(x * z), $MachinePrecision], If[LessEqual[x, -1.55e-66], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.9e-14], (-z), If[LessEqual[x, 7.6e+95], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.25e+179], N[(x * z), $MachinePrecision], N[(x * y), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.7 \cdot 10^{+193}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -550000000:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -1.55 \cdot 10^{-66}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.9 \cdot 10^{-14}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 7.6 \cdot 10^{+95}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.25 \cdot 10^{+179}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -1.69999999999999993e193 or -5.5e8 < x < -1.5499999999999999e-66 or 1.9000000000000001e-14 < x < 7.5999999999999999e95 or 1.25e179 < x Initial program 90.1%
Taylor expanded in y around inf 68.2%
if -1.69999999999999993e193 < x < -5.5e8 or 7.5999999999999999e95 < x < 1.25e179Initial program 96.5%
Taylor expanded in x around inf 98.4%
+-commutative98.4%
Simplified98.4%
Taylor expanded in z around inf 64.0%
if -1.5499999999999999e-66 < x < 1.9000000000000001e-14Initial program 100.0%
Taylor expanded in x around 0 78.2%
neg-mul-178.2%
Simplified78.2%
Final simplification71.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.1e-66) (not (<= x 1.9e-14))) (* x (+ y z)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.1e-66) || !(x <= 1.9e-14)) {
tmp = x * (y + z);
} 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 <= (-2.1d-66)) .or. (.not. (x <= 1.9d-14))) then
tmp = x * (y + z)
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.1e-66) || !(x <= 1.9e-14)) {
tmp = x * (y + z);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.1e-66) or not (x <= 1.9e-14): tmp = x * (y + z) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.1e-66) || !(x <= 1.9e-14)) tmp = Float64(x * Float64(y + z)); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.1e-66) || ~((x <= 1.9e-14))) tmp = x * (y + z); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.1e-66], N[Not[LessEqual[x, 1.9e-14]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.1 \cdot 10^{-66} \lor \neg \left(x \leq 1.9 \cdot 10^{-14}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -2.1e-66 or 1.9000000000000001e-14 < x Initial program 92.8%
Taylor expanded in x around inf 95.5%
+-commutative95.5%
Simplified95.5%
if -2.1e-66 < x < 1.9000000000000001e-14Initial program 100.0%
Taylor expanded in x around 0 78.2%
neg-mul-178.2%
Simplified78.2%
Final simplification87.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -8.2e-67) (not (<= x 0.00136))) (* x (+ y z)) (* z (+ x -1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8.2e-67) || !(x <= 0.00136)) {
tmp = x * (y + z);
} else {
tmp = z * (x + -1.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) :: tmp
if ((x <= (-8.2d-67)) .or. (.not. (x <= 0.00136d0))) then
tmp = x * (y + z)
else
tmp = z * (x + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -8.2e-67) || !(x <= 0.00136)) {
tmp = x * (y + z);
} else {
tmp = z * (x + -1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8.2e-67) or not (x <= 0.00136): tmp = x * (y + z) else: tmp = z * (x + -1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8.2e-67) || !(x <= 0.00136)) tmp = Float64(x * Float64(y + z)); else tmp = Float64(z * Float64(x + -1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -8.2e-67) || ~((x <= 0.00136))) tmp = x * (y + z); else tmp = z * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8.2e-67], N[Not[LessEqual[x, 0.00136]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], N[(z * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.2 \cdot 10^{-67} \lor \neg \left(x \leq 0.00136\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if x < -8.1999999999999994e-67 or 0.00136 < x Initial program 92.6%
Taylor expanded in x around inf 96.8%
+-commutative96.8%
Simplified96.8%
if -8.1999999999999994e-67 < x < 0.00136Initial program 100.0%
Taylor expanded in y around 0 77.5%
Final simplification87.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -7e-67) (not (<= x 0.025))) (* x (+ y z)) (- (* x z) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7e-67) || !(x <= 0.025)) {
tmp = x * (y + z);
} else {
tmp = (x * z) - 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 <= (-7d-67)) .or. (.not. (x <= 0.025d0))) then
tmp = x * (y + z)
else
tmp = (x * z) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -7e-67) || !(x <= 0.025)) {
tmp = x * (y + z);
} else {
tmp = (x * z) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7e-67) or not (x <= 0.025): tmp = x * (y + z) else: tmp = (x * z) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7e-67) || !(x <= 0.025)) tmp = Float64(x * Float64(y + z)); else tmp = Float64(Float64(x * z) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -7e-67) || ~((x <= 0.025))) tmp = x * (y + z); else tmp = (x * z) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7e-67], N[Not[LessEqual[x, 0.025]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], N[(N[(x * z), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7 \cdot 10^{-67} \lor \neg \left(x \leq 0.025\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot z - z\\
\end{array}
\end{array}
if x < -7.0000000000000001e-67 or 0.025000000000000001 < x Initial program 92.6%
Taylor expanded in x around inf 96.8%
+-commutative96.8%
Simplified96.8%
if -7.0000000000000001e-67 < x < 0.025000000000000001Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around 0 77.5%
Final simplification87.8%
(FPCore (x y z) :precision binary64 (if (<= x -2.3e-67) (* x y) (if (<= x 3.7e-14) (- z) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.3e-67) {
tmp = x * y;
} else if (x <= 3.7e-14) {
tmp = -z;
} else {
tmp = x * y;
}
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 <= (-2.3d-67)) then
tmp = x * y
else if (x <= 3.7d-14) then
tmp = -z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -2.3e-67) {
tmp = x * y;
} else if (x <= 3.7e-14) {
tmp = -z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.3e-67: tmp = x * y elif x <= 3.7e-14: tmp = -z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.3e-67) tmp = Float64(x * y); elseif (x <= 3.7e-14) tmp = Float64(-z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.3e-67) tmp = x * y; elseif (x <= 3.7e-14) tmp = -z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.3e-67], N[(x * y), $MachinePrecision], If[LessEqual[x, 3.7e-14], (-z), N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.3 \cdot 10^{-67}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 3.7 \cdot 10^{-14}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -2.3e-67 or 3.70000000000000001e-14 < x Initial program 92.8%
Taylor expanded in y around inf 54.4%
if -2.3e-67 < x < 3.70000000000000001e-14Initial program 100.0%
Taylor expanded in x around 0 78.2%
neg-mul-178.2%
Simplified78.2%
Final simplification65.3%
(FPCore (x y z) :precision binary64 (- (* x (+ y z)) z))
double code(double x, double y, double z) {
return (x * (y + z)) - 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 + z)) - z
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) - z;
}
def code(x, y, z): return (x * (y + z)) - z
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) - z) end
function tmp = code(x, y, z) tmp = (x * (y + z)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(y + z\right) - z
\end{array}
Initial program 96.1%
*-commutative96.1%
sub-neg96.1%
distribute-rgt-in96.1%
metadata-eval96.1%
neg-mul-196.1%
associate-+r+96.1%
unsub-neg96.1%
+-commutative96.1%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.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 96.1%
Taylor expanded in x around 0 38.6%
neg-mul-138.6%
Simplified38.6%
Final simplification38.6%
herbie shell --seed 2023279
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))