
(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 (- (* (+ z y) x) z))
double code(double x, double y, double z) {
return ((z + y) * 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 = ((z + y) * x) - z
end function
public static double code(double x, double y, double z) {
return ((z + y) * x) - z;
}
def code(x, y, z): return ((z + y) * x) - z
function code(x, y, z) return Float64(Float64(Float64(z + y) * x) - z) end
function tmp = code(x, y, z) tmp = ((z + y) * x) - z; end
code[x_, y_, z_] := N[(N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
\left(z + y\right) \cdot x - z
\end{array}
Initial program 98.8%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
associate-+l+N/A
*-rgt-identityN/A
*-inversesN/A
associate-/l*N/A
associate-*l/N/A
remove-double-negN/A
mul-1-negN/A
distribute-lft-neg-inN/A
*-commutativeN/A
mul-1-negN/A
unsub-negN/A
associate-+r-N/A
Simplified100.0%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f64N/A
+-lowering-+.f64100.0
Applied egg-rr100.0%
(FPCore (x y z) :precision binary64 (if (<= y -4.8e-20) (* y x) (if (<= y -5e-83) (- 0.0 z) (if (<= y 7.5e-55) (* z x) (* y x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4.8e-20) {
tmp = y * x;
} else if (y <= -5e-83) {
tmp = 0.0 - z;
} else if (y <= 7.5e-55) {
tmp = z * x;
} else {
tmp = y * 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 (y <= (-4.8d-20)) then
tmp = y * x
else if (y <= (-5d-83)) then
tmp = 0.0d0 - z
else if (y <= 7.5d-55) then
tmp = z * x
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -4.8e-20) {
tmp = y * x;
} else if (y <= -5e-83) {
tmp = 0.0 - z;
} else if (y <= 7.5e-55) {
tmp = z * x;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4.8e-20: tmp = y * x elif y <= -5e-83: tmp = 0.0 - z elif y <= 7.5e-55: tmp = z * x else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4.8e-20) tmp = Float64(y * x); elseif (y <= -5e-83) tmp = Float64(0.0 - z); elseif (y <= 7.5e-55) tmp = Float64(z * x); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4.8e-20) tmp = y * x; elseif (y <= -5e-83) tmp = 0.0 - z; elseif (y <= 7.5e-55) tmp = z * x; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4.8e-20], N[(y * x), $MachinePrecision], If[LessEqual[y, -5e-83], N[(0.0 - z), $MachinePrecision], If[LessEqual[y, 7.5e-55], N[(z * x), $MachinePrecision], N[(y * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.8 \cdot 10^{-20}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -5 \cdot 10^{-83}:\\
\;\;\;\;0 - z\\
\mathbf{elif}\;y \leq 7.5 \cdot 10^{-55}:\\
\;\;\;\;z \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -4.79999999999999986e-20 or 7.50000000000000023e-55 < y Initial program 97.8%
Taylor expanded in y around inf
+-rgt-identityN/A
accelerator-lowering-fma.f6471.1
Simplified71.1%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6471.1
Applied egg-rr71.1%
if -4.79999999999999986e-20 < y < -5e-83Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f6474.7
Simplified74.7%
sub0-negN/A
neg-lowering-neg.f6474.7
Applied egg-rr74.7%
if -5e-83 < y < 7.50000000000000023e-55Initial program 100.0%
Taylor expanded in x around inf
+-rgt-identityN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
+-lowering-+.f6469.5
Simplified69.5%
Taylor expanded in z around inf
+-rgt-identityN/A
*-commutativeN/A
accelerator-lowering-fma.f6455.5
Simplified55.5%
+-rgt-identityN/A
remove-double-negN/A
neg-sub0N/A
Applied egg-rr55.5%
Final simplification64.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (+ z y) x))) (if (<= x -1.0) t_0 (if (<= x 7.6e-20) (fma y x (- 0.0 z)) t_0))))
double code(double x, double y, double z) {
double t_0 = (z + y) * x;
double tmp;
if (x <= -1.0) {
tmp = t_0;
} else if (x <= 7.6e-20) {
tmp = fma(y, x, (0.0 - z));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(z + y) * x) tmp = 0.0 if (x <= -1.0) tmp = t_0; elseif (x <= 7.6e-20) tmp = fma(y, x, Float64(0.0 - z)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, -1.0], t$95$0, If[LessEqual[x, 7.6e-20], N[(y * x + N[(0.0 - z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(z + y\right) \cdot x\\
\mathbf{if}\;x \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 7.6 \cdot 10^{-20}:\\
\;\;\;\;\mathsf{fma}\left(y, x, 0 - z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1 or 7.5999999999999995e-20 < x Initial program 98.0%
Taylor expanded in x around inf
+-rgt-identityN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
+-lowering-+.f6499.0
Simplified99.0%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f64N/A
+-lowering-+.f6499.0
Applied egg-rr99.0%
if -1 < x < 7.5999999999999995e-20Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f6499.7
Simplified99.7%
*-commutativeN/A
accelerator-lowering-fma.f64N/A
--lowering--.f6499.7
Applied egg-rr99.7%
flip3--N/A
metadata-evalN/A
div-subN/A
sqr-powN/A
pow-prod-downN/A
sqr-negN/A
neg-sub0N/A
neg-sub0N/A
pow-prod-downN/A
sqr-powN/A
neg-sub0N/A
cube-negN/A
sub0-negN/A
metadata-evalN/A
flip3--N/A
Applied egg-rr99.7%
Final simplification99.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (+ z y) x))) (if (<= x -3.1e-76) t_0 (if (<= x 1.4e-83) (- 0.0 z) t_0))))
double code(double x, double y, double z) {
double t_0 = (z + y) * x;
double tmp;
if (x <= -3.1e-76) {
tmp = t_0;
} else if (x <= 1.4e-83) {
tmp = 0.0 - 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 + y) * x
if (x <= (-3.1d-76)) then
tmp = t_0
else if (x <= 1.4d-83) then
tmp = 0.0d0 - 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 + y) * x;
double tmp;
if (x <= -3.1e-76) {
tmp = t_0;
} else if (x <= 1.4e-83) {
tmp = 0.0 - z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (z + y) * x tmp = 0 if x <= -3.1e-76: tmp = t_0 elif x <= 1.4e-83: tmp = 0.0 - z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(z + y) * x) tmp = 0.0 if (x <= -3.1e-76) tmp = t_0; elseif (x <= 1.4e-83) tmp = Float64(0.0 - z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (z + y) * x; tmp = 0.0; if (x <= -3.1e-76) tmp = t_0; elseif (x <= 1.4e-83) tmp = 0.0 - z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, -3.1e-76], t$95$0, If[LessEqual[x, 1.4e-83], N[(0.0 - z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(z + y\right) \cdot x\\
\mathbf{if}\;x \leq -3.1 \cdot 10^{-76}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.4 \cdot 10^{-83}:\\
\;\;\;\;0 - z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -3.0999999999999997e-76 or 1.4e-83 < x Initial program 98.3%
Taylor expanded in x around inf
+-rgt-identityN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
+-lowering-+.f6493.4
Simplified93.4%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f64N/A
+-lowering-+.f6493.4
Applied egg-rr93.4%
if -3.0999999999999997e-76 < x < 1.4e-83Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f6473.4
Simplified73.4%
sub0-negN/A
neg-lowering-neg.f6473.4
Applied egg-rr73.4%
Final simplification87.4%
(FPCore (x y z) :precision binary64 (if (<= y -1.3e-19) (* y x) (if (<= y 1.15e+83) (* z (+ x -1.0)) (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.3e-19) {
tmp = y * x;
} else if (y <= 1.15e+83) {
tmp = z * (x + -1.0);
} else {
tmp = y * 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 (y <= (-1.3d-19)) then
tmp = y * x
else if (y <= 1.15d+83) then
tmp = z * (x + (-1.0d0))
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.3e-19) {
tmp = y * x;
} else if (y <= 1.15e+83) {
tmp = z * (x + -1.0);
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.3e-19: tmp = y * x elif y <= 1.15e+83: tmp = z * (x + -1.0) else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.3e-19) tmp = Float64(y * x); elseif (y <= 1.15e+83) tmp = Float64(z * Float64(x + -1.0)); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.3e-19) tmp = y * x; elseif (y <= 1.15e+83) tmp = z * (x + -1.0); else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.3e-19], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.15e+83], N[(z * N[(x + -1.0), $MachinePrecision]), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.3 \cdot 10^{-19}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1.15 \cdot 10^{+83}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -1.30000000000000006e-19 or 1.14999999999999997e83 < y Initial program 97.5%
Taylor expanded in y around inf
+-rgt-identityN/A
accelerator-lowering-fma.f6476.0
Simplified76.0%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6476.0
Applied egg-rr76.0%
if -1.30000000000000006e-19 < y < 1.14999999999999997e83Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
associate-+l+N/A
*-rgt-identityN/A
*-inversesN/A
associate-/l*N/A
associate-*l/N/A
remove-double-negN/A
mul-1-negN/A
distribute-lft-neg-inN/A
*-commutativeN/A
mul-1-negN/A
unsub-negN/A
associate-+r-N/A
Simplified100.0%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f64N/A
+-lowering-+.f64100.0
Applied egg-rr100.0%
Taylor expanded in z around inf
Simplified80.3%
sub-negN/A
*-commutativeN/A
neg-mul-1N/A
distribute-rgt-outN/A
*-lowering-*.f64N/A
+-lowering-+.f6480.3
Applied egg-rr80.3%
(FPCore (x y z) :precision binary64 (if (<= x -2.4e-9) (* y x) (if (<= x 1.55e-83) (- 0.0 z) (* y x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.4e-9) {
tmp = y * x;
} else if (x <= 1.55e-83) {
tmp = 0.0 - z;
} else {
tmp = y * 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 <= (-2.4d-9)) then
tmp = y * x
else if (x <= 1.55d-83) then
tmp = 0.0d0 - z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -2.4e-9) {
tmp = y * x;
} else if (x <= 1.55e-83) {
tmp = 0.0 - z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.4e-9: tmp = y * x elif x <= 1.55e-83: tmp = 0.0 - z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.4e-9) tmp = Float64(y * x); elseif (x <= 1.55e-83) tmp = Float64(0.0 - z); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.4e-9) tmp = y * x; elseif (x <= 1.55e-83) tmp = 0.0 - z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.4e-9], N[(y * x), $MachinePrecision], If[LessEqual[x, 1.55e-83], N[(0.0 - z), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.4 \cdot 10^{-9}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 1.55 \cdot 10^{-83}:\\
\;\;\;\;0 - z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -2.4e-9 or 1.54999999999999996e-83 < x Initial program 98.2%
Taylor expanded in y around inf
+-rgt-identityN/A
accelerator-lowering-fma.f6455.4
Simplified55.4%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6455.4
Applied egg-rr55.4%
if -2.4e-9 < x < 1.54999999999999996e-83Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f6469.5
Simplified69.5%
sub0-negN/A
neg-lowering-neg.f6469.5
Applied egg-rr69.5%
Final simplification60.5%
(FPCore (x y z) :precision binary64 (- 0.0 z))
double code(double x, double y, double z) {
return 0.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 = 0.0d0 - z
end function
public static double code(double x, double y, double z) {
return 0.0 - z;
}
def code(x, y, z): return 0.0 - z
function code(x, y, z) return Float64(0.0 - z) end
function tmp = code(x, y, z) tmp = 0.0 - z; end
code[x_, y_, z_] := N[(0.0 - z), $MachinePrecision]
\begin{array}{l}
\\
0 - z
\end{array}
Initial program 98.8%
Taylor expanded in x around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f6428.0
Simplified28.0%
sub0-negN/A
neg-lowering-neg.f6428.0
Applied egg-rr28.0%
Final simplification28.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 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
neg-sub0N/A
--lowering--.f6428.0
Simplified28.0%
sub0-negN/A
neg-lowering-neg.f6428.0
Applied egg-rr28.0%
neg-sub0N/A
flip3--N/A
metadata-evalN/A
div-subN/A
sqr-powN/A
pow-prod-downN/A
sqr-negN/A
neg-sub0N/A
neg-sub0N/A
pow-prod-downN/A
sqr-powN/A
neg-sub0N/A
cube-negN/A
sub0-negN/A
metadata-evalN/A
flip3--N/A
Applied egg-rr2.7%
herbie shell --seed 2024195
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))